Initialization and Exit

next up previous contents
Next: Error Handling Up: Environmental Management Previous: Timers and Synchronization

Initialization and Exit

initializationexit   One goal of MPI is to achieve source code portability. By this we mean that a program written using MPI and complying with the relevant language standards is portable as written, and must not require any source code changes when moved from one system to another. This explicitly does not say anything about how an MPI program is started or launched from the command line, nor what the user must do to set up the environment in which an MPI program will run. However, an implementation may require some setup to be performed before other MPI routines may be called. To provide for this, MPI includes an initialization routine MPI_INIT.

MPI_Init(int *argc, char ***argv)


This routine must be called before any other MPI routine. It must be called at most once; subsequent calls are erroneous (see MPI_INITIALIZED).

All MPI programs must contain a call to MPI_INIT; this routine must be called before any other MPI routine (apart from MPI_INITIALIZED) is called. The version for ANSI C accepts the argc and argv that are provided by the arguments to main:

int main(argc, argv)
int argc;
char **argv;
    MPI_Init(&argc, &argv);

    /* parse arguments */
    /* main program    */

    MPI_Finalize();     /* see below */

The Fortran version takes only IERROR.

An MPI implementation is free to require that the arguments in the C binding must be the arguments to main.



This routines cleans up all MPI state. Once this routine is called, no MPI routine (even MPI_INIT) may be called. The user must ensure that all pending communications involving a process complete before the process calls MPI_FINALIZE.


    OUT       flag            Flag is true if MPI_INIT has been called
                               and false otherwise
MPI_Initialized(int *flag)


This routine may be used to determine whether MPI_INIT has been called. It is the only routine that may be called before MPI_INIT is called.

 MPI_ABORT(comm, errorcode)

    IN  comm      communicator of tasks to abort
    IN  errorcode error code to return to invoking

MPI_Abort(MPI_Comm comm, int errorcode)


This routine makes a ``best attempt'' to abort all tasks in the group of comm. This function does not require that the invoking environment take any action with the error code. However, a Unix or POSIX environment should handle this as a return errorcode from the main program or an abort(errorcode).

MPI implementations are required to define the behavior of MPI_ABORT at least for a comm of MPI_COMM_WORLD. MPI implementations may MPI_COMM_WORLD ignore the comm argument and act as if the comm was MPI_COMM_WORLD.

 Advice to users. The behavior of MPI_ABORT
     (comm, errorcode),for comm other then MPI_COMM_WORLD, 
     is implementation-dependent. One the other hand, a call to 
     MPI_ABORT(MPI_COMM_WORLD, errorcode) should always cause all 
     processes in the group of MPI_COMM_WORLD to abort . 
     (End of advice to users) 

next up previous contents
Next: Error Handling Up: Environmental Management Previous: Timers and Synchronization

Jack Dongarra
Fri Sep 1 06:16:55 EDT 1995