load the probability distribution from arr into this we only use this in the sampler array, but fortran has no friend classes, so its public @param[in] arr array containing the (not necessarily normalized) probabilities we want to use for sampling
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(AliasSampler_t), | intent(inout) | :: | this | |||
integer, | intent(in) | :: | rank_with_info |
The intra-node rank that contains the weights to be used all other arr of all other ranks are ignored (and can be allocated with size 0). |
||
real(kind=dp), | intent(in) | :: | arr(:) |
subroutine init_AliasSampler_t(this, rank_with_info, arr)
class(AliasSampler_t), intent(inout) :: this
integer, intent(in) :: rank_with_info
!! The **intra-node** rank that contains the weights to be used
!! all other arr of all other ranks are ignored (and can be allocated with size 0).
real(dp), intent(in) :: arr(:)
block
logical :: early_return(1)
integer :: ierr
early_return = near_zero(sum(arr))
call MPI_Bcast(early_return, size(early_return, kind=MPIArg), MPI_LOGICAL, rank_with_info, mpi_comm_intra, ierr)
if (early_return(1)) then
! if we reach this point, probs is uninitialized -> null it
this%probs%ptr => null()
return
end if
end block
! load the data - assume this is pre-allocated
call this%table%init(rank_with_info, arr)
call this%init_probs(rank_with_info, arr)
end subroutine init_AliasSampler_t