0
我在Fortran77中編寫了一個並行程序。我有以下問題:從另一個處理器調用變量
- 我有N個處理器。
- 每個處理器包含大小S.
- 的陣列A使用一些功能,每個處理器上(說秩X),我計算兩個整數Y和Z的值,其中Z < S(Y的值和Z在每個處理器上都不相同)。
- 我想獲得A(Z)的上處理器y以處理器X.從處理器X發送的數值X到處理器Y和然後發送A(Z)從值
我認爲第一處理器Y到處理器X.但是這是不可能的,因爲處理器Y不知道數值X,所以它不知道從哪個處理器接收數值X。
我試過了,但我一直沒有能夠拿出任何可以實現這個動作的代碼。所以我沒有發佈任何代碼。
編輯:
我會試着用一個例子來解釋它。假設我在處理器X =(比如說2)。在處理器2上,我計算了兩個整數的值,Y =(比如說34)和Z =比例(5)。我想使用處理器34上的A(5)值來處理器2上的計算。我該怎麼做?
編輯:
在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
我不再幫助人們在FORTRAN77中編寫新程序,我認爲這是不道德的,有點像醫學院教醫生在沒有麻醉劑的情況下截肢。這是21世紀,甚至免費的編譯器提供了幾乎完整的Fortran 2003實現。 –
我很抱歉,但我應該添加一個子程序到已經存在的更大的代碼中,這不屬於我,並且全部用F77編寫。我在這裏沒有選擇。 – jhaprade
現代Fortran當然可以與Fortran 77混合使用。 –