Skip to content

Commit b504645

Browse files
committed
Make common MPI transport stage-independent
1 parent d086e7a commit b504645

5 files changed

Lines changed: 19 additions & 28 deletions

File tree

src/common/include/macros.fpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
! rank. That's because for both cudaMemAdvise (preferred location) and cudaMemPrefetchAsync we use location = device_id = 0. For an
1717
! example see misc/nvidia_uvm/bind.sh.
1818
#:def PREFER_GPU(*args)
19-
#ifdef MFC_SIMULATION
2019
#ifdef __NVCOMPILER_GPU_UNIFIED_MEM
2120
block
2221
! NVIDIA CUDA Fortran 25.3+: uses submodules (cuda_runtime_api, gpu_reductions, sort) See
@@ -52,7 +51,6 @@
5251
end if
5352
end block
5453
#endif
55-
#endif
5654
#:enddef
5755
5856
! Allocate and create GPU device memory

src/common/m_mpi_common.fpp

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,27 @@ module m_mpi_common
4040
integer(kind=8) :: halo_size
4141
$:GPU_DECLARE(create='[halo_size]')
4242

43+
logical, private :: exchange_all_chemistry_temperatures
44+
logical, private :: use_rdma_transport
45+
4346
contains
4447

4548
!> Initialize the module.
46-
impure subroutine s_initialize_mpi_common_module
49+
impure subroutine s_initialize_mpi_common_module(exchange_all_chemistry_temperatures_in, use_rdma_transport_in)
50+
51+
logical, intent(in) :: exchange_all_chemistry_temperatures_in
52+
logical, intent(in) :: use_rdma_transport_in
53+
54+
exchange_all_chemistry_temperatures = exchange_all_chemistry_temperatures_in
55+
use_rdma_transport = use_rdma_transport_in
4756

4857
#ifdef MFC_MPI
4958
! Allocating buff_send/recv and. Please note that for the sake of simplicity, both variables are provided sufficient storage
5059
! to hold the largest buffer in the computational domain.
5160

5261
if (qbmm .and. .not. polytropic) then
5362
v_size = sys_size + 2*nb*nnode
54-
else if (chemistry .and. chem_params%diffusion) then
63+
else if (chemistry .and. (chem_params%diffusion .or. exchange_all_chemistry_temperatures)) then
5564
v_size = sys_size + 1
5665
else
5766
v_size = sys_size
@@ -311,7 +320,6 @@ contains
311320
Rc_min_glb = Rc_min_loc
312321
ccfl_max_glb = ccfl_max_loc
313322

314-
#ifdef MFC_SIMULATION
315323
#ifdef MFC_MPI
316324
block
317325
integer :: ierr
@@ -346,7 +354,6 @@ contains
346354
end if
347355

348356
if (bubbles_lagrange) bubs_glb = bubs_loc
349-
#endif
350357
#endif
351358

