Missing MPI Finalize

From HPCBugBase

Jump to: navigation, search

HPCBugBase Menu

Submit feedback


Overview


Index


Index by Languages

Contents

[edit] Fault Description

The MPI specification says that all processes must call MPI_Finalize before exiting. Failing to call MPI_Finalize in an execution path where MPI_Init was called is a defect. The possible outcome includes:

  • Resources allocated by the MPI library are left unallocated (at least until they are collected by the operation system after the application exits).
  • Since the call of MPI_Finalize implies an implicit barrier in some implementation, runtime failures can occur if some process exits without calling it while other processes are still performing MPI operations.

The typical scenario is that MPI_Finalize is forgotten in an error checking branch. Here's an example.

#include <mpi.h>
#include <stdio.h>
int main(int argc, char**argv)
{
    FILE *fp;
    MPI_Status status;
    status = MPI_Init(&argc, &argv);
    if (status != MPI_SUCCESS) {
        return -1;
    }
    fp = fopen(...);
    if (fp == NULL) {
        // Missing MPI_Finalize
        return -1;
    }
    ...
    fclose(fp);
    MPI_Finalize();
    return 0;
}

In the example above, the program exits without calling MPI_Finalize when the file open has failed.

In a slightly modified version of the above code, Deadlock can occur if the rank-0 process failed to open the file (unless the implementation detects one of the processes has terminated).

if (rank == 0) {
    fp = fopen(...);
    if (fp == NULL) {
        // Missing MPI_Finalize
        exit(-1);
    }
    ...
    fclose(fp);
}
MPI_Bcast( ... );

[edit] Statistics (Frequency)

[edit] Other Findings and Contexts

Pages referring to this entry: Six Most Basic MPI Functions Use of Language Features 

Personal tools