MPI_Comm_create

MPI_Comm_create

MPI_Comm_create creates a new communicator to include specified processes from an existing communicator.

Fortran Syntax

Subroutine MPI_Comm_create(old_comm, new_group, new_comm, ierr)

C Syntax

int MPI_Cart_create(MPI_Comm old_comm, MPI_Group *new_group, MPI_Comm *new_comm)


Example in Fortran


     include "mpif.h"
     integer comm_world, group_world, comm_worker, group_worker, ierr

     comm_world = MPI_COMM_WORLD
     call MPI_Comm_group(comm_world, group_world, ierr)
     call MPI_Group_excl(group_world, 1, 0, group_worker, ierr)  ! process 0 not member

     call MPI_Comm_create(comm_world, group_worker, comm_worker, ierr)

Example in C


  #include "mpi.h";
  MPI_Comm  comm_world, comm_worker;
  MPI_Group group_world, group_worker;
  int ierr;

  comm_world = MPI_COMM_WORLD;
  MPI_Comm_group(comm_world, &group_world);
  MPI_Group_excl(group_world, 1, 0, &group_worker);  /* process 0 not member */

  MPI_Comm_create(comm_world, group_worker, &comm_worker);

In the above example, first we identify the MPI_COMM_WORLD communicator’s group handle. Then we create a new group, group_worker, consisting of all but process 0 of MPI_COMM_WORLD as members by way of MPI_Group_excl. Finally, MPI_Comm_create is used to create a new communicator whose member processes are those of the new group just created. With this new communicator, message passing can now proceed among its member processes.

Upon completion of task, the created communicator may be released by calling MPI_Comm_free.