Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
henryleberre committed Jan 6, 2024
1 parent d8366a3 commit 359d6ab
Show file tree
Hide file tree
Showing 11 changed files with 58 additions and 66 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/pretty.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,7 @@ jobs:
steps:
- uses: actions/checkout@v3

- name: Format diff
run: ./mfc.sh format diff
- name: Check formatting
run: |
./mfc.sh format
git diff --exit-code
2 changes: 1 addition & 1 deletion src/simulation/m_bubbles.fpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ contains

!$acc update device(rs, vs)
if (.not. polytropic) then
!$acc update device(ps, ms)
!$acc update device(ps, ms)
end if

end subroutine
Expand Down
2 changes: 1 addition & 1 deletion src/simulation/m_data_output.fpp
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ contains
if (prim_vars_wrt .or. (n == 0 .and. p == 0)) then
call s_convert_conservative_to_primitive_variables(q_cons_vf, q_prim_vf)
do i = 1, sys_size
!$acc update host(q_prim_vf(i)%sf(:,:,:))
!$acc update host(q_prim_vf(i)%sf(:,:,:))
end do
! q_prim_vf(bubxb) stores the value of nb needed in riemann solvers, so replace with true primitive value (=1d0)
if (qbmm) then
Expand Down
8 changes: 4 additions & 4 deletions src/simulation/m_global_parameters.fpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ module m_global_parameters
integer :: cpu_start, cpu_end, cpu_rate

#:if not MFC_CASE_OPTIMIZATION
!$acc declare create(num_dims, weno_polyn, weno_order)
!$acc declare create(num_dims, weno_polyn, weno_order)
#:endif

!$acc declare create(mpp_lim, num_fluids, model_eqns, mixture_err, alt_soundspeed, avg_state, mapped_weno, mp_weno, weno_eps, hypoelasticity, relax, palpha_eps,ptgalpha_eps)
Expand Down Expand Up @@ -282,7 +282,7 @@ module m_global_parameters
integer :: R0_type

#:if not MFC_CASE_OPTIMIZATION
!$acc declare create(nb)
!$acc declare create(nb)
#:endif

!$acc declare create(R0ref, Ca, Web, Re_inv, weight, R0, V0, bubbles, polytropic, polydisperse, qbmm, nmomsp, nmomtot, R0_type, ptil, bubble_model, thermal, poly_sigma)
Expand Down Expand Up @@ -495,8 +495,8 @@ contains
#:if not MFC_CASE_OPTIMIZATION
! Determining the degree of the WENO polynomials
weno_polyn = (weno_order - 1)/2
!$acc update device(weno_polyn)
!$acc update device(nb)
!$acc update device(weno_polyn)
!$acc update device(nb)
#:endif

! Initializing the number of fluids for which viscous effects will
Expand Down
28 changes: 14 additions & 14 deletions src/simulation/m_mpi_proxy.fpp
Original file line number Diff line number Diff line change
Expand Up @@ -991,7 +991,7 @@ contains
#if defined(MFC_OpenACC) && defined(__PGI)
if (cu_mpi .eqv. .false.) then
!$acc update device(q_cons_buff_recv)
!$acc update device(q_cons_buff_recv)
end if
#endif
Expand Down Expand Up @@ -1272,7 +1272,7 @@ contains
end if
if (cu_mpi .eqv. .false.) then
!$acc update device(q_cons_buff_recv)
!$acc update device(q_cons_buff_recv)
end if
! Unpacking buffer received from bc_x%end
Expand Down Expand Up @@ -1560,7 +1560,7 @@ contains
#if defined(MFC_OpenACC) && defined(__PGI)
if (cu_mpi .eqv. .false.) then
!$acc update device(q_cons_buff_recv)
!$acc update device(q_cons_buff_recv)
end if
#endif
Expand Down Expand Up @@ -1843,7 +1843,7 @@ contains
#if defined(MFC_OpenACC) && defined(__PGI)
if (cu_mpi .eqv. .false.) then
!$acc update device(q_cons_buff_recv)
!$acc update device(q_cons_buff_recv)
end if
#endif
Expand Down Expand Up @@ -1979,8 +1979,8 @@ contains
MPI_DOUBLE_PRECISION, bc_z%beg, 0, &
MPI_COMM_WORLD, MPI_STATUS_IGNORE, ierr)
!$acc end host_data
!$acc wait
!$acc end host_data
!$acc wait
else
#endif
Expand Down Expand Up @@ -2068,8 +2068,8 @@ contains
MPI_DOUBLE_PRECISION, bc_z%beg, 0, &
MPI_COMM_WORLD, MPI_STATUS_IGNORE, ierr)
!$acc end host_data
!$acc wait
!$acc end host_data
!$acc wait
else
#endif
Expand All @@ -2093,7 +2093,7 @@ contains
#if defined(MFC_OpenACC) && defined(__PGI)
if (cu_mpi .eqv. .false.) then
!$acc update device(q_cons_buff_recv)
!$acc update device(q_cons_buff_recv)
end if
#endif
Expand Down Expand Up @@ -2224,8 +2224,8 @@ contains
MPI_DOUBLE_PRECISION, bc_z%end, 1, &
MPI_COMM_WORLD, MPI_STATUS_IGNORE, ierr)
!$acc end host_data
!$acc wait
!$acc end host_data
!$acc wait
else
#endif
!$acc update host(q_cons_buff_send)
Expand Down Expand Up @@ -2314,8 +2314,8 @@ contains
MPI_DOUBLE_PRECISION, bc_z%end, 1, &
MPI_COMM_WORLD, MPI_STATUS_IGNORE, ierr)
!$acc end host_data
!$acc wait
!$acc end host_data
!$acc wait
else
#endif
!$acc update host(q_cons_buff_send)
Expand All @@ -2338,7 +2338,7 @@ contains
#if defined(MFC_OpenACC) && defined(__PGI)
if (cu_mpi .eqv. .false.) then
!$acc update device(q_cons_buff_recv)
!$acc update device(q_cons_buff_recv)
end if
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/simulation/m_qbmm.fpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ contains
nterms = 7
end if

