fortran - 关于 mpi_gatherv 的一些提示
问题描述
我试图通过一个简单的例子来理解 mpi_gatherv:
每个等级都有一个名为 x_local 的数组,大小为“id+1”,因此等级 1 具有 x_local(1),等级 2 具有 x_local(2),依此类推。我总共使用了 4 个 procs。
为简单起见 x_local = real(id+1)
在输出时,我想要一个数组 x (仅适用于根处理器),如下所示:
x=(1,2,2,3,3,3,4,4,4,4)
这是我的代码:
subroutine testGatherV
! Global variables
use mpi
use mpivar
! Local variables
implicit none
integer i, ierr, displs(nid), rcounts(nid)
real, dimension(:), allocatable:: x_local
real, dimension(:), allocatable:: x
allocate(x_local(id+1))
allocate(x(10))
!
x=-1.0
displs(1) = 0
displs(2) = 1
displs(3) = 3
displs(4) = 6
rcounts(1) = 1
rcounts(2) = 2
rcounts(3) = 3
rcounts(4) = 4
x_local = real(id+1)
call mpi_gatherv(x_local, id+1, MPI_REAL, x, rcounts, displs, &
MPI_REAL, 0, MPI_COMM_WORLD, ierr)
if(id.eq.0) write(*,*) 'x = ', x
end
输出是:
x = 0.0000000000000000 0.0000000000000000 0.0000000000000000 4.0000000000000000 4.0000000000000000 -1.0000000000000000 -1.0000000000000000 -1.0000000000000000 -1.0000000000000000 -1.0000000000000000
我哪里错了?任何帮助都感激不尽。谢谢你。
解决方案
推荐阅读
- angular - 复杂对象未完全在 api 调用中传递(Angular + net core 3)
- php - 在 Stripe PHP 上捕获特定错误以显示自定义消息
- php - Laravel 迁移数据库关系似乎是正确的。错误信息说外键不兼容
- botframework - 在不丢失实体映射的情况下刷新调度模型
- django - Django serializer with a filed that has a OneToOne relationship
- kubernetes - 每次部署只运行一次初始化容器
- python-3.x - 如何读取目录中的文件并写入文件
- css - 在 cinnamon.css 中编辑元素的属性
- android - 无法从 CalendarView 解析令牌“AbstractCalendarViewDelegate”
- javascript - 重新启动应用程序后调用 AccessToken.getCurrentAccessToken() 时获取 null