!************************************************************************ ! * This file has been written as a sample solution to an exercise in a ! * course given at the Edinburgh Parallel Computing Centre. It is made ! * freely available with the understanding that every copy of this file ! * must include this header and that EPCC takes no responsibility for ! * the use of the enclosed teaching material. ! * ! * Author: Joel Malard ! * ! * Contact: epcc-tec@epcc.ed.ac.uk ! * ! * Purpose: A program to try out non-blocking point-to-point ! * communications. ! * ! * Contents: F90 source code. ! * ! ************************************************************************/ program ring include "mpif.h" integer to_right, to_left parameter (to_right = 201, to_left = 102) integer ierror, rank, my_rank, size integer right, left integer other, sum, i integer send_status(MPI_STATUS_SIZE), recv_status(MPI_STATUS_SIZE) integer request call MPI_Init(ierror) call MPI_Comm_rank(MPI_COMM_WORLD, my_rank, ierror) call MPI_Comm_size(MPI_COMM_WORLD, size, ierror) right = my_rank + 1 if (right == size) right = 0 left = my_rank - 1 if (left == -1) left = size-1 sum = 0 rank = my_rank do i = 0, size-1 call MPI_Issend(rank, 1, MPI_INTEGER, right, to_right, . MPI_COMM_WORLD, request, ierror) call MPI_Recv(other, 1, MPI_INTEGER, left, to_right, . MPI_COMM_WORLD, recv_status, ierror) call MPI_Wait(request, send_status, ierror) sum = sum + other rank = other enddo write(*, '("PE",i1,": Sum = ",i4)') rank, sum call MPI_Finalize(ierror) stop end