C OMP omp_get_wtime()返回时间0.00 [英] C OMP omp_get_wtime() returning time 0.00

查看:201
本文介绍了C OMP omp_get_wtime()返回时间0.00的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用过omp_get_wtime(),但是当我想打印时间时,我总是得到0.00,这是哪里出了问题?

I have used a omp_get_wtime() but when i want to print the time i always get 0.00, where is the problem ?

#define SIZE 500
#define nthreads 10

(...)

void sumTab(int mX[][SIZE], int mY[][SIZE], int mZ[][SIZE]) {
int i,k;
double start = omp_get_wtime();
#pragma omp parallel for schedule(dynamic,3) private(i) num_threads(nthreads)
for(i=0 ; i<SIZE ; i++)
{

   for(k=0 ; k<SIZE ; k++)  
   {

     mZ[i][k]=mX[i][k]+mY[i][k];
     printf("Thread no %d \t  [%d] [%d] result: %d\n", omp_get_thread_num(),i,k, mZ[i][k]); 
     }
}

printf("Time: \t %f \n", omp_get_wtime()-start); 
}

推荐答案

确保在文件的标题中包含omp.h库.

Make sure you include the omp.h library in the header of the file.

#include <omp.h>

double start_time = omp_get_wtime();
#pragma omp parallel [...]
// code
double time = omp_get_wtime() - start_time;

此库将在编译时删除此警告:

This library will remove this warning in compilation:

warning: implicit declaration of function ‘omp_get_wtime’ [-Wimplicit-function-declaration]

时间会正确显示.

这篇关于C OMP omp_get_wtime()返回时间0.00的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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