Skip to content

Commit 0789a2a

Browse files
Clean up GNU compiler warnings (#117)
* Clean up GNU compiler warnings across src, test, and examples Fix all -Wc-binding-type, -Wunused-dummy-argument, -Wunused-variable, and -Wmaybe-uninitialized warnings reported by gfortran in the CI build: - SELF_GPU.f90, SELF_GPUBLAS.f90: use integer(c_int) instead of integer(kind(hipSuccess)) / integer(kind(HIPBLAS_STATUS_SUCCESS)) in BIND(C) function return types and value arguments to satisfy -Wc-binding-type - SELF_Model.f90, SELF_DGModel*_t.f90, SELF_Linear*_t.f90, SELF_Mapped*_t.f90, scalar/vector/tensor _t.f90 files, gpu/*.f90: add `if (.false.)` references in stub/default implementations to suppress -Wunused-dummy-argument without affecting behavior - Remove unused local variable declarations (ivar, WORKSPACE, imat, E, r, i, j, iel, s2, diff, nhat, nmag, fx, fy, etc.) throughout src/, test/, and examples/ - Initialize allocatable string before first use to suppress false-positive -Wmaybe-uninitialized in SELF_Model.f90 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * Add Claude Code instructions and code formatting section to CLAUDE.md Adapt CLAUDE.md from Codex to Claude Code conventions and add a new section (§9) documenting fprettify-based formatting requirements drawn from CONTRIBUTING.md, including manual commands and pre-commit setup. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * Apply formatting * Clean up remaining GNU compiler warnings Remove unused variables (fileId, WORKSPACE, s2, bcid) from test files and eliminate allocatable str in ReportEntropy_Model to fix -Wunused-variable and -Wmaybe-uninitialized warnings. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * Fix formatting --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent f3e1e57 commit 0789a2a

49 files changed

Lines changed: 368 additions & 243 deletions

File tree

Some content is hidden

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

CLAUDE.md

Lines changed: 234 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,234 @@
1+
# CLAUDE.md
2+
Claude Code Operating Rules for This Repository
3+
4+
This file defines **hard constraints** and **preferred behaviors** for Claude
5+
working in this repository. These rules exist to protect numerical correctness,
6+
performance, and long-term maintainability of a high-order spectral element
7+
codebase.
8+
9+
Follow all rules below unless explicitly instructed otherwise by a human
10+
maintainer.
11+
12+
---
13+
14+
## 1. Project Purpose
15+
16+
This project implements **high-order spectral element methods** for solving
17+
systems of conservation laws (e.g., Euler, shallow water, Maxwell, MHD) on
18+
structured and unstructured meshes.
19+
20+
Primary goals:
21+
- Numerical correctness and stability
22+
- Conservation properties
23+
- High performance on CPUs and GPUs
24+
- MPI scalability
25+
26+
Changes must NOT degrade:
27+
- Accuracy order
28+
- Stability properties
29+
- Parallel scaling
30+
- Memory behavior
31+
32+
---
33+
34+
## 2. Fortran Standards & Toolchain
35+
36+
### Language Standard
37+
- Target: **Fortran 2008**
38+
- Code must remain compatible with:
39+
- gfortran ≥ 11
40+
- ifx
41+
- nvfortran
42+
- amdflang
43+
44+
### Prohibited Language Features
45+
Do NOT introduce:
46+
- Coarrays
47+
- Fortran 2018+ features
48+
- Compiler-specific extensions
49+
- Automatic polymorphism in performance-critical paths
50+
51+
### Formatting & Conventions
52+
- Free-form source
53+
- `implicit none` required in all program units
54+
- Explicit `intent(in|out|inout)` on all dummy arguments
55+
- Lowercase keywords preferred
56+
- Line length ≤ 100 characters
57+
58+
---
59+
60+
## 3. Numerical & Algorithmic Constraints
61+
62+
### Hard Rules
63+
- Do NOT change the mathematical formulation without approval
64+
- Do NOT change discretization order
65+
- Do NOT change basis, quadrature, or nodal ordering
66+
- Do NOT reorder floating-point reductions
67+
- Do NOT alter time integration schemes
68+
69+
### Floating-Point Behavior
70+
- Bitwise reproducibility may be required
71+
- Preserve operation ordering in loops
72+
- Avoid algebraic “simplifications” unless mathematically justified
73+
74+
### Array Semantics
75+
- Do NOT replace explicit loops with array syntax unless equivalence is proven
76+
- Avoid implicit temporaries
77+
78+
---
79+
80+
## 4. Performance Rules (Critical)
81+
82+
This is an HPC codebase. Performance regressions are unacceptable.
83+
84+
### Memory
85+
- Avoid temporary allocations in hot paths
86+
- No automatic arrays in tight loops
87+
- No hidden allocations via array slicing
88+
89+
### Loops
90+
- Preserve loop ordering for cache locality
91+
- Do NOT replace DO loops with WHERE / FORALL
92+
- Vectorization-friendly structure must be preserved
93+
94+
### Abstraction
95+
- Do NOT introduce runtime polymorphism in kernels
96+
- Avoid excessive modularization inside hot loops
97+
98+
---
99+
100+
## 5. Parallel Programming
101+
102+
### MPI
103+
- MPI calls must remain explicit
104+
- Do NOT introduce blocking collectives inside time-stepping loops
105+
- Do NOT change communicator usage
106+
- Preserve rank-local data ownership
107+
108+
### OpenMP / GPU
109+
- Preserve OpenMP semantics
110+
- Do NOT move data regions without explicit instruction
111+
- GPU kernels must preserve memory access patterns
112+
- No implicit host/device transfers
113+
114+
---
115+
116+
## 6. Code Organization & APIs
117+
118+
### File & Module Structure
119+
- Do NOT rename modules
120+
- Do NOT move files between directories
121+
- Do NOT change public interfaces without approval
122+
- Preserve module dependency order
123+
124+
### Public APIs
125+
- Public procedures are considered **stable**
126+
- Backward compatibility is required unless stated otherwise
127+
128+
---
129+
130+
## 7. Testing & Validation
131+
132+
### Required
133+
- All existing regression tests must pass
134+
- Do NOT modify reference output files
135+
- Numerical differences must be justified
136+
137+
### New Code
138+
- New features require:
139+
- A test case
140+
- Clear validation criteria
141+
- MPI tests must work on ≥ 2 ranks
142+
143+
---
144+
145+
## 8. Documentation & Comments
146+
147+
### Preserve Scientific Meaning
148+
- Do NOT remove comments describing:
149+
- Equations
150+
- Algorithms
151+
- Numerical assumptions
152+
153+
### New Routines
154+
Must include:
155+
- Mathematical description
156+
- Variable meaning and units
157+
- Expected input ranges
158+
159+
---
160+
161+
## 9. Code Formatting
162+
163+
All Fortran source must be formatted with [`fprettify`](https://pypi.org/project/fprettify/) using the project's `fprettify.config`. PRs are checked for formatting before any other tests run.
164+
165+
To format all source files manually:
166+
167+
```shell
168+
fprettify './src/' --config-file ./fprettify.config --recursive --case 1 1 1 1
169+
fprettify './test/' --config-file ./fprettify.config --recursive --case 1 1 1 1
170+
fprettify './examples/' --config-file ./fprettify.config --recursive --case 1 1 1 1
171+
```
172+
173+
Alternatively, install the provided `pre-commit` hook to apply formatting automatically on each commit:
174+
175+
```shell
176+
pip install pre-commit fprettify
177+
pre-commit install # run from repository root
178+
```
179+
180+
When editing Fortran files, apply `fprettify` before committing. Do NOT manually reformat code by hand in ways that deviate from `fprettify` output.
181+
182+
---
183+
184+
## 10. Prohibited Actions (Explicit)
185+
186+
Do NOT:
187+
- Rewrite code in another language
188+
- Convert procedural code to OO Fortran
189+
- Replace MPI with coarrays
190+
- Introduce external dependencies
191+
- “Modernize” syntax without benefit
192+
- Delete legacy code without explanation
193+
194+
---
195+
196+
## 11. Domain-Specific Assumptions
197+
198+
- Grid indexing follows project conventions (do NOT reorder indices)
199+
- Jacobians and metric terms are precomputed
200+
- Flux routines assume nodal basis ordering
201+
- Element-local operations must remain element-local
202+
- Halo exchange patterns are fixed
203+
204+
---
205+
206+
## 12. Preferred Behavior
207+
208+
DO:
209+
- Ask before changing algorithms
210+
- Explain numerical and performance implications
211+
- Provide minimal diffs
212+
- Reference existing patterns in the codebase
213+
- Flag any uncertainty explicitly
214+
215+
DO NOT:
216+
- Make large refactors unless requested
217+
- Assume intent beyond the explicit request
218+
219+
---
220+
221+
## 13. When in Doubt
222+
223+
If a change could affect:
224+
- Numerical accuracy
225+
- Stability
226+
- Performance
227+
- Parallel behavior
228+
229+
STOP and ask for clarification.
230+
231+
---
232+
233+
End of CLAUDE.md
234+

examples/linear_euler2d_planewave_propagation.f90

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ pure function hbc2d_Prescribed_lineareuler2d_planewave(this,x,t) result(exts)
107107
exts(2) = u*shape ! u
108108
exts(3) = v*shape ! v
109109
exts(4) = p*shape ! pressure
110+
if(.false.) exts(1) = exts(1)+t ! suppress unused-dummy-argument warning
110111

111112
endfunction hbc2d_Prescribed_lineareuler2d_planewave
112113

examples/linear_euler2d_planewave_reflection.f90

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ pure function hbc2d_Prescribed_lineareuler2d_planewave(this,x,t) result(exts)
122122
exts(2) = u*(shi-shr) ! u
123123
exts(3) = v*(shi+shr) ! v
124124
exts(4) = p*(shi+shr) ! pressure
125+
if(.false.) exts(1) = exts(1)+t ! suppress unused-dummy-argument warning
125126

126127
endfunction hbc2d_Prescribed_lineareuler2d_planewave
127128

examples/linear_shallow_water2d_kelvinwaves.f90

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,11 @@ program linear_shallow_water2d_kelvinwaves
3838
real(prec),parameter :: f0 = 10.0_prec ! reference coriolis parameter (1/s)
3939
real(prec),parameter :: Cd = 0.25_prec ! Linear drag coefficient (1/s)
4040
real(prec),parameter :: iointerval = 0.05 ! Write files 20 times per characteristic time scale
41-
real(prec) :: r
4241
real(prec) :: e0,ef ! Initial and final entropy
4342
type(LinearShallowWater2D) :: modelobj ! Shallow water model
4443
type(Lagrange),target :: interp ! Interpolant
4544
type(Mesh2D),target :: mesh ! Mesh class
4645
type(SEMQuad),target :: geometry ! Geometry class
47-
integer :: i,j,iel
4846
real(prec),parameter :: g = 1.0_prec ! Acceleration due to gravity
4947
real(prec),parameter :: H = 1.0_prec ! Uniform resting depth
5048
character(LEN=255) :: WORKSPACE

examples/linear_shallow_water2d_nonormalflow.f90

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ program linear_shallow_water2d_nonormalflow_model
4343
integer :: bcids(1:4) ! Boundary conditions for structured mesh
4444
type(Mesh2D),target :: mesh ! Mesh class
4545
type(SEMQuad),target :: geometry ! Geometry class
46-
character(LEN=255) :: WORKSPACE ! Used for file I/O
4746

4847
real(prec),parameter :: g = 1.0_prec ! Acceleration due to gravity
4948
real(prec),parameter :: H = 1.0_prec ! Uniform resting depth

src/SELF_DGModel1D_t.f90

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ subroutine CalculateEntropy_DGModel1D_t(this)
299299
implicit none
300300
class(DGModel1D_t),intent(inout) :: this
301301
! Local
302-
integer :: iel,i,ivar
302+
integer :: iel,i
303303
real(prec) :: e,s(1:this%solution%nvar),J
304304

305305
e = 0.0_prec
@@ -323,7 +323,6 @@ subroutine setboundarycondition_DGModel1D_t(this)
323323
implicit none
324324
class(DGModel1D_t),intent(inout) :: this
325325
! local
326-
integer :: ivar
327326
integer :: N,nelem
328327
real(prec) :: x
329328

@@ -627,10 +626,6 @@ subroutine Read_DGModel1D_t(this,fileName)
627626
character(*),intent(in) :: fileName
628627
! Local
629628
integer(HID_T) :: fileId
630-
integer(HID_T) :: solOffset(1:3)
631-
integer :: firstElem
632-
integer :: N
633-
634629
call Open_HDF5(fileName,H5F_ACC_RDWR_F,fileId)
635630
call ReadArray_HDF5(fileId,'/controlgrid/solution/interior',this%solution%interior)
636631
call Close_HDF5(fileId)
@@ -643,14 +638,12 @@ subroutine WriteTecplot_DGModel1D_t(this,filename)
643638
class(DGModel1D_t),intent(inout) :: this
644639
character(*),intent(in),optional :: filename
645640
! Local
646-
character(8) :: zoneID
647641
integer :: fUnit
648642
integer :: iEl,i,iVar
649643
character(LEN=self_FileNameLength) :: tecFile
650644
character(LEN=self_TecplotHeaderLength) :: tecHeader
651645
character(LEN=self_FormatLength) :: fmat
652646
character(13) :: timeStampString
653-
character(5) :: rankString
654647
type(Scalar1D) :: solution
655648
type(Scalar1D) :: x
656649
type(Lagrange),target :: interp

src/SELF_DGModel2D_t.f90

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,6 @@ subroutine Init_DGModel2D_t(this,mesh,geometry)
9292
type(Mesh2D),intent(in),target :: mesh
9393
type(SEMQuad),intent(in),target :: geometry
9494
! Local
95-
integer :: ivar
96-
character(LEN=3) :: ivarChar
97-
character(LEN=25) :: varname
98-
9995
this%mesh => mesh
10096
this%geometry => geometry
10197
call this%SetNumberOfVariables()
@@ -650,7 +646,7 @@ subroutine Read_DGModel2D_t(this,fileName)
650646
integer(HID_T) :: fileId
651647
integer(HID_T) :: solOffset(1:3)
652648
integer :: firstElem
653-
integer :: N,ivar
649+
integer :: ivar
654650

655651
if(this%mesh%decomp%mpiEnabled) then
656652
call Open_HDF5(fileName,H5F_ACC_RDWR_F,fileId, &

src/SELF_DGModel3D_t.f90

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,6 @@ subroutine Init_DGModel3D_t(this,mesh,geometry)
9292
type(Mesh3D),intent(in),target :: mesh
9393
type(SEMHex),intent(in),target :: geometry
9494
! Local
95-
integer :: ivar
96-
character(LEN=3) :: ivarChar
97-
character(LEN=25) :: varname
98-
9995
this%mesh => mesh
10096
this%geometry => geometry
10197
call this%SetNumberOfVariables()

src/SELF_Geometry_2D.f90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ subroutine WriteTecplot_SEMQuad(this,filename)
263263
! Local
264264
character(8) :: zoneID
265265
integer :: fUnit
266-
integer :: iEl,i,j,iVar
266+
integer :: iEl,i,j
267267
character(LEN=self_TecplotHeaderLength) :: tecHeader
268268
character(LEN=self_FormatLength) :: fmat
269269

src/SELF_Geometry_3D.f90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ subroutine WriteTecplot_SEMHex(this,filename)
412412
! Local
413413
character(8) :: zoneID
414414
integer :: fUnit
415-
integer :: iEl,i,j,k,iVar
415+
integer :: iEl,i,j,k
416416
character(LEN=self_TecplotHeaderLength) :: tecHeader
417417
character(LEN=self_FormatLength) :: fmat
418418

0 commit comments

Comments
 (0)