Skip to content

Code tidying #907

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
20 changes: 7 additions & 13 deletions src/common/m_boundary_common.fpp
Original file line number Diff line number Diff line change
Expand Up @@ -1021,9 +1021,9 @@ contains
integer, intent(in) :: bc_dir, bc_loc
integer, intent(in) :: k, l

#ifdef MFC_SIMULATION
integer :: j, i

#ifdef MFC_SIMULATION
if (bc_dir == 1) then !< x-direction
if (bc_loc == -1) then !bc_x%beg
do i = 1, sys_size
Expand Down Expand Up @@ -1665,7 +1665,7 @@ contains

character(LEN=*), intent(in) :: step_dirpath

integer :: dir, loc, i
integer :: dir, loc
character(len=path_len) :: file_path

character(len=10) :: status
Expand Down Expand Up @@ -1706,12 +1706,10 @@ contains
integer :: dir, loc
character(len=path_len) :: file_loc, file_path

character(len=10) :: status

#ifdef MFC_MPI
integer :: ierr
integer :: file_id
integer :: offset
integer(KIND=MPI_ADDRESS_KIND) :: offset
character(len=7) :: proc_rank_str
logical :: dir_check

Expand Down Expand Up @@ -1770,8 +1768,6 @@ contains
logical :: file_exist
character(len=path_len) :: file_path

character(len=10) :: status

! Read bc_types
file_path = trim(step_dirpath)//'/bc_type.dat'
inquire (FILE=trim(file_path), EXIST=file_exist)
Expand Down Expand Up @@ -1813,12 +1809,10 @@ contains
integer :: dir, loc
character(len=path_len) :: file_loc, file_path

character(len=10) :: status

#ifdef MFC_MPI
integer :: ierr
integer :: file_id
integer :: offset
integer(KIND=MPI_ADDRESS_KIND) :: offset
character(len=7) :: proc_rank_str
logical :: dir_check

Expand All @@ -1841,7 +1835,7 @@ contains
file_path = trim(file_loc)//'/bc_'//trim(proc_rank_str)//'.dat'
call MPI_File_open(MPI_COMM_SELF, trim(file_path), MPI_MODE_RDONLY, MPI_INFO_NULL, file_id, ierr)

offset = 0
offset = int(0, KIND=MPI_ADDRESS_KIND)

! Read bc_types
do dir = 1, num_dims
Expand Down Expand Up @@ -1933,9 +1927,9 @@ contains
!! boundary locations and cell-width distributions, based on
!! the boundary conditions.
subroutine s_populate_grid_variables_buffers

#ifndef MFC_PRE_PROCESS
integer :: i !< Generic loop iterator

#endif
#ifdef MFC_SIMULATION
! Required for compatibility between codes
type(int_bounds_info) :: offset_x, offset_y, offset_z
Expand Down
5 changes: 3 additions & 2 deletions src/common/m_checker_common.fpp
Original file line number Diff line number Diff line change
Expand Up @@ -331,8 +331,9 @@ contains
!> Checks constraints on the surface tension parameters.
!! Called by s_check_inputs_common for all three stages
impure subroutine s_check_inputs_surface_tension

#ifdef MFC_PRE_PROCESS
integer :: i
#endif

@:PROHIBIT(surface_tension .and. sigma < 0._wp, &
"sigma must be greater than or equal to zero")
Expand All @@ -354,7 +355,7 @@ contains
@:PROHIBIT(surface_tension .and. f_is_default(patch_icpp(i)%cf_val), &
"patch_icpp(i)%cf_val must be set if surface_tension is enabled")
end do
#endif MFC_PRE_PROCESS
#endif

end subroutine s_check_inputs_surface_tension

Expand Down
15 changes: 11 additions & 4 deletions src/common/m_finite_differences.fpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,18 +70,20 @@ contains
!! @param s_cc Locations of the cell-centers in the s-coordinate direction
!! @param fd_coeff_s Finite-diff. coefficients in the s-coordinate direction
pure subroutine s_compute_finite_difference_coefficients(q, s_cc, fd_coeff_s, local_buff_size, &
fd_number_in, fd_order_in, offset_s)
fd_order_in, fd_number_in, offset_s)

integer :: lB, lE !< loop bounds
integer, intent(IN) :: q
integer, intent(IN) :: local_buff_size, fd_number_in, fd_order_in
integer, intent(IN) :: local_buff_size, fd_order_in
integer, optional, intent(IN) :: fd_number_in

type(int_bounds_info), optional, intent(IN) :: offset_s
real(wp), allocatable, dimension(:, :), intent(INOUT) :: fd_coeff_s

real(wp), &
dimension(-local_buff_size:q + local_buff_size), &
intent(IN) :: s_cc

integer :: fd_number
integer :: i !< Generic loop iterator

