MPI 检查通讯器是否 MPI_COMM_WORLD
MPI Check if communicator is MPI_COMM_WORLD
我需要检查 MPI 通信器是否 MPI_COMM_WORLD comm
。这意味着所有处理器都在这个通信器中。
我试过了
int isCommWolrd(MPI_Comm comm) {
int size_comm = 0;
int size_comm_world = 0;
MPI_Comm_size(comm, &size_comm);
MPI_Comm_size(MPI_COMM_WORLD, &size_comm_world);
return (size_comm == size_comm_world);
}
只检查通信器的尺寸是否足够。会不会出现阴性的假阳性?
使用MPI_Comm_compare()
并检查结果是MPI_IDENT
int MPI_Comm_compare(MPI_Comm comm1, MPI_Comm comm2, int *result)
MPI_IDENT results if and only if comm1 and comm2 are handles for the same object (identical groups and same contexts).
MPI_CONGRUENT
results if the underlying groups are identical in constituents and rank order; these communicators differ only by context.
MPI_SIMILAR
results of the group members of both communicators are the same but the rank order differs. MPI_UNEQUAL results otherwise.
你的方法会导致误报。例如,如果您 MPI_Comm_dup(MPI_COMM_WORLD, &comm)
,那么生成的 comm
与 MPI_COMM_WORLD
具有相同的大小,但它是不同的通信器。
我需要检查 MPI 通信器是否 MPI_COMM_WORLD comm
。这意味着所有处理器都在这个通信器中。
我试过了
int isCommWolrd(MPI_Comm comm) {
int size_comm = 0;
int size_comm_world = 0;
MPI_Comm_size(comm, &size_comm);
MPI_Comm_size(MPI_COMM_WORLD, &size_comm_world);
return (size_comm == size_comm_world);
}
只检查通信器的尺寸是否足够。会不会出现阴性的假阳性?
使用MPI_Comm_compare()
并检查结果是MPI_IDENT
int MPI_Comm_compare(MPI_Comm comm1, MPI_Comm comm2, int *result)
MPI_IDENT results if and only if comm1 and comm2 are handles for the same object (identical groups and same contexts). MPI_CONGRUENT results if the underlying groups are identical in constituents and rank order; these communicators differ only by context. MPI_SIMILAR results of the group members of both communicators are the same but the rank order differs. MPI_UNEQUAL results otherwise.
你的方法会导致误报。例如,如果您 MPI_Comm_dup(MPI_COMM_WORLD, &comm)
,那么生成的 comm
与 MPI_COMM_WORLD
具有相同的大小,但它是不同的通信器。