Does OpenMP implementation clean up the threads itself?

General OpenMP discussion

Does OpenMP implementation clean up the threads itself?

Postby openmp_guy » Tue Aug 12, 2008 11:03 am

Hi,

I have a MFC application that spawns win32 worker thread that uses omp threads in it; I am using parallel for inside worker thread. The development platform is visual studio professional 2008. Using window task manager on a 8 processor manchine running xp professional 64bit, I observed that, each time the application entering the worker thread created by object of the CWinthread, there were 7 additional threads created by omp (I assumed) for a total of 8 threads reported by the windows task manager. When the MFC worker thread return, only one thread was deleted; the remaining 7 threads were still in the application process as reported in windows task manager. My question is how to get rid of those threads spawned by omp, or are they harmless? Thanks!

Long
openmp_guy
 
Posts: 7
Joined: Fri Jul 25, 2008 4:55 pm

Re: Does OpenMP implementation clean up the threads itself?

Postby ejd » Wed Aug 13, 2008 5:04 am

OpenMP doesn't have any explicit thread handling mechanism to destroy threads. An implementation is suppose to do all of this as part of the "fork-join" model. A lot of implementations will keep the threads around after a parallel region to decrease the overhead of re-creating the threads for the next parallel region. However, once the program exits, these threads should be destroyed. I do not know the specifics of the Microsoft implementation, but you should be able to see whether or not these threads are burning up cpu time. If they aren't, then I would think that they are harmless. You might want to post this on a Microsoft forum and see what they say.
ejd
 
Posts: 1025
Joined: Wed Jan 16, 2008 7:21 am

Re: Does OpenMP implementation clean up the threads itself?

Postby openmp_guy » Wed Aug 13, 2008 8:18 am

Thanks for the comments.
With windows' task manager, I could see that the orphaned :D threads cumulated radpidly as worker thread entered and left; this worries me. After the worker thread finished, however, it did not seem to incur any memory, cpu or resource penalty. Also, the threads were destroyed when the program exited.
Another interesting observation: The omp threads were destroyed properly If they were used directly inside the worker thread; The problem only occured when the omp threads were created inside an external function which were called by the worker thread.

Long
openmp_guy
 
Posts: 7
Joined: Fri Jul 25, 2008 4:55 pm

Re: Does OpenMP implementation clean up the threads itself?

Postby openmp_guy » Thu Aug 14, 2008 11:39 am

For anyone interested,

I recompiled the application with intel C++ compiler within ms visual studio 2008 professional. The omp threads were released properly after leaving the mfc worker thread. The issue is definitely caused by MS C++ compiler.

After I tried the intel C++ compiler, I went on and found the same issue was discussed in Microsoft forum. Some one suggested using omp_set_dynamic() to control omp thread creation process. I used omp_set_dynamic(1) in my main program's initialization code. And it works! On my 8 processor machine, the main program spawned a worker thread which then spawned 7 more omp threads. When the worker thread existed, these 7 omp were still there; however, when new worker thread was subsequently created, the machine reused the existing 7 omp threads. These 7 omp threads would be distroyed when the main process, or program exit.

Hope this would help someone with the same issue.

Regards,
Long
openmp_guy
 
Posts: 7
Joined: Fri Jul 25, 2008 4:55 pm


Return to Using OpenMP

Who is online

Users browsing this forum: No registered users and 11 guests