我需要将流程分成几个沟通者。在一个写甚至,和其他奇数。我编写了代码,但是当我运行它时,我会收到错误。帮助理解什么是问题。或者以正确的方式告诉我。抱歉英语不好。
int world_rank, world_size;
int *odd, *even;
MPI_Comm_rank(MPI_COMM_WORLD, &world_rank);
MPI_Comm_size(MPI_COMM_WORLD, &world_size);
int oddSize = world_size / 2;
int evenSize = world_size - oddSize;
odd = new int[oddSize];
even = new int[evenSize];
MPI_Comm odd_comm, even_comm;
MPI_Group odd_group, even_group, group_world;
MPI_Comm_group(MPI_COMM_WORLD, &group_world);
for (int i = 0, j = 0, p = 0; i < world_size; i++)
{
if (i % 2 == 0)
{
odd[j] = i;
j++;
}
else
{
even[p] = i;
p++;
}
}
MPI_Group_incl(group_world, oddSize, odd, &odd_group);
MPI_Comm_create(MPI_COMM_WORLD, odd_group, &odd_comm);
}
我的错误记录:
job aborted:
[ranks] message
[0] terminated
[1] fatal error
Fatal error in MPI_Comm_rank: Invalid communicator, error stack:
MPI_Comm_rank(MPI_COMM_NULL, rank=0x0111FC70) failed
Invalid communicator
[2] terminated
[3] fatal error
Fatal error in MPI_Comm_rank: Invalid communicator, error stack:
MPI_Comm_rank(MPI_COMM_NULL, rank=0x009FFDB8) failed
Invalid communicator
[4] terminated
[5] fatal error
Fatal error in MPI_Comm_rank: Invalid communicator, error stack:
MPI_Comm_rank(MPI_COMM_NULL, rank=0x00BDF7E4) failed
Invalid communicator
---- error analysis -----
[1,3,5,9,17] on DRON