Skip to content

Commit ff7234f

Browse files
authored
Merge branch 'master' into 2/3D_Extend_IC
2 parents fd4aca9 + 2aad1d4 commit ff7234f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+2890
-6470
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/frontier/submit.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,9 @@ sbatch <<EOT
3333
#SBATCH -A CFD154 # charge account
3434
#SBATCH -N 1 # Number of nodes required
3535
$sbatch_device_opts
36-
#SBATCH -t 01:59:00 # Duration of the job (Ex: 15 mins)
36+
#SBATCH -t 03:59:00 # Duration of the job (Ex: 15 mins)
3737
#SBATCH -o$job_slug.out # Combined output and error messages file
3838
#SBATCH -p extended # Extended partition for shorter queues
39-
#SBATCH -q debug # Use debug QOS - only one job per user allowed in queue!
4039
#SBATCH -W # Do not exit until the submitted job terminates.
4140
4241
set -e

.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

.github/workflows/pmd.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Source DRYness
2+
3+
on: [push, pull_request, workflow_dispatch]
4+
5+
jobs:
6+
pmd:
7+
name: PMD
8+
runs-on: "ubuntu-latest"
9+
env:
10+
pr_everything: 0
11+
steps:
12+
- name: Clone - PR
13+
uses: actions/checkout@v4
14+
15+
- name: Set up Java
16+
uses: actions/setup-java@v4
17+
with:
18+
distribution: temurin
19+
java-version: '17'
20+
21+
- name: Run CPD for Fortran
22+
continue-on-error: true
23+
run: |
24+
# Get latest PMD version from GitHub API
25+
PMD_VERSION=$(curl -s https://api.github.com/repos/pmd/pmd/releases/latest | grep '"tag_name":' | cut -d'"' -f4 | sed 's/pmd_releases\///')
26+
echo "Using PMD version: $PMD_VERSION"
27+
28+
curl -sSL -o pmd.zip \
29+
"https://github.com/pmd/pmd/releases/download/pmd_releases/${PMD_VERSION}/pmd-dist-${PMD_VERSION}-bin.zip"
30+
unzip -q pmd.zip
31+
PMD_HOME="pmd-bin-${PMD_VERSION}"
32+
33+
"${PMD_HOME}/bin/pmd" cpd \
34+
--dir src \
35+
--language fortran \
36+
--minimum-tokens=40

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/include/macros.fpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818

1919
#:def DEALLOCATE(*args)
2020
@:LOG({'@:DEALLOCATE(${re.sub(' +', ' ', ', '.join(args))}$)'})
21-
deallocate (${', '.join(args)}$)
2221
!$acc exit data delete(${', '.join(args)}$)
22+
deallocate (${', '.join(args)}$)
2323
#:enddef DEALLOCATE
2424

2525
#:def ACC_SETUP_VFs(*args)

0 commit comments

Comments
 (0)