From 6b9a28c8bdbde30241905d737f22c93efd1f141e Mon Sep 17 00:00:00 2001 From: Tanush Prathi Date: Sun, 13 Jul 2025 21:13:27 -0400 Subject: [PATCH 1/2] Save allocate instrinsics --- src/common/m_derived_types.fpp | 6 ++++++ src/common/m_helper_basic.fpp | 23 ++++++++++++++++++++++- src/common/m_mpi_common.fpp | 6 ++++-- src/common/m_variables_conversion.fpp | 2 +- src/post_process/m_global_parameters.fpp | 5 +++++ src/post_process/m_start_up.f90 | 3 +++ src/pre_process/m_global_parameters.fpp | 6 ++++++ src/pre_process/m_start_up.fpp | 3 +++ src/simulation/m_global_parameters.fpp | 16 +++++++++++----- src/simulation/m_mpi_proxy.fpp | 4 ++-- src/simulation/m_pressure_relaxation.fpp | 2 +- src/simulation/m_riemann_solvers.fpp | 2 +- src/simulation/m_start_up.fpp | 2 ++ src/simulation/m_viscous.fpp | 2 +- 14 files changed, 68 insertions(+), 14 deletions(-) diff --git a/src/common/m_derived_types.fpp b/src/common/m_derived_types.fpp index 59156d1c12..42eefdc986 100644 --- a/src/common/m_derived_types.fpp +++ b/src/common/m_derived_types.fpp @@ -443,4 +443,10 @@ module m_derived_types end type bubbles_lagrange_parameters + !> Max and min number of cells in a direction of each combination of x-,y-, and z- + type cell_num_bounds + integer :: mn_max, np_max, mp_max, mnp_max + integer :: mn_min, np_min, mp_min, mnp_min + end type cell_num_bounds + end module m_derived_types diff --git a/src/common/m_helper_basic.fpp b/src/common/m_helper_basic.fpp index c78140c94b..6cb1d9c4ef 100644 --- a/src/common/m_helper_basic.fpp +++ b/src/common/m_helper_basic.fpp @@ -16,7 +16,8 @@ module m_helper_basic f_is_default, & f_all_default, & f_is_integer, & - s_configure_coordinate_bounds + s_configure_coordinate_bounds, & + s_update_cell_bounds contains @@ -146,4 +147,24 @@ contains end subroutine s_configure_coordinate_bounds + !> Updates the min and max number of cells in each set of axes + !! @param bounds Min ans max values to update + !! @param m Number of cells in x-axis + !! @param n Number of cells in y-axis + !! @param p Number of cells in z-axis + pure elemental subroutine s_update_cell_bounds(bounds, m, n, p) + type(cell_num_bounds), intent(out) :: bounds + integer, intent(in) :: m, n, p + + bounds%mn_max = max(m, n) + bounds%np_max = max(n, p) + bounds%mp_max = max(m, p) + bounds%mnp_max = max(m, n, p) + bounds%mn_min = min(m, n) + bounds%np_min = min(n, p) + bounds%mp_min = min(m, p) + bounds%mnp_min = min(m, n, p) + + end subroutine s_update_cell_bounds + end module m_helper_basic diff --git a/src/common/m_mpi_common.fpp b/src/common/m_mpi_common.fpp index 568dddb299..47319d8395 100644 --- a/src/common/m_mpi_common.fpp +++ b/src/common/m_mpi_common.fpp @@ -67,10 +67,10 @@ contains & (m + 2*buff_size + 1)* & & (n + 2*buff_size + 1)* & & (p + 2*buff_size + 1)/ & - & (min(m, n, p) + 2*buff_size + 1)) + & (cells_bounds%mnp_min + 2*buff_size + 1)) else halo_size = -1 + buff_size*(v_size)* & - & (max(m, n) + 2*buff_size + 1) + & (cells_bounds%mn_max + 2*buff_size + 1) end if else halo_size = -1 + buff_size*(v_size) @@ -1446,6 +1446,8 @@ contains end if end do + call s_update_cell_bounds(cells_bounds, m, n, p) + ! Boundary condition at the beginning if (proc_coords(1) > 0 .or. (bc_x%beg == BC_PERIODIC .and. num_procs_x > 1)) then proc_coords(1) = proc_coords(1) - 1 diff --git a/src/common/m_variables_conversion.fpp b/src/common/m_variables_conversion.fpp index 6a67b56315..5174e25cc2 100644 --- a/src/common/m_variables_conversion.fpp +++ b/src/common/m_variables_conversion.fpp @@ -637,7 +637,7 @@ contains #ifdef MFC_SIMULATION if (viscous) then - @:ALLOCATE(Res(1:2, 1:maxval(Re_size))) + @:ALLOCATE(Res(1:2, 1:Re_size_max)) do i = 1, 2 do j = 1, Re_size(i) Res(i, j) = fluid_pp(Re_idx(i, j))%Re(i) diff --git a/src/post_process/m_global_parameters.fpp b/src/post_process/m_global_parameters.fpp index 0f1c764670..1bf27344f1 100644 --- a/src/post_process/m_global_parameters.fpp +++ b/src/post_process/m_global_parameters.fpp @@ -38,6 +38,9 @@ module m_global_parameters integer :: p !> @} + !> @name Max and min number of cells in a direction of each combination of x-,y-, and z- + type(cell_num_bounds) :: cells_bounds + integer(8) :: nGlobal ! Total number of cells in global domain !> @name Cylindrical coordinates (either axisymmetric or full 3D) @@ -336,6 +339,8 @@ contains ! Computational domain parameters m = dflt_int; n = 0; p = 0 + call s_update_cell_bounds(cells_bounds, m, n, p) + m_root = dflt_int cyl_coord = .false. diff --git a/src/post_process/m_start_up.f90 b/src/post_process/m_start_up.f90 index b733f43dd9..e7337a347d 100644 --- a/src/post_process/m_start_up.f90 +++ b/src/post_process/m_start_up.f90 @@ -111,6 +111,9 @@ impure subroutine s_read_input_file end if close (1) + + call s_update_cell_bounds(cells_bounds, m, n, p) + ! Store m,n,p into global m,n,p m_glb = m n_glb = n diff --git a/src/pre_process/m_global_parameters.fpp b/src/pre_process/m_global_parameters.fpp index 2358cd71f4..b9f45b5d12 100644 --- a/src/pre_process/m_global_parameters.fpp +++ b/src/pre_process/m_global_parameters.fpp @@ -40,6 +40,9 @@ module m_global_parameters integer :: n integer :: p + !> @name Max and min number of cells in a direction of each combination of x-,y-, and z- + type(cell_num_bounds) :: cells_bounds + integer(8) :: nGlobal !< Global number of cells in the domain integer :: m_glb, n_glb, p_glb !< Global number of cells in each direction @@ -306,6 +309,9 @@ contains ! Computational domain parameters m = dflt_int; n = 0; p = 0 + call s_update_cell_bounds(cells_bounds, m, n, p) + + cyl_coord = .false. x_domain%beg = dflt_real diff --git a/src/pre_process/m_start_up.fpp b/src/pre_process/m_start_up.fpp index 6f8c6f17a6..c0bc231709 100644 --- a/src/pre_process/m_start_up.fpp +++ b/src/pre_process/m_start_up.fpp @@ -169,6 +169,9 @@ contains 'likely due to a datatype mismatch. Exiting.') end if close (1) + + call s_update_cell_bounds(cells_bounds, m, n, p) + ! Store m,n,p into global m,n,p m_glb = m n_glb = n diff --git a/src/simulation/m_global_parameters.fpp b/src/simulation/m_global_parameters.fpp index 560f71d1a3..865c08fa9d 100644 --- a/src/simulation/m_global_parameters.fpp +++ b/src/simulation/m_global_parameters.fpp @@ -43,6 +43,9 @@ module m_global_parameters integer :: m, n, p !> @} + !> @name Max and min number of cells in a direction of each combination of x-,y-, and z- + type(cell_num_bounds) :: cells_bounds + !> @name Global number of cells in each direction !> @{ integer :: m_glb, n_glb, p_glb @@ -273,10 +276,11 @@ module m_global_parameters !! numbers, will be non-negligible. !> @{ integer, dimension(2) :: Re_size + integer :: Re_size_max integer, allocatable, dimension(:, :) :: Re_idx !> @} - $:GPU_DECLARE(create='[Re_size,Re_idx]') + $:GPU_DECLARE(create='[Re_size,Re_size_max,Re_idx]') ! The WENO average (WA) flag regulates whether the calculation of any cell- ! average spatial derivatives is carried out in each cell by utilizing the @@ -525,6 +529,7 @@ contains ! Computational domain parameters m = dflt_int; n = 0; p = 0 + call s_update_cell_bounds(cells_bounds, m, n, p) cyl_coord = .false. @@ -809,6 +814,7 @@ contains ! of fluids for which the physical and geometric curvatures of the ! interfaces will be computed Re_size = 0 + Re_size_max = 0 ! Gamma/Pi_inf Model if (model_eqns == 1) then @@ -1036,13 +1042,15 @@ contains if (Re_size(1) > 0._wp) shear_stress = .true. if (Re_size(2) > 0._wp) bulk_stress = .true. - $:GPU_UPDATE(device='[Re_size,viscous,shear_stress,bulk_stress]') + Re_size_max = maxval(Re_size) + + $:GPU_UPDATE(device='[Re_size,Re_size_max,viscous,shear_stress,bulk_stress]') ! Bookkeeping the indexes of any viscous fluids and any pairs of ! fluids whose interface will support effects of surface tension if (viscous) then - @:ALLOCATE(Re_idx(1:2, 1:maxval(Re_size))) + @:ALLOCATE(Re_idx(1:2, 1:Re_size_max)) k = 0 do i = 1, num_fluids @@ -1169,8 +1177,6 @@ contains if (ib) allocate (MPI_IO_IB_DATA%var%sf(0:m, 0:n, 0:p)) Np = 0 - $:GPU_UPDATE(device='[Re_size]') - if (elasticity) then fd_number = max(1, fd_order/2) end if diff --git a/src/simulation/m_mpi_proxy.fpp b/src/simulation/m_mpi_proxy.fpp index e500a00898..168fd78fcf 100644 --- a/src/simulation/m_mpi_proxy.fpp +++ b/src/simulation/m_mpi_proxy.fpp @@ -62,10 +62,10 @@ contains & (m + 2*gp_layers + 1)* & & (n + 2*gp_layers + 1)* & & (p + 2*gp_layers + 1)/ & - & (min(m, n, p) + 2*gp_layers + 1) + & (cells_bounds%mnp_min + 2*gp_layers + 1) else i_halo_size = -1 + gp_layers* & - & (max(m, n) + 2*gp_layers + 1) + & (cells_bounds%mn_max + 2*gp_layers + 1) end if else i_halo_size = -1 + gp_layers diff --git a/src/simulation/m_pressure_relaxation.fpp b/src/simulation/m_pressure_relaxation.fpp index 624cfa5390..5affd3342f 100644 --- a/src/simulation/m_pressure_relaxation.fpp +++ b/src/simulation/m_pressure_relaxation.fpp @@ -42,7 +42,7 @@ contains $:GPU_UPDATE(device='[gamma_min, pres_inf]') if (viscous) then - @:ALLOCATE(Res(1:2, 1:maxval(Re_size))) + @:ALLOCATE(Res(1:2, 1:Re_size_max)) do i = 1, 2 do j = 1, Re_size(i) Res(i, j) = fluid_pp(Re_idx(i, j))%Re(i) diff --git a/src/simulation/m_riemann_solvers.fpp b/src/simulation/m_riemann_solvers.fpp index a189d7e3c3..1b77e17bfd 100644 --- a/src/simulation/m_riemann_solvers.fpp +++ b/src/simulation/m_riemann_solvers.fpp @@ -3169,7 +3169,7 @@ contains $:GPU_UPDATE(device='[Gs]') if (viscous) then - @:ALLOCATE(Res(1:2, 1:maxval(Re_size))) + @:ALLOCATE(Res(1:2, 1:Re_size_max)) end if if (viscous) then diff --git a/src/simulation/m_start_up.fpp b/src/simulation/m_start_up.fpp index 57106cfac9..765ec1b50f 100644 --- a/src/simulation/m_start_up.fpp +++ b/src/simulation/m_start_up.fpp @@ -210,6 +210,8 @@ contains n_glb = n p_glb = p + call s_update_cell_bounds(cells_bounds, m, n, p) + if (cfl_adap_dt .or. cfl_const_dt) cfl_dt = .true. if (any((/bc_x%beg, bc_x%end, bc_y%beg, bc_y%end, bc_z%beg, bc_z%end/) == -17) .or. & diff --git a/src/simulation/m_viscous.fpp b/src/simulation/m_viscous.fpp index ef301f5856..2aeec0a532 100644 --- a/src/simulation/m_viscous.fpp +++ b/src/simulation/m_viscous.fpp @@ -35,7 +35,7 @@ contains integer :: i, j !< generic loop iterators - @:ALLOCATE(Res_viscous(1:2, 1:maxval(Re_size))) + @:ALLOCATE(Res_viscous(1:2, 1:Re_size_max)) do i = 1, 2 do j = 1, Re_size(i) From 50aca4c3190499529c9ae6c9241d8d02a82c4b98 Mon Sep 17 00:00:00 2001 From: Tanush Prathi Date: Sun, 13 Jul 2025 21:20:45 -0400 Subject: [PATCH 2/2] Ran formatter --- src/common/m_helper_basic.fpp | 2 +- src/post_process/m_global_parameters.fpp | 2 +- src/pre_process/m_global_parameters.fpp | 1 - 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/common/m_helper_basic.fpp b/src/common/m_helper_basic.fpp index 6cb1d9c4ef..8abc6eb0ff 100644 --- a/src/common/m_helper_basic.fpp +++ b/src/common/m_helper_basic.fpp @@ -147,7 +147,7 @@ contains end subroutine s_configure_coordinate_bounds - !> Updates the min and max number of cells in each set of axes + !> Updates the min and max number of cells in each set of axes !! @param bounds Min ans max values to update !! @param m Number of cells in x-axis !! @param n Number of cells in y-axis diff --git a/src/post_process/m_global_parameters.fpp b/src/post_process/m_global_parameters.fpp index 1bf27344f1..7799870715 100644 --- a/src/post_process/m_global_parameters.fpp +++ b/src/post_process/m_global_parameters.fpp @@ -340,7 +340,7 @@ contains ! Computational domain parameters m = dflt_int; n = 0; p = 0 call s_update_cell_bounds(cells_bounds, m, n, p) - + m_root = dflt_int cyl_coord = .false. diff --git a/src/pre_process/m_global_parameters.fpp b/src/pre_process/m_global_parameters.fpp index b9f45b5d12..3df1d12250 100644 --- a/src/pre_process/m_global_parameters.fpp +++ b/src/pre_process/m_global_parameters.fpp @@ -311,7 +311,6 @@ contains call s_update_cell_bounds(cells_bounds, m, n, p) - cyl_coord = .false. x_domain%beg = dflt_real