OpenMP® Forum

Discussion on the OpenMP specification run by the OpenMP ARB. OpenMP and the OpenMP logo are registered trademarks of the OpenMP Architecture Review Board in the United States and other countries. All rights reserved.

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.

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".

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.