Skip to content

Commit a9950c3

Browse files
zka26jatkinson1000
andauthored
Example 5: fix parallel .mod race by separate Fortran module dirs per target (#460)
Example 5: fix parallel .mod race by separating module dirs * Set Fortran module output dirs per mod_good and mod_bad and add to include paths * docs(cmake): add brief comment on isolating .mod output per target * fix indentation and align target names for Example 5 --------- Co-authored-by: Jack Atkinson <[email protected]>
1 parent 0faa738 commit a9950c3

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

examples/5_Looping/CMakeLists.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@ target_link_libraries(simplenet_infer_fortran_bad
3636
PRIVATE FTorch::ftorch)
3737
target_sources(simplenet_infer_fortran_bad
3838
PRIVATE bad/fortran_ml_mod.f90)
39+
# Both targets define the same Fortran module name (ml_mod). Write .mod files
40+
# to per-target directories to avoid collisions during parallel builds
41+
set_target_properties(simplenet_infer_fortran_bad PROPERTIES
42+
Fortran_MODULE_DIRECTORY
43+
${CMAKE_CURRENT_BINARY_DIR}/mod_bad
44+
)
45+
target_include_directories(simplenet_infer_fortran_bad PRIVATE
46+
${CMAKE_CURRENT_BINARY_DIR}/mod_bad)
3947

4048
# Fortran example - good
4149
add_executable(simplenet_infer_fortran_good
@@ -44,3 +52,10 @@ target_link_libraries(simplenet_infer_fortran_good
4452
PRIVATE FTorch::ftorch)
4553
target_sources(simplenet_infer_fortran_good
4654
PRIVATE good/fortran_ml_mod.f90)
55+
# Same purpose as above: isolate this target's .mod output for parallel builds
56+
set_target_properties(simplenet_infer_fortran_good PROPERTIES
57+
Fortran_MODULE_DIRECTORY
58+
${CMAKE_CURRENT_BINARY_DIR}/mod_good
59+
)
60+
target_include_directories(simplenet_infer_fortran_good PRIVATE
61+
${CMAKE_CURRENT_BINARY_DIR}/mod_good)

0 commit comments

Comments
 (0)