Fortran 从另一个处理器调用变量
我正在用Fortran77编写一个并行程序。我有以下问题:Fortran 从另一个处理器调用变量,fortran,mpi,mpi-rma,Fortran,Mpi,Mpi Rma,我正在用Fortran77编写一个并行程序。我有以下问题: 我有N个处理器 每个处理器包含一个大小为S的数组 使用一些函数,在每个处理器上(比如秩X),我计算两个整数Y和Z的值,其中Z
program var_access
implicit none
include 'mpif.h'
integer ierr
integer i
integer rank
integer disp_int
integer X, Y, Z
integer S
parameter (S = 10)
integer A(S)
integer AYS
integer win, NP
integer (kind=MPI_ADDRESS_KIND) lowerbound, size, realextent, disp_aint
integer n
integer, allocatable :: seed(:)
real rnd(3)
call MPI_Init(ierr)
call MPI_Comm_size(MPI_COMM_WORLD,NP,ierr)
call MPI_Comm_rank(MPI_COMM_WORLD,rank,ierr)
! Produce random numbers
call random_seed(size = n)
allocate(seed(n))
do i=1, n
seed(i) = i
end do
call random_seed(put = seed)
call random_number(rnd)
X = floor(NP*rnd(1))
Y = floor(NP*rnd(2))
Z = ceiling(S*rnd(3))
! Determine the size of one data element in the array in bytes
call MPI_Type_get_extent(MPI_INT, lowerbound, realextent, ierr)
disp_int = realextent
! Determine the size of the entire data array in bytes
size = S * realextent
! create the actual memory window
call MPI_Win_create(A, size, disp_int ,MPI_INFO_NULL, MPI_COMM_WORLD, win, ierr)
! Fill array A with some data
do i = 1, S
A(i) = S * rank + i
if (rank.eq.Y) write (*,*) rank, i, A(i), rnd(1), rnd(2), rnd(3)
end do
! Synchronize window
call MPI_Win_fence(0, win, ierr)
if(rank .eq. X) then
disp_aint = Z - 1
call MPI_Get(AYS, 1, MPI_INT, Y, disp_aint, 1, MPI_INT, win, ierr)
endif
! Synchronize window, completing all accesses to it
call MPI_Win_fence(0, win, ierr)
if(rank .eq. X) then
write (*,*) Y,Z,"# ", AYS
endif
call MPI_Win_free(win, ierr)
call MPI_Finalize(ierr)
end program var_access
但这是不可能的,因为处理器Y不知道数字
值X,因此它不知道从哪个处理器接收数据
数值X来自
这实际上是可能的。使用MPI_ANY_源作为MPI_Recv的源列就足够了。您可以通过检查返回的状态来检测到底是哪个处理器发送了数据。我不再帮助人们用FORTRAN77编写新程序,我认为这是不道德的,有点像医学院教医生在没有麻醉的情况下截肢肢体。现在是21世纪,即使是免费的编译器也提供了Fortran 2003的几乎完整的实现。很抱歉,我应该在已经存在的更大的代码中添加一个子程序,它不属于我,并且都是用F77编写的。我在这里没有选择。现代Fortran当然可以与Fortran 77混合使用。你研究过OpenMP和MPI吗?你说,这是Fortran 77,但从你问题的其余部分的描述来看,它看起来好像你在尝试使用F2008特性的协排?您实际使用的是哪种并行性?