Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C OMP omp_get_wtime() returning time 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); 
}
like image 575
kxyz Avatar asked May 27 '13 17:05

kxyz


2 Answers

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]

And the time will show correctly.

like image 196
zhalk Avatar answered Oct 04 '22 22:10

zhalk


Try to print with "% g" that leaves it as scientific notation.

like image 35
rodolf Avatar answered Oct 04 '22 22:10

rodolf