Fortran77 で並列プログラムを書いています。次の問題があります。
- N 個のプロセッサがあります。
- 各プロセッサには、サイズ S の配列 A が含まれています。
- すべてのプロセッサ (ランク X など) で何らかの関数を使用して、2 つの整数 Y と Z の値を計算します。ここで、Z < S (Y と Z の値はプロセッサごとに異なります)。
- プロセッサ Y の A(Z) の値をプロセッサ X に取得したいと考えています。
最初にプロセッサ X からプロセッサ Y に数値 X を送信し、次にプロセッサ Y からプロセッサ X に A(Z) を送信することを考えました。どのプロセッサから数値 X を受け取るかを知っています。
試してみましたが、このアクションを実装できるコードを思いつくことができませんでした。だから私はコードを投稿していません。
編集:
例を挙げて説明しようと思います。プロセッサ X=(たとえば 2) を使用しているとします。プロセッサ 2 で、2 つの整数 Y=(たとえば 34) と Z=say(5) の値を計算します。プロセッサ 2 での計算にプロセッサ 34 の A(5) の値を使用したいのですが、どうすればよいですか?
編集:
MPI フォーラムの誰かが、mpi_get の使用法を非常に明確に示す次のコードを提供してくれました。
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