Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Ahmadi__Afshin
Beginner
153 Views

CPU Execution Time

Jump to solution

I am using mkl_get_cpu_clocks() function to measure the CPU execution time of LAPACKE_dgesv. My code is like:

unsigned MKL_INT64 t1,t2;
mkl_get_cpu_clocks(&t1);
run LAPACKE_dgesv()
mkl_get_cpu_clocks(&t2);
printf("Elapsed MKL: %lf  \n", (double)(t2-t1)/1000000000);

However, the returned elapsed time is not even close to the execution time. The actual execution time is about 27 seconds while the returned time is about 64 seconds!

I checked the Intel MKL manual and unfortunately there is not enough discussion about mkl_get_cpu_clocks. Can you please help? Thank you.

Intel MKL version: 18 update 3

OS: Linux

-Afshin

0 Kudos
1 Solution
Khang_N_Intel
Employee
153 Views

Hi Afshin,

The function mkl_get_cpu_frequency() will provide the cpu frequency at that instant.  The cpu frequency is not fixed.  It will vary depending on the current state of your machine.  There are many factors that can affect the cpu frequency.  That is the reason why your code returns different value every time you run.

According to the Intel(R) MKL manual, the dsecnd() function returns the cpu time. It gets the time from the elapsed cpu clocks divided by frequency. Obtaining the frequency may take some time when the second/dsecnd function runs for the first time. To eliminate the effect of this extra time on your measurements, make the first call to dsecnd in advance.

Hope this helps,

 

Best Regards,

Khang

View solution in original post

7 Replies
Khang_N_Intel
Employee
153 Views

Hi Afshin,

If you want to get the CPU execution time, you can use the mkl function "dsecnd" to measure the elapsed time in seconds.

mkl_get_cpu_clocks will return the elapsed time in CPU clocks, not in seconds.  If you want the result in seconds then you need to divide the result by the CPU frequency which can be obtained by calling the mkl function mkl_get_cpu_frequency.

I would suggest replacing the number 1000.... in your printing statement with this function call: mkl_get_cpu_frequency().

Which function did you use to get the result of 27 seconds?

The results I got from using the functions dsecnd and mkl_get_clocks are very close to each other.

Best Regards,

Khang

 

Ahmadi__Afshin
Beginner
153 Views

Nguyen, Khang T (Intel) (Intel) wrote:

Hi Afshin,

If you want to get the CPU execution time, you can use the mkl function "dsecnd" to measure the elapsed time in seconds.

mkl_get_cpu_clocks will return the elapsed time in CPU clocks, not in seconds.  If you want the result in seconds then you need to divide the result by the CPU frequency which can be obtained by calling the mkl function mkl_get_cpu_frequency.

I would suggest replacing the number 1000.... in your printing statement with this function call: mkl_get_cpu_frequency().

Which function did you use to get the result of 27 seconds?

The results I got from using the functions dsecnd and mkl_get_clocks are very close to each other.

Best Regards,

Khang

 

Hi Khang,

Thank you for your reply. I replace the 1000.. in my code with (mkl_get_cpu_frequency()*1e9), but is the mkl_get_cpu_frequency function accurate enough? Because every time I run my program it returns a different value (2.7GHz, 3.1GHz, etc) which directly affects the execution time measurement. I also tried mkl_get_clocks_frequency() which gave me better results but sometimes it is slightly higher than what dsecnd returned.

Does dsecnd return the CPU time or wall time?

 

 

Khang_N_Intel
Employee
154 Views

Hi Afshin,

The function mkl_get_cpu_frequency() will provide the cpu frequency at that instant.  The cpu frequency is not fixed.  It will vary depending on the current state of your machine.  There are many factors that can affect the cpu frequency.  That is the reason why your code returns different value every time you run.

According to the Intel(R) MKL manual, the dsecnd() function returns the cpu time. It gets the time from the elapsed cpu clocks divided by frequency. Obtaining the frequency may take some time when the second/dsecnd function runs for the first time. To eliminate the effect of this extra time on your measurements, make the first call to dsecnd in advance.

Hope this helps,

 

Best Regards,

Khang

View solution in original post

Khang_N_Intel
Employee
153 Views

Hi Afshin,

I guess you might already knew about this. Just in case, you are not aware of:

1) To ensure consistency, make sure to get rid or stop all other non-necessary programs when you run your code.

2) Keep the same system configuration every time you run your code.

3) Do not run your code immediately one after another.  Depending on the situation, you might let the system running for 5 or 15 minutes before running the code again.

Doing the above steps, although no guarantee,  would minimize the chance the cpu frequency would vary and to ensure the system stabilization between each run.

Best Regards,

Khang

Khang_N_Intel
Employee
153 Views

Oooops!, correction on item #3, let the system running idle for 5 or 15 minutes before running the code again.

I apologize for the error.

 

Khang

Ahmadi__Afshin
Beginner
153 Views

Thank you very much, Khan. Your points are really helpful.

Khang_N_Intel
Employee
153 Views

Hi Afshin,

You are very welcome!

Let me know if you have any other questions about Intel(R) MKL.

Best Regards,
Khang

Reply