Open MPI logo

MPI_Finalize(3) man page (version 5.0.0rc2)

  |   Home   |   Support   |   FAQ   |  

« Return to documentation listing

Table of Contents


C]MPI_FinalizeR] - Terminates MPI execution environment.


C Syntax

C]#include <mpi.h>int MPI_Finalize()R]Fortran Syntax

C]USE MPI! or the older form: INCLUDE [aq]mpif.h[aq]MPI_FINALIZE(IERROR) INTEGER IERRORR]Fortran 2008 Syntax

C]USE mpi_f08MPI_Finalize(ierror) INTEGER, OPTIONAL, INTENT(OUT) :: ierrorR]Output Parameter

C]IERRORR] : Fortran only: Error status (integer).


This routine cleans up all MPI states. Once this routine is called, no MPI routine (not even C]MPI_InitR]) may be called, except for C]MPI_Get_versionR], C]MPI_InitializedR], and C]MPI_FinalizedR]. Unless there has been a call to C]MPI_AbortR], you must ensure that all pending communications involving a process are complete before the process calls C]MPI_FinalizeR]. If the call returns, each process may either continue local computations or exit without participating in further communication with other processes. At the moment when the last process calls C]MPI_FinalizeR], all pending sends must be matched by a receive, and all pending receives must be matched by a send.

C]MPI_FinalizeR] is collective over all connected processes. If no processes were spawned, accepted, or connected, then this means it is collective over C]MPI_COMM_WORLDR]. Otherwise, it is collective over the union of all processes that have been and continue to be connected.


All processes must call this routine before exiting. All processes will still exist but may not make any further MPI calls. C]MPI_FinalizeR] guarantees that all local actions required by communications the user has completed will, in fact, occur before it returns. However, C]MPI_FinalizeR] guarantees nothing about pending communications that have not been completed; completion is ensured only by C]MPI_WaitR], C]MPI_Test,R] or C]MPI_Request_freeR] combined with some other verification of completion.

For example, a successful return from a blocking communication operation or from C]MPI_WaitR] or C]MPI_TestR] means that the communication is completed by the user and the buffer can be reused, but does not guarantee that the local process has no more work to do. Similarly, a successful return from C]MPI_Request_freeR] with a request handle generated by an C]MPI_IsendR] nullifies the handle but does not guarantee that the operation has completed. The C]MPI_IsendR] is complete only when a matching receive has completed.

If you would like to cause actions to happen when a process finishes, attach an attribute to C]MPI_COMM_SELFR] with a callback function. Then, when C]MPI_FinalizeR] is called, it will first execute the equivalent of an C]MPI_Comm_freeR] on C]MPI_COMM_SELFR]. This will cause the delete callback function to be executed on all keys associated with C]MPI_COMM_SELFR] in an arbitrary order. If no key has been attached to C]MPI_COMM_SELFR], then no callback is invoked. This freeing of C]MPI_COMM_SELFR] happens before any other parts of MPI are affected. Calling C]MPI_FinalizedR] will thus return [lq]false[rq] in any of these callback functions. Once you have done this with C]MPI_COMM_SELFR], the results of C]MPI_FinalizeR] are not specified.


Almost all MPI routines return an error value; C routines as the value of the function and Fortran routines in the last argument.

Before the error value is returned, the current MPI error handler is called. By default, this error handler aborts the MPI job, except for I/O function errors. The error handler may be changed with C]MPI_Comm_set_errhandlerR]; the predefined error handler C]MPI_ERRORS_RETURNR] may be used to cause error values to be returned. Note that MPI does not guarantee that an MPI program can continue past an error.

See Also

C]MPI_InitR](3) C]MPI_Init_threadR](3) C]MPI_InitializedR](3) C]MPI_FinalizedR](3)

Table of Contents

« Return to documentation listing