使用 MPI 从不同过程中收集小矩阵部分 [英] Gathering small matrix portions from different processes with MPI
问题描述
我花了一些时间思考计算矩阵的方案,一切都说得通,但还有最后一部分我不知道如何处理.
I've spent some time thinking about a scheme to compute a matrix, everything makes sense, but there's one last part that I'm not sure how to handle.
这是我打算做的(场景):
Here's what I intend to do(scenario) :
- 要求计算一个 10(w)x5(h) 矩阵.
- 我有 10 个处理器可用.
- 在每个处理器上声明一个 1x5 矩阵,包括等级 0 的 proc.
- 计算每个处理器上的每个子矩阵的偏移量.
- MPI_Barrier 等待所有 10 个处理器完成计算.
显示完整矩阵.
一路走到第五步,我很高兴,但我不知道该怎么做才能越过障碍.没有一个处理器具有完整的 10x5 矩阵.一开始我想我不需要一个,我想要这样的东西:
All the way to step five I'm good to go, but I don't know what to do past the barrier. None of the processors have the complete 10x5 matrix. In the beginning I figured I wouldn't need to have one, I wanted something like this :
foreach(procX in proc(0-9))
showColumn(procX)
但我不知道在 MPI_Barrier 之后将调用哪个处理器,我不知道如何按照处理器的顺序打印内容(否则矩阵将无法正确打印).
But I don't know which processor will be called after MPI_Barrier and I don't know how to printf things with the order of the processors in mind(otherwise the matrix will not be printed correctly).
有没有人知道如何正常处理这个问题?我已经阅读了很多关于让每个处理器处理矩阵部分的内容,但我找不到任何关于如何组合这些不同部分的信息.
Does anyone have an idea on how to deal with this normally? I've read a lot about letting each processor work on parts of the matrix, but I couldn't find anything on how to have those different parts combined.
我没有在我的代码中使用分散(即,没有使用主从技术)
I'm not using scatters in my code(i.e., not using the master-slave technique)
谢谢
推荐答案
如果你不想在单个进程中收集整个矩阵,你可以使用这样的循环:
If you don't want to gather the entire matrix on a single process, you can use a loop like this:
for ( i = 0; i < 9; i++ )
{
if ( i == myRank )
{
// print local matrix
}
MPI_Barrier(MPI_COMM_WORLD);
}
这篇关于使用 MPI 从不同过程中收集小矩阵部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!