Rookie HPC

About

Docs

Tools

Tests

MPI_Comm_set_name

Definition

MPI_Comm_set_name assigns a name to a communicator. This is a local operation; the change is only visible on the MPI process calling the routine.

Copy

Feedback

int MPI_Comm_set_name(MPI_Comm comm,
                      const char* name);

Parameters

comm
The communicator concerned.
name
The name to assign to the communicator. A copy of the name will be made, so that if the variable given was dynamically allocated, it can be freed safely after the call. Leading spaces in the name passed are significant, but the trailing ones are not.

Returned value

MPI_SUCCESS
The routine successfully completed.

Example

Copy

Feedback

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

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

    // Set the name of the default communicator
    char name[] = "My default communicator";
    MPI_Comm_set_name(MPI_COMM_WORLD, name);

    // Get the name of the default communicator and print it
    char verification_name[MPI_MAX_OBJECT_NAME];
    int verification_name_length;
    MPI_Comm_get_name(MPI_COMM_WORLD, verification_name, &verification_name_length);
    printf("The default communicator has been renamed as \"%s\".\n", verification_name);

    MPI_Finalize();

    return EXIT_SUCCESS;
}