MPI_Comm_split说明 [英] MPI_Comm_split explanation

查看:270
本文介绍了MPI_Comm_split说明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以向我解释并告诉我有关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.

这就是函数的作用.但是它是怎么做到的呢?
嗯,这就是两个参数colorkey起作用的地方:

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 of comm for which color will have the same numerical value will be part of the same sub-communicator newcomm. For example, if you were to define color = rank%2; (with rank the rank of the process in comm), 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 set key = rank;, then the order of ranking (not the ranking itself) in each new communicators newcomm will follow the order of ranking in the original communicator comm. But if you don't care about the ordering, you can as well set key=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 duplicate comm into newcomm (just as MPI_Comm_dup())
  • MPI_Comm_split(comm, rank, rank, &newcomm) will just return an equivalent of MPI_COMM_SELF for each of the processes

这篇关于MPI_Comm_split说明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