compilation - -fopenmp flag in compile and link -


i have openmp code

#include <omp.h> #include <stdio.h>  int main() {   #pragma omp parallel   {     fprintf(stderr, "thread %d\n", omp_get_thread_num());   }    return 0; } 

when compile , link , use -fopenmp

gcc-6 -std=c99 -wall -wextra -pedantic -fopenmp -iinclude -c -o build/main.o src/main.c gcc-6 -o bin/main  build/main.o  -fopenmp 

the code work

$ ./bin/main  thread 0 thread 1 thread 2 thread 3 

but don't when put flag in link

gcc-6 -std=c99 -wall -wextra -pedantic -iinclude -c -o build/main.o src/main.c src/main.c: in function 'main': src/main.c:6:0: warning: ignoring #pragma omp parallel [-wunknown-pragmas]    #pragma omp parallel gcc-6 -o bin/main  build/main.o  -fopenmp 

the code work not in parallel

$ ./bin/main  thread 0 

why need add -fopenmp in compile , link time?

why need add -fopenmp in compile , link time?

because required both @ compile time (to enable #pragma omp handling) , @ link time (to link required support libraries).


Comments

Popular posts from this blog

python - How to insert QWidgets in the middle of a Layout? -

python - serve multiple gunicorn django instances under nginx ubuntu -

module - Prestashop displayPaymentReturn hook url -