Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 14 additions & 12 deletions src/common/m_boundary_common.fpp
Original file line number Diff line number Diff line change
Expand Up @@ -456,34 +456,35 @@ contains
end subroutine s_finalize_boundary_common_module

!> Populate ghost cell buffers of the Lagrangian-bubble beta (void fraction) variables based on the boundary conditions.
impure subroutine s_populate_beta_buffers(q_beta, kahan_comp, bc_type, nvar)
impure subroutine s_populate_beta_buffers(q_beta, kahan_comp, bc_type, nvar, vars_comm)

type(scalar_field), dimension(:), intent(inout) :: q_beta
type(scalar_field), dimension(:), intent(inout) :: kahan_comp
type(integer_field), dimension(1:num_dims,1:2), intent(in) :: bc_type
integer, intent(in) :: nvar
integer, dimension(:), intent(in) :: vars_comm

call s_populate_beta_bc_direction(1, -1, bc%x, bc_type(1, 1), q_beta, kahan_comp, nvar)
call s_populate_beta_bc_direction(1, 1, bc%x, bc_type(1, 2), q_beta, kahan_comp, nvar)
call s_populate_beta_bc_direction(1, -1, bc%x, bc_type(1, 1), q_beta, kahan_comp, nvar, vars_comm)
call s_populate_beta_bc_direction(1, 1, bc%x, bc_type(1, 2), q_beta, kahan_comp, nvar, vars_comm)

! n > 0 always for bubbles_lagrange
#:if not MFC_CASE_OPTIMIZATION or num_dims > 1
call s_populate_beta_bc_direction(2, -1, bc%y, bc_type(2, 1), q_beta, kahan_comp, nvar)
call s_populate_beta_bc_direction(2, 1, bc%y, bc_type(2, 2), q_beta, kahan_comp, nvar)
call s_populate_beta_bc_direction(2, -1, bc%y, bc_type(2, 1), q_beta, kahan_comp, nvar, vars_comm)
call s_populate_beta_bc_direction(2, 1, bc%y, bc_type(2, 2), q_beta, kahan_comp, nvar, vars_comm)
#:endif

if (p == 0) return

#:if not MFC_CASE_OPTIMIZATION or num_dims > 2
call s_populate_beta_bc_direction(3, -1, bc%z, bc_type(3, 1), q_beta, kahan_comp, nvar)
call s_populate_beta_bc_direction(3, 1, bc%z, bc_type(3, 2), q_beta, kahan_comp, nvar)
call s_populate_beta_bc_direction(3, -1, bc%z, bc_type(3, 1), q_beta, kahan_comp, nvar, vars_comm)
call s_populate_beta_bc_direction(3, 1, bc%z, bc_type(3, 2), q_beta, kahan_comp, nvar, vars_comm)
#:endif

end subroutine s_populate_beta_buffers

!> Populate beta variable buffers for one direction and location, by dispatching the per-cell beta BC routines over the boundary
!! face and performing the paired MPI reduction for processor boundaries.
impure subroutine s_populate_beta_bc_direction(bc_dir, bc_loc, bc_bounds, bc_type_edge, q_beta, kahan_comp, nvar)
impure subroutine s_populate_beta_bc_direction(bc_dir, bc_loc, bc_bounds, bc_type_edge, q_beta, kahan_comp, nvar, vars_comm)

integer, intent(in) :: bc_dir, bc_loc
type(int_bounds_info), intent(in) :: bc_bounds
Expand All @@ -492,6 +493,7 @@ contains
type(scalar_field), dimension(:), intent(inout) :: kahan_comp
integer, intent(in) :: nvar
integer :: bc_edge, k_beg, k_end, l_beg, l_end, k, l, bc_code
integer, dimension(:), intent(in) :: vars_comm

if (bc_loc == -1) then
bc_edge = bc_bounds%beg
Expand All @@ -511,7 +513,7 @@ contains
l_beg = beta_bc_bounds(2)%beg; l_end = beta_bc_bounds(2)%end
end if

$:GPU_PARALLEL_LOOP(private='[l, k, bc_code]', collapse=2)
$:GPU_PARALLEL_LOOP(private='[l, k, bc_code]', collapse=2, copyin = '[vars_comm]')
do l = l_beg, l_end
do k = k_beg, k_end
! bc_type is not allocated over the beta ghost extents in x and y, so those directions dispatch on the
Expand All @@ -524,9 +526,9 @@ contains

select case (bc_code)
case (BC_PERIODIC)
call s_beta_periodic(q_beta, kahan_comp, bc_dir, bc_loc, k, l, nvar)
call s_beta_periodic(q_beta, kahan_comp, bc_dir, bc_loc, k, l, nvar, vars_comm)
case (BC_REFLECTIVE)
call s_beta_reflective(q_beta, kahan_comp, bc_dir, bc_loc, k, l, nvar)
call s_beta_reflective(q_beta, kahan_comp, bc_dir, bc_loc, k, l, nvar, vars_comm)
end select
end do
end do
Expand All @@ -536,7 +538,7 @@ contains
! The beta reduction is a paired exchange (rightward accumulate at bc_loc = -1, leftward distribute at bc_loc = 1), so it
! must run at both locations whenever either edge of the direction is a processor boundary.
if (bc_bounds%beg >= 0 .or. bc_bounds%end >= 0) then
call s_mpi_reduce_beta_variables_buffers(q_beta, kahan_comp, bc_dir, bc_loc, nvar)
call s_mpi_reduce_beta_variables_buffers(q_beta, kahan_comp, bc_dir, bc_loc, nvar, vars_comm)
end if

end subroutine s_populate_beta_bc_direction
Expand Down
Loading
Loading