Subject: hpff-interpret: Local code vs. global code

From: "Dr A.C. Marshall" <[email-masked]>
Date: Fri, 7 Jun 1996 10:39:50 +0100 (BST)

---------------------------------------------------------------------------
[email-masked] is a mailing list for corrections,
clarifications, and interpretations related to High Performance Fortran.
Instructions for adding or deleting yourself from this list appear at the
bottom of this message.
---------------------------------------------------------------------------

Dear all,

I have been having trouble with an example from the HPF Handbook P225/6 
and Figures 8.1 and 8.2.

There is an example "Munch_Columns" which has been written as an HPF_LOCAL
EXTRINSIC:

EXTRINSIC (HPF_LOCAL) SUBROUTINE MUNCHCOLUMNS(A)
 REAL A(:,:)
 INTEGER i,j
 !HPF$ INDEPENDENT, NEW(I)
  DO j=1,ubound(A,2)
   i = 1
   DO WHILE (i <= ubound(A,1))
    IF (A(i,j) /= 0.0) THEN
     A(1:i-1,j) = A(i,j)
     EXIT
    END IF
    i = i + 1
   END DO
  END DO
END

Assuming that A is DISTRIBUTEd (*, BLOCK) (which it is) then each instance 
of "Munch_Columns" is free to work on its own set of columns. There is NO 
synchronisation within the EXTRINSIC and, if appropriate, each "j" iteration
can be executed concurrently.

The code given in Fig 8.2 (the GLOBAL HPF code) is quite clearly incorrect in 
a number of areas (incorrect MASK 
specification and wrong number of dimensions given in references to A 
[whoops]). I claim, however, that the following could be used as GLOBAL code:

EXTRINSIC (HPF) SUBROUTINE MUNCHCOLUMNS(A)
 REAL A(:,:)
 INTEGER i,j
 !HPF$ DISTRIBUTE A(*,BLOCK)
 !HPF$ INDEPENDENT, NEW(I)
  DO j=1,ubound(A,2)
   i = 1
   DO WHILE (i <= ubound(A,1))
    IF (A(i,j) /= 0.0) THEN
     A(1:i-1,j) = A(i,j)
     EXIT
    END IF
    i = i + 1
   END DO
  END DO
END

As far as I can tell this code should work correctly. If this is true 
then each processor will be able to work on its own set of columns and 
accoring to the INDEPENDENT directive, if appropriate, each "j" iteration
can be executed concurrently.

The thing which confuses me is the paragraph half way down page 226: 

	"While MUNCHCOLUMNS could be expressed as global HPF code
	the local version might be faster because it exploits the 
	idea that only a prefix of each column needs to be examined 
	and processed. Each processor may take a different time to 
	process its first column; the local code clearly indicates
	that the processes synchronise only after processing all 
	columns not after processing each column."

Basically, I do not understand why the global version needs to synchronise
after processing each column. According to the INDEPENDENT directive, the
"j" iterations (which select the column to work on) do not interfere with 
each other, so they can be performed without synchronisation. 

Clearly I am missing something here! Could some kind soul please explain 
why the local version is likely to be faster than the global version. I 
appreciate that one answer could be that INDEPENDENT is generally parsed 
and then ignored whereas a call to a local extrinsic is guaranteed to 
exploit parallelism, however, does not seem to be the reason cited in 
the handbook. 

If indeed the MUNCHCOLUMNS example does NOT actually demonstrate how local
code can be used to avoid unecessary synchronisation then could somebody 
cite an example that does?

Adam Marshall (in a state of confusion)

-- 
     Dr AC Marshall                    | 
     Computing Services Department,    |
     University of Liverpool,          |        WATCH THIS SPACE
     PO Box 147. L69 3BX               | 
     email: [email-masked]            |
     Tel: +44-151-794 3722             |
     Fax: +44-151-794 3759             |

     Take a look at:     HPC Info: http://www.liv.ac.uk/HPC/HPCpage.html
                         Adam Info: http://www.liv.ac.uk/~adamm/HomePage.html

---------------------------------------------------------------------------
To (un)subscribe to this list, send mail to
[email-masked].
Leave the subject line blank, and in the body put the line
(un)subscribe <email-address>
---------------------------------------------------------------------------