if (present(offset_s)) then
Expand All @@ -91,10 +93,15 @@ contains
lB = 0
lE = q
end if
if (present(fd_number_in)) then
fd_number = fd_number_in
else
fd_number = 2
end if

#ifdef MFC_POST_PROCESS
if (allocated(fd_coeff_s)) deallocate (fd_coeff_s)
allocate (fd_coeff_s(-fd_number_in:fd_number_in, lb:lE))
allocate (fd_coeff_s(-fd_number:fd_number, lb:lE))
#endif

! Computing the 1st order finite-difference coefficients
Expand Down
17 changes: 13 additions & 4 deletions src/common/m_helper_basic.fpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
module m_helper_basic

use m_derived_types !< Definitions of the derived types
use m_precision_select !< Definitions of the precision types

implicit none

Expand All @@ -24,7 +25,7 @@ contains
!> This procedure checks if two floating point numbers of wp are within tolerance.
!! @param a First number.
!! @param b Second number.
!! @param tol_input Relative error (default = 1.e-10_wp).
!! @param tol_input Relative error (default = 1.e-10_wp for double and 1e-6 for single).
!! @return Result of the comparison.
logical pure elemental function f_approx_equal(a, b, tol_input) result(res)
$:GPU_ROUTINE(parallelism='[seq]')
Expand All @@ -35,7 +36,11 @@ contains
if (present(tol_input)) then
tol = tol_input
else
tol = 1.e-10_wp
if (wp == single_precision) then
tol = 1.e-6_wp
else
tol = 1.e-10_wp
end if
end if

if (a == b) then
Expand All @@ -50,7 +55,7 @@ contains
!> This procedure checks if the point numbers of wp belongs to another array are within tolerance.
!! @param a First number.
!! @param b Array that contains several point numbers.
!! @param tol_input Relative error (default = 1e-10_wp).
!! @param tol_input Relative error (default = 1.e-10_wp for double and 1e-6 for single).
!! @return Result of the comparison.
logical pure function f_approx_in_array(a, b, tol_input) result(res)
$:GPU_ROUTINE(parallelism='[seq]')
Expand All @@ -65,7 +70,11 @@ contains
if (present(tol_input)) then
tol = tol_input
else
tol = 1e-10_wp
if (wp == single_precision) then
tol = 1.e-6_wp
else
tol = 1.e-10_wp
end if
end if

do i = 1, size(b)
Expand Down
18 changes: 15 additions & 3 deletions src/common/m_mpi_common.fpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,17 @@ contains
type(scalar_field), intent(in), optional :: beta

integer, dimension(num_dims) :: sizes_glb, sizes_loc
integer, dimension(1) :: airfoil_glb, airfoil_loc, airfoil_start
#ifndef MFC_POST_PROCESS

integer, dimension(1) :: airfoil_glb, airfoil_loc, airfoil_start
#endif
#ifdef MFC_MPI

! Generic loop iterator
integer :: i, j
integer :: i
#ifndef MFC_POST_PROCESS
integer :: j
#endif
integer :: ierr !< Generic flag used to identify and report MPI errors

!Altered system size for the lagrangian subgrid bubble model
Expand Down Expand Up @@ -369,11 +374,18 @@ contains
real(wp), intent(out) :: icfl_max_glb
real(wp), intent(out) :: vcfl_max_glb
real(wp), intent(out) :: Rc_min_glb

#ifdef MFC_SIMULATION
#ifdef MFC_MPI
integer :: ierr !< Generic flag used to identify and report MPI errors
#endif
#endif
! Initiate the global variables to the local values
icfl_max_glb = icfl_max_loc
vcfl_max_glb = vcfl_max_loc
Rc_min_glb = Rc_min_loc

