Subject: Conditional assignments in FORALL

From: John Merlin <[email-masked]>
Date: Sat, 27 Jun 92 17:25:47 BST

I've realised I was being very thick when I suggested introducing 
C-style conditional expressions into HPF, as Fortran 90 already
provides exactly this functionality with the 'MERGE' intrinsic:

	e1 ? e2 : e3         in C is equivalent to
	MERGE (e2, e3, e1)   in F90.

It's elemental, so it can be used in 'forall-assignment's (I would
maintain!).

Thus, one interpretation of Chuck's example:

 	FORALL ( I = 1:N )
 	  IF ( ABS(A(I)) < EPS ) THEN
 	    A(I) = 0.0                 ! s1
 	  ELSE
 	    A(I) = A(I-1) + A(I+1)     ! s2
 	  END IF
 	END FORALL

(the interpretation where concurrency extends over both branches
of the IF, so old values are always used on the RHS of 's1' and 's2'), 
can be expressed simply as:

	FORALL (i=1:n)  a(i) = MERGE (0.0, a(i-1)+a(i+1), ABS(a(i)) < eps)

The case where no 's2' branch is performed until all 's1' branches
have executed (but using the old values in the mask) can be written:

	temp = ABS (a) < eps
	FORALL (i=1:n, temp)       a(i) = 0.0
	FORALL (i=1:n, .NOT.temp)  a(i) = a(i-1) + a(i+1)

I'm beginning to reach a very conservative opinion about what should be
allowed in a FORALL construct:  that IF and DO should be restricted to 
forbid references to the FORALL indices, that stmts should be executed 
in strict sequential order and be severly limited in type (perhaps just 
forall-assignments, elemental subroutine calls, IF and DO -- and perhaps 
excluding the last 2), that 'forall-subscript-expr's can't reference 
'forall-indices', etc  (i.e. pretty much as in Mark Snir's proposal but 
restricting the allowable stmts in a FORALL to those whose semantics 
are very obvious!)

                      Cheers,
                          John Merlin.

---

From: David Loveman <[email-masked]>
Date: Tue, 30 Jun 92 09:04:42 PDT

>	FORALL (i=1:n, .NOT.temp)  a(i) = a(i-1) + a(i+1)

doesn't quite work - the FORALL requires a scalar mask espression.  The
fixup is easy:

	temp = ABS (a) < eps
	FORALL (i=1:n, temp(i))       a(i) = 0.0
	FORALL (i=1:n, .NOT.temp(i))  a(i) = a(i-1) + a(i+1)

-David