如何在MPI中构建并行二叉树?

时间:2021-11-18 13:48:31

I want to build a binary tree from 4 processors in MPI. At root, all processors work together, next level I divide the processors into 2 groups and in this way at leaf each processor is responsible to build local tree.

我想在MPI中用4个处理器构建一个二叉树。从根本上说,所有处理器一起工作,下一级我将处理器分成2组,这样叶子每个处理器负责构建本地树。

I used mpi_comm_slpit to split current communicator into 2 parts. But the problem is how do I keep track parent-child relationship? like serial programming, we use pointer to point left-right child? How can I handle it in MPI? Thanks.

我使用mpi_comm_slpit将当前的通信器分成两部分。但问题是如何跟踪亲子关系?像串口编程一样,我们使用指向左右孩子的指针?我怎样才能在MPI中处理它?谢谢。

     [1-4]        <-- root
 [1-2]   [2-3] 
[1] [2] [3] [4] 

1 个解决方案

#1


There is no need to divide the communicator. In a binary tree the work is 2^n where n is the level. Depending on if you are traversing upwards or downwards you will have increase in idle processors or increase in number of processors (try imagining this). So for example if you start from top could divide your work done by root into 2. Now W1 to root (proc0) and W2 to (proc1). Next step proc0 and proc1 divide W1 and W2 into 2 parts. W11 to proc0, W12 to proc3, W21 to proc1 W22 to proc4 and so on ....

没有必要划分通信器。在二叉树中,工作是2 ^ n,其中n是级别。根据您是向上还是向下移动,您将增加空闲处理器或增加处理器数量(尝试想象一下)。因此,例如,如果你从顶部开始可以将你的工作由root分成2.现在W1到root(proc0)和W2到(proc1)。下一步proc0和proc1将W1和W2分成2部分。 W11到proc0,W12到proc3,W21到proc1 W22到proc4等等....

Hope this helps. Playing with communicators would complicate things ;)

希望这可以帮助。玩传播者会使事情复杂化;)

#1


There is no need to divide the communicator. In a binary tree the work is 2^n where n is the level. Depending on if you are traversing upwards or downwards you will have increase in idle processors or increase in number of processors (try imagining this). So for example if you start from top could divide your work done by root into 2. Now W1 to root (proc0) and W2 to (proc1). Next step proc0 and proc1 divide W1 and W2 into 2 parts. W11 to proc0, W12 to proc3, W21 to proc1 W22 to proc4 and so on ....

没有必要划分通信器。在二叉树中,工作是2 ^ n,其中n是级别。根据您是向上还是向下移动,您将增加空闲处理器或增加处理器数量(尝试想象一下)。因此,例如,如果你从顶部开始可以将你的工作由root分成2.现在W1到root(proc0)和W2到(proc1)。下一步proc0和proc1将W1和W2分成2部分。 W11到proc0,W12到proc3,W21到proc1 W22到proc4等等....

Hope this helps. Playing with communicators would complicate things ;)

希望这可以帮助。玩传播者会使事情复杂化;)