OpenMP的时间和时钟()计算两个不同的结果 [英] OpenMP time and clock() calculates two different results

查看:403
本文介绍了OpenMP的时间和时钟()计算两个不同的结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有顺序code通过的OpenMP并行。我已经把相应的编译指示并进行测试。同时,通过检查主要功能所花费的时间测试我间preT的性能增益。奇怪的是通过计算所经过的时间CPU_TIME() omp_get_wtime()返回两个不同的结果。你觉得原因是什么?

CPU_TIME()通过计算的运行时间功能类似于连续的时间。

运算开始前

  ctime1_ = CPU_TIME();
#IFDEF _OPENMP
ctime1 = omp_get_wtime();
#万一

计算结束后

  ctime2_ = CPU_TIME();
#IFDEF _OPENMP
ctime2 = omp_get_wtime();
#万一

CPU_TIME()函数定义

 双CPU_TIME(无效)
{
  双重价值;
  值=(双)时钟()/(双)CLOCKS_PER_SEC;
  返回值;
}

印刷效果

 的printf( - ,ctime2  -  ctime1,ctime2_  -  ctime1_%F%F秒\\ n);

样的结果。

  7.009537  - 11.575277秒。


解决方案

时钟功能测量CPU时间,你积极地花费在CPU上的时候,OMP功能措施的时间,因为它在执行过程中已经过去了,两个完全不同的东西。

您进程似乎在等待什么地方被阻塞。

I have sequential code to parallelize via OpenMP. I have put corresponding pragmas and test it. While testing I interpret performance gain by checking time spent in main function. The weird thing is the elapsed time calculated via cpu_time() and omp_get_wtime() returns two different results. What do you think the reason is?

The elapsed time calculated via cpu_time() function is similar to sequential time.

Before computation starts

ctime1_ = cpu_time();
#ifdef _OPENMP
ctime1 = omp_get_wtime();
#endif

After computation ends

ctime2_ = cpu_time();
#ifdef _OPENMP
ctime2 = omp_get_wtime();
#endif

cpu_time() function definition

double cpu_time(void)
{
  double value;
  value = (double) clock () / (double) CLOCKS_PER_SEC;
  return value;
}

Printing result

printf("%f - %f seconds.\n", ctime2 - ctime1, ctime2_ - ctime1_);

Sample result

7.009537 - 11.575277 seconds.

解决方案

The clock function measures cpu time, the time you spend actively on the CPU, the OMP function measures the time as it has passed during execution, two completely different things.

Your process seems to be blocked in waiting somewhere.

这篇关于OpenMP的时间和时钟()计算两个不同的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