[ HPF Home | Versions | Compilers | Projects | Publications | Applications | Benchmarks | Events | Contact ] |
This example illustrates F77_LOCAL programming using the default LAYOUT("0DF77_ARRAY"0D) and PASS_BY("0D*"0D) attributes, and the use of inquiry routines from the local level using the LAYOUT("0DHPF_ARRAY"0D) attribute.
PROGRAM EXAMPLE ! Declare the data array and a verification copy INTEGER, PARAMETER :: NX = 100, NY = 100 REAL, DIMENSION(NX,NY) :: X, Y !HPF$ DISTRIBUTE(BLOCK,BLOCK) :: X, Y ! The global sum will be computed ! by forming partial sums on the processors REAL PARTIAL_SUM(NUMBER_OF_PROCESSORS()) !HPF$ DISTRIBUTE PARTIAL_SUM(BLOCK) ! Local subgrid parameters are declared per processor ! for a rank-two array INTEGER, DIMENSION(NUMBER_OF_PROCESSORS(),2) :: & LB, UB, NUMBER !HPF$ DISTRIBUTE(BLOCK,*) :: LB, UB, NUMBER ! Define interfaces INTERFACE EXTRINSIC(F77_LOCAL) SUBROUTINE LOCAL1 & ( LB1, UB1, LB2, UB2, X , X_DESC ) INTEGER, DIMENSION(:) :: LB1, UB1, LB2, UB2 REAL,DIMENSION(:,:),LAYOUT('HPF_ARRAY') :: X REAL,DIMENSION(:,:),LAYOUT('HPF_ARRAY'), & PASS_BY('HPF_HANDLE') :: X_DESC !HPF$ DISTRIBUTE(BLOCK) :: LB1, UB1, LB2, UB2 !HPF$ DISTRIBUTE(BLOCK,BLOCK) :: X, X_DESC END EXTRINSIC(F77_LOCAL) SUBROUTINE LOCAL2(N,X,R) INTEGER N(:) REAL X(:,:), R(:) ! Defaults ! LAYOUT('F77_ARRAY') sequential, column-major storage ! PASS_BY('*') pass by reference (local address) !HPF$ DISTRIBUTE N(BLOCK) !HPF$ DISTRIBUTE X(BLOCK,BLOCK) !HPF$ DISTRIBUTE R(BLOCK) END END INTERFACE ! Determine result using only global HPF ! Initialize values FORALL (I=1:NX,J=1:NY) X(I,J) = I + (J-1) * NX ! Determine and report global sum PRINT *, 'Global HPF result: ',SUM(X) ! Determine result using local subroutines ! Initialize values ( assume stride = 1 ) CALL HPF_SUBGRID_INFO( Y, IERR, LB=lb, UB=UB ) IF (IERR.NE.0) STOP 'ERROR!' CALL LOCAL1( LB(:,1), UB(:,1), LB(:,2), UB(:,2), Y , Y ) ! DETERMINE AND REPORT GLOBAL SUM NUMBER = UB - LB + 1 CALL LOCAL2 ( NUMBER(:,1) * NUMBER(:,2) , Y , PARTIAL_SUM ) PRINT *, 'F77_LOCAL result #1 : ',SUM(PARTIAL_SUM) END
SUBROUTINE LOCAL1( LB1, UB1, LB2, UB2, X , DESCRX ) REAL X ( LB1 : UB1 , LB2 : UB2 ) INTEGER DESCRX ( * ) ! Get the global extent of the first axis ! This is an HPF_LOCAL type of inquiry routine with an 'F77_' prefix CALL F77_GLOBAL_SIZE ( NX , DESCRX , 1 ) ! Initialize elements of the array DO J = LB2, UB2 DO I = LB2, UB2 X(I,J) = I + (J-1) * NX END DO END DO END SUBROUTINE LOCAL2(N,X,R) ! Here, the correspondence to the global indices is not important ! Only the total size of the subgrid is passed in REAL X(N) R = 0. DO I = 1, N R = R + X(I) END DO END
©2000-2006 Rice University | [ Contact Us | HiPerSoft | Computer Science ] |