"Six Function" MPI Programs
MPI_INIT, MPI_COMM_SIZE, MPI_COMM_RANK,
MPI_SEND, MPI_RECV, MPI_FINALIZE

Sample MPI C and C++ programs:
  • greetings.c, greetings.cpp, trap.c, trap.cpp
    Josh Blake's Sample MPI Prog Makefile, sample hostfile
  • Other intro MPI programs (from the LAM Tutorial slides)
    simpleMpi.c, simpleMpi.cpp simple2Mpi.c, simple2Mpi.cpp, simple3Mpi.c, simple3Mpi.cpp

    These six functions allow you to write many programs in MPI: (see MPI Tutorial Slides)
    "Six Function MPI" starts on p. 26
    (Fortran examples are also included in these slides)

    Use mpicc for C programs, mpiCC for C++ programs
    1. MPI_INIT
      • Function main: int main(int argc, char **argv)
        program examples p. 28, 29 of slides
      • In C: MPI_Init(&argc, &argv)
      • In C++: MPI::Init(argc, argv)

    2. MPI_COMM_SIZE
      • int size (declared in function main)
        program examples p. 38, 39 of slides
      • In C: MPI_Comm_size(MPI_COMM_WORLD, &size)
      • In C++: size = MPI::COMM_WORLD.Get_size()

    3. MPI_COMM_RANK
      • int rank (declared in function main)
        program examples p. 38, 39 of slides
      • In C: MPI_Comm_rank(MPI_COMM_WORLD, &rank)
      • In C++: MPI::COMM_WORLD.Get_rank()

    4. MPI_SEND
      • Sending an array of double: double data[100]
        count=100
        program examples p. 69-72 of slides
      • In C: MPI_Send(data, count, MPI_DOUBLE, dest, tag, MPI_COMM_WORLD)
      • In C++: MPI::COMM_WORLD.Send(data, count, MPI::DOUBLE, dest, tag)

    5. MPI_RECV
      • Receiving an array of double: double data[100]
        count=100
        program examples p. 69-72 of slides
      • In C: MPI_Recv(data, count, MPI_DOUBLE, from, tag, MPI_COMM_WORLD, &status)
      • In C++: MPI::COMM_WORLD.Recv(data, count, MPI::DOUBLE, from, tag, status)

    6. MPI_FINALIZE
      • program example p. 28, 29 of slides
      • In C: MPI_Finalize()
      • In C++: MPI::Finalize()

    7. MPI Data types:
      • C: p. 53, 54 of slides
      • C++: p. 55, 56