DO CONCURRENT: when to use a locality-spec

Hello, I have a rather basic question regarding the (optional) specification of locality for variables used inside a do concurrent construct:

  • In which practical cases is a locality-spec necessary (for correctness) or perhaps preferred (for performance)?
  • Aside variables with SAVE attribute, for which the default locality-spec is SHARED, do we need to be careful with something else?

For instance, in the below example from IBM, is the locality-spec required or just superfluous?

INTEGER,DIMENSION(N) :: J, K
INTEGER              :: I, M
M = 10
I = 15
DO CONCURRENT (I = 1:N, J(I)> 0)LOCAL (M) SHARED (J, K)
   M =  MOD (K(I), J(I))
   K(I) = K(I) – M
END DO
PRINT *, I, M             ! Prints 15 10
3 Likes