Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/simulation/m_bubbles_EE.fpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ contains

type(scalar_field), dimension(sys_size), intent(inout) :: q_cons_vf
real(wp) :: nR3bar
integer(wp) :: i, j, k, l
integer :: i, j, k, l

$:GPU_PARALLEL_LOOP(private='[i, j, k, l, nR3bar]', collapse=3)
do l = 0, p
Expand Down
2 changes: 1 addition & 1 deletion src/simulation/m_bubbles_EL.fpp
Original file line number Diff line number Diff line change
Expand Up @@ -1796,7 +1796,7 @@ contains
do i = 0, m
lag_void_max = max(lag_void_max, 1._wp - q_beta(1)%sf(i, j, k))
call s_get_char_vol(i, j, k, volcell)
if ((1._wp - q_beta(1)%sf(i, j, k)) > 5.0d-11) then
if ((1._wp - q_beta(1)%sf(i, j, k)) > 5.0e-11_wp) then
lag_void_avg = lag_void_avg + (1._wp - q_beta(1)%sf(i, j, k))*volcell
lag_vol = lag_vol + volcell
end if
Expand Down
33 changes: 32 additions & 1 deletion toolchain/mfc/lint_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,14 @@ def check_double_precision(repo_root: Path) -> list[str]:
"""
errors: list[str] = []
src_dir = repo_root / SRC_DIR
# The d-literal alternative catches double-precision literals with signed or
# multi-digit exponents (e.g. 5.0d-11, 2.5d+3, 1.0d12), not just '[0-9]d0'.
# The identifier boundaries keep it from matching inside names like cart2d12_coords.
precision_re = re.compile(
r"\b(?:double_precision|double\s+precision|dsqrt|dexp|dlog|dble|dabs|" r"dprod|dmin|dmax|dfloat|dreal|dcos|dsin|dtan|dsign|dtanh|dsinh|dcosh)\b|" r"\breal\s*\(\s*[48]\s*\)|" r"[0-9]d0",
r"\b(?:double_precision|double\s+precision|dsqrt|dexp|dlog|dble|dabs|"
r"dprod|dmin|dmax|dfloat|dreal|dcos|dsin|dtan|dsign|dtanh|dsinh|dcosh)\b|"
r"\breal\s*\(\s*[48]\s*\)|"
r"(?<![A-Za-z0-9_])[0-9]\.?[0-9]*[dD][-+]?[0-9]+(?![A-Za-z0-9_])",
re.IGNORECASE,
)

Expand Down Expand Up @@ -264,6 +270,30 @@ def check_false_integers(repo_root: Path) -> list[str]:
return errors


def check_integer_wp(repo_root: Path) -> list[str]:
"""Flag ``integer(wp)`` declarations.

``wp`` is a floating-point kind parameter; using it as an integer kind is a
copy-paste error. Integers take the default kind: plain ``integer``.
"""
errors: list[str] = []
src_dir = repo_root / SRC_DIR
integer_wp_re = re.compile(r"\binteger\s*\(\s*wp\s*\)", re.IGNORECASE)

for src in _fortran_fpp_files(src_dir):
lines = src.read_text(encoding="utf-8").splitlines()
rel = src.relative_to(repo_root)

for i, line in enumerate(lines):
stripped = line.strip()
if _is_comment_or_blank(stripped):
continue
if integer_wp_re.search(stripped.split("!")[0]):
errors.append(f" {rel}:{i + 1} 'integer(wp)' uses a floating-point kind. Fix: use plain 'integer'")

return errors


def check_junk_comments(repo_root: Path) -> list[str]:
"""Flag junk separator patterns (===, ----+) in Python and shell scripts.

Expand Down Expand Up @@ -445,6 +475,7 @@ def main():
all_errors.extend(check_double_precision(repo_root))
all_errors.extend(check_junk_code(repo_root))
all_errors.extend(check_false_integers(repo_root))
all_errors.extend(check_integer_wp(repo_root))
all_errors.extend(check_junk_comments(repo_root))
all_errors.extend(check_fypp_list_duplicates(repo_root))
all_errors.extend(check_duplicate_lines(repo_root))
Expand Down
51 changes: 47 additions & 4 deletions toolchain/mfc/test_lint_source.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
"""Tests for the manual registry-bound broadcast lint in lint_source.py."""

from mfc.lint_source import _extract_bcast_roots, check_manual_registry_bcasts
from mfc.lint_source import (
_extract_bcast_roots,
check_double_precision,
check_integer_wp,
check_manual_registry_bcasts,
)

BCAST_TAIL = ", 1, mpi_p, 0, MPI_COMM_WORLD, ierr)"

Expand Down Expand Up @@ -43,10 +48,48 @@ def test_struct_members_and_loop_indices_skipped():
assert _extract_bcast_roots(lines) == []


def _write_src(tmp_path, rel: str, body: str):
"""Write a source file under tmp_path/src/<rel> for a lint check to scan."""
path = tmp_path / "src" / rel
path.parent.mkdir(parents=True, exist_ok=True)
path.write_text(body, encoding="utf-8")


def _write_proxy(tmp_path, target_dir: str, body: str):
proxy_dir = tmp_path / "src" / target_dir
proxy_dir.mkdir(parents=True)
(proxy_dir / "m_mpi_proxy.fpp").write_text(body, encoding="utf-8")
_write_src(tmp_path, f"{target_dir}/m_mpi_proxy.fpp", body)


def test_double_precision_flags_signed_d_exponent(tmp_path):
_write_src(tmp_path, "simulation/m_x.fpp", " if (x > 5.0d-11) then\n")
errors = check_double_precision(tmp_path)
assert len(errors) == 1
assert "5.0d-11" in errors[0]


def test_double_precision_clean_cases(tmp_path):
body = "\n".join(
[
" integer, dimension(2) :: cart2d12_coords, cart2d13_coords", # identifier, not a literal
" call MPI_CART_COORDS(comm, rank, 2, cart2d12_coords, ierr)",
" x = 5.0e-11_wp", # correct working-precision literal
"",
]
)
_write_src(tmp_path, "simulation/m_y.fpp", body)
assert check_double_precision(tmp_path) == []


def test_integer_wp_flagged(tmp_path):
_write_src(tmp_path, "simulation/m_z.fpp", " integer(wp) :: i, j, k, l\n")
errors = check_integer_wp(tmp_path)
assert len(errors) == 1
assert "integer(wp)" in errors[0]


def test_integer_wp_clean(tmp_path):
body = " integer :: i\n real(wp) :: x\n"
_write_src(tmp_path, "simulation/m_ok.fpp", body)
assert check_integer_wp(tmp_path) == []


def test_manual_broadcast_of_registry_scalar_is_flagged(tmp_path):
Expand Down
Loading