1

I've never used an atomic directive before and I cannot find answers on the documentation. Every time I try to use it in this loop I get an error of the type:

PGCC-S-0155-Invalid atomic expression

PGCC-S-0155-Invalid atomic region

PGCC-S-0155-Invalid atomic read

I tried several atomic clauses without success.

#pragma acc parallel loop collapse(2) present(c, L, R)
for (i = 1; i < endi; i++){
    for (j = 0; j < endj; j++) 


      #pragma acc atomic
      A = c[i][j] - c[i-1][j];
      #pragma acc atomic
      B = c[i+1][j] - c[i][j];

      A = 0.5*(A+B);

      #pragma acc atomic
      L[i][j]   = c[i][j] + 0.5*A;

      #pragma acc atomic
      R[i-1][j] = c[i][j] - 0.5*A;



    }
}
Smoden
  • 21
  • 3
  • None of these cases are valid use cases for atomics. Are you looking how to apply them to you're own code or just trying to understand their use? For the former, please provide a complete reproducible example so we can help you through these issues. – Mat Colgrove May 12 '20 at 03:10
  • I thought I have to use _atomic_ because, for example, for _A = c[i][j] - c[i-1][j];_ it happens that in two iterations there's the reading of the same data at the same moment. – Smoden May 12 '20 at 14:21
  • What are "A" and "B"? Atomics should only be used when updating shared global data that may be updated by multiple threads. Here A and B look to be local private scalars. Again, having a complete reproducing example is highly recommended since it's much easier to give recommendations when there a full context. – Mat Colgrove May 12 '20 at 15:24
  • To be a bit more clear, the atomic only needs to be used when there's potential collisions, i.e. multiple threads updating the same data. Since each thread is updating different elements of L and R, no atomic is needed. If each thread was updating the same elements of L and R, then you might need atomic. Though just assigning would lead to incorrect answers since atomics don't enforce ordering and the value assigned would be which ever thread last updated the element. The classic example for using atomics is a histogram where a value in a shared bin needs to be atomically incremented. – Mat Colgrove May 12 '20 at 15:33

0 Answers0