I know this has been asked before but if you look at the causes of the issues that prompted previous users to ask the same question , they were different and this this issue could have multiple causes , that is why am asking again.
I have a program in c with omp, I am trying to measure the execution time for a loop to add numbers except that am getting an error that the reference the function omp_get_wtime()
is undefined while I have the library file included in the header section of my code file...
Why am i getting this error and how can I resolve it?
#include <omp.h>
#include <stdlib.h>
#include <string.h>
int main(){
//number of threads to use
int no_threads=3;
//mark the execution go mark
double start=omp_get_wtime();
//parallelize the loop
#pragma omp parallel num_threads(no_threads)
for(int i=0;i<1000;i ){
printf("%d",i);
}
double end_time=omp_get_wtime();
printf("%f",end_time-start);
}
I tried to compile even before I started using the #pragma directive and got the error that the omp function is undefined and the function in the file. Please help me resolve this.
CodePudding user response:
You should build an OMP program with a flag.
gcc -fopenmp test.c