------- Comment #4 from dominiq at lps dot ens dot fr 2007-10-08 12:05 ------- You can add xlf to the (3, 1, 4, 2) list. I think this is the right answer. The following code
PROGRAM TST IMPLICIT NONE INTEGER :: P(4),Q(4),I P = (/2,4,1,3/) FORALL(I=1:4) Q(P(I)) = I END FORALL PRINT *, Q do I=1,4 Q(P(I)) = I END do PRINT *, Q do I=4,1,-1 Q(P(I)) = I END do PRINT *, Q FORALL(I=1:4) P(P(I)) = I END FORALL PRINT *, P do I=1,4 P(P(I)) = I END do PRINT *, P do I=4,1,-1 P(P(I)) = I END do PRINT *, P END PROGRAM TST gives with gfortran 3 1 4 2 3 1 4 2 3 1 4 2 3 1 4 3 3 1 4 3 2 1 4 3 My understanding of the FORALL construct is that it is equivalent to any of the first three loops, followed by P=Q, i.e., P is changed only when all the Q's have been computed. Comparing the fourth and fifth lines show that P is changed within the FORALL before all the rhs has been visited and the sixth line shows that this depends on the order of their computation. Note that the code is valid only if P is a permutation. Would it contains a single repetition, say (/2,4,1,2/), it would be invalid because Q(2) depends on the order (4 for the first do loop, 1 for the second). -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33686