dynamic values in exit condition of for loop

General OpenMP discussion

dynamic values in exit condition of for loop

Postby uzzal36 » Thu Apr 05, 2012 8:46 pm

Hi,

Do you guys have any suggestion on the following parallelization? In the code "ne" and "ne2" are two integer vectors. As shown, the exit condition of the first parallel "for loop" depends on "ne" and values can be added into "ne" inside the loop. But, what I am getting is, the code consider only the INITIAL size of ne when terminates, even though the size is increasing inside the loop.

I appreciate your helps. Thanks.

regards,
Mostofa

#pragma omp parallel for shared(ne) private(ne2, k)
for (j = 0; j < ne.size(); j++)
{
// SOME ADDITIONAL CODES ARE HERE that insert values to "ne2"
for(k = 0; k < ne2.size(); k++)
{
#pragma omp critical
ne.push_back(ne2[k]);
}
}
uzzal36
 
Posts: 10
Joined: Tue Sep 21, 2010 9:22 am

Re: dynamic values in exit condition of for loop

Postby gutha.raghu » Thu Apr 05, 2012 11:08 pm

try this:

#pragma omp parallel for shared(ne,ne2) private(j, k)
for (j = 0; j < ne.size(); j++)
{
// SOME ADDITIONAL CODES ARE HERE that insert values to "ne2"
for(k = 0; k < ne2.size(); k++)
{
#pragma omp critical
ne.push_back(ne2[k]);
}
}
gutha.raghu
 
Posts: 8
Joined: Thu Apr 05, 2012 4:55 am

Re: dynamic values in exit condition of for loop

Postby uzzal36 » Thu Apr 05, 2012 11:27 pm

Thanks.

But, ne2 is not a shared variable. Usually every thread will generate many integers and store them into ne2. Later these all ne2's will be added to ne. Therefore, taking ne2 as shared will bind to have more critical statement when inserting data to ne2.
uzzal36
 
Posts: 10
Joined: Tue Sep 21, 2010 9:22 am

Re: dynamic values in exit condition of for loop

Postby MarkB » Fri Apr 06, 2012 4:16 am

You are not allowed to modify the upper bound of a parallel for loop while it is executing.

Something along these lines might work, though may not be very efficient:

jlo=0;
jhi=ne.size();
while (jlo < jhi) {
#pragma omp parallel for shared(ne,jlo,jhi) private(ne2, k)
for (j = jlo; j < jhi; j++)
{
// SOME ADDITIONAL CODES ARE HERE that insert values to "ne2"
for(k = 0; k < ne2.size(); k++)
{
#pragma omp critical
ne.push_back(ne2[k]);
}
}
jlo =jhi;
jhi = ne.size();
}
MarkB
 
Posts: 450
Joined: Thu Jan 08, 2009 10:12 am
Location: EPCC, University of Edinburgh

Re: dynamic values in exit condition of for loop

Postby uzzal36 » Fri Apr 06, 2012 1:36 pm

Thanks. I thought OpenMP works with dynamic limit.
uzzal36
 
Posts: 10
Joined: Tue Sep 21, 2010 9:22 am

Re: dynamic values in exit condition of for loop

Postby gutha.raghu » Thu Apr 12, 2012 3:11 am

yes its true inside parallel for loop we cant modify either initialization variables or comparison variables...
gutha.raghu
 
Posts: 8
Joined: Thu Apr 05, 2012 4:55 am


Return to Using OpenMP

Who is online

Users browsing this forum: No registered users and 2 guests