Rookie HPC

Miscellaneous

C | FORTRAN-legacy | FORTRAN-2008

MPI_Init

Definition

MPI_Init initialises the MPI environment, it is equivalent to invoking MPI_Init_thread with the MPI_THREAD_SINGLE thread support level. The MPI_Init routine must be called by each MPI process, once and before any other MPI routine.

Copy

Feedback

int MPI_Init(int* argc,
             char*** argv);

Parameters

argc
The number of arguments passed through main, or NULL.
argv
The argument values passed through main, or NULL.

Returned value

The error code returned during the initialisation.

MPI_SUCCESS
The routine successfully completed.

Example

Copy

Feedback

#include <stdio.h>
#include <stdlib.h>
#include <mpi.h>

/**
 * @brief Illustrates how to initialise the MPI environment.
 **/
int main(int argc, char* argv[])
{
    // Initilialise MPI and check its completion
    MPI_Init(&argc, &argv);

    // Get my rank
    int my_rank;
    MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);

    printf("Process %d has initialised its MPI environment.\n", my_rank);

    // Tell MPI to shut down.
    MPI_Finalize();

    return EXIT_SUCCESS;
}