I have this 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 I compile and link and use the -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 I only put the flag in the 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 but not in parallel
$ ./bin/main
thread 0
why I need add -fopenmp
in compile and link time?
why I need add -fopenmp in compile and link time?
Because it is required both at compile time (to enable the #pragma omp
handling) and at link time (to link required support libraries).
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments