MPI通讯模式 [英] MPI Communication Pattern
本文介绍了MPI通讯模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道是否有一个聪明的方法来做到这一点.假设我有三个节点,0、1、2.还说每个节点都有一个数组a0,a1,a2.如果每个节点的内容都类似
I was wondering if there was a smart way to do this. Let's say I have three nodes, 0, 1, 2. And let's say each node has an array, a0, a1, a2. If the contents of each node is something like
a0 = {0, 1, 2, 1}
a1 = {1, 2, 2, 0}
a2 = {0, 0, 1, 2}
是否存在一种巧妙的通信模式,以便将每个数字移至其对应的节点,即
Is there a clever communication pattern so to move each number to it's corresponding node, i.e.
a0 = {0, 0, 0, 0}
a1 = {1, 1, 1, 1}
a2 = {2, 2, 2, 2}
我想到的方法将涉及排序和临时缓冲区,但我想知道是否有更聪明的方法?
The approach I have in mind, would involve sorting and temporary buffers, but I was wondering if there was a smarter way?
推荐答案
您可以通过以下方式为此使用MPI_Alltoallv
:
You can use MPI_Alltoallv
for this in the following way:
- 将
local_data
(a
)按每个元素的相应节点升序排列. - 创建一个
send_displacements
数组,使send_displacements[r]
表示local_data
中引用节点r
的第一个元素的索引. - 创建一个
send_counts
数组,以使send_counts[r]
等于local_data
中与节点r
相对应的元素数.可以计算send_counts[r] = send_displacements[r+1] - send_displacements[r]
,除了最后一个排名. -
MPI_Alltoall(send_counts, 1, MPI_INT, recv_counts, 1, MPI_INT, comm)
- 计算
recv_displacements
使得recv_displacements[r] = sum(recv_counts[r'] for all r' < r)
. - 准备具有sum(recv_counts)个元素的
recv_data
. -
MPI_Alltoallv(local_data, send_counts, send_displacements, MPI_INT, recv_data, recv_counts, recv_displacements, MPI_INT, comm)
- Sort the
local_data
(a
) by corresponding node of each element in increasing order. - Create a
send_displacements
array such thatsend_displacements[r]
indicates the index of the first element in thelocal_data
that refers to noder
. - Create a
send_counts
array such thatsend_counts[r]
equals the number of elements inlocal_data
that correspond to noder
. This can be computedsend_counts[r] = send_displacements[r+1] - send_displacements[r]
except for the last rank. MPI_Alltoall(send_counts, 1, MPI_INT, recv_counts, 1, MPI_INT, comm)
- Compute
recv_displacements
such thatrecv_displacements[r] = sum(recv_counts[r'] for all r' < r)
. - Prepare a
recv_data
with sum(recv_counts) elements. MPI_Alltoallv(local_data, send_counts, send_displacements, MPI_INT, recv_data, recv_counts, recv_displacements, MPI_INT, comm)
这篇关于MPI通讯模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文