Skip to content

Commit 73712a7

Browse files
committed
Merge remote-tracking branch 'upstream/master' into MPIRefactor
2 parents da744d7 + db44da1 commit 73712a7

35 files changed

+934
-1110
lines changed

.cursor/rules/mfc-agent-rules.mdc

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
---
2+
description: Full MFC project rules – consolidated for Agent Mode
3+
alwaysApply: true
4+
---
5+
6+
# 0 Purpose & Scope
7+
Consolidated guidance for the MFC exascale, many-physics solver.
8+
Written primarily for Fortran/Fypp; the OpenACC and style sections matter only when
9+
`.fpp` / `.f90` files are in view.
10+
11+
---
12+
13+
# 1 Global Project Context (always)
14+
- **Project**: *MFC* is modern Fortran 2008+ generated with **Fypp**.
15+
- Sources `src/`, tests `tests/`, examples `examples/`.
16+
- Most sources are `.fpp`; CMake transpiles them to `.f90`.
17+
- **Fypp macros** live in `src/<subprogram>/include/` you should scan these first.
18+
`<subprogram>` ∈ {`simulation`,`common`,`pre_process`,`post_process`}.
19+
- Only `simulation` (+ its `common` calls) is GPU-accelerated via **OpenACC**.
20+
- Assume free-form Fortran 2008+, `implicit none`, explicit `intent`, and modern
21+
intrinsics.
22+
- Prefer `module … contains … subroutine foo()`; avoid `COMMON` blocks and
23+
file-level `include` files.
24+
- **Read the full codebase and docs *before* changing code.**
25+
Docs: <https://mflowcode.github.io/documentation/md_readme.html> and the respository root `README.md`.
26+
27+
### Incremental-change workflow
28+
1. Draft a step-by-step plan.
29+
2. After each step, build:
30+
```bash
31+
./mfc.sh build -t pre_process simulation -j $(nproc)
32+
```
33+
3. If it compiles, run focused tests:
34+
```bash
35+
./mfc.sh test -j $(nproc) -f EA8FA07E -t 9E2CA336
36+
```
37+
4. Roll back & fix if a step fails.
38+
39+
* Do not run ./mfc.sh test -j $(nproc) without any other arguments (it takes too long to run all tests).
40+
41+
---
42+
43+
# 2 Style & Naming Conventions (for \*.fpp / \*.f90)
44+
45+
* **Indent 2 spaces**; continuation lines align under `&`.
46+
* Lower-case keywords and intrinsics (`do`, `end subroutine`, …).
47+
* **Modules**: `m_<feature>` (e.g. `m_transport`).
48+
* **Public procedures**:
49+
* Subroutine → `s_<verb>_<noun>` (e.g. `s_compute_flux`)
50+
* Function → `f_<verb>_<noun>`
51+
* Private helpers stay in the module; avoid nested procedures.
52+
* **Size limits**: subroutine ≤ 500 lines, helper ≤ 150, function ≤ 100,
53+
module/file ≤ 1000.
54+
* ≤ 6 arguments per routine; otherwise pass a derived-type “params” struct.
55+
* No `goto` (except unavoidable legacy); no global state (`COMMON`, `save`).
56+
* Every variable: `intent(in|out|inout)` + appropriate `dimension` / `allocatable`
57+
/ `pointer`.
58+
* Use `s_mpi_abort(<msg>)` for errors, not `stop`.
59+
* Mark OpenACC-callable helpers that are called from OpenACC parallel loops immediately after declaration:
60+
```fortran
61+
subroutine s_flux_update(...)
62+
!$acc routine seq
63+
...
64+
end subroutine
65+
```
66+
67+
---
68+
69+
# 3 OpenACC Programming Guidelines (for kernels)
70+
71+
Wrap tight loops with
72+
73+
```fortran
74+
!$acc parallel loop gang vector default(present) reduction(...)
75+
```
76+
* Add `collapse(n)` to merge nested loops when safe.
77+
* Declare loop-local variables with `private(...)`.
78+
* Allocate large arrays with `managed` or move them into a persistent
79+
`!$acc enter data` region at start-up.
80+
* **Do not** place `stop` / `error stop` inside device code.
81+
* Must compile with Cray `ftn` and NVIDIA `nvfortran` for GPU offloading; also build CPU-only with
82+
GNU `gfortran` and Intel `ifx`/`ifort`.

.github/workflows/phoenix/bench.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,13 @@ if [ "$job_device" == "gpu" ]; then
88
device_opts="--gpu -g $gpu_ids"
99
fi
1010

11+
mkdir -p /storage/scratch1/6/sbryngelson3/mytmp_build
12+
export TMPDIR=/storage/scratch1/6/sbryngelson3/mytmp_build
13+
1114
if ["$job_device" == "gpu"]; then
1215
./mfc.sh bench --mem 12 -j $(nproc) -o "$job_slug.yaml" -- -c phoenix-bench $device_opts -n $n_ranks
1316
else
1417
./mfc.sh bench --mem 1 -j $(nproc) -o "$job_slug.yaml" -- -c phoenix-bench $device_opts -n $n_ranks
1518
fi
19+
20+
unset TMPDIR

CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,13 +135,17 @@ if (CMAKE_Fortran_COMPILER_ID STREQUAL "GNU")
135135
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
136136
add_compile_options(
137137
-Wall
138+
-Wextra
138139
-fcheck=all,no-array-temps
139140
-fbacktrace
140141
-fimplicit-none
141-
#-ffpe-trap=invalid,zero,denormal,overflow
142142
-fsignaling-nans
143143
-finit-real=snan
144144
-finit-integer=-99999999
145+
-Wintrinsic-shadow
146+
-Wunderflow
147+
-Wrealloc-lhs
148+
-Wsurprising
145149
)
146150
endif()
147151

misc/length-subroutines.sh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/bin/bash
2+
3+
# Use gawk if available, otherwise fall back to awk
4+
if command -v gawk > /dev/null; then
5+
AWK_CMD="gawk"
6+
IGNORECASE_BLOCK='BEGIN { IGNORECASE = 1 }'
7+
else
8+
AWK_CMD="awk"
9+
IGNORECASE_BLOCK=''
10+
echo "Warning: gawk not found. Case-insensitive matching may not work as expected." >&2
11+
fi
12+
13+
find . -type f \( -name "*.f90" -o -name "*.fpp" \) | while read file; do
14+
"$AWK_CMD" "
15+
$IGNORECASE_BLOCK
16+
/^[ \t]*((pure|elemental|impure)[ \t]+)*subroutine[ \t]+[a-zA-Z_][a-zA-Z0-9_]*[ \t]*\\(/ {
17+
in_sub = 1
18+
match(\$0, /subroutine[ \t]+([a-zA-Z_][a-zA-Z0-9_]*)/, arr)
19+
sub_name = arr[1]
20+
start_line = NR
21+
next
22+
}
23+
/^[ \t]*end[ \t]+subroutine[ \t]*([a-zA-Z_][a-zA-Z0-9_]*)?[ \t]*\$/ && in_sub {
24+
end_line = NR
25+
print (end_line - start_line + 1) \"\t\" FILENAME \": \" sub_name
26+
in_sub = 0
27+
}
28+
" "$file"
29+
done | sort -nr | awk -F'\t' '{print $2 " : " $1 " lines"}' | head -20

src/common/m_boundary_common.fpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ contains
156156
case (BC_CHAR_SUP_OUTFLOW:BC_GHOST_EXTRAP)
157157
call s_ghost_cell_extrapolation(q_prim_vf, 2, -1, k, l)
158158
case (BC_AXIS)
159-
call s_axis(q_prim_vf, 2, -1, k, l, pb, mv)
159+
call s_axis(q_prim_vf, pb, mv, k, l)
160160
case (BC_REFLECTIVE)
161161
call s_symmetry(q_prim_vf, 2, -1, k, l, pb, mv)
162162
case (BC_PERIODIC)
@@ -735,11 +735,10 @@ contains
735735

736736
end subroutine s_periodic
737737

738-
pure subroutine s_axis(q_prim_vf, bc_dir, bc_loc, k, l, pb, mv)
739-
!$acc routine seq
738+
pure subroutine s_axis(q_prim_vf, pb, mv, k, l)
739+
!$acc routine seq
740740
type(scalar_field), dimension(sys_size), intent(inout) :: q_prim_vf
741-
real(wp), optional, dimension(idwbuff(1)%beg:, idwbuff(2)%beg:, idwbuff(3)%beg:, 1:, 1:), intent(inout) :: pb, mv
742-
integer, intent(in) :: bc_dir, bc_loc
741+
real(wp), dimension(idwbuff(1)%beg:, idwbuff(2)%beg:, idwbuff(3)%beg:, 1:, 1:), intent(inout) :: pb, mv
743742
integer, intent(in) :: k, l
744743

745744
integer :: j, q, i

src/common/m_finite_differences.fpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ contains
1515
integer :: x, y, z !< Generic loop iterators
1616

1717
real(wp) :: divergence
18-
19-
!$acc parallel loop collapse(3) private(divergence)
18+
!$acc parallel loop collapse(3) gang vector default(present) private(divergence)
2019
do x = ix_s%beg, ix_s%end
2120
do y = iy_s%beg, iy_s%end
2221
do z = iz_s%beg, iz_s%end

src/common/m_mpi_common.fpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -350,21 +350,17 @@ contains
350350
!! @param Rc_min_glb Global minimum Rc stability criterion
351351
impure subroutine s_mpi_reduce_stability_criteria_extrema(icfl_max_loc, &
352352
vcfl_max_loc, &
353-
ccfl_max_loc, &
354353
Rc_min_loc, &
355354
icfl_max_glb, &
356355
vcfl_max_glb, &
357-
ccfl_max_glb, &
358356
Rc_min_glb)
359357
360358
real(wp), intent(in) :: icfl_max_loc
361359
real(wp), intent(in) :: vcfl_max_loc
362-
real(wp), intent(in) :: ccfl_max_loc
363360
real(wp), intent(in) :: Rc_min_loc
364361
365362
real(wp), intent(out) :: icfl_max_glb
366363
real(wp), intent(out) :: vcfl_max_glb
367-
real(wp), intent(out) :: ccfl_max_glb
368364
real(wp), intent(out) :: Rc_min_glb
369365
370366
#ifdef MFC_SIMULATION

src/common/m_phase_change.fpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ contains
143143

144144
! Calling pT-equilibrium for either finishing phase-change module, or as an IC for the pTg-equilibrium
145145
! for this case, MFL cannot be either 0 or 1, so I chose it to be 2
146-
call s_infinite_pt_relaxation_k(j, k, l, 2, pS, p_infpT, rM, q_cons_vf, rhoe, TS)
146+
call s_infinite_pt_relaxation_k(j, k, l, 2, pS, p_infpT, q_cons_vf, rhoe, TS)
147147

148148
! check if pTg-equilibrium is required
149149
! NOTE that NOTHING else needs to be updated OTHER than the individual partial densities
@@ -164,7 +164,7 @@ contains
164164
q_cons_vf(vp + contxb - 1)%sf(j, k, l) = (1.0_wp - mixM)*rM
165165

166166
! calling pT-equilibrium for overheated vapor, which is MFL = 0
167-
call s_infinite_pt_relaxation_k(j, k, l, 0, pSOV, p_infOV, rM, q_cons_vf, rhoe, TSOV)
167+
call s_infinite_pt_relaxation_k(j, k, l, 0, pSOV, p_infOV, q_cons_vf, rhoe, TSOV)
168168

169169
! calculating Saturation temperature
170170
call s_TSat(pSOV, TSatOV, TSOV)
@@ -177,7 +177,7 @@ contains
177177
q_cons_vf(vp + contxb - 1)%sf(j, k, l) = mixM*rM
178178

179179
! calling pT-equilibrium for subcooled liquid, which is MFL = 1
180-
call s_infinite_pt_relaxation_k(j, k, l, 1, pSSL, p_infSL, rM, q_cons_vf, rhoe, TSSL)
180+
call s_infinite_pt_relaxation_k(j, k, l, 1, pSSL, p_infSL, q_cons_vf, rhoe, TSSL)
181181

182182
! calculating Saturation temperature
183183
call s_TSat(pSSL, TSatSL, TSSL)
@@ -281,7 +281,7 @@ contains
281281
!! @param q_cons_vf Cell-average conservative variables
282282
!! @param rhoe mixture energy
283283
!! @param TS equilibrium temperature at the interface
284-
pure subroutine s_infinite_pt_relaxation_k(j, k, l, MFL, pS, p_infpT, rM, q_cons_vf, rhoe, TS)
284+
pure subroutine s_infinite_pt_relaxation_k(j, k, l, MFL, pS, p_infpT, q_cons_vf, rhoe, TS)
285285

286286
#ifdef _CRAYFTN
287287
!DIR$ INLINEALWAYS s_infinite_pt_relaxation_k
@@ -293,7 +293,6 @@ contains
293293
integer, intent(in) :: j, k, l, MFL
294294
real(wp), intent(out) :: pS
295295
real(wp), dimension(num_fluids), intent(out) :: p_infpT
296-
real(wp), intent(in) :: rM
297296
type(scalar_field), dimension(sys_size), intent(in) :: q_cons_vf
298297
real(wp), intent(in) :: rhoe
299298
real(wp), intent(out) :: TS

src/common/m_variables_conversion.fpp

Lines changed: 13 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,11 @@ contains
9191

9292
if (model_eqns == 1) then ! Gamma/pi_inf model
9393
call s_convert_mixture_to_mixture_variables(q_vf, i, j, k, &
94-
rho, gamma, pi_inf, qv, Re_K, G_K, G)
94+
rho, gamma, pi_inf, qv)
9595

9696
else if (bubbles_euler) then
9797
call s_convert_species_to_mixture_variables_bubbles(q_vf, i, j, k, &
98-
rho, gamma, pi_inf, qv, Re_K, G_K, G)
98+
rho, gamma, pi_inf, qv, Re_K)
9999
else
100100
! Volume fraction model
101101
call s_convert_species_to_mixture_variables(q_vf, i, j, k, &
@@ -206,7 +206,7 @@ contains
206206
!! @param pi_inf liquid stiffness
207207
!! @param qv fluid reference energy
208208
subroutine s_convert_mixture_to_mixture_variables(q_vf, i, j, k, &
209-
rho, gamma, pi_inf, qv, Re_K, G_K, G)
209+
rho, gamma, pi_inf, qv)
210210

211211
type(scalar_field), dimension(sys_size), intent(in) :: q_vf
212212
integer, intent(in) :: i, j, k
@@ -216,11 +216,6 @@ contains
216216
real(wp), intent(out), target :: pi_inf
217217
real(wp), intent(out), target :: qv
218218

219-
real(wp), optional, dimension(2), intent(out) :: Re_K
220-
221-
real(wp), optional, intent(out) :: G_K
222-
real(wp), optional, dimension(num_fluids), intent(in) :: G
223-
224219
! Transferring the density, the specific heat ratio function and the
225220
! liquid stiffness function, respectively
226221
rho = q_vf(1)%sf(i, j, k)
@@ -253,7 +248,7 @@ contains
253248
!! @param pi_inf liquid stiffness
254249
!! @param qv fluid reference energy
255250
subroutine s_convert_species_to_mixture_variables_bubbles(q_vf, j, k, l, &
256-
rho, gamma, pi_inf, qv, Re_K, G_K, G)
251+
rho, gamma, pi_inf, qv, Re_K)
257252

258253
type(scalar_field), dimension(sys_size), intent(in) :: q_vf
259254

@@ -265,8 +260,6 @@ contains
265260
real(wp), intent(out), target :: qv
266261

267262
real(wp), optional, dimension(2), intent(out) :: Re_K
268-
real(wp), optional, intent(out) :: G_K
269-
real(wp), optional, dimension(num_fluids), intent(in) :: G
270263

271264
integer :: i, q
272265
real(wp), dimension(num_fluids) :: alpha_rho_K, alpha_K
@@ -463,7 +456,7 @@ contains
463456

464457
pure subroutine s_convert_species_to_mixture_variables_acc(rho_K, &
465458
gamma_K, pi_inf_K, qv_K, &
466-
alpha_K, alpha_rho_K, Re_K, k, l, r, &
459+
alpha_K, alpha_rho_K, Re_K, &
467460
G_K, G)
468461
#ifdef _CRAYFTN
469462
!DIR$ INLINEALWAYS s_convert_species_to_mixture_variables_acc
@@ -480,8 +473,6 @@ contains
480473
real(wp), optional, intent(out) :: G_K
481474
real(wp), optional, dimension(num_fluids), intent(in) :: G
482475

483-
integer, intent(in) :: k, l, r
484-
485476
integer :: i, j !< Generic loop iterators
486477
real(wp) :: alpha_K_sum
487478

@@ -547,7 +538,7 @@ contains
547538

548539
pure subroutine s_convert_species_to_mixture_variables_bubbles_acc(rho_K, &
549540
gamma_K, pi_inf_K, qv_K, &
550-
alpha_K, alpha_rho_K, Re_K, k, l, r)
541+
alpha_K, alpha_rho_K, Re_K)
551542
#ifdef _CRAYFTN
552543
!DIR$ INLINEALWAYS s_convert_species_to_mixture_variables_bubbles_acc
553544
#else
@@ -560,7 +551,6 @@ contains
560551
!! Partial densities and volume fractions
561552

562553
real(wp), dimension(2), intent(out) :: Re_K
563-
integer, intent(in) :: k, l, r
564554

565555
integer :: i, j !< Generic loop iterators
566556

@@ -819,16 +809,12 @@ contains
819809
subroutine s_convert_conservative_to_primitive_variables(qK_cons_vf, &
820810
q_T_sf, &
821811
qK_prim_vf, &
822-
ibounds, &
823-
gm_alphaK_vf)
812+
ibounds)
824813

825814
type(scalar_field), dimension(sys_size), intent(in) :: qK_cons_vf
826815
type(scalar_field), intent(inout) :: q_T_sf
827816
type(scalar_field), dimension(sys_size), intent(inout) :: qK_prim_vf
828817
type(int_bounds_info), dimension(1:3), intent(in) :: ibounds
829-
type(scalar_field), &
830-
allocatable, optional, dimension(:), &
831-
intent(in) :: gm_alphaK_vf
832818

833819
real(wp), dimension(num_fluids) :: alpha_K, alpha_rho_K
834820
real(wp), dimension(2) :: Re_K
@@ -902,13 +888,13 @@ contains
902888
! If in simulation, use acc mixture subroutines
903889
if (elasticity) then
904890
call s_convert_species_to_mixture_variables_acc(rho_K, gamma_K, pi_inf_K, qv_K, alpha_K, &
905-
alpha_rho_K, Re_K, j, k, l, G_K, Gs)
891+
alpha_rho_K, Re_K, G_K, Gs)
906892
else if (bubbles_euler) then
907893
call s_convert_species_to_mixture_variables_bubbles_acc(rho_K, gamma_K, pi_inf_K, qv_K, &
908-
alpha_K, alpha_rho_K, Re_K, j, k, l)
894+
alpha_K, alpha_rho_K, Re_K)
909895
else
910896
call s_convert_species_to_mixture_variables_acc(rho_K, gamma_K, pi_inf_K, qv_K, &
911-
alpha_K, alpha_rho_K, Re_K, j, k, l)
897+
alpha_K, alpha_rho_K, Re_K)
912898
end if
913899
#else
914900
! If pre-processing, use non acc mixture subroutines
@@ -1513,13 +1499,13 @@ contains
15131499
if (elasticity) then
15141500
call s_convert_species_to_mixture_variables_acc(rho_K, gamma_K, pi_inf_K, qv_K, &
15151501
alpha_K, alpha_rho_K, Re_K, &
1516-
j, k, l, G_K, Gs)
1502+
G_K, Gs)
15171503
else if (bubbles_euler) then
15181504
call s_convert_species_to_mixture_variables_bubbles_acc(rho_K, gamma_K, &
1519-
pi_inf_K, qv_K, alpha_K, alpha_rho_K, Re_K, j, k, l)
1505+
pi_inf_K, qv_K, alpha_K, alpha_rho_K, Re_K)
15201506
else
15211507
call s_convert_species_to_mixture_variables_acc(rho_K, gamma_K, pi_inf_K, qv_K, &
1522-
alpha_K, alpha_rho_K, Re_K, j, k, l)
1508+
alpha_K, alpha_rho_K, Re_K)
15231509
end if
15241510

15251511
! Computing the energy from the pressure

0 commit comments

Comments
 (0)