Skip to content

CMake: Fix parallel-build race on shared ungrib Fortran modules#288

Open
MHBalsmeier wants to merge 1 commit into
wrf-model:developfrom
MHBalsmeier:cmake_race_condition
Open

CMake: Fix parallel-build race on shared ungrib Fortran modules#288
MHBalsmeier wants to merge 1 commit into
wrf-model:developfrom
MHBalsmeier:cmake_race_condition

Conversation

@MHBalsmeier

Copy link
Copy Markdown

TYPE: bug fix

KEYWORDS: cmake, ungrib, parallel build, fortran module, race condition

SOURCE: internal

DESCRIPTION OF CHANGES:
Problem:
In the CMake build, the ungrib, g1print, and g2print targets each
recompiled shared sources (gridinfo.F, filelist.F, table.F,
module_stringutil.F, gribcode.F, module_debug.F, debug_cio.c,
module_datarray.F) into a single shared Fortran_MODULE_DIRECTORY. Under
a parallel build (-j), two targets could compile the same source at the
same time and both write the same .mod, causing an intermittent fatal
error, e.g.:

f951: Fatal Error: Cannot rename module file '.../gridinfo.mod0' to
'.../gridinfo.mod': No such file or directory

Because it is a timing-dependent race, the build failed only on some
runs.

Solution:
Compile each shared source exactly once into the pgu library and have
ungrib, g1print, and g2print link pgu instead of recompiling those
sources. This mirrors the traditional Makefile build, where shared
objects are built once and linked into each executable. The existing
link dependencies on pgu also guarantee the shared modules are built
before the executables, removing the race without disabling parallelism.

TESTS CONDUCTED:
Clean parallel build (-j) of WPS repeated multiple times; ungrib,
g1print, and g2print build and link successfully with no module-rename
errors.

RELEASE NOTE: Fix intermittent parallel-build failure caused by
concurrent writes to shared ungrib Fortran module files.

@islas islas self-requested a review June 9, 2026 22:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant