No concurrent threads with openMP

My problem is that I am not parallelizing with openMP.

My system: ubuntu 11.4 Intel (R) Core (TM) i5 CPU M 430 @ 2.27GHz

Compiler: g ++ Version: 4.5.2 with the -fopenmp flag

With this code, I can 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 someone help please?

+5
source share
3 answers

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 successful compilation.

EDIT: If the syntax correction does not work, my next idea is to ask which command is used to compile the code?

+5
source
#pragma omp parallel private(nthreads, tid)   {

, hrandjet

, { .

#pragma omp parallel private(nthreads, tid)   
{

Windows XP.

0

Is the output preceded

Thread 0 getting environment info...

If not, the problem is as above - the open bracket ({) should be on a new line. To verify this, try initializing

int tid = 1

and see if the output is displayed. If not, #pragma is ignored by your compiler (possibly due to a bracket problem).

0
source

All Articles