setup_AliasTable_t Subroutine

private subroutine setup_AliasTable_t(this, rank_with_info, arr)

pseudo-constructor for alias tables

Type Bound

AliasTable_t

Arguments

Type IntentOptional Attributes Name
class(AliasTable_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(:)

arr array containing the (not necessarily normalized) probabilities we want to use for sampling


Contents

Source Code


Source Code

    subroutine setup_AliasTable_t(this, rank_with_info, arr)
        !! pseudo-constructor for alias tables
        class(AliasTable_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(:)
            !! arr  array containing the (not necessarily normalized) probabilities we
            !!              want to use for sampling

        character(*), parameter :: t_r = "setupTable"
        integer :: ierr

        block
            logical :: error_found(1)
            integer :: ierr
            error_found = near_zero(sum(arr))
            call MPI_Bcast(error_found, size(error_found, kind=MPIArg), MPI_LOGICAL, rank_with_info, mpi_comm_intra, ierr)
            if (error_found(1) .or. ierr /= 0) then
                call stop_all(t_r,  "Trying to setup empty alias table")
            end if
        end block

        ! allocate the shared memory segment for the alias table
        block
            integer(int64) :: arrSize(1)
            arrSize = size(arr, kind=int64)
            call MPI_Bcast(arrSize, size(arrSize, kind=MPIArg), MPI_INTEGER8, rank_with_info, mpi_comm_intra, ierr)
            ! allocate the probabilities
            call this%bias%shared_alloc(arrSize(1))
            call this%alias%shared_alloc(arrSize(1))
        end block



        call this%init(rank_with_info, arr)

        ! Sync the shared resource between tasks
        call this%bias%sync()
        call this%alias%sync()

    end subroutine setup_AliasTable_t