C /* C * The root node sends out a message to the next node in the ring and each node then passes the C * message along to the next node. The root node times how long it takes for the message to get back to it. C */ program main include 'mpif.h' double precision start, finish double precision buf(64) integer my_rank integer n_processes integer next integer ierr integer BUFSIZE = 64 integer tag = 2001 call MPI_INIT(ierr) call MPI_COMM_RANK(MPI_COMM_WORLD, my_rank, ierr) call MPI_COMM_SIZE(MPI_COMM_WORLD, n_processes, ierr) C /* C * If this process is the root process send a messege to the next node C * and wait to recieve one from the last node. Time how long it takes C * for the messege to get around the ring. If this process is not the C * root node, wait to recieve a messege from the previous node and C * then send it to the next node. C */ start = MPI_Wtime() print *, 'Hello world! I am ', my_rank, ' of ', n_processes if (my_rank .eq. 0) then C /* send to the next node */ call MPI_SEND(buf, BUFSIZE, MPI_DOUBLE_PRECISION, my_rank+1, 1 tag, MPI_COMM_WORLD, ierr) C /* recieve from the last node */ call MPI_RECV(buf, BUFSIZE, MPI_DOUBLE_PRECISION, n_processes-1, 1 tag, MPI_COMM_WORLD, status, ierr) else C /* recieve from the previous node */ call MPI_RECV(buf, BUFSIZE, MPI_DOUBLE_PRECISION, my_rank-1, tag, 1 MPI_COMM_WORLD, status, ierr) C /* send to the next node */ if (my_rank .eq. (n_processes-1)) then next=0 else next=my_rank+1 endif print *, 'P',my_rank,': next= ',next call MPI_SEND(buf, BUFSIZE, MPI_DOUBLE_PRECISION, next, tag, 1 MPI_COMM_WORLD, ierr) endif finish=MPI_Wtime() C /* Print out the results. */ if (my_rank .eq. 0) then print *, 'Total time used was ', finish-start, ' seconds' endif call MPI_FINALIZE(ierr) end