PROGRAM MPIPRG INCLUDE 'mpif.h' PARAMETER ( N = 1024 ) INTEGER MYRANK, NPROCS, IERR, SRC, DEST, TAG INTEGER STATUS(MPI_STATUS_SIZE) DOUBLE PRECISION A(N), B(N), SUM * CALL MPI_INIT(IERR) CALL MPI_COMM_RANK( MPI_COMM_WORLD, MYRANK, IERR) CALL MPI_COMM_SIZE( MPI_COMM_WORLD, NPROCS, IERR) * DO I = 1, N A(I) = DBLE(MYRANK) ENDDO * SRC = MYRANK-1 IF ( SRC .LT. 0 ) SRC = NPROCS - 1 DEST = MYRANK + 1 IF ( DEST .GE. NPROCS ) DEST = 0 * TAG = 111 CALL MPI_SEND( A, N, MPI_DOUBLE_PRECISION, DEST, TAG, + MPI_COMM_WORLD, IERR ) CALL MPI_RECV( B, N, MPI_DOUBLE_PRECISION, SRC, TAG, + MPI_COMM_WORLD, STATUS, IERR ) * SUM = 0.D0 DO I = 1, N SUM = SUM + B(I) ENDDO * PRINT 1000, MYRANK, SUM/N 1000 FORMAT(' Process ', I3, ': value = ', 1PG12.5) * CALL MPI_FINALIZE(IERR) STOP END