MPI_SCAN的收集结果 [英] Gathering results of MPI_SCAN

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

问题描述

我有这个数组[1 2 3 4 5 6 7 8 9],我正在对此进行扫描操作.

I have this array [1 2 3 4 5 6 7 8 9] and i am performing scan operation on that.

我有3个mpi任务,每个任务包含3个元素,然后每个任务计算其扫描并将结果返回给主任务

I have 3 mpi tasks and each task gets 3 elements then each task calculates its scan and returns result to master task

task 0 - [1 2 3] => [1 3 6] 
task 1 - [4 5 6 ] => [4 9 15] 
task 2 - [7 8 9] => [7 15 24]

现在任务0获得所有结果[1 3 6] [4 9 15] [7 15 24]

Now task 0 gets all the results [1 3 6] [4 9 15] [7 15 24]

如何合并这些结果以产生最终扫描输出?

How can I combine these results to produce final scan output?

阵列的最终扫描输出为[1 3 6 10 15 21 28 36 45]

final scan output of array would be [1 3 6 10 15 21 28 36 45]

有人可以帮我吗?

推荐答案

您是否要实施自己的扫描操作?由于这不是MPI_SCAN的作用.它对存储在每个节点上的输入数组的每个 i 个元素逐个元素地执行扫描操作,结果将更像:

Are you trying to implement your own scan operation? Since this is not what MPI_SCAN does. It applies the scan operation elementwise over each i-th element of the input array stored on each node and the result will be more like:

rank 0 - [1 2 3] => [ 1  2  3]
rank 1 - [4 5 6] => [ 5  7  9]
rank 2 - [7 8 9] => [12 15 18]

但是,为了获得所需的结果,应将6(任务0中第一次扫描的最后一个元素)添加到下一次扫描的所有元素中:

Nevertheless, in order to obtain the result that you want, you should add 6 (the last element from the first scan in task 0) to all elements in the next scans:

[ 1  3  6][ 4  9 15][ 7 15 24]
           +6 -------------->
            =
[ 1  3  6][10 15 21][13 21 30]

然后,您应将15(任务1中扫描的最后一个元素之前 6添加)添加到下一次扫描的所有元素中,依此类推.

Then you should add 15 (the last element from the scan in task 1 before 6 was added) to all elements in the next scans and so forth.

[ 1  3  6][10 15 21][13 21 30]
                    +15 ---->
                    =
[ 1  3  6][10 15 21][28 36 45]

或者,您可以仅将6添加到第二次扫描的结果中,然后将21添加到第三次扫描的结果中,依此类推.

Alternatively you could add 6 only to the results from the second scan, then add 21 to the results from the third scan and so forth.

也许您可以找到一些使用MPI操作的巧妙方法.

Maybe you can find some clever way to do that using MPI operations.

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

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