MPI_Comm_split说明 [英] MPI_Comm_split explanation
问题描述
有人可以向我解释并告诉我有关MPI_Comm_split通信器的更多信息吗?
Can someone explain and tell me more about MPI_Comm_split communicator?
MPI_Comm_split(MPI_COMM_WORLD, my_row, my_rank,&my_row_comm);
这只是我通过阅读一些基本文档遇到的示例.也许有人可以告诉我此沟通工具的工作方式?
This is just example i met by reading some basic documentations. Maybe someone could tell me how this communicator is working?
推荐答案
首先,让我们看一下手册页:
Just to begin with, let's have a look at the man page:
MPI_Comm_split(3) MPI MPI_Comm_split(3)
NAME
MPI_Comm_split - Creates new communicators based on colors and keys
SYNOPSIS
int MPI_Comm_split(MPI_Comm comm, int color, int key, MPI_Comm *newcomm)
INPUT PARAMETERS
comm - communicator (handle)
color - control of subset assignment (nonnegative integer). Processes
with the same color are in the same new communicator
key - control of rank assignment (integer)
OUTPUT PARAMETERS
newcomm
- new communicator (handle)
那怎么办?
嗯,顾名思义,它将把传播器comm
分解成 disjoint 子传播器newcomm
. comm
的每个进程将成为这些子通信器中唯一的一个,因此,输出newcomm
仅是一个单个通信器(对于当前进程).但是,从全局上来说,您必须了解newcomm
的许多版本是不同的子通信器,将输入comm
划分为分区.
So what does that do?
Well, as the name suggests, it will split the communicator comm
into disjoint sub-communicators newcomm
. Each process of comm
will be into one unique of these sub-communicators, hence the fact that the output newcomm
is only one single communicator (for the current process). However, globally speaking, you have to understand that the many versions of newcomm
are different sub-communicators, partitioning the input comm
.
这就是函数的作用.但是它是怎么做到的呢?
嗯,这就是两个参数color
和key
起作用的地方:
So that is what the function does. But how does it do it?
Well, that's where the two parameters color
and key
come into play:
-
color
是一个整数值,它允许确定当前进程将落入哪个子通信器中.更具体地说,comm
的所有具有相同数值的comm
进程将是同一子通信器newcomm
的一部分.例如,如果要定义color = rank%2;
(comm
中进程的等级为rank
),则将创建(全局)两个新的通信器:一个用于奇数级进程,另一个用于偶数级的过程.但是,请记住,每个过程只会看到它们属于其中的这些新的传播者之一.因此,总而言之,color
允许区分您将创建的各个团队",例如球衣足球队将在比赛中穿脱以彰显自己的个性(因此我以为是这样命名). -
key
仅允许选择决定如何将这些过程分类为它们所属的新通信器.例如,如果设置key = rank;
,则每个新传播者newcomm
中排名的顺序(而不是排名本身)将遵循原始传播者comm
中的排名顺序.但是,如果您不关心顺序,也可以设置key=0;
,并且每个新传播者的排名将由图书馆决定...
color
is an integer value that permits to decide in which of the sub-communicators the current process will fall. More specifically, all processes ofcomm
for whichcolor
will have the same numerical value will be part of the same sub-communicatornewcomm
. For example, if you were to definecolor = rank%2;
(withrank
the rank of the process incomm
), then you would create (globally) two new communicators: one for the processes of odd ranks, and one for the processes of even ranks. However, keep in mind that each processes will only be seeing the one of these new communicators they are part of... So in summary,color
permits to tell apart the various "teams" you will create, like the colour of the jersey football teams will wear to distinguish themselves during a match (hence the naming I presume).key
will just permit to optionally decide how the processes will be ranked into the new communicators they are part of. For example, if you setkey = rank;
, then the order of ranking (not the ranking itself) in each new communicatorsnewcomm
will follow the order of ranking in the original communicatorcomm
. But if you don't care about the ordering, you can as well setkey=0;
and the ranking in each of the new communicators will be whatever the library decides...
最后,举两个简单的例子:
Finally, two trivial examples:
-
MPI_Comm_split(comm, 0, rank, &newcomm)
只会将comm
复制到newcomm
中(与MPI_Comm_dup()
一样) -
MPI_Comm_split(comm, rank, rank, &newcomm)
只会为每个进程返回等效的MPI_COMM_SELF
MPI_Comm_split(comm, 0, rank, &newcomm)
will just duplicatecomm
intonewcomm
(just asMPI_Comm_dup()
)MPI_Comm_split(comm, rank, rank, &newcomm)
will just return an equivalent ofMPI_COMM_SELF
for each of the processes
这篇关于MPI_Comm_split说明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!