Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29273 Discussions

calculate the time of running a code

yingwu
Beginner
733 Views

Hi,

I usually use call CPU_TIME() to calculate the time of running a code so that I can compare the performances of my codes. Unfortunately, since now I start to use openmp in my code, I find the time returned by CPU_TIME() is the total time the 4 cores have used, instead of the total time the code runs. So is there any way to give me the actual time? It seems SYSTEM_CLOCK() or DATE_AND_TIME() work, but I do not know how.

0 Kudos
1 Solution
TimP
Honored Contributor III
733 Views

cpu_time() tries to give you the total CPU time of all threads. Sometimes, people ask for the average level of parallelism, which you get by dividing this by the elapsed time.

With system_clock(), you should use integer*8 in order to get adequate resolution and range.

The portable way is with omp_get_wtime() (but it will work only with the OpenMP compile switches). Typically, on linux systems, it's a wrapper for gettimeofday(), so there is no point in trying the latter, except as a way to make it work without OpenMP.

date_and_time() is fine if you simply want to display it. It's difficult to calculate intervals accurately.

View solution in original post

0 Kudos
3 Replies
TimP
Honored Contributor III
734 Views

cpu_time() tries to give you the total CPU time of all threads. Sometimes, people ask for the average level of parallelism, which you get by dividing this by the elapsed time.

With system_clock(), you should use integer*8 in order to get adequate resolution and range.

The portable way is with omp_get_wtime() (but it will work only with the OpenMP compile switches). Typically, on linux systems, it's a wrapper for gettimeofday(), so there is no point in trying the latter, except as a way to make it work without OpenMP.

date_and_time() is fine if you simply want to display it. It's difficult to calculate intervals accurately.

0 Kudos
yingwu
Beginner
732 Views

Hi Tim,

0 Kudos
roddur
Beginner
733 Views
As another way, without affecting your main code, tou can try time ./a.out in unix system
0 Kudos
Reply