1

我正在将 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 会对性能产生负面影响。

我会很感激你关于如何重构它的建议。

4

1 回答 1

2

你可以在 2 个MPI_BCAST电话中完成。

  CALL MPI_BCAST([a, b, c, d], 4, MPI_INTEGER, root, MPI_COMM_WORLD, ierr)
  CALL MPI_BCAST([t, r, p], 3, MPI_DOUBLE_PRECISION, root, MPI_COMM_WORLD, ierr)

4and3可能并不完全正确,但想法仍然相同:将您的相似变量分组为一个数组并广播它们。

于 2013-06-30T20:43:17.430 回答