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);
}
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.
Try to print with "% g" that leaves it as scientific notation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With