#ifdef MFC_SIMULATION
#ifdef MFC_MPI
! Reducing local extrema of ICFL, VCFL, CCFL and Rc numbers to their
! global extrema and bookkeeping the results on the rank 0 processor
call MPI_REDUCE(icfl_max_loc, icfl_max_glb, 1, &
Expand Down
19 changes: 12 additions & 7 deletions src/common/m_nvtx.f90
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,24 @@ end subroutine nvtxRangePop

subroutine nvtxStartRange(name, id)
character(kind=c_char, len=*), intent(IN) :: name
integer, intent(IN), optional :: id
integer, intent(in), optional :: id
integer :: id_color
#if defined(MFC_OpenACC) && defined(__PGI)
type(nvtxEventAttributes) :: event
#endif
if (present(id)) then
id_color = col(mod(id, 7) + 1)
end if
tempName = trim(name)//c_null_char

#if defined(MFC_OpenACC) && defined(__PGI)

tempName = trim(name)//c_null_char

if (.not. present(id)) then
call nvtxRangePush(tempName)
else
event%color = col(mod(id, 7) + 1)
if (present(id)) then
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this work, too? you need to run nsys with cpu and gpu modes to find out

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is one output with --nsys and --gpu
Now that each row represent a specific NVTX range, I think this code works properly.

[3/8] Executing 'nvtx_sum' stats report
 Time (%)  Total Time (ns)  Instances     Avg (ns)         Med (ns)        Min (ns)       Max (ns)     StdDev (ns)   Style           Range        
 --------  ---------------  ---------  ---------------  ---------------  -------------  -------------  -----------  -------  ---------------------
     22.5    2,208,358,145          1  2,208,358,145.0  2,208,358,145.0  2,208,358,145  2,208,358,145          0.0  PushPop  SIMULATION-TIME-MARCH
     19.1    1,867,369,618          1  1,867,369,618.0  1,867,369,618.0  1,867,369,618  1,867,369,618          0.0  PushPop  INIT                 
     13.0    1,274,854,743          1  1,274,854,743.0  1,274,854,743.0  1,274,854,743  1,274,854,743          0.0  PushPop  INIT-MODULES         
     12.5    1,223,361,067         50     24,467,221.3     23,591,994.0     21,520,831     50,213,333  3,972,174.3  PushPop  TIMESTEP             
      8.3      817,515,022          1    817,515,022.0    817,515,022.0    817,515,022    817,515,022          0.0  PushPop  SAVE-DATA            
      6.5      637,690,738        150      4,251,271.6      4,070,501.5      3,991,106     27,681,810  1,927,606.5  PushPop  COMPUTE-RHS          
      6.0      591,356,493          1    591,356,493.0    591,356,493.0    591,356,493    591,356,493          0.0  PushPop  INIT-MPI             
      4.3      421,111,172          1    421,111,172.0    421,111,172.0    421,111,172    421,111,172          0.0  PushPop  MPI:MPI_Init         
      3.6      349,779,183        450        777,287.1        764,172.0        749,605      3,553,709    132,730.3  PushPop  RHS-ADVECTION-SRC    
      1.5      142,218,607        450        316,041.3        303,346.0        282,750      4,176,763    182,804.3  PushPop  RHS-WENO             
      0.8       81,742,288        450        181,649.5        165,865.5        160,829      6,887,448    316,954.3  PushPop  RHS-RIEMANN-SOLVER   
      0.7       66,194,030          1     66,194,030.0     66,194,030.0     66,194,030     66,194,030          0.0  PushPop  FINALIZE-MODULES     
      0.6       62,960,296          1     62,960,296.0     62,960,296.0     62,960,296     62,960,296          0.0  PushPop  MPI:MPI_Finalize     
      0.3       30,719,602        150        204,797.3        164,348.0        160,500      6,002,360    476,562.6  PushPop  RHS-COMMUNICATION    
      0.1       11,811,929        150         78,746.2         76,288.5         74,967        317,997     19,778.8  PushPop  RHS-ACOUSTIC-SRC     
      0.1       10,396,748        150         69,311.7         44,600.0         41,059      3,761,697    303,513.2  PushPop  RHS-CONVERT          
      0.0        1,134,973          1      1,134,973.0      1,134,973.0      1,134,973      1,134,973          0.0  PushPop  INIT-GPU-VARS        
      0.0          225,778        745            303.1            322.0            163          1,897        119.6  PushPop  MPI:MPI_Bcast        
      0.0          144,716        450            321.6            311.5            172            748         84.4  PushPop  RHS-HYPOELASTICITY   
      0.0          125,007        450            277.8            265.0            152            602         76.3  PushPop  RHS-MHD              
      0.0           75,393         51          1,478.3            838.0            721          7,647      1,806.1  PushPop  MPI:MPI_Barrier      
      0.0           72,677        200            363.4            326.0            164          5,742        391.1  PushPop  RHS-ELASTIC          

event%color = id_color
event%message = c_loc(tempName)
call nvtxRangePushEx(event)
else
call nvtxRangePushA(tempName)
end if

#endif
Expand Down
4 changes: 2 additions & 2 deletions src/common/m_phase_change.fpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ contains
!> This subroutine should dispatch to the correct relaxation solver based
!! some parameter. It replaces the procedure pointer, which CCE
!! is breaking on.
impure subroutine s_relaxation_solver(q_cons_vf)
type(scalar_field), dimension(sys_size), intent(inout) :: q_cons_vf
impure subroutine s_relaxation_solver()
!type(scalar_field), dimension(sys_size), intent(inout) :: q_cons_vf
! This is empty because in current master the procedure pointer
! was never assigned
@:ASSERT(.false., "s_relaxation_solver called but it currently does nothing")
Expand Down
Loading
Loading