loop parallization with decrement

General OpenMP discussion

loop parallization with decrement

Postby flashpixx » Tue Nov 15, 2011 10:51 am

Hello,

I'm new to OpenMP. I have worked with MPI for some times only, so I have a little problem with this loop:

Code: Select all
        #pragma omp parallel for shared(n, l_wavefront)
        for(std::size_t i=p_size-1; i > 0; --i)


n and l_wavefront are two variables that must shared on each thread, but the the compiler returns this
error: "invalid controlling predicate"

Other loop with for(std::size_t i=0; i < <value>; ++i) works fine. How I can parallize my "decrement loop" in a correct way?

Thanks a lot
flashpixx
 
Posts: 6
Joined: Tue Nov 15, 2011 10:18 am

Re: loop parallization with decrement

Postby ftinetti » Tue Nov 15, 2011 12:31 pm

Hi,

I'll take a look at the spec, since there are specific conditions for parallelizing for loops. In the meantime, please send:
1) Compiler and compiler options you are using
2) The loop body, if it is too long, please send specifically those lines in which p_size and i are used

Just curious: computer: CPUs/cores, RAM, OS?
ftinetti
 
Posts: 582
Joined: Wed Feb 10, 2010 2:44 pm

Re: loop parallization with decrement

Postby flashpixx » Tue Nov 15, 2011 12:43 pm

Compiler is G++ 4.2.1 under OSX, G++ 4.5.3 under x64 Gentoo Linux and g++ under Cygwin (I don't know the version yet, but it's a default install)

the full loop shows:

Code: Select all
        for(std::size_t i=p_size-1; i > 0; --i)
            for(std::size_t j=0; (i+j) < p_size; ++j)
               
                l_wavefront.insert(  std::pair<std::size_t, std::pair<std::size_t,std::size_t> >(n++ % p_threads, std::pair<std::size_t,std::size_t>(j, i+j))  );


l_wavefront is a std::multimap, so I would like to parallize the outer loop (and add a critical section around the insert), n is a shared std::size_t variable

Thanks
flashpixx
 
Posts: 6
Joined: Tue Nov 15, 2011 10:18 am

Re: loop parallization with decrement

Postby ftinetti » Tue Nov 15, 2011 1:41 pm

Hmmm... I don't see anything strange according to the Spec. 3.0, section 2.5.1 (you may take a look at the Spec too). The inner loop would have problems, (from the Spec):
for (init-expr; test-expr; incr-expr) structured-block

init-expr One of the following:
var = lb
integer-type var = lb
random-access-iterator-type var = lb
pointer-type var = lb

test-expr One of the following:
var relational-op b
b relational-op var

incr-expr One of the following:
++var
var++
--var
var--
var += incr
var -= incr
var = var + incr
var = incr + var
var = var - incr

var One of the following:
A variable of a signed or unsigned integer type.
For C++, a variable of a random access iterator type.
For C, a variable of a pointer type.
If this variable would otherwise be shared, it is implicitly made
private in the loop construct. This variable must not be
modified during the execution of the for-loop other than in increxpr.
Unless the variable is specified lastprivate on the
loop construct, its value after the loop is unspecified.


but you are not trying to parallelize the inner loop... just in case you can try with
Code: Select all
            for(std::size_t j=0; j < (p_size-i); ++j)

and I will not be of much more help, sorry.
ftinetti
 
Posts: 582
Joined: Wed Feb 10, 2010 2:44 pm

Re: loop parallization with decrement

Postby flashpixx » Tue Nov 15, 2011 2:17 pm

My question was: Should / Must I change the loop structur or can I use the preprocessor commands for a straight-forward change. Thanks for your answer, that solves the problem :-)
flashpixx
 
Posts: 6
Joined: Tue Nov 15, 2011 10:18 am

Re: loop parallization with decrement

Postby ftinetti » Tue Nov 15, 2011 3:11 pm

Sorry, I neither understand your question (if any) nor what solved the problem...
ftinetti
 
Posts: 582
Joined: Wed Feb 10, 2010 2:44 pm


Return to Using OpenMP

Who is online

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