-1

I have a program in C with an OpenMP library. I am trying to measure the execution time for a loop to add numbers except that I 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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Son of Man
  • 1,213
  • 2
  • 7
  • 27
  • 1
    is this duplicated with https://stackoverflow.com/questions/19332319/undefined-reference-to-omp-get-wtime – long.kl Feb 11 '22 at 08:56

1 Answers1

1

You should build an OMP program with a flag.

gcc -fopenmp test.c
Zongru Zhan
  • 546
  • 2
  • 8