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
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 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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With