2

I am wondering why my entire application runs in less than 8 seconds while the time obtained from clock_gettime is 19.3468 seconds which is more than two times as much as what happens in reality. Where is the problem from?

clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &time_start);

... // many calculations

clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &time_stop);
double time_diff=(time_stop.tv_sec-time_start.tv_sec+
    (1e-9)*(time_stop.tv_nsec-time_start.tv_nsec);

Update:

I am not using any OpenMP explicitly.

ar2015
  • 5,558
  • 8
  • 53
  • 110
  • 3
    Related: [Understanding the different clocks of clock_gettime()](http://stackoverflow.com/questions/7506952/understanding-the-different-clocks-of-clock-gettime) – dxiv Dec 25 '15 at 02:58
  • @dxiv but process time is always less than wall time not more. – ar2015 Dec 25 '15 at 02:59
  • 1
    You are asking about CPU time. Think multiple CPUs. – dxiv Dec 25 '15 at 03:00
  • @dxiv do you mean multiple cores? i am not using openMP – ar2015 Dec 25 '15 at 03:02
  • The `// many calculations` block may be executing on multiple threads, and be using multiple CPUs/cores, even without explicitly using openMP. – dxiv Dec 25 '15 at 03:08

1 Answers1

3

CLOCK_MONOTONIC should be used if you want to measure total elapsed time, including time spent blocked waiting for IO, but it will also include slowdowns caused by other processes getting scheduled while your program is trying to run.

KunMing Xie
  • 1,613
  • 17
  • 15