352359
end subroutine s_mpi_reduce_stability_criteria_extrema
@@ -564,14 +571,10 @@ contains
564571
v_size = nVar + 2*nb*nnode
565572
buffer_counts = (/buff_size*v_size*(n + 1)*(p + 1), buff_size*v_size*(m + 2*buff_size + 1)*(p + 1), &
566573
& buff_size*v_size*(m + 2*buff_size + 1)*(n + 2*buff_size + 1)/)
567-
#ifdef MFC_SIMULATION
568-
else if (present(q_T_sf) .and. chemistry .and. chem_params%diffusion) then
569-
#else
570-
else if (present(q_T_sf) .and. chemistry) then
571-
! post_process converts cons->prim over the ghost-inclusive bounds, so the temperature
572-
! Newton guess must be valid at rank seams for EVERY chemistry run (not only diffusion):
574+
else if (present(q_T_sf) .and. chemistry .and. (chem_params%diffusion .or. exchange_all_chemistry_temperatures)) then
575+
! Consumers that convert over ghost-inclusive bounds request temperature exchange for every chemistry run.
576+
! The temperature Newton guess must be valid at rank seams even when diffusion is disabled:
573577
! an unexchanged seam ghost is an uninitialized guess -> NaN T/pres/c in the output
574-
#endif
575578
chem_diff_comm = .true.
576579
v_size = nVar + 1
577580
buffer_counts = (/buff_size*v_size*(n + 1)*(p + 1), buff_size*v_size*(m + 2*buff_size + 1)*(p + 1), &
@@ -800,9 +803,8 @@ contains
800803
call nvtxEndRange ! Packbuf
801804

802805
! Send/Recv
803-
#ifdef MFC_SIMULATION
804806
#:for rdma_mpi in [False, True]
805-
if (rdma_mpi .eqv. ${'.true.' if rdma_mpi else '.false.'}$) then
807+
if (use_rdma_transport .eqv. ${'.true.' if rdma_mpi else '.false.'}$) then
806808
#:if rdma_mpi
807809
#:call GPU_HOST_DATA(use_device_addr='[buff_send, buff_recv]')
808810
call nvtxStartRange("RHS-COMM-SENDRECV-RDMA")
@@ -830,10 +832,6 @@ contains
830832
#:endif
831833
end if
832834
#:endfor
833-
#else
834-
call MPI_SENDRECV(buff_send, buffer_count, mpi_p, dst_proc, send_tag, buff_recv, buffer_count, mpi_p, src_proc, recv_tag, &
835-
& MPI_COMM_WORLD, MPI_STATUS_IGNORE, ierr)
836-
#endif
837835

838836
! Unpack Received Buffer
839837
call nvtxStartRange("RHS-COMM-UNPACKBUF")
@@ -1190,9 +1188,8 @@ contains
11901188
call nvtxEndRange ! Packbuf
11911189

11921190
! Send/Recv
1193-
#ifdef MFC_SIMULATION
11941191
#:for rdma_mpi in [False, True]
1195-
if (rdma_mpi .eqv. ${'.true.' if rdma_mpi else '.false.'}$) then
1192+
if (use_rdma_transport .eqv. ${'.true.' if rdma_mpi else '.false.'}$) then
11961193
#:if rdma_mpi
11971194
#:call GPU_HOST_DATA(use_device_addr='[buff_send, buff_recv]')
11981195
call nvtxStartRange("BETA-COMM-SENDRECV-RDMA")
@@ -1220,10 +1217,6 @@ contains
12201217
#:endif
12211218
end if
12221219
#:endfor
1223-
#else
1224-
call MPI_SENDRECV(buff_send, buffer_count, mpi_p, dst_proc, send_tag, buff_recv, buffer_count, mpi_p, src_proc, recv_tag, &
1225-
& MPI_COMM_WORLD, MPI_STATUS_IGNORE, ierr)
1226-
#endif
12271220

12281221
! Unpack Received Buffer (skip if no source rank)
12291222
call nvtxStartRange("BETA-COMM-UNPACKBUF")

src/post_process/m_start_up.fpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -784,7 +784,7 @@ contains
784784
end if
785785
if (num_procs > 1) then
786786
call s_initialize_mpi_proxy_module()
787-
call s_initialize_mpi_common_module()
787+
call s_initialize_mpi_common_module(exchange_all_chemistry_temperatures_in=.true., use_rdma_transport_in=.false.)
788788
end if
789789
call s_initialize_boundary_common_module()
790790
call s_initialize_variables_conversion_module(store_mixture_fields=.true., lagrange_beta_index=beta_idx)

src/pre_process/m_start_up.fpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ contains
476476
if (bubbles_euler .or. bubbles_lagrange) then
477477
call s_initialize_bubbles_model()
478478
end if
479-
call s_initialize_mpi_common_module()
479+
call s_initialize_mpi_common_module(exchange_all_chemistry_temperatures_in=.false., use_rdma_transport_in=.false.)
480480
call s_initialize_data_output_module()
481481
call s_initialize_variables_conversion_module()
482482
call s_initialize_grid_module()

src/simulation/m_start_up.fpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -816,7 +816,7 @@ contains
816816
if (bubbles_euler .or. bubbles_lagrange) then
817817
call s_initialize_bubbles_model()
818818
end if
819-
call s_initialize_mpi_common_module()
819+
call s_initialize_mpi_common_module(exchange_all_chemistry_temperatures_in=.false., use_rdma_transport_in=rdma_mpi)
820820
call s_initialize_mpi_proxy_module()
821821
call s_initialize_variables_conversion_module(enforce_density_floor=.true., preserve_qbmm_number=.true.)
822822
if (grid_geometry == 3) call s_initialize_fftw_module()

0 commit comments

Comments
 (0)