I wanna run Thimoty's Rolfe implementation of mergesort in MPI, but to get it working I need to compile this wallClock.c file that he provides.
#include <time.h>
double wallClock(void)
{
struct timeval tv;
double current;
gettimeofday(&tv, NULL); // Omit the timezone struct
current = tv.tv_sec + 1.0e-06 * tv.tv_usec;
return current;
}
When compiling I get the following error:
wallClock.c:12: error: storage size of ‘tv’ isn’t known
How can I fix this?
btw, I changed his #include <sys/time.h>
to #include <time.h>
it generated the following errors
wallClock.c:15: error: ‘NULL’ undeclared (first use in this function)
wallClock.c:15: error: (Each undeclared identifier is reported only once
wallClock.c:15: error: for each function it appears in.)
I tried including stdlib.h (to fix the NULL undeclared one) and got even more obscure errors.
btw, I changed his
#include <sys/time.h>
to#include <time.h>
Wrong move. The standard says:
The
<sys/time.h>
header shall define thetimeval
structure, which shall include at least the following members:time_t tv_sec Seconds. suseconds_t tv_usec Microsecods.
I took the time and compiled your code, after changing time.h
to sys/time.h
and adding stdlib.h
. I got no errors. I'm using gcc version 4.6.2 20111125 on a fairly recent Linux distro.
Ideally, you should be using the modern POSIX clock_gettime
(with struct timespec
) instead of the now-deprecated (since 2008) gettimeofday
. clock_gettime
/ timespec
is also defined in <time.h>
, so you already have everything almost right.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With