subroutine Init_DomainDecomposition(this,comm)
implicit none
class(DomainDecomposition),intent(inout) :: this
integer,intent(in),optional :: comm
! Local
integer :: ierror
integer :: nodeComm,localRank
integer(c_int) :: num_devices,hip_err,device_id
this%mpiComm = MPI_COMM_NULL
this%mpiPrec = prec
this%rankId = 0
this%nRanks = 1
this%nElem = 0
this%mpiEnabled = .false.
this%ownsMpi = .false.
call AcquireMPI(this%mpiComm,this%ownsMpi,comm)
call mpi_comm_rank(this%mpiComm,this%rankId,ierror)
call mpi_comm_size(this%mpiComm,this%nRanks,ierror)
print*,__FILE__," : Rank ",this%rankId+1,"/",this%nRanks," checking in."
if(this%nRanks > 1) then
this%mpiEnabled = .true.
else
print*,__FILE__," : No domain decomposition used."
endif
if(prec == real32) then
this%mpiPrec = MPI_FLOAT
else
this%mpiPrec = MPI_DOUBLE
endif
allocate(this%offsetElem(1:this%nRanks+1))
hip_err = hipGetDeviceCount(num_devices)
if(hip_err /= 0) then
print*,'Failed to get device count on rank',this%rankId
call MPI_Abort(this%mpiComm,hip_err,ierror)
endif
! Assign GPU device ID based on node-local MPI rank so multi-node
! placement is independent of the launcher's global rank ordering.
call MPI_Comm_split_type(this%mpiComm,MPI_COMM_TYPE_SHARED,this%rankId, &
MPI_INFO_NULL,nodeComm,ierror)
call MPI_Comm_rank(nodeComm,localRank,ierror)
call MPI_Comm_free(nodeComm,ierror)
device_id = modulo(localRank,num_devices)
hip_err = hipSetDevice(device_id)
print*,__FILE__," : Rank ",this%rankId+1," assigned to device ",device_id
if(hip_err /= 0) then
print*,'Failed to set device for rank',this%rankId,'to device',device_id
call MPI_Abort(this%mpiComm,hip_err,ierror)
endif
this%initialized = .true.
endsubroutine Init_DomainDecomposition