我正在将 F77 程序重构为更新的 Fortran 标准(90 甚至更新)。
我有一个模块,其中定义了一些变量。这些变量当前被放入公共块中,因为在外部子程序中,所有这些变量仅使用一个 MPI_BCAST 调用并利用该公共块中变量的连续存储来广播。
module foo
implicit none
integer :: a,b,c,d
real*8 :: r,t,p
common/com/ a,b,c,d,r,t,p
end module foo
subroutine bar
...
com_length = 4*4 + 3*8 ! 4 integers + 3 real(8)
! bcasting 'com' common block, i.e. all variables at once
call mpi_bcast(a,com_length,mpi_byte,root,comm,ierr)
...
end subroutine bar
问题是公共块的长度com_length
是手动计算的,容易出错。如果缺少 COMMON 块定义,调试将需要很长时间,因为即使 valgrind 也不会注意到 OOB。另一方面,为每个变量单独调用 MPI_BCAST 会对性能产生负面影响。
我会很感激你关于如何重构它的建议。