Mixing OpenMP and pthreads

General OpenMP discussion

Mixing OpenMP and pthreads

Postby mburns99 » Mon Jan 28, 2008 9:45 am

Is it possible to mix OpenMP with pthreads? I'm using OpenMP to spawn and control my threads, but need the condition variables from pthreads (pthread_cond_wait(), pthread_cond_signal()) to get my threads to wait on some condition. I've written it up, but it's crashing (exit ode 060?), so I'm wondering if I should not be mixing things like this. Anyone know? Or, is there a way to mimic the pthread condition variable using stuff in OpenMP 2.5? I'm on Intel Linux using the OpenMP built into GCC 4.2.1.
mburns99
 
Posts: 2
Joined: Mon Jan 28, 2008 9:38 am

Re: Mixing OpenMP and pthreads

Postby lfm » Tue Jan 29, 2008 3:30 pm

OpenMP doesn't have conditions variables.

What you are doing might work if the gcc OpenMP implementation uses pthreads and maps an OpenMP thread to a pthread, which I think it does. I assume you are using pthread mutexes as well, so you have code like:

pthread_mutex_lock(&lock);
pthread_mutex_wait(&cond, &mutex);

and the other thread does:
pthread_cond_signal(&cond).

Again, I think this should work, so maybe something else is wrong. You might want to take a look at the gcc source code, and do some gdb'ing around in the core files.

-- Larry
lfm
 
Posts: 135
Joined: Sun Oct 21, 2007 4:58 pm
Location: OpenMP ARB

Re: Mixing OpenMP and pthreads

Postby mburns99 » Tue Jan 29, 2008 4:00 pm

Yes, that's basically what I'm doing. I now realize that I'm not really crashing - my program finishes without dumping core, but has a nonzero exit status. I get a variety of exit status values - 60, 48, 12, 10, ...

Of course, I was hoping to avoid having to bust open the GCC source... oh, well :)

--Mike
mburns99
 
Posts: 2
Joined: Mon Jan 28, 2008 9:38 am

Re: Mixing OpenMP and pthreads

Postby lfm » Tue Jan 29, 2008 4:36 pm

Are you calling exit or returning out of main? Anyway, try just calling exit(0)? Can you verify that your program is working correctly?
lfm
 
Posts: 135
Joined: Sun Oct 21, 2007 4:58 pm
Location: OpenMP ARB


Return to Using OpenMP

Who is online

Users browsing this forum: Google [Bot] and 1 guest