Rookie HPC

About

Docs

Tools

Tests

MPI_Comm_get_name

Definition

MPI_Comm_get_name gets the name of a communicator.

Copy

Feedback

int MPI_Comm_get_name(MPI_Comm comm,
                      char* name,
                      int* length);

Parameters

comm
The communicator to query.
name
The variable in which store the name assigned to the communicator given, or an empty string if no name has been assigned to this communicator yet. The exception being the three predefined communicators: MPI_COMM_WORLD, MPI_COMM_SELF and the communicator returned by MPI_Comm_get_parent (if not MPI_COMM_NULL), which are assigned the names “MPI_COMM_WORLD”, “MPI_COMM_SELF” and “MPI_COMM_PARENT” by default (although this can be overriden at any time). The array passed must be already allocated and able to hold up to MPI_MAX_OBJECT_NAME characters.
length
The variable in which store the length of the name obtained.

Returned value

MPI_SUCCESS
The routine successfully completed.

Example

Copy

Feedback

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

/**
 * @brief Illustrates how to get the name of a communicator.
 **/
int main(int argc, char* argv[])
{
    MPI_Init(&argc, &argv);

    // Get the name of the default communicator
    char name[MPI_MAX_OBJECT_NAME];
    int name_length;
    MPI_Comm_get_name(MPI_COMM_WORLD, name, &name_length);
    printf("The default communicator is named \"%s\".\n", name);

    MPI_Finalize();

    return EXIT_SUCCESS;
}