User forums > Using Code::Blocks
Linux Code::Blocks and OPENMP
(1/1)
cybernike:
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;
}
Jenna:
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".
cybernike:
THANKS!!!!
myle:
--- 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;
}
--- End code ---
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?
Navigation
[0] Message Index
Go to full version