Author Topic: Compile OpenMp File  (Read 12885 times)

Offline dm83

  • Single posting newcomer
  • *
  • Posts: 3
Compile OpenMp File
« on: December 03, 2010, 11:30:37 am »
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!!!

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5490
Re: Compile OpenMp File
« Reply #1 on: December 03, 2010, 12:41:12 pm »
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 ;-)

Offline dm83

  • Single posting newcomer
  • *
  • Posts: 3
Re: Compile OpenMp File
« Reply #2 on: December 03, 2010, 01:45:04 pm »
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?


Offline dm83

  • Single posting newcomer
  • *
  • Posts: 3
Re: Compile OpenMp File
« Reply #3 on: December 03, 2010, 02:10:55 pm »
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

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Compile OpenMp File
« Reply #4 on: December 03, 2010, 02:16:51 pm »
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
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5490
Re: Compile OpenMp File
« Reply #5 on: December 03, 2010, 02:35:56 pm »
as said link with the omp library

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5490
Re: Compile OpenMp File
« Reply #6 on: December 05, 2010, 09:41:37 am »
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 :
Code
		<Compiler>
<Add option="-Wall" />
<Add option="-fexceptions" />
<Add option="-fopenmp" />
</Compiler>
<Linker>
<Add library="libgomp" />
</Linker>

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7255
Re: Compile OpenMp File
« Reply #7 on: December 05, 2010, 10:25:03 am »
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").