[ HPF Home | Versions | Compilers | Projects | Publications | Applications | Benchmarks | Events | Contact ] |
The first example shows an INTERFACE block, call, and subroutine definition for matrix multiplication:
! The NEWMATMULT routine computes C=A*B. A copy of row A(I,*) and ! column B(*,J) is broadcast to the processor that computes C(I,J) ! before the call to NEWMATMULT.
INTERFACE EXTRINSIC(HPF_LOCAL) SUBROUTINE NEWMATMULT(A, B, C) REAL, DIMENSION(:,:), INTENT(IN) :: A, B REAL, DIMENSION(:,:), INTENT(OUT) :: C !HPF$ ALIGN B(I,J) WITH *C(*,J) END SUBROUTINE NEWMATMULT END INTERFACE ... CALL NEWMATMULT(A,B,C) ...
! The Local Subroutine Definition: ! Each processor is passed 3 arrays of rank 2. Assume that the ! global HPF arrays A,B and C have dimensions LxM, MxN and LxN, ! respectively. The local array CC is (a copy of) a rectangular ! subarray of C. Let I1,I2,...,Ir and J1,J2,...,Js be, ! respectively, the row and column indices of this subarray at a ! processor. Then AA is (a copy of) the subarray of A with row ! indices I1,...,Ir and column indices 1,...,M; and BB is (a copy ! of) the subarray of B with row indices 1,...,M and column ! indices J1,...,Js. C may be replicated, in which case copies ! of C(I,J) will be consistently updated at various processors.
EXTRINSIC(HPF_LOCAL) SUBROUTINE NEWMATMULT(AA, BB, CC) REAL, DIMENSION(:,:), INTENT(IN) :: AA, BB REAL, DIMENSION(:,:), INTENT(OUT) :: CC !HPF$ ALIGN BB(I,J) WITH *CC(*,J) INTEGER I,J
! loop uses local indices
DO I = LBOUND(CC,1), UBOUND(CC,1) DO J = LBOUND(CC,2), UBOUND(CC,2) CC(I,J) = DOT_PRODUCT(AA(I,:), BB(:,J)) END DO END DO RETURN END The second example shows an INTERFACE block, call, and subroutine definition for sum reduction:
! The SREDUCE routine computes at each processor the sum of ! the local elements of an array of rank 1. It returns an ! array that consists of one sum per processor. The sum ! reduction is completed by reducing this array of partial ! sums. The function fails if the array is replicated. ! (Replicated arrays could be handled by a more complicated code.)
INTERFACE EXTRINSIC(HPF_LOCAL) FUNCTION SREDUCE(A) RESULT(R) REAL, DIMENSION(NUMBER_OF_PROCESSORS()) :: R !HPF$ DISTRIBUTE (BLOCK) :: R REAL, DIMENSION(:), INTENT(IN) :: AA
INTEGER COPIES
CALL GLOBAL_ALIGNMENT(AA, NUMBER_OF_COPIES = COPIES) IF (COPIES > 1) CALL ERROR() ! array is replicated ! Additional code to check that template is not replicated ... ! Array is not replicated - compute local sum R(1) = SUM(AA) RETURN END
©2000-2006 Rice University | [ Contact Us | HiPerSoft | Computer Science ] |