Skip to content

Commit 52b6903

Browse files
authored
Merge branch 'master' into debug-testhang
2 parents b8f485a + c933e72 commit 52b6903

Some content is hidden

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

44 files changed

+1042
-935
lines changed

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

Lines changed: 119 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,27 @@ alwaysApply: true
44
---
55

66
# 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.
7+
Consolidated guidance for the MFC exascale, many-physics solver.
8+
Written primarily for Fortran/Fypp; the GPU and style sections matter only when `.fpp` / `.f90` files are in view.
109

1110
---
1211

1312
# 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** or **OpenMP**.
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`.
13+
- **Project**: *MFC* is modern Fortran 2008+ generated with **Fypp**.
14+
- Sources `src/`, tests `tests/`, examples `examples/`.
15+
- Most sources are `.fpp`; CMake transpiles them to `.f90`.
16+
- **Fypp macros** live in `src/<subprogram>/include/` you should scan these first.
17+
`<subprogram>` ∈ {`simulation`,`common`,`pre_process`,`post_process`}.
18+
- Only `simulation` (+ its `common` calls) is GPU-accelerated via **OpenACC** or **OpenMP**.
19+
- Assume free-form Fortran 2008+, `implicit none`, explicit `intent`, and modern intrinsics.
20+
- Prefer `module … contains … subroutine foo()`; avoid `COMMON` blocks and file-level `include` files.
21+
- **Read the full codebase and docs *before* changing code.**
22+
- Docs: <https://mflowcode.github.io/documentation/md_readme.html> and the repository root `README.md`.
2623

2724
### Incremental-change workflow
28-
1. Draft a step-by-step plan.
29-
2. After each step, build:
25+
26+
1. Draft a step-by-step plan.
27+
2. After each step, build:
3028
```bash
3129
./mfc.sh build -t pre_process simulation -j $(nproc)
3230
```
@@ -49,12 +47,10 @@ Written primarily for Fortran/Fypp; the OpenACC and style sections matter only w
4947
* Subroutine → `s_<verb>_<noun>` (e.g. `s_compute_flux`)
5048
* Function → `f_<verb>_<noun>`
5149
* 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.
50+
* **Size limits**: subroutine ≤ 500 lines, helper ≤ 150, function ≤ 100, module/file ≤ 1000.
51+
* ≤ 6 arguments per routine; otherwise pass a derived-type "params" struct.
5552
* No `goto` (except unavoidable legacy); no global state (`COMMON`, `save`).
56-
* Every variable: `intent(in|out|inout)` + appropriate `dimension` / `allocatable`
57-
/ `pointer`.
53+
* Every variable: `intent(in|out|inout)` + appropriate `dimension` / `allocatable` / `pointer`.
5854
* Use `s_mpi_abort(<msg>)` for errors, not `stop`.
5955
* Mark GPU-callable helpers that are called from GPU parallel loops immediately after declaration:
6056
```fortran
@@ -66,12 +62,41 @@ Written primarily for Fortran/Fypp; the OpenACC and style sections matter only w
6662

6763
---
6864

69-
# 3 FYPP Macros for GPU acceleration Pogramming Guidelines (for kernels)
65+
# 3 File & Module Structure
7066

71-
Do not directly use OpenACC or OpenMP directives directly. Instead, use the FYPP macros contained in src/common/include/parallel_macros.fpp
67+
- **File Naming**:
68+
- `.fpp` files: Fypp preprocessed files that get translated to `.f90`
69+
- Modules are named with `m_` prefix followed by feature name: `m_helper_basic`, `m_viscous`
70+
- Primary program file is named `p_main.fpp`
7271

73-
Wrap tight loops with
72+
- **Module Layout**:
73+
- Start with Fypp include for macros: `#:include 'macros.fpp'`
74+
- Header comments using `!>` style documentation
75+
- `module` declaration with name matching filename
76+
- `use` statements for dependencies
77+
- `implicit none` statement
78+
- `private` declaration followed by explicit `public` exports
79+
- `contains` section
80+
- Implementation of subroutines and functions
81+
82+
---
83+
84+
# 4 Fypp Macros
85+
86+
- **Fypp Directives**:
87+
- Start with `#:` (e.g., `#:include`, `#:def`, `#:enddef`)
88+
- Macros defined in `include/*.fpp` files
89+
- Used for code generation, conditional compilation, and GPU offloading
90+
91+
---
7492

93+
# 5 FYPP Macros for GPU Acceleration Programming Guidelines (for GPU kernels)
94+
95+
- Do not use OpenACC or OpenMP directives directly.
96+
- Instead, use the FYPP macros contained in `src/common/include/parallel_macros.fpp`
97+
- Documentation on how to use the Fypp macros for GPU offloading is available at https://mflowcode.github.io/documentation/md_gpuParallelization.html
98+
99+
Wrap tight loops with
75100
```fortran
76101
$:GPU_PARALLEL_FOR(private='[...]', copy='[...]')
77102
```
@@ -80,5 +105,73 @@ $:GPU_PARALLEL_FOR(private='[...]', copy='[...]')
80105
* Allocate large arrays with `managed` or move them into a persistent
81106
`$:GPU_ENTER_DATA(...)` region at start-up.
82107
* **Do not** place `stop` / `error stop` inside device code.
83-
* Must compile with Cray `ftn` and NVIDIA `nvfortran` for GPU offloading; also build CPU-only with
108+
* Must compile with Cray `ftn` or NVIDIA `nvfortran` for GPU offloading; also build CPU-only with
84109
GNU `gfortran` and Intel `ifx`/`ifort`.
110+
111+
- Example GPU macros include the below, among others:
112+
- `$:GPU_ROUTINE(parallelism='[seq]')` - Marks GPU-callable routines
113+
- `$:GPU_PARALLEL_LOOP(collapse=N)` - Parallelizes loops
114+
- `$:GPU_LOOP(parallelism='[seq]')` - Marks sequential loops
115+
- `$:GPU_UPDATE(device='[var1,var2]')` - Updates device data
116+
- `$:GPU_ENTER_DATA(copyin='[var]')` - Copies data to device
117+
- `$:GPU_EXIT_DATA(delete='[var]')` - Removes data from device
118+
119+
---
120+
121+
# 6 Documentation Style
122+
123+
- **Subroutine/Function Documentation**:
124+
```fortran
125+
!> This procedure <description>
126+
!! @param param_name Description of the parameter
127+
!! @return Description of the return value (for functions)
128+
```
129+
which conforms to the Doxygen Fortran format.
130+
131+
# 7 Error Handling
132+
133+
- **Assertions**:
134+
- Use the fypp `ASSERT` macro for validating conditions
135+
- Example: `@:ASSERT(predicate, message)`
136+
137+
- **Error Reporting**:
138+
- Use `s_mpi_abort(error_message)` for error termination, not `stop`
139+
- No `stop` / `error stop` inside device code
140+
141+
# 8 Memory Management
142+
143+
- **Allocation/Deallocation**:
144+
- Use fypp macro `@:ALLOCATE(var1, var2)` macro for device-aware allocation
145+
- Use fypp macro `@:DEALLOCATE(var1, var2)` macro for device-aware deallocation
146+
147+
# 9. Additional Observed Patterns
148+
149+
- **Derived Types**:
150+
- Extensive use of derived types for encapsulation
151+
- Use pointers within derived types (e.g., `pointer, dimension(:,:,:) => null()`)
152+
- Clear documentation of derived type components
153+
154+
- **Pure & Elemental Functions**:
155+
- Use `pure` and `elemental` attributes for side-effect-free functions
156+
- Combine them for operations on arrays (`pure elemental function`)
157+
158+
- **Precision Handling**:
159+
- Use `wp` (working precision) parameter from `m_precision_select`
160+
- Never hardcode precision with `real*8` or similar
161+
162+
- **Loop Optimization**:
163+
- Favor array operations over explicit loops when possible
164+
- Use `collapse=N` directive to optimize nested loops
165+
166+
# 10. Fortran Practices to Avoid
167+
168+
- **Fixed Format**: Only free-form Fortran is used
169+
- No column-position dependent code
170+
171+
- **Older Intrinsics**: Avoid outdated Fortran features like:
172+
- `equivalence` statements
173+
- `data` statements (use initialization expressions)
174+
- Character*N (use `character(len=N)` instead)
175+
176+
- **Using same variable for multiple purposes**: Maintain single responsibility
177+
- Each variable should have one clear purpose

.fortls.json

Lines changed: 0 additions & 94 deletions
This file was deleted.

.fortlsrc

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@
2626
"pp_suffixes": [".fpp"],
2727
"pp_defs": {
2828
"MFC": 1,
29-
"MFC_DOUBLE_PRECISION": 1
29+
"MFC_SINGLE_PRECISION": 1,
30+
"MFC_OPENACC": 1,
31+
"MFC_MPI": 1
3032
},
3133
"lowercase_intrinsics": true,
3234
"debug_log": false,
@@ -60,26 +62,11 @@
6062
"disable_diagnostics_for_external_modules": true,
6163
"max_line_length": -1,
6264
"max_comment_line_length": -1,
63-
"symbol_skip_mem": [
64-
"mpi_*"
65-
],
6665
"disable_var_diagnostics": false,
6766
"disable_fypp": false,
6867
"fypp_strict": false,
69-
"error_suppression_list": [
70-
"include-not-found",
71-
"mod-not-found",
72-
"module-not-found",
73-
"declared-twice",
74-
"no-matching-declaration",
75-
"invalid-parent",
76-
"parsing-error",
77-
"fypp-error",
78-
"preprocessor-error",
79-
"implicit-type"
80-
],
8168
"incremental_sync": false,
82-
"debug_parser": false,
69+
"debug_parser": true,
8370
"skip_parse_errors": true,
8471
"disable_parser": [
8572
"src/post_process/m_data_output.fpp",

.github/workflows/frontier/submit.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ sbatch <<EOT
3333
#SBATCH -A CFD154 # charge account
3434
#SBATCH -N 1 # Number of nodes required
3535
$sbatch_device_opts
36-
#SBATCH -t 02: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
3939
#SBATCH -W # Do not exit until the submitted job terminates.

CMakeLists.txt

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -479,17 +479,6 @@ function(MFC_SETUP_TARGET)
479479
"-foffload-options=-lgfortran\ -lm"
480480
"-fno-exceptions")
481481
elseif(CMAKE_Fortran_COMPILER_ID STREQUAL "NVHPC" OR CMAKE_Fortran_COMPILER_ID STREQUAL "PGI")
482-
find_package(cuTENSOR)
483-
if (NOT cuTENSOR_FOUND)
484-
message(WARNING
485-
"Failed to locate the NVIDIA cuTENSOR library. MFC will be "
486-
"built without support for it, disallowing the use of "
487-
"cu_tensor=T. This can result in degraded performance.")
488-
else()
489-
target_link_libraries (${a_target} PRIVATE cuTENSOR::cuTENSOR)
490-
target_compile_definitions(${a_target} PRIVATE MFC_cuTENSOR)
491-
endif()
492-
493482
foreach (cc ${MFC_CUDA_CC})
494483
target_compile_options(${a_target}
495484
PRIVATE -gpu=cc${cc}

0 commit comments

Comments
 (0)