C****************************************************************************** C MPI Timing Program - Fortran Version C FILE: mpi_timing.f C OTHER FILES: timing_fgettod.c C DESCRIPTION: MPI timing example code. Fortran version. C In this example code, an MPI timing test is performed. C The processor with taskid = 0 will send "reps" number of messages to C the processor with taskid = 1, waiting for a reply between each rep. C Before and after timings are made for each rep and an average C calculated when completed. C AUTHOR: Blaise Barney. Converted to MPI: George L. Gusciora (1/23/95) C LAST REVISED: 12/14/95 Blaise Barney C***************************************************************************** program timing include 'mpif.h' IMPLICIT NONE external timing_fgettod integer REPS parameter(REPS = 20) integer mytid, wtid, rcode, n, onevalue, times1(2), & times2(2), rtt, artt, outmsg, dest, type integer inmsg, source, taskid, numtasks, ierr integer status(MPI_STATUS_SIZE) C***************************************************************************** C processing performed by both task 0 and 1 C***************************************************************************** call MPI_INIT( ierr ) call MPI_COMM_RANK( MPI_COMM_WORLD, taskid, ierr ) call MPI_COMM_SIZE( MPI_COMM_WORLD, numtasks, ierr ) if (numtasks .ne. 2) then print *, 'Error: Set environment variable MP_PROCS to 2.' go to 999 endif print *, 'task ID = ',taskid type = 1 C**************************************************************************** C Task 0 processing C**************************************************************************** if (taskid .eq. 0) then write(*,*)'Doing round trip test, minimal message size, ', & 'reps=',REPS artt = 0 dest = 1 source = 1 do 10 n = 1, REPS C Get first time - seconds and microseconds call timing_fgettod(%REF(times1)) call MPI_SEND( outmsg, 1, MPI_INTEGER, dest, 0, & MPI_COMM_WORLD, ierr ) call MPI_RECV( inmsg, 1, MPI_INTEGER, MPI_ANY_SOURCE, & 0, MPI_COMM_WORLD, status, ierr ) C Get ending time - in seconds and microseconds call timing_fgettod(%REF(times2)) C Calculate round trip time and print, then accumulate time. rtt = ((times2(1) - times1(1))*1000000) + times2(2) - & times1(2) write(*,9) n, rtt 9 format('round trip#',i3,' uSec =',i6) artt = artt + rtt 10 continue C Print final average from all round trips write(*,*)'*** Round Trip Avg sec =', artt/REPS endif C**************************************************************************** C Task one processing C*************************************************************************** if (taskid .eq. 1) then dest = 0 source = 0 do 20 n = 1, REPS call MPI_RECV( inmsg, 1, MPI_INTEGER, & source, 0, MPI_COMM_WORLD, status, ierr ) call MPI_SEND( outmsg, 1, MPI_INTEGER, source, 0, & MPI_COMM_WORLD, ierr ) 20 continue endif call MPI_FINALIZE(ierr) 999 end