HI, I would like to ask for some help for the error when passing arguments to the subroutine when using hybrid Openacc and MPI programing model. I have simplified the program like this:
module gulemath
contains
SUBROUTINE write_int(m,devicenum)
!$acc routine seq
implicit none
INTEGER(kind=4) m,devicenum
write(*,*) 'm and device_num',m,devicenum
end
end module gulemath
program main
use gulemath
use mpi
use openacc
implicit none
integer(kind=4)::i,n_m,nmax,n_north,prd
integer(kind=4):: num_device,idx_device
character(len=40) filedgcombine,filecoef1,prc_name
integer(kind=4)::ierr,myid,numprocs,rc
call MPI_INIT_thread(MPI_THREAD_MULTIPLE,prd,ierr)
call MPI_COMM_RANK(MPI_COMM_WORLD,myid,ierr)
call MPI_COMM_SIZE(MPI_COMM_WORLD,numprocs,ierr)
nmax=360
n_north=180
num_device= acc_get_num_devices(acc_device_nvidia)
If(myid/=0) then
idx_device=mod(myid,num_device)
call acc_init(acc_device_nvidia)
call acc_set_device_num(idx_device,acc_device_nvidia)
!$acc kernels
!$acc loop independent
do i=myid, n_north, numprocs-1 ! loop 1
call write_int(i,idx_device)
n_m=i
call write_int(n_m,idx_device)
end do ! loop i
!$acc end kernels
write(*,*) 'after loop 1'
end if
If(myid/=0) then
write(*,*) 'my id', myid,numprocs
idx_device=mod(myid,num_device)
call acc_set_device_num(idx_device,acc_device_nvidia)
!$acc parallel
!$acc loop independent
do i=myid-1,nmax-1 ,numprocs-1 ! loop 2
write(*,*) i
call write_int(i,idx_device)
n_m=i
call write_int(n_m,idx_device)
end do ! loop i
!$acc end parallel
end if
call MPI_FINALIZE(rc)
end ! the main program
You could see that there are two loops which could be executed in parallel. In each loop, I would like to pass the loop variable to the subroutine and print out the variable. It could be pass right in the first loop, however, it is not correctly passed in the second loop.
I compile the program in this command line:
mpif90 -acc -gpu=cc70 -gpu=cuda11.0 -Minfo -Mlarge_arrays printm.f90 -o printm
and run it like this:
srun -p sgpu mpirun -np 2 --oversubscribe ./printm
Could you please tell me where is wrong?
Many thanks!