This is my c++ code.
double start_time = time(NULL);
double start_clock = clock();
#pragma omp parallel for private(i)
for(i=0;i<max_i;i++)
PROCESS(i);
double end_time = time(NULL);
double end_clock = clock();
printf("%lf second(s)\n", end_time-start_time);
printf("%lf second(s)\n", (end_clock-start_clock)/CLOCKS_PER_SEC);
and this is the output.
took 2.000000 second(s)
took 11.410000 second(s)
Does anyone know why these are not consistent? Is there any other way of measuring this? BTW, 2 seconds seems more reasonable based on the time I’m seeing here.
The
clock()function returns the amount of CPU time used by your process since it started, not the absolute time according to a real-time clock.In another comment you said that
CODE_BLOCKis a parallel loop – which means in your case, it used the equivalent of 11.41 seconds of CPU time in 2 seconds of real (“wall clock”) time. Evidently you’re using the power of about 6 CPUs in parallel.