I want to use Fortran with MPI to do the resample with replacement on an array DATA(10^7). I want to do 1000 times resample with replacement, and plan to split these 1000 tasks across 10 processors.
These are some of my codes:
real :: DATA(10^7), DATA_resample(10^7)
integer :: org_index_int(10^7)
integer :: new_index_int(10^7)
real :: new_index_real(10^7)
call MPI_INIT(ierror)
call MPI_COMM_RANK(MPI_COMM_WORLD, mid, ierror)
call random_init(.true., .true.)
! resample with replacement
! for myid=0 : irep_beg, irep_end = 1, 100
! for myid=9 : irep_beg, irep_end = 901, 1000
do irep=irep_beg, irep_end
call random_number(new_index_real)
new_index_int=floor(new_index_real)+1
DATA_resample=DATA(new_index_int)
end do
call MPI_FINALIZE(ierror)
When I use MPI, “random_num” gives the exact same array “new_index_real” across all processors. But I want each of the 1000 resamples to be independent. What could I do make this work?
New contributor
Jia is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.