There are times in which it would be convenient to have actions happen when an MPI-/ process finishes. For example, a routine may do initializations that are useful until the MPI-/ job (or that part of the job that being terminated in the case of dynamically created processes) is finished. This can be accomplished in MPI-// by attaching an attribute to MPI_COMM_SELF with a callback function. When MPI_FINALIZE is called, it will first execute the equivalent of an MPI_COMM_FREE on MPI_COMM_SELF. This will cause the delete callback function to be executed on all keys associated with MPI_COMM_SELF, in an arbitrary order. If no key has been attached to MPI_COMM_SELF, then no callback is invoked. The ``freeing'' of MPI_COMM_SELF occurs before any other parts of MPI-/ are affected. Thus, for example, calling MPI_FINALIZED will return false in any of these callback functions. Once done with MPI_COMM_SELF, the order and rest of the actions taken by MPI_FINALIZE is not specified.
MPI-Standard for MARMOT