【发布时间】:2012-05-27 06:34:01
【问题描述】:
我有通过 OpenMP 并行化的顺序代码。我已经输入了相应的编译指示并对其进行了测试。我通过检查在 main 函数中花费的时间来衡量性能增益。
奇怪的是通过cpu_time() 和omp_get_wtime() 计算的经过时间是不同的。为什么?
根据cpu_time()的经过时间与顺序时间相似。
计算开始前:
ctime1_ = cpu_time();
#ifdef _OPENMP
ctime1 = omp_get_wtime();
#endif
计算结束后:
ctime2_ = cpu_time();
#ifdef _OPENMP
ctime2 = omp_get_wtime();
#endif
cpu_time() 函数定义:
double cpu_time(void)
{
double value;
value = (double) clock () / (double) CLOCKS_PER_SEC;
return value;
}
打印结果:
printf("%f - %f seconds.\n", ctime2 - ctime1, ctime2_ - ctime1_);
示例结果:
7.009537 - 11.575277 seconds.
【问题讨论】: