I am confused about some of the output of the program below. Could someone
enlighten me please?
The code compiles without any complaints, and produces identical output with
both the Compaq Visual Fortran and the Sun One Studio 8 Early Access compilers:
Version one...
which: T T F
t1: 3 6 9
t2: 9 18 27
sys: 3 6 27
Version two...
which: T T F
sys: 3 6 36
Version three...
which: T T F
t1: 3 6 9
t2: 9 18 27
sys: 3 6 27
Version four...
which: T T F
sys: 3 6 36
Version 1 does as I would expect.
I wouldn't expect anything from version 2, since the WHERE acts elementwise, but
in the code below this is impossible. The MATMUL requires the whole of both
right hand sides to be evaluated first preventing an elementwise evaluation.
Version 3 does as I would expect.
Version 4 does not. I would have expected the first two actual arguments of the
elemental intrinsic function MERGE to be evaluated before being passed to it...
and therefore for it to give the same result for sys as version 3. It does not.
Could someone explain where I am going wrong on this one please?
PROGRAM test_WHERE_MATMUL_prog
IMPLICIT NONE
INTEGER, PARAMETER, DIMENSION(3,3) :: mat=RESHAPE((/1,2,3,1,2,3,1,2,3/),(/3,3/))
INTEGER, PARAMETER, DIMENSION(3) :: s1=(/1,1,1/)
INTEGER, PARAMETER, DIMENSION(3) :: s2=(/2,2,2/)
LOGICAL, PARAMETER, DIMENSION(3) :: which=(/.TRUE.,.TRUE.,.FALSE./)
INTEGER, DIMENSION(3) :: sys
INTEGER, DIMENSION(3) :: t1
INTEGER, DIMENSION(3) :: t2
PRINT *,'Version one...'
sys=0
t1=MATMUL(mat,s1)
t2=MATMUL(mat,s1+s2)
WHERE (which)
sys=sys+t1
ELSEWHERE
sys=sys+t2
END WHERE
PRINT '(A10,3L5)','which:',which
PRINT '(A10,3I5)','t1:',t1
PRINT '(A10,3I5)','t2:',t2
PRINT '(A10,3I5)','sys:',sys
PRINT *,'Version two...'
sys=0
WHERE (which)
sys=sys+MATMUL(mat,s1)
ELSEWHERE
sys=sys+MATMUL(mat,s2+s2)
END WHERE
PRINT '(A10,3L5)','which:',which
PRINT '(A10,3I5)','sys:',sys
PRINT *,'Version three...'
sys=0
t1=MATMUL(mat,s1)
t2=MATMUL(mat,s1+s2)
sys=sys+MERGE(&
& t1, &
& t2, &
& which)
PRINT '(A10,3L5)','which:',which
PRINT '(A10,3I5)','t1:',t1
PRINT '(A10,3I5)','t2:',t2
PRINT '(A10,3I5)','sys:',sys
PRINT *,'Version four...'
sys=0
sys=sys+MERGE(&
& MATMUL(mat,s1), &
& MATMUL(mat,s2+s2), &
& which)
PRINT '(A10,3L5)','which:',which
PRINT '(A10,3I5)','sys:',sys
END PROGRAM test_WHERE_MATMUL_prog
--
==============================================
Paul Suckling
Research Associate
School of Mathematics and Statistics
The University of Birmingham
Edgbaston, Birmingham, B152TT, U.K.
+44(0)121 4146460
http://www.mat.bham.ac.uk/P.M.Suckling/
==============================================
|