OpenMP - running things in parallel and some in sequence within them

Posted by Sayan Ghosh on Stack Overflow See other posts from Stack Overflow or by Sayan Ghosh
Published on 2010-04-19T01:49:08Z Indexed on 2010/04/19 1:53 UTC
Read the original article Hit count: 260

Filed under:

Hi,

I have a scenario like:

for (i = 0; i < n; i++)
{
for (j = 0; j < m; j++)
{
for (k = 0; k < x; k++)
{
val = 2*i + j + 4*k
if (val != 0)
{
for(t = 0; t < l; t++)
{
someFunction((i + t) + someFunction(j + t) + k*t)
}
}
}
}
}

Considering this is block A, Now I have two more similar blocks in my code. I want to put them in parallel, so I used OpenMP pragmas. However I am not able to parallelize it, because I am a tad confused that which variables would be shared and private in this case. If the function call in the inner loop was an operation like sum += x, then I could have added a reduction clause. In general, how would one approach parallelizing a code using OpenMP, when we there is a nested for loop, and then another inner for loop doing the main operation. I tried declaring a parallel region, and then simply putting pragma fors before the blocks, but definitely I am missing a point there!

Thanks, Sayan

© Stack Overflow or respective owner

Related posts about openmp