Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

no parallel threads with openMP

Tags:

c++

openmp

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?

like image 896
Sankp Avatar asked Aug 01 '11 14:08

Sankp


1 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 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?

like image 86
NGaffney Avatar answered Sep 29 '22 05:09

NGaffney