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

Best Time routine/function for benchmark timing tests?

anthonyrichards
New Contributor III
477 Views
I have tried calling CPU_TIME(T) before and after code and got zero difference on frequent occasions. I could expect this if there is more than one cpu and the timer gets time from one of them only. When you have a multi-core CPU, what is the best way to get correct timing information about code execution that may be parallelised to run on more than one cpu using xmm registers?
0 Kudos
4 Replies
TimP
Honored Contributor III
477 Views
cpu_time usually has a resolution of 0.01 seconds, so will be unable to resolve smaller time intervals. When running multiple threads on any current OS, cpu_time attempts to add up the time spent by all threads on the associated process. You don't normally expect to reduce the total cpu time of all threads; usually you are interested in overall elapsed time. Only on Win9x did cpu_time measure elapsed time.
As Windows has equally poor resolution in system_clock, you should consider elapsed time timers such as omp_get_wtime, if using OpenMP or auto-parallel.
Windows performance timers or _rdtsc() may be useful, but require you to make a C wrapper, unless you figure out how to access the Windows timers via USE iso_c_binding. With _rdtsc, in principle, you must assure that you compare times taken only on the same CPU.
0 Kudos
jimdempseyatthecove
Honored Contributor III
477 Views
As TimP suggests, using omp_get_wtime can be used even for code that is not parallel, as well as code that is parallelwithout OpenMP. You just have to link in the appropriate OpenMP library (easiest way is to declare program is OpenMP but not use OpenMP parallelization in your code). Of course, if your program is already using OpenMP, there is nothing to doother than calling the function.

An alternate method is to use the Windows functions QueryPerformanceCounterand QueryPerformanceCounterFrequency. These functions are available to IVF (interfaces can be found in the IVF include folder).

Jim Dempsey
0 Kudos
anthonyrichards
New Contributor III
477 Views
Thanks for the info. I will try the omp routine.
0 Kudos
Robert_van_Amerongen
New Contributor III
477 Views
I have used the Window timer functions several time. Maybe the attached files helps you, incaseyou want to go that way!
Robert
0 Kudos
Reply