Reputation: 49
I am learning omp and came across nested loops involving arrays assignments etc. with details:
a
, b
, and c
have been initializedThe following code seems working fine though but I was wondering if
there is a way we could accomplish the task without using the schedule
clause.
#pragma omp parallel
{
int temp = 0;
#pragma omp for
for(int i = 0 ; i < 10; i++)
for(int j = i + 1; j < 10; j++)
{
if(a[i] > a[j])
{
temp = a[i];
a[i] = a[j];
a[j] = temp;
temp = b[i];
b[i] = b[j];
b[j] = temp;
temp = c[i];
c[i] = c[j];
c[j] = temp;
}
}
}
I tried avoiding schedule
by introducing critical
clause around the assignments but that didn't work. Can we in any way use a reduction
clause here?
Moreover, if anyone could guide best practices to follow when dealing with arrays specially when these are depending on previous/next values (e.g, A[i] = A[i+1] - delta;
).
The results came out correct when using schedule
clause but I want to avoid it and bring results with reduced execution cost.
Upvotes: 1
Views: 72