diff --git a/.github/workflows/pretty.yml b/.github/workflows/pretty.yml index 68ea46ea8..4c37aeb59 100644 --- a/.github/workflows/pretty.yml +++ b/.github/workflows/pretty.yml @@ -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 diff --git a/src/simulation/m_bubbles.fpp b/src/simulation/m_bubbles.fpp index 052ac3210..ee80c674d 100644 --- a/src/simulation/m_bubbles.fpp +++ b/src/simulation/m_bubbles.fpp @@ -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 diff --git a/src/simulation/m_data_output.fpp b/src/simulation/m_data_output.fpp index d6ea41516..1ed0fa589 100644 --- a/src/simulation/m_data_output.fpp +++ b/src/simulation/m_data_output.fpp @@ -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 diff --git a/src/simulation/m_global_parameters.fpp b/src/simulation/m_global_parameters.fpp index 18b3702c0..b4d507781 100644 --- a/src/simulation/m_global_parameters.fpp +++ b/src/simulation/m_global_parameters.fpp @@ -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) @@ -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) @@ -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 diff --git a/src/simulation/m_mpi_proxy.fpp b/src/simulation/m_mpi_proxy.fpp index c165401f4..b5e01e985 100644 --- a/src/simulation/m_mpi_proxy.fpp +++ b/src/simulation/m_mpi_proxy.fpp @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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) @@ -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) @@ -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 diff --git a/src/simulation/m_qbmm.fpp b/src/simulation/m_qbmm.fpp index a1291621e..311385404 100644 --- a/src/simulation/m_qbmm.fpp +++ b/src/simulation/m_qbmm.fpp @@ -58,7 +58,7 @@ contains nterms = 7 end if - !$acc update device(nterms) + !$acc update device(nterms) #:endif diff --git a/src/simulation/m_start_up.fpp b/src/simulation/m_start_up.fpp index cd812be58..044c6c02d 100644 --- a/src/simulation/m_start_up.fpp +++ b/src/simulation/m_start_up.fpp @@ -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 @@ -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) @@ -1168,10 +1168,10 @@ 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) @@ -1179,7 +1179,7 @@ contains !$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 diff --git a/src/simulation/m_time_steppers.fpp b/src/simulation/m_time_steppers.fpp index fc1e1065f..325bdf79a 100644 --- a/src/simulation/m_time_steppers.fpp +++ b/src/simulation/m_time_steppers.fpp @@ -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 diff --git a/src/simulation/m_weno.fpp b/src/simulation/m_weno.fpp index f1facc15e..e4a071b84 100644 --- a/src/simulation/m_weno.fpp +++ b/src/simulation/m_weno.fpp @@ -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 diff --git a/toolchain/bootstrap/format.sh b/toolchain/bootstrap/format.sh index ccafd4fc9..24b0839d9 100644 --- a/toolchain/bootstrap/format.sh +++ b/toolchain/bootstrap/format.sh @@ -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 @@ -36,4 +23,4 @@ if [ "$ret" != '0' ]; then exit 1 fi -ok "MFC format complete." +ok "Done. MFC has been formatted." diff --git a/toolchain/indenter.py b/toolchain/indenter.py index 284e27519..1561cbe6f 100644 --- a/toolchain/indenter.py +++ b/toolchain/indenter.py @@ -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): @@ -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