Reputation: 51
My problem is that I get no parallelization with openMP.
My system: ubuntu 11.4 Intel(R) Core(TM) i5 CPU M 430 @ 2.27GHz
Compiler: g++ Version: 4.5.2 with flag -fopenmp
With this code I see that there is only one thread:
int nthreads, tid, procs, maxt, inpar, dynamic, nested;
// Start parallel region
#pragma omp parallel private(nthreads, tid) {
// Obtain thread number
tid = omp_get_thread_num();
// Only master thread does this
if (tid == 0)
{
printf("Thread %d getting environment info...\n", tid);
// Get environment information
procs = omp_get_num_procs();
nthreads = omp_get_num_threads();
maxt = omp_get_max_threads();
inpar = omp_in_parallel();
dynamic = omp_get_dynamic();
nested = omp_get_nested();
// Print environment information
printf("Number of processors = %d\n", procs);
printf("Number of threads = %d\n", nthreads);
printf("Max threads = %d\n", maxt);
printf("In parallel? = %d\n", inpar);
printf("Dynamic threads enabled? = %d\n", dynamic);
printf("Nested parallelism supported? = %d\n", nested);
}
}
because I see the following output:
Number of processors = 4
Number of threads = 1
Max threads = 4
In parallel? = 0
Dynamic threads enabled? = 0
Nested parallelism supported? = 0
What is the problem?
Can some one help, please?
Upvotes: 5
Views: 4438
Reputation: 1532
Your code works for me on Ubuntu 11.04 with the g++ compiler version 4.5.2 however I had to change
#pragma omp parallel private(nthreads, tid) {
to
#pragma omp parallel private(nthreads, tid)
{
for it to compile successfully.
EDIT: If fixing the syntax doesn't work my next idea would be to ask what is the exact command that you are using to compile code?
Upvotes: 5
Reputation: 983
Is the output prefaced by
Thread 0 getting environment info...
If not, the problem is as stated above - the open bracket ( { ) must be on a new line. To prove this further, try initializing
int tid = 1
and see if the output still shows up. If not, the #pragma is being ignored by your compiler (probably because of the bracket issue).
Upvotes: 0
Reputation: 247
#pragma omp parallel private(nthreads, tid) {
is incorrect syntax, as noted by hrandjet
The pragma must end with a new line, so the { should be on the next line.
#pragma omp parallel private(nthreads, tid)
{
This works for me on Windows XP.
Upvotes: 0