Nawal
Nawal

Reputation: 77

MPI_Comm_create error

I want to create a communicator group for the processors along the diagonal in a grid. here is my attempt but it gives me an error message after running tho code. Why is this error message

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

int main(int argc, char  **argv)
{

    int i,iproc, index;
    int Numprocs, MyRank;
    int New_numprocs, NewMyRank;
    int *process_rank, Group_Diag;
int diag;
    MPI_Group   GroupWorld,new_group;
    MPI_Comm    Diag_Group , newComm; 

int track =0;
  /* ....MPI Initialisation....*/

    MPI_Init(&argc, &argv); 
    MPI_Comm_rank(MPI_COMM_WORLD, &MyRank);
    MPI_Comm_size(MPI_COMM_WORLD, &Numprocs);


    diag = sqrt(Numprocs);
    if(diag * diag != Numprocs)
        {
        printf("number of processes should be a perfect square\n");
        MPI_Finalize();
        exit(-1);
        }

        process_rank = (int *)malloc(diag * sizeof(int));
        for(int idx =0; idx < diag ; idx ++)
        {

        process_rank[idx] = track;  
        track = track + diag + 1;
        printf("rank : %d , track %d\n " , MyRank , track);
        }
        MPI_Comm_group(MPI_COMM_WORLD , &GroupWorld);
        MPI_Group_incl(GroupWorld, diag , process_rank , &new_group);
        MPI_Comm_create(MPI_COMM_WORLD , new_group , &newComm);
        if(MyRank % (diag+1) ==0)
            {
            MPI_Comm_rank(newComm , &NewMyRank);
            MPI_Comm_size(newComm , &Numprocs);
            printf("old rank : %d , new rank %d" , MyRank , NewMyRank);
            }

    MPI_Finalize(); 
return 0;
}

and this is the error message:

24 at [0x0000000000e97078], src/mpi/group/grouputil.c[74]
[1] 48 at [0x0000000000e984b8], src/mpi/group/grouputil.c[74]
[2] 24 at [0x0000000001c39078], src/mpi/group/grouputil.c[74]
[2] 48 at [0x0000000001c3a4b8], src/mpi/group/grouputil.c[74]
[0] 8 at [0x0000000000d377f8], src/util/procmap/local_proc.c[93]
[0] 8 at [0x0000000000d37748], src/util/procmap/local_proc.c[92]
[0] 32 at [0x0000000000d37678], src/mpid/ch3/src/mpid_vc.c[102]
[0] 24 at [0x0000000000d36078], src/mpi/group/grouputil.c[74]
[0] 48 at [0x0000000000d374b8], src/mpi/group/grouputil.c[74]
[0] 504 at [0x0000000000d35a78], src/mpi/comm/commutil.c[258]
[0] 504 at [0x0000000000d357d8], src/mpi/comm/commutil.c[258]
[0] 504 at [0x0000000000d35298], src/mpi/comm/commutil.c[258]
[3] 8 at [0x00000000012487f8], src/util/procmap/local_proc.c[93]
[3] 8 at [0x0000000001248748], src/util/procmap/local_proc.c[92]
[3] 32 at [0x0000000001248678], src/mpid/ch3/src/mpid_vc.c[102]
[3] 24 at [0x0000000001247078], src/mpi/group/grouputil.c[74]
[3] 48 at [0x00000000012484b8], src/mpi/group/grouputil.c[74]
[3] 504 at [0x0000000001246a78], src/mpi/comm/commutil.c[258]
[3] 504 at [0x0000000001246298], src/mpi/comm/commutil.c[258]

Upvotes: 0

Views: 251

Answers (1)

Hristo Iliev
Hristo Iliev

Reputation: 74485

Why don't you simply use MPI_Comm_split?

int rank;
MPI_Comm newComm;

MPI_Comm_rank(MPI_COMM_WORLD, &rank);

MPI_Comm_split(MPI_COMM_WORLD, rank % (diag+1) ? MPI_UNDEFINED : 0, rank, &newComm);

if (newComm != MPI_COMM_NULL)
{
  // Code for ranks on the main diagonal
}
else
{
  // Code for off-diagonal ranks
}

MPI_Comm_free(&newComm);

The split operation groups ranks according to the "colour" specified as the second argument. A colour of MPI_UNDEFINED means that the rank doesn't want to participate in the split and MPI_COMM_NULL is returned instead of a new subcommunicator handle.

Upvotes: 1

Related Questions