Hi everybody,
I'm a new user on this forum so i excuse with you for all my mistakes.
i have to compile a c source file in OpenMp ambient. when i compile the file, the code blocks' compiler don't recognize the parallel regions. In
fact i should add the -fopenmp option to compiler.
How can i do this?
Thank you very very much.
Bye bye all!!!
build options of your project -> Compiler settings -> Other options :
put there the -fopenmp
Maybe you also need to link with an openmp library, it has been some time since I used OpenMP, but I had it working with CB ;-)
Thank you but I have already do this but it didn't work.
I have also imported the omp.h library.
What can i do?
This is my code:
#include <omp.h>
#include <stdio.h>
#include <stdlib.h>
void main()
{
int x,nt,tid;
int ris;
omp_set_nested(1);
ris=omp_get_nested();
if (ris)
printf("Nested parallelism enabled\n");
omp_set_num_threads(5);
#pragma omp parallel private (nt,tid)
{
tid = omp_get_thread_num();
printf("Ciao sono il thread %d\n",tid);
nt = omp_get_num_threads();
if (omp_get_thread_num()==1)
printf("Il numero di threads e': %d\n",nt);
}
omp_set_num_threads(3);
#pragma omp parallel private (x)
{
x=x+1;
printf("Valore = %d\n",x);
}
}
and this is the response of the compiler:
Prova.c undefined reference to 'omp_set_nested'
Prova.c undefined reference to 'omp_get_nested'
Prova.c undefined reference to 'omp_set_num_threads'
Prova.c undefined reference to 'GOMP_parallel_start'
Prova.c undefined reference to 'GOMP_parallel_end'
Prova.c undefined reference to 'omp_set_num_threads'
Prova.c undefined reference to 'GOMP_parallel_start'
Prova.c undefined reference to 'GOMP_parallel_end'
build finished: 8 errors, 0 warnings
Read this please: http://wiki.codeblocks.org/index.php?title=FAQ#Q:_How_do_I_troubleshoot_an_compiler_problem.3F
Also please use code tags for such long pastes
as said link with the omp library
looked up my CB-OMP projects.
This is what you need to do :
compiler options : -fopenmp
linker options : add the library : libgomp
Snipper from the cbp file :
<Compiler>
<Add option="-Wall" />
<Add option="-fexceptions" />
<Add option="-fopenmp" />
</Compiler>
<Linker>
<Add library="libgomp" />
</Linker>
In the Projects "Build options -> Linker settings -> Link libraries" itshould be enough to add "gomp" (the lib prefix will not be used on commandline, just "-lgomp").