I'm having issues with trying to recode a nested for loop in order to parallelize it:
for(i=0; i<n; i++)
{
for(j=0; j<n; j++)
{
if(asubsref(struct1,j) > 0)
asubsref(struct2,j) = asubsref(struct3,j) + 1;
}
for(j=0; j<n; j++)
asubsref(struct1,j) = asubsref(struct2,j) - asubsref(struct3,i);
}
Struct1/struct2 are two structs with a width/height/int-float array respectively. struct3 is a float struct.
My attempt so far was to make them into two different loops but alas, it didn't work as I'd get a lot of incorrect results:
#pragma omp parallel
{
#pragma omp for private(j)
for(i=0; i<n; i++)
{
for(j=0; j<n; j++)
{
if(asubsref(struct1,j) > 0)
asubsref(struct2,j) += 1;
}
}
#pragma omp for private(j)
for(i=0; i<n; i++)
{
k = asubsref(struct3,i);
for (j=0; j<n; j++)
{
asubsref(struct1,j) -= k;
}
}
}
I'm not looking for an answer but some guidance to help me thinking how to go about this/tips toward the answer and the like.
asubsref(bin,j) = asubsref(bin,j) + 1;andasubsref(bin,j) += 1;are identical statements? Ifasubsrefhas side effects, this may not be true.asubsref)