The call to MPI_FINALIZE should occur on the same thread that initialized MPI-/. We call this thread the main thread. The call should occur only after all the process threads have completed their MPI-/ calls, and have no pending communications or I/O operations.
MPI-Standard for MARMOT