From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 16850 invoked by alias); 8 Oct 2007 12:05:30 -0000 Received: (qmail 16793 invoked by uid 48); 8 Oct 2007 12:05:17 -0000 Date: Mon, 08 Oct 2007 12:05:00 -0000 Message-ID: <20071008120517.16792.qmail@sourceware.org> X-Bugzilla-Reason: CC References: Subject: [Bug fortran/33686] FORALL loop gives wrong result In-Reply-To: Reply-To: gcc-bugzilla@gcc.gnu.org To: gcc-bugs@gcc.gnu.org From: "dominiq at lps dot ens dot fr" Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2007-10/txt/msg00640.txt.bz2 ------- 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