c Compile with: c Helios: mpif77 -o hello hello.f c Hive, Portland: mpif77 -fc=pgf77 -o hello hello.f 1 program test 2 include 'mpif.h' 3 integer ierr,id,lpname 4 character*255 pname 6 call MPI_INIT( ierr ) 7 call MPI_COMM_RANK(MPI_COMM_WORLD, id, ierr) 8 call MPI_GET_PROCESSOR_NAME(pname,lpname,ierr) 9 write(6,*)'Process',id,' running on ',pname(1:lpname) 10 call MPI_FINALIZE(ierr) 12 end c Explanations: c Line 1: Program name, standard Fortran c Line 2: MPI header files contain the prototypes for MPI c functions/subroutines, as well as definitions of macros, c special constants, and datatypes used by MPI. An c appropriate "include" statement must appear in any c source file that contains MPI function calls or constants. c Line 3: Definition of integers c Line 4: Definition of characters c Line 6: The first MPI routine called in any MPI program must be c the initialization routine MPI_INIT. This routine c establishes the MPI environment, returning an error code c if there is a problem. MPI_INIT may be called only once c in any program! c Line 7: A processor can determine its rank in a communicator c (MPI_COMM_WORLD) with a call to MPI_COMM_RANK. The rank c is returned in 'id'. The error code 'ierr' returned is c MPI_SUCCESS if the routine ran successfully (that is, c the integer returned is equal to the pre-defined integer c constant MPI_SUCCESS). Thus, you can test for successful c operation with c if (ierr.eq.MPI_SUCCESS) THEN c ...routine ran correctly... c END IF c Line 8: The name of the processor on which the present process c runs is returned in 'pname' and the c number of characters in the name of the processor is c returned in 'lpname' c Line 9: Write out information c Line 10: The last MPI routine called should be MPI_FINALIZE c which cleans up all MPI data structures, cancels c operations that never completed, etc. MPI_FINALIZE c must be called by all processes; if any one process c does not reach this statement, the program will appear c to hang. Once MPI_FINALIZE has been called, no other c MPI routines (including MPI_INIT) may be called. c The error code 'ierr' returned is c MPI_SUCCESS if the routine ran successfully (that is, c the integer returned is equal to the pre-defined integer c constant MPI_SUCCESS). Thus, you can test for successful c operation with c if (ierr.eq.MPI_SUCCESS) THEN c ...routine ran correctly... c END IF c Line 12: End of program c c c Each process executes the same code, including probing for c its rank and processor name and printing the string. The order c of the printed lines is essentially random! There is no intrinsic c synchronization of operations on different processors. Each c time the code is run, the order of the output lines may change.