MPI通讯模式 [英] MPI Communication Pattern

查看:254
本文介绍了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:

  1. local_data(a)按每个元素的相应节点升序排列.
  2. 创建一个send_displacements数组,使send_displacements[r]表示local_data中引用节点r的第一个元素的索引.
  3. 创建一个send_counts数组,以使send_counts[r]等于local_data中与节点r相对应的元素数.可以计算send_counts[r] = send_displacements[r+1] - send_displacements[r],除了最后一个排名.
  4. MPI_Alltoall(send_counts, 1, MPI_INT, recv_counts, 1, MPI_INT, comm)
  5. 计算recv_displacements使得recv_displacements[r] = sum(recv_counts[r'] for all r' < r).
  6. 准备具有sum(recv_counts)个元素的recv_data.
  7. MPI_Alltoallv(local_data, send_counts, send_displacements, MPI_INT, recv_data, recv_counts, recv_displacements, MPI_INT, comm)
  1. Sort the local_data (a) by corresponding node of each element in increasing order.
  2. Create a send_displacements array such that send_displacements[r] indicates the index of the first element in the local_data that refers to node r.
  3. Create a send_counts array such that send_counts[r] equals the number of elements in local_data that correspond to node r. This can be computed send_counts[r] = send_displacements[r+1] - send_displacements[r] except for the last rank.
  4. MPI_Alltoall(send_counts, 1, MPI_INT, recv_counts, 1, MPI_INT, comm)
  5. Compute recv_displacements such that recv_displacements[r] = sum(recv_counts[r'] for all r' < r).
  6. Prepare a recv_data with sum(recv_counts) elements.
  7. MPI_Alltoallv(local_data, send_counts, send_displacements, MPI_INT, recv_data, recv_counts, recv_displacements, MPI_INT, comm)

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

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