!$acc update device(nterms)
!$acc update device(nterms)

#:endif

Expand Down
12 changes: 6 additions & 6 deletions src/simulation/m_start_up.fpp
Original file line number Diff line number Diff line change
Expand Up @@ -891,7 +891,7 @@ contains

if (probe_wrt) then
do i = 1, sys_size
!$acc update host(q_cons_ts(1)%vf(i)%sf)
!$acc update host(q_cons_ts(1)%vf(i)%sf)
end do
end if

Expand Down Expand Up @@ -999,8 +999,8 @@ contains
end do

if (qbmm .and. .not. polytropic) then
!$acc update host(pb_ts(1)%sf)
!$acc update host(mv_ts(1)%sf)
!$acc update host(pb_ts(1)%sf)
!$acc update host(mv_ts(1)%sf)
end if

call s_write_data_files(q_cons_ts(1)%vf, q_prim_vf, t_step)
Expand Down Expand Up @@ -1168,18 +1168,18 @@ contains
!$acc update device(m, n, p)
!$acc update device(momxb, momxe, bubxb, bubxe, advxb, advxe, contxb, contxe, strxb, strxe)
do i = 1, sys_size
!$acc update device(q_cons_ts(1)%vf(i)%sf)
!$acc update device(q_cons_ts(1)%vf(i)%sf)
end do
if (qbmm .and. .not. polytropic) then
!$acc update device(pb_ts(1)%sf, mv_ts(1)%sf)
!$acc update device(pb_ts(1)%sf, mv_ts(1)%sf)
end if
!$acc update device(dt, sys_size, pref, rhoref, gamma_idx, pi_inf_idx, E_idx, alf_idx, stress_idx, mpp_lim, bubbles, hypoelasticity, alt_soundspeed, avg_state, num_fluids, model_eqns, num_dims, mixture_err, nb, weight, grid_geometry, cyl_coord, mapped_weno, mp_weno, weno_eps)
!$acc update device(nb, R0ref, Ca, Web, Re_inv, weight, R0, V0, bubbles, polytropic, polydisperse, qbmm, R0_type, ptil, bubble_model, thermal, poly_sigma)
!$acc update device(R_n, R_v, phi_vn, phi_nv, Pe_c, Tw, pv, M_n, M_v, k_n, k_v, pb0, mass_n0, mass_v0, Pe_T, Re_trans_T, Re_trans_c, Im_trans_T, Im_trans_c, omegaN , mul0, ss, gamma_v, mu_v, gamma_m, gamma_n, mu_n, gam)
!$acc update device(monopole, num_mono)
!$acc update device(relax)
if (relax) then
!$acc update device(palpha_eps, ptgalpha_eps)
!$acc update device(palpha_eps, ptgalpha_eps)
end if
end subroutine s_initialize_gpu_vars

Expand Down
2 changes: 1 addition & 1 deletion src/simulation/m_time_steppers.fpp
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,7 @@ contains
integer :: i !< Generic loop iterator

do i = 1, sys_size
!$acc update host(q_prim_vf(i)%sf)
!$acc update host(q_prim_vf(i)%sf)
end do

if (t_step == t_step_start) then
Expand Down
6 changes: 3 additions & 3 deletions src/simulation/m_weno.fpp
Original file line number Diff line number Diff line change
Expand Up @@ -449,11 +449,11 @@ contains

! END: Computing WENO5 Coefficients ================================
if (weno_dir == 1) then
!$acc update device(poly_coef_cbL_x, poly_coef_cbR_x, d_cbL_x, d_cbR_x, beta_coef_x)
!$acc update device(poly_coef_cbL_x, poly_coef_cbR_x, d_cbL_x, d_cbR_x, beta_coef_x)
elseif (weno_dir == 2) then
!$acc update device(poly_coef_cbL_y, poly_coef_cbR_y, d_cbL_y, d_cbR_y, beta_coef_y)
!$acc update device(poly_coef_cbL_y, poly_coef_cbR_y, d_cbL_y, d_cbR_y, beta_coef_y)
else
!$acc update device(poly_coef_cbL_z, poly_coef_cbR_z, d_cbL_z, d_cbR_z, beta_coef_z)
!$acc update device(poly_coef_cbL_z, poly_coef_cbR_z, d_cbL_z, d_cbR_z, beta_coef_z)
end if

! Nullifying WENO coefficients and cell-boundary locations pointers
Expand Down
33 changes: 10 additions & 23 deletions toolchain/bootstrap/format.sh
Original file line number Diff line number Diff line change
@@ -1,32 +1,19 @@
#!/bin/bash

log "MFC format..."
log "Formatting MFC:"

opts="--recursive --silent --indent 4 --c-relations --enable-replacements --enable-decl --whitespace-comma 1 --whitespace-multdiv 0 --whitespace-plusminus 1 --case 1 1 1 1 --strict-indent --line-length 1000"
fortran_files=$(find ${@:-src} -type f | grep -Ev 'src/.+/autogen/')

if [ "$1" == "diff" ]; then
log "Checking format diff..."
shift

out_prettify=$(fprettify ${@:-src} --exclude "src/*/autogen" $opts -s -d)
if [ -z "${out_prettify}" ]; then
ok "Already pretty!"
exit 0
else
error "Not pretty, run ./mfc.sh format"
exit 1
fi
fi

# Indent acc directives
srcfiles=( src/*/*.f* )
includefiles=( src/*/include/*.f* )
files=( "${srcfiles[@]}" "${includefiles[@]}" )
for filename in ${files[@]}; do
log "+ Indenting acc directives..."
for filename in $fortran_files; do
python3 toolchain/indenter.py "$filename"
done

fprettify ${@:-src} --exclude "src/*/autogen" $opts
log "+ Running fprettify..."
fprettify $fortran_files --exclude "src/*/autogen" \
--recursive --silent --indent 4 --c-relations --enable-replacements \
--enable-decl --whitespace-comma 1 --whitespace-multdiv 0 \
--whitespace-plusminus 1 --case 1 1 1 1 --strict-indent --line-length 1000
ret="$?"

if [ "$ret" != '0' ]; then
Expand All @@ -36,4 +23,4 @@ if [ "$ret" != '0' ]; then
exit 1
fi

ok "MFC format complete."
ok "Done. MFC has been formatted."
23 changes: 13 additions & 10 deletions toolchain/indenter.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
#!/usr/bin/env python3
import sys
import os

import os, argparse

def main():
num_args = len(sys.argv)
if num_args != 2:
raise ValueError('Invalid number of arguments, found ', num_args)
parser = argparse.ArgumentParser(
prog='indenter.py',
description='Adjust indentation of OpenACC directives in a Fortran file')
parser.add_argument('filepath', metavar='input_file', type=str, help='File to format')
args = vars(parser.parse_args())

filepath = args['filepath']

infile = str(sys.argv[1])
outfile = infile+".new"
adjust_indentation(infile, outfile)
os.replace(outfile,infile)
temp_filepath = f"{filepath}.new"
adjust_indentation(filepath, temp_filepath)
os.replace(temp_filepath, filepath)

# pylint: disable=too-many-branches
def adjust_indentation(input_file, output_file):
Expand Down Expand Up @@ -70,7 +73,7 @@ def adjust_indentation(input_file, output_file):
lines[i].lstrip().startswith(startingloop2)) and \
i+1 < len(lines) and lines[i+1].strip() == '':
file_out.write(lines[i])
i +=2
i += 2
else:
file_out.write(lines[i])
i += 1
Expand Down

0 comments on commit 359d6ab

Please sign in to comment.