MPI_FINALIZE, MPI_Finalize Purpose Terminates all MPI processing. C synopsis #include int MPI_Finalize(void); C++ synopsis #include mpi.h void MPI::Finalize(); FORTRAN synopsis include 'mpif.h' or use mpi MPI_FINALIZE(INTEGER IERROR) Parameters IERROR is the FORTRAN return code. It is always the last argument. Description Make sure this subroutine is the last MPI call. Any MPI calls made after MPI_FINALIZE raise an error. You must be sure that all pending communications involving a task have completed before the task calls MPI_FINALIZE. You must also be sure that all files opened by the task have been closed before the task calls MPI_FINALIZE. Although MPI_FINALIZE terminates MPI processing, it does not terminate the task. It is possible to continue with non-MPI processing after calling MPI_FINALIZE, but no other MPI calls (including MPI_INIT) can be made. In a threads environment, both MPI_INIT and MPI_FINALIZE must be called on the same thread. MPI_FINALIZE closes the communication library and terminates the service threads. It does not affect any threads you created, other than returning an error if one subsequently makes an MPI call. If you had registered a SIGIO handler, it is restored as a signal handler; however, the SIGIO signal is blocked when MPI_FINALIZE returns. If you want to catch SIGIO after MPI_FINALIZE has been called, you should unblock it. At MPI_FINALIZE there is now an implicit MPI_COMM_FREE of MPI_COMM_SELF. Because MPI_COMM_SELF cannot have been freed by user code and cannot be used after MPI_FINALIZE, there is no direct effect of this change. The value of this implicit free is that any attribute that a user may attach to MPI_COMM_SELF will be deleted in MPI_FINALIZE and its attribute delete function called. A library layered on MPI can take advantage of this to force its own cleanup code to run whenever MPI_FINALIZE gets called. This is done by packaging the cleanup logic as an attribute delete function and attaching an attribute to MPI_COMM_SELF. It is legitimate to make MPI calls in the attribute callbacks and a call to MPI_FINALIZED inside a delete function will report that MPI is still active. If an attribute delete function returns a non-zero return code, the code it does return is passed to the error handler associated with MPI_COMM_WORLD. The default handler, MPI_ERROR_ARE_FATAL, will embed the error code in the message it prints. If there is a returning error handler on MPI_COMM_WORLD, MPI_FINALIZE will return a code indicating that a delete callback failed. MPI_FINALIZE does not return the error return code issued by the delete function. Notes The MPI standard does not specify the state of MPI tasks after MPI_FINALIZE, therefore, an assumption that all tasks continue may not be portable. If MPI_BUFFER_ATTACH has been used and MPI_BUFFER_DETACH has been not called, there will be an implicit MPI_BUFFER_DETACH within MPI_FINALIZE. See MPI_BUFFER_DETACH. Errors MPI_COMM_SELF attribute delete function returned error MPI already finalized MPI not initialized Related information MPI_ABORT MPI_BUFFER_DETACH MPI_INIT