MPI_SCATTER Fortran 矩阵(按行)
按行而不是按列分散 Fortran 90 矩阵的最佳方法是什么?也就是说,假设我有一个矩阵 a(4,50),我想将它 MPI_SCATTER 到两个进程上,其中每个部分都是 alocal(2,50),其中第 0 行有第 1 行和第 2 行,第 1 行有第 3 行和4. 现在,在 C 中,这很简单,因为数组是行优先的,但在 Fortran 90 中它们是列优先的。
我试图避免使用 TRANSPOSE 在散射之前翻转 a (即,使内存使用加倍),并且我认为 MPI 中必须有一种方法可以做到这一点。会是 MPI_TYPE_VECTOR 吗? MPI_TYPE_CREATE_SUBARRAY?
同样,如果我有一个 3d 数组 b(4,50,3) 并且我想要两个 blocal(2,50,3) 分散矩阵如上分布,该怎么办?
What is the best way to scatter a Fortran 90 matrix by its rows rather than columns? That is, let's say I have a matrix a(4,50) and I want to MPI_SCATTER it onto two processes where each part is alocal(2,50), where rank 0 has rows 1 and 2, and rank 1 has 3 and 4. Now, in C, this is simple since arrays are row-major, but in Fortran 90 they are column-major.
I'm trying to avoid using TRANSPOSE to flip a before scattering (i.e, doubling the memory use), and I figure there must be a way in MPI to do this. Would it be MPI_TYPE_VECTOR? MPI_TYPE_CREATE_SUBARRAY?
Likewise, what if I have a 3d array b(4,50,3) and I want two scattered matrices of blocal(2,50,3) distributed as above?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的,MPI_TYPE_VECTOR 和 MPI_TYPE_CREATE_SUBARRAY 就是您想要的。前者针对您的第一个问题,后者针对您的第二个问题。如果您想让我为您写电话,请发表评论!
Yes, MPI_TYPE_VECTOR and MPI_TYPE_CREATE_SUBARRAY are what you want. The former for your first problem, the latter for your second. Comment if you want me to write the calls for you !
大多数 MPI 数据传输调用不是都有
stride
参数吗?将其设置为数据类型的大小乘以矩阵的高度,然后就可以了...我已经查看了 MPI 参考 并且没有明确的论据,但是如果您查看示例 5.12,它们将展示如何发送跨步整数
MPI_Scatterv
和MPI_Gatherv
。Didn't most of the MPI data transfer calls have a
stride
argument? Set it to the size of the data type times the height of the matrix and there you go...I've taken a look to the MPI reference and there wasn't a explicit argument to that, but if you go to the example 5.12, they show how to send strided ints with
MPI_Scatterv
andMPI_Gatherv
.