我想为网格中对角线上的处理器创建一个通信器组。这是我的尝试,但在运行代码后它给了我一条错误信息。为什么会出现此错误消息
#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;
}
这是错误消息:
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]
答案 0 :(得分:1)
为什么不简单地使用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);
拆分操作组根据指定为第二个参数的“颜色”进行排名。颜色MPI_UNDEFINED
表示排名不想参与拆分,而是返回MPI_COMM_NULL
而不是新的子通讯器句柄。