This is the presentation layer of a two-part module. For an explanation of the layers and how to navigate within and between them, return to the top page of this module.
This workshop focuses on the IBM implementation.
1.4 How to Use MPI
#include "mpi.h" for C programs
include 'mpif.h' for Fortran programs
(covered in the IBM SP Parallel Environment module)
2. MPI programs
Click here for C version
program hello
include 'mpif.h'
integer rank, size, ierror, tag, status(MPI_STATUS_SIZE)
character(12) message
call MPI_INIT(ierror)
call MPI_COMM_SIZE(MPI_COMM_WORLD, size, ierror)
call MPI_COMM_RANK(MPI_COMM_WORLD, rank, ierror)
tag = 100
if (rank .eq. 0) then
message = 'Hello, world'
do i=1, size-1
call MPI_SEND(message, 12, MPI_CHARACTER, i, tag,
& MPI_COMM_WORLD, ierror)
enddo
else
call MPI_RECV(message, 12, MPI_CHARACTER, 0, tag,
& MPI_COMM_WORLD, status, ierror)
endif
print*, 'node', rank, ':', message
call MPI_FINALIZE(ierror)
end
call MPI_SEND(startbuf,count,datatype, \ | / ---DATA--- dest,tag,comm, ierror) \ | / ENVELOPE
--------------------------------------- MPI Datatype Fortran Datatype --------------------------------------- MPI_INTEGER INTEGER MPI_REAL REAL MPI_DOUBLE_PRECISION DOUBLE PRECISION MPI_COMPLEX COMPLEX MPI_LOGICAL LOGICAL MPI_CHARACTER CHARACTER(1) MPI_BYTE MPI_PACKED ---------------------------------------
Message Passing Interface Forum (1995) MPI: A Message Passing Interface Standard. June 12, 1995. Available online or in postscript.
Return to:
Workshop Materials
Virtual Workshop Modules
MPI Documentation
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |