C OMP omp_get_wtime() returning time 0.00
39,275
Solution 1
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.
Solution 2
Try to print with "% g" that leaves it as scientific notation.
Author by
kxyz
Updated on July 29, 2020Comments
-
kxyz almost 4 years
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); }
-
pooria over 5 yearsThere isn't any difference between what you wrote and what he said. They are equal.