[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.c++

CPU time Vs WALL time, Sometimes Walltime lesser than Cputime ?

anto.anish

10/17/2008 8:08:00 PM

Hi -

I have been using clock() for calculating CPU time and time() for
calculating Wall time. However, since time() does not provided milli/
microsecond accurancy, i started using gettimeofday() as below to
calculate walltime,

struct timeval tv1,tv2;
struct timezone tz1, tz2;
gettimeofday(&tv1,&tz1);
double time_start1 = (double) tv1.tv_sec + (double)tv1.tv_usec/
1000000.0;
//ALL ALGO PROCESSING HERE
gettimeofday(&tv2,&tz2);
double time_stop1 = (double) tv2.tv_sec + (double)tv2.tv_usec/
1000000.0;
LOGGER.info("BackgroundEstimationAlgoT Run WALL_TIME: %0.3f",(double)
(time_stop1 - time_start1));

Certain times, i have been noticing that WALLTIME calculated is lesser
than CPUTIME. I am not sure why ? Double checked the simple code,
nothing seems to be wrong in simple substraction. My understanding was
always WALLTIME(elapsed time) remains higher than CPUTIME(compute
time).

I test my application on a Linux cluster with 24 compute nodes.
Any pointers as to why is this happening ?

Thanks
Anish
2 Answers

Victor Bazarov

10/17/2008 8:20:00 PM

0

anto.anish@gmail.com wrote:
> Hi -
>
> I have been using clock() for calculating CPU time and time() for
> calculating Wall time. However, since time() does not provided milli/
> microsecond accurancy, i started using gettimeofday() as below to
> calculate walltime,
>
> struct timeval tv1,tv2;
> struct timezone tz1, tz2;
> gettimeofday(&tv1,&tz1);
> double time_start1 = (double) tv1.tv_sec + (double)tv1.tv_usec/
> 1000000.0;
> //ALL ALGO PROCESSING HERE
> gettimeofday(&tv2,&tz2);
> double time_stop1 = (double) tv2.tv_sec + (double)tv2.tv_usec/
> 1000000.0;
> LOGGER.info("BackgroundEstimationAlgoT Run WALL_TIME: %0.3f",(double)
> (time_stop1 - time_start1));
>
> Certain times, i have been noticing that WALLTIME calculated is lesser
> than CPUTIME. I am not sure why ? Double checked the simple code,
> nothing seems to be wrong in simple substraction. My understanding was
> always WALLTIME(elapsed time) remains higher than CPUTIME(compute
> time).
>
> I test my application on a Linux cluster with 24 compute nodes.
> Any pointers as to why is this happening ?

A few initial points...

Linux-specific questions belong to a Linux newsgroup.

'gettimeofday' is a non-standard function.

If your system has more than one logical CPU or your CPU is capable of
executing more than one instruction at a time, it is generally possible
to get more total CPU seconds than run-time, AIUI.

And the last one: what's your C++ language question?

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask

James Kanze

10/18/2008 6:29:00 AM

0

On Oct 17, 10:07 pm, anto.an...@gmail.com wrote:
> Hi -
>
> I have been using clock() for calculating CPU time and time()
> for calculating Wall time. However,  since time() does not
> provided milli/ microsecond accurancy, i started using
> gettimeofday() as below to calculate walltime,

> struct timeval tv1,tv2;
> struct timezone tz1, tz2;
> gettimeofday(&tv1,&tz1);
> double time_start1 = (double) tv1.tv_sec + (double)tv1.tv_usec/
> 1000000.0;
> //ALL ALGO PROCESSING HERE
> gettimeofday(&tv2,&tz2);
> double time_stop1 = (double) tv2.tv_sec + (double)tv2.tv_usec/
> 1000000.0;
> LOGGER.info("BackgroundEstimationAlgoT Run WALL_TIME: %0.3f",(double)
> (time_stop1 - time_start1));

> Certain times, i have been noticing that WALLTIME calculated
> is lesser than CPUTIME. I am not sure why ? Double checked the
> simple code, nothing seems to be wrong in simple substraction.
> My understanding was always WALLTIME(elapsed time) remains
> higher than CPUTIME(compute time).

You don't seem to be measuring CPU time at all here, so I'm not
sure what you're comparing. Clock() is supposed to return CPU
time, to the systems best approximation: it doesn't always, and
there will be some jitter, so it's quite possible for
differences of clock() to return a value larger than the
differences between to calls to time() (or gettimeofday()). The
differences shouldn't normally be very larger, however.

> I test my application on a Linux cluster with 24 compute
> nodes.

That could also affect things, if you were running multiple
threads. I would expect (but the standard doesn't say anything
about it) that clock() would be the sum of the times spent in
two threads.

--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34