Next: MPI Indispensable Functions Previous: Fortran versus C

## Initialization, Communicators, Handles, and Clean-Up

The first MPI routine called in any MPI program must be the initialization routine MPI_Init(). Every MPI program must call this routine once, before any other MPI routines. Making multiple calls to MPI_Init() is erroneous. The C version of the routine accepts the arguments to `main`, namely `argc` and `argv` as arguments.

MPI_Init() defines something called MPI_COMM_WORLD for each process that calls it.
MPI_COMM_WORLD is a communicator. All MPI communication calls require a communicator argument and MPI processes can only communicate if they share a communicator.

Every communicator contains a group which is a list of processes. Secondly, a group is in fact local to a particular process. The group contained within a communicator has been previously agreed across the processes at the time when the communicator was set up. The processes are ordered and numbered consecutively from zero, the number of each process being known as its rank. The rank identifies each process within the communicator. The group of MPI_COMM_WORLD is the set of all MPI processes.

MPI maintains internal data structures related to communications etc. and these are referenced by the user through handles. Handles are returned to the user from some MPI calls and can be used in other MPI calls.

An MPI program should call the MPI routine MPI_Finalize() when all communications have completed. This routine cleans up all MPI data structures etc. It does NOT cancel outstanding communications, so it is the responsibility of the programmer to make sure all communications have completed. Once this routine is called, no other calls can be made to MPI routines, not even MPI_INIT, so a process cannot later re-enroll in MPI.