OpenMP thread number

Hello,

I add OpenMP directives in my code, do "setenv OMP_NUM_THREADS 4", then run the code. When the code is running, I use "top" utility to look at this running job. One column "THR" in the "top" screen shows "6" for this job. I only set to use at most 4 threads, why are there "6" threads? I then tested different thread numbers, when I set thread number to 1,2,3,4, respectively, the running process actually uses 3,4,5,6 threads respectively. So, even if I want it to run serially by set 1 thread, it still create 3 threads.

If I compile the real serial code which has no OpenMP directives at all, the code would run as a real serial code, "top" indicates only 1 thread is created.

This kind of behavior is not expected, anything wrong with SUN compiler or parallel run time system? I am using Studio8 compiler on 4-processor SUN fire V880 system.

Anybody has similar experience?

Thanks for any input or comments.

Jeff

[973 byte] By [bubblecfd] at [2007-11-14]
# 1

It's likely that you're running on Solaris 8 or older, and not

using the 1-to-1 libthread. (/usr/lib/lwp on Solaris 8)

That threads library creates extra threads for "internal" use,

like catching signals.

The OMP variable controls how many threads the OMP library

creates, not how many will be in the process.

The extra threads don't normally run code except during special

cases like signal processing.

On newer versions of Solaris you can use "prstat -L" to get a top-like

display showing all active LWP's. This would be a good tool to see

how many threads are actually doing work at once in your OpenMP program.

--chris

ChrisQuenelle at 2007-7-5 > top of java,Development Tools,Solaris and Linux Development Tools...
# 2

By default Solaris OS creates a set of deamon threads for multithreaded programs, that is why the user seems more threads. Starting Solaris 10, se should see one thread only.

You can create a helloworld, link it with libthread and you will get 3 threads by default.

- Michael I.

songweili at 2007-7-5 > top of java,Development Tools,Solaris and Linux Development Tools...