Does OpenMP play nice with C++ promises and futures?

General OpenMP discussion

Does OpenMP play nice with C++ promises and futures?

Postby Nontagonist » Tue May 01, 2012 1:59 pm

Hi folks

I've been considering writing some of my first multiprocessing code and I'm
lookiing at using OpenMP. Having browsed some parts of the spec it seems
that OpenMP doesn't have much to say about communicating between running
threads, although it does have facilities for handing data to a new thread and
getting data out of a thread that has completed its run.

My application has a highly parallelisable subproblem which requires some
communication between the threads and a master while running each instance
of the subproblem. Perhaps more importantly, this subproblem may need to be
solved many many times during an execution of the program. It seems wasteful
to have to set up and tear down the many threads needed for the subproblem.
I'd rather set them up once and then hand them a batch of work to complete,
then leave them waiting on a mutex or something until there's another batch of
work to do.

C++11 has things called promises and futures which are intended to be used mainly
for inter-thread communications. Promises and futures may be suitable for getting
data between threads in my application.

Does anybody know whether C++11 promises and futures play nice with OpenMP?

FWIW, I'd most likely be using GCC 4.7, so OpenMP 3.1 features would be available.


Regards, Nontagonist.
Nontagonist
 
Posts: 3
Joined: Tue May 01, 2012 1:18 pm

Re: Does OpenMP play nice with C++ promises and futures?

Postby MarkB » Wed May 02, 2012 6:17 am

I would not recommend trying to mix OpenMP with C++11 threading features. There is nothing to specify how the two APIs are supposed to interact,
and even if it did "work" with GCC, you would most likely have non-portable code. You should be able design a C++11 program to create threads once and keep them alive.
MarkB
 
Posts: 432
Joined: Thu Jan 08, 2009 10:12 am

Re: Does OpenMP play nice with C++ promises and futures?

Postby Nontagonist » Wed May 02, 2012 3:27 pm

Thanks for the reply.

I've just found out that GCC implements almost none of C++11's concurrency
features, so I'll either be using another compiler or finding another way to do it.

Perhaps I'll have a look at Boost and see what it can do for me.


Regards, Nontagonist.
Nontagonist
 
Posts: 3
Joined: Tue May 01, 2012 1:18 pm

Re: Does OpenMP play nice with C++ promises and futures?

Postby ftinetti » Wed May 02, 2012 3:38 pm

Hi,

I'm curious, would you describe what you need to do? perhaps at a pseudo code level...?

Thanks in advance,

Fernando.
ftinetti
 
Posts: 580
Joined: Wed Feb 10, 2010 2:44 pm

Re: Does OpenMP play nice with C++ promises and futures?

Postby Nontagonist » Wed May 02, 2012 6:48 pm

Fernando wrote:

> I'm curious, would you describe what you need to do? perhaps at a pseudo code level...?

I don't want to go into detail, but here's an outline:

1 Do some inherently sequential processing to decompose the problem into a (possibly large)
number of (possibly large) data structures which must later be manipulated in synchrony.

2 Solve a (large) number of subproblems on variants of the aforementioned data structures,
In each of a number of threads:
a) while communicating with a master thread regarding modifications to the data structure,
b) while modifying a copy of the data structure in response to those instructions,
c) while detecting specific changes in the data structure and reporting them to the master,
d) when the master indicates that there are no more modifications necessary, return a copy
of the final version of the data structure to be stored for later use,
e) wait for another unit of work or for an instruction to terminate the thread.

3 Examine the final products to find solutions to the original problem.

Sorry to be so vague, but I don't really want to get into the specifics of the problem at hand
at this point and in this forum I'm only interested in discussing the concurrency-related aspects.

BTW, I've recently noticed that the GCC online docs mention that C++11 futures are partially
implemented in at least the latest svn repository.

Regards, Graham.
Nontagonist
 
Posts: 3
Joined: Tue May 01, 2012 1:18 pm

Re: Does OpenMP play nice with C++ promises and futures?

Postby rafi » Mon May 21, 2012 11:59 pm

I think the c++ is better for OpenMP
rafi
 
Posts: 1
Joined: Sun May 20, 2012 11:51 pm


Return to Using OpenMP

Who is online

Users browsing this forum: Google [Bot], Yahoo [Bot] and 8 guests