parallel for with inner reduction...

General OpenMP discussion

parallel for with inner reduction...

Postby gutha.raghu » Thu Apr 05, 2012 5:09 am

why the following code snippet giving wrong results in serial and parallel versions and what is the exact parallel code will be...

#pragma omp parallel for schedule(static,10) private(j,k) shared(temp,sp2,sp1,sp3)
for (j=0; j<sp1->NumElements(); j++)
{
temp[j] = 0;

for (k=0; k<sp2->NumElements(); k++)
{
if (j >= k)
temp[j] += sp2->ptr[k] * sp1->ptr[j-k];
}

for (k=0; k<sp3->NumElements(); k++)
{

if (j > k)
temp[j] -= sp3->ptr[k] * temp[j-k-1];
}
}
gutha.raghu
 
Posts: 8
Joined: Thu Apr 05, 2012 4:55 am

Re: parallel for with inner reduction...

Postby MarkB » Fri Apr 06, 2012 3:54 am

I'm afraid your j loop is not parallelisable as it stands: there is a dependency on temp in the final k loop.
MarkB
 
Posts: 422
Joined: Thu Jan 08, 2009 10:12 am

Re: parallel for with inner reduction...

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

ok...yeah i got it..its between temp[j],temp[j-k-1]

so not possible to parallelize....i am a fresher to openmp...so don't mind it
gutha.raghu
 
Posts: 8
Joined: Thu Apr 05, 2012 4:55 am


Return to Using OpenMP

Who is online

Users browsing this forum: Google [Bot] and 6 guests

cron