parallel_merge_reservoirs Subroutine

public subroutine parallel_merge_reservoirs(res)

Merge neutral particle reservoirs across MPI processes

Arguments

TypeIntentOptionalAttributesName
type(NeutralParticleReservoir), intent(inout) :: res

Neutral Particle Reservoir


Calls

proc~~parallel_merge_reservoirs~~CallsGraph proc~parallel_merge_reservoirs parallel_merge_reservoirs proc~my_rank my_rank proc~parallel_merge_reservoirs->proc~my_rank proc~num_ranks num_ranks proc~parallel_merge_reservoirs->proc~num_ranks proc~merge_reservoirs merge_reservoirs proc~parallel_merge_reservoirs->proc~merge_reservoirs proc~init_reservoir init_reservoir proc~parallel_merge_reservoirs->proc~init_reservoir interface~parallel_sum parallel_sum proc~parallel_merge_reservoirs->interface~parallel_sum proc~merge_reservoirs->proc~init_reservoir float float proc~merge_reservoirs->float proc~update_reservoir update_reservoir proc~merge_reservoirs->proc~update_reservoir interface~randu randu proc~merge_reservoirs->interface~randu proc~init_reservoir->interface~randu proc~parallel_sum_d1 parallel_sum_d1 interface~parallel_sum->proc~parallel_sum_d1 proc~parallel_sum_i2 parallel_sum_i2 interface~parallel_sum->proc~parallel_sum_i2 proc~parallel_sum_i3 parallel_sum_i3 interface~parallel_sum->proc~parallel_sum_i3 proc~parallel_sum_d2 parallel_sum_d2 interface~parallel_sum->proc~parallel_sum_d2 proc~parallel_sum_d4 parallel_sum_d4 interface~parallel_sum->proc~parallel_sum_d4 proc~parallel_sum_d5 parallel_sum_d5 interface~parallel_sum->proc~parallel_sum_d5 proc~parallel_sum_i1 parallel_sum_i1 interface~parallel_sum->proc~parallel_sum_i1 proc~parallel_sum_i0 parallel_sum_i0 interface~parallel_sum->proc~parallel_sum_i0 proc~parallel_sum_d3 parallel_sum_d3 interface~parallel_sum->proc~parallel_sum_d3 proc~parallel_sum_d0 parallel_sum_d0 interface~parallel_sum->proc~parallel_sum_d0 proc~parallel_sum_d1->proc~parallel_sum_d1 mpi_allreduce mpi_allreduce proc~parallel_sum_d1->mpi_allreduce proc~parallel_sum_i2->proc~parallel_sum_i1 proc~parallel_sum_i2->mpi_allreduce proc~parallel_sum_i3->proc~parallel_sum_i1 proc~parallel_sum_i3->mpi_allreduce proc~update_reservoir->proc~init_reservoir proc~update_reservoir->interface~randu interface~randind randind proc~update_reservoir->interface~randind proc~parallel_sum_d2->proc~parallel_sum_d1 proc~parallel_sum_d2->mpi_allreduce proc~parallel_sum_d4->proc~parallel_sum_d1 proc~parallel_sum_d4->mpi_allreduce proc~parallel_sum_d5->proc~parallel_sum_d1 proc~parallel_sum_d5->mpi_allreduce proc~parallel_sum_i1->proc~parallel_sum_i1 proc~parallel_sum_i1->mpi_allreduce proc~parallel_sum_i0->mpi_allreduce proc~parallel_sum_d3->proc~parallel_sum_d1 proc~parallel_sum_d3->mpi_allreduce proc~parallel_sum_d0->mpi_allreduce

Called by

proc~~parallel_merge_reservoirs~~CalledByGraph proc~parallel_merge_reservoirs parallel_merge_reservoirs proc~dcx dcx proc~dcx->proc~parallel_merge_reservoirs proc~parallel_merge_populations parallel_merge_populations proc~dcx->proc~parallel_merge_populations proc~fida_f fida_f proc~fida_f->proc~parallel_merge_reservoirs proc~pfida_f pfida_f proc~pfida_f->proc~parallel_merge_reservoirs proc~halo halo proc~halo->proc~parallel_merge_reservoirs proc~halo->proc~parallel_merge_populations proc~pfida_mc pfida_mc proc~pfida_mc->proc~parallel_merge_reservoirs proc~parallel_merge_populations->proc~parallel_merge_reservoirs proc~fida_mc fida_mc proc~fida_mc->proc~parallel_merge_reservoirs program~fidasim fidasim program~fidasim->proc~dcx program~fidasim->proc~fida_f program~fidasim->proc~pfida_f program~fidasim->proc~halo program~fidasim->proc~pfida_mc program~fidasim->proc~fida_mc proc~ndmc ndmc program~fidasim->proc~ndmc proc~ndmc->proc~parallel_merge_populations

Contents


Source Code

subroutine parallel_merge_reservoirs(res)
    !+ Merge neutral particle reservoirs across MPI processes
    type(NeutralParticleReservoir), intent(inout) :: res
        !+ Neutral Particle Reservoir

    integer :: proc, num_procs, i, j, k
    integer(Int32), dimension(:), allocatable :: nums, inds
    real(Float64), dimension(:), allocatable :: Ws
    real(Float64), dimension(:,:), allocatable :: wghts
    real(Float64), dimension(:,:,:), allocatable :: vels
    type(NeutralParticleReservoir) :: res1, res2

    proc = my_rank() + 1
    num_procs = num_ranks()

    k = res%k

    allocate(nums(num_procs), inds(num_procs), Ws(num_procs))
    nums = 0
    inds = 0
    Ws = 0.d0
    nums(proc) = res%n
    inds(proc) = res%i
    Ws(proc) = res%W

    call parallel_sum(nums)
    call parallel_sum(inds)
    call parallel_sum(Ws)

    allocate(vels(3,reservoir_size,num_procs))
    allocate(wghts(reservoir_size,num_procs))
    vels = 0.d0; wghts = 0.d0

    do i=1,min(k,res%n)
        vels(:,i,proc) = res%R(i)%v
        wghts(i,proc) = res%R(i)%w
    enddo
    call parallel_sum(vels)
    call parallel_sum(wghts)

    call init_reservoir(res1)
    res1%n = nums(1)
    res1%i = inds(1)
    res1%W = Ws(1)
    do i=1,min(k,res1%n)
        res1%R(i) = NeutralParticle(wghts(i,1),vels(:,i,1))
    enddo
    call init_reservoir(res2)
    do i=2,num_procs
        res2%n = nums(i)
        res2%i = inds(i)
        res2%W = Ws(i)
        do j=1,min(k,res2%n)
            res2%R(j) = NeutralParticle(wghts(j,i),vels(:,j,i))
        enddo
        call merge_reservoirs(res1,res2)
    enddo
    deallocate(vels,wghts,nums,inds,Ws)

    res = res1

end subroutine parallel_merge_reservoirs