Help: max num thread is always 1

General OpenMP discussion

Help: max num thread is always 1

Postby vortex » Tue Aug 27, 2013 9:34 am

I am new to OpenMP programing. I am trying to add a piece of C++ code using openmp to an old program which uses c++, c and Fortran. When I linked the openmp code to others, omp_get_max_threads() always returned 1. I have explicitly set omp_set_dynamic(0) and omp_set_num_threads(4) but still get max thread=1 and receive 4 same thread number from the parallel region. For example, I linked an openmp hello world to the old codes. When the "hello world" is called from the main program, there are 4 "hello world" messages from thread 1 instead of from thread 0,1,2,3 and 4. However, the openmp hello world code worked correctly on the same machine when it was separated from other codes.

The original makefile doesn't use openmp. I just simply added flag openmp to the corresponding CXX compiler and linker as follows:

CXX = icpc -pthread --> CXX= icpc -pthread -openmp

LINK_EXE =$CXX -thread -o --> LINK_EXE =$CXX -thread -openmp -o

I am wondering whether there is anything wrong in my makefile. Did anyone encounter a similar problem?

Thanks you!
Posts: 1
Joined: Mon Aug 26, 2013 4:09 pm

Re: Help: max num thread is always 1

Postby MarkB » Tue Aug 27, 2013 12:20 pm

Are you calling omp_get_max_threads() from inside the parallel region? If so, this will return 1 if nested parallelism is disabled, since the value is the maximum number of threads which would be used if the calling thread encountered a parallel region at that point.

Are you storing the result of omp_get_thread_num() in a variable before printing it? If so, you need to make sure the variable is private. If it is shared, then you may simply end up printing the value from the last thread which assigned a value to it.

Hope that helps,
Posts: 611
Joined: Thu Jan 08, 2009 10:12 am
Location: EPCC, University of Edinburgh

Return to Using OpenMP

Who is online

Users browsing this forum: No registered users and 4 guests