Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenMP and STL-style for

I'm trying to parallelize my program with openMP. The program is using STL-iterators heavily. It is said that openMP 3.0 can deal with this:

std::vector<int> N(2*N_max+1);

std::vector<int>::const_iterator n,m;
#pragma omp parallel for
for (n=N.begin(); n!=N.end(); ++n){
     //Task to be in parallel
};

But I got the following error:

error: invalid controlling predicate

I'm using gcc 4.5.0, (openMP3 implemented in 4.4.0) and my build string is:

g++  -O0 -g3 -Wall -c -fmessage-length=0 -fopenmp -MMD -MP  
like image 704
galadog Avatar asked Jan 25 '11 17:01

galadog


People also ask

What is OpenMP and what is it used for?

OpenMP is typically used for loop-level parallelism, but it also supports function-level parallelism. This mechanism is called OpenMP sections. The structure of sections is straightforward and can be useful in many instances. Consider one of the most important algorithms in computer science, the quicksort.

Why use OpenMP?

Why OpenMP? More efficient, and lower-level parallel code is possible, however OpenMP hides the low-level details and allows the programmer to describe the parallel code with high-level constructs, which is as simple as it can get. OpenMP has directives that allow the programmer to: specify the parallel region.

Is OpenMP multiprocessing or multithreading?

OpenMP is an implementation of multithreading, a method of parallelizing whereby a primary thread (a series of instructions executed consecutively) forks a specified number of sub-threads and the system divides a task among them.

How does OpenMP work?

OpenMP introduces parallelism into your application by launching a set of threads that execute portions of your code concurrently. There are mechanisms, described below, that determine how many threads are launched and what portion of your code and what portion of your data each thread will use.


2 Answers

Standard OpenMP doesn't bear with C++ iterators in general. The standard requires iterators to be random access iterators with constant time for random access. It also only permits < and <= or > and >= in test expressions of for loops, but not !=.

If you are using iterators and STL heavily, you might be better off with Thread building blocks.

like image 150
lunaryorn Avatar answered Oct 18 '22 09:10

lunaryorn


Unfortunately the OpenMP V3.0 spec didn't include "!=" as part of the legal syntax for a canonical for loop. However, if you have access to a recent Intel compiler they allowed it as an extension.

like image 32
ejd Avatar answered Oct 18 '22 08:10

ejd