execute of OpenMP program

General OpenMP discussion

execute of OpenMP program

Postby marx » Thu May 01, 2008 8:16 am

Hello!

When I execute my parallel program with OpenMP by this line:

Code: Select all
$ ./my_program


I discover that this program was executed by two threads. I thought that when I run the program without "OMP_NUM_THREADS" it will be executed with only one thread :? . The computer is a 2 processors machine, and maybe this is the answer, why there was 2 threads involved in execution of program ? Could somebody tell me how is calculated the default number of threads in this case? And why there is two threads not one.

Thanks for your help
With greetz
MarX

p.s. I compile the program on GCC with the -fopenmp flag
marx
 
Posts: 6
Joined: Sun Jan 06, 2008 4:41 am
Location: Wlodawa - Poland

Re: execute of OpenMP program

Postby ejd » Thu May 01, 2008 9:13 am

If you look at the OpenMP spec, you will find that the number of threads created when you encounter a parallel region is controlled by an ICV (Internal Control Variable), that for purposes of documentation is named "nthreads-var". This ICV has an initial value which is "implementation defined". By the OpenMP spec anything "implementation defined" must be documented by the implementation. That means that somewhere in the gcc documentation it must say what the initial value is. If you look at "The GNU OpenMP Implementation" manual, you will find that it is located under section 3.3 OMP_NUM_THREADS, where it states "if undefined one thread per CPU online is used".
ejd
 
Posts: 1025
Joined: Wed Jan 16, 2008 7:21 am

Re: execute of OpenMP program

Postby marx » Thu May 01, 2008 9:37 am

Thank you for your post. I have found answer also on https://docs.loni.org/wiki/Using_OpenMP, where was written:
The default number of threads that a program uses when it runs is the number of online processors on the machine.
So everything is clear now :mrgreen:

Thanks
Have a nice day
MarX
marx
 
Posts: 6
Joined: Sun Jan 06, 2008 4:41 am
Location: Wlodawa - Poland

Re: execute of OpenMP program

Postby ejd » Thu May 01, 2008 9:56 am

The answer you found on the web site you indicated is the answer for IBM's implementation on AIX. Your question was for gcc. The answer happens to be the same for these two - at this time. Please note, that the answer could vary between releases and can definitely vary between vendors.
ejd
 
Posts: 1025
Joined: Wed Jan 16, 2008 7:21 am


Return to Using OpenMP

Who is online

Users browsing this forum: Yahoo [Bot] and 6 guests