Author Topic: Linux Code::Blocks and OPENMP  (Read 7903 times)

Offline cybernike

  • Single posting newcomer
  • *
  • Posts: 4
Linux Code::Blocks and OPENMP
« on: May 14, 2008, 01:32:05 am »
I tried to run the following very simple program. It works fine if I compile directly using g++, but C::B fails to compile. The errors are like:

undefined reference to 'GOMP_parallel_start'
undefined reference to 'GOMP_parallel_emd'
....

Any thoughts?

-------------------
#include <omp.h>
#include <stdio.h>
int main (int argc, char *argv[]) {
   int id, nthreads;
   #pragma omp parallel private (id)
   {
      id = omp_get_thread_num ();
      printf (“Hello World from thread %d\n”, id);
      #pragma omp barrier
      if (id == 0) {
         nthreads = omp_get_num_threads ();
         printf (“There are %d threads\n”, nthreads);
      }
   }
   return 0;
}

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7252
Re: Linux Code::Blocks and OPENMP
« Reply #1 on: May 14, 2008, 07:43:31 am »
You have to add "libgomp.so" to the link-libraries.

Right-click your project in the manager,
left-click on "Build options",
highlight your project,
left-click "Linker Settings",
add "gomp" (without the quotes) to the "Link libraries".

Offline cybernike

  • Single posting newcomer
  • *
  • Posts: 4
Re: Linux Code::Blocks and OPENMP
« Reply #2 on: May 14, 2008, 08:06:57 am »
THANKS!!!!

Offline myle

  • Single posting newcomer
  • *
  • Posts: 3
Re: Linux Code::Blocks and OPENMP
« Reply #3 on: May 23, 2008, 04:51:24 pm »
Code
#include <stdio.h>
#include <omp.h>
int main(int argc, char **argv)
{
    int id;
#pragma omp parallel private(id)
      {
          id = omp_get_thread_num();
          printf("Hello World from %d\n", id);
      }
   fprintf(stderr, "Program terminated\n");
   return 0;
}

prints 2 times the Hello World message when I run it through Code::Blocks in contrast to the only one time that the message is printed when I run it through console. Why is that so?