2017-01-16 158 views
2

我想测量每个线程花费大量代码的时间。我想看看我的负载平衡策略是否同等地将工人组块分割开来。 通常情况下,我的代码如下所示:如何测量openmp中每个线程的执行时间?

#pragma omp parallel for schedule(dynamic,chunk) private(i) 
for(i=0;i<n;i++){ 
//loop code here 
} 

UPDATE 我使用OpenMP 3.1用gcc

+0

什么是你的编译器(gcc/linux下,ICC,窗户,MacOS的)和OpenMP实现?有一些openmp分析器/跟踪解决方案...你是否想在每个“for”循环中测量线程时间,或者只需要关于线程的聚合信息? (为什么不在这里添加timer_start和timer_stop以及线程本地存储?) – osgx

+0

这更多的是测量每个线程完成每个迭代块的时间。循环编码看起来很有趣,你能发展吗? – Marouen

+1

您应该使用明确支持OpenMP的性能分析工具,如Score-P/Vampir,Allinea MAP,HPCToolkit。 – Zulan

回答

2

您可以只打印每个线程的时间这样(没有测试过,甚至没有编译):

#pragma omp parallel 
{ 
    double wtime = omp_get_wtime(); 
    #pragma omp for schedule(dynamic, 1) nowait 
    for (int i=0; i<n; i++) { 
     // whatever 
    } 
    wtime = omp_get_wtime() - wtime; 
    printf("Time taken by thread %d is %f\n", omp_get_thread_num(), wtime); 
} 

NB的nowait比删除barrierfor循环结束,否则这不会有任何兴趣。

病程的同时,使用适当的分析工具是一种更好的方法......

+0

工作得很好,只需在wtime中纠正小写字母t即可。谢谢。 – Marouen