Skip to content

Fix Fortran Wrapper Parameter Passing Bug in barrier and forget Functions#116

Open
kellih wants to merge 3 commits intoMxUI:masterfrom
kellih:fortran-wrapper-fixes
Open

Fix Fortran Wrapper Parameter Passing Bug in barrier and forget Functions#116
kellih wants to merge 3 commits intoMxUI:masterfrom
kellih:fortran-wrapper-fixes

Conversation

@kellih
Copy link
Copy Markdown

@kellih kellih commented Apr 3, 2026

Problem:
Fortran wrapper interfaces for barrier_* and forget_* functions incorrectly used the value attribute on scalar parameters (time values and reset flags), causing segmentation faults when called from Fortran code. The C++ implementation expects pointers (double *t, int *reset_log), but Fortran's value attribute passes by-value instead of by-reference.

Additional bug uncovered by commit 3ffd697 in CMakeLists.txt where MPI REQUIRED was not included for Fortran wrapper.

Scope:
Affects 90 function interfaces across all three spatial dimensions:

  • 1D wrapper: 10 barrier + 20 forget functions
  • 2D wrapper: 10 barrier + 20 forget functions
  • 3D wrapper: 10 barrier + 20 forget functions

Changes Made:

  1. Fortran Wrapper Fixes (wrappers/Fortran/)
  • mui_f_wrapper_1d.f90 (lines 13865-14072): Fixed all 30 functions
  • mui_f_wrapper_2d.f90 (lines 14228-14440): Fixed all 30 functions
  • mui_f_wrapper_3d.f90 (lines 14427-14640): Fixed all 30 functions
  • Removed , value attribute from scalar real and integer parameters
  • Kept value attribute on type(c_ptr) parameters (correct usage)
  1. CMake Build Configuration (CMakeLists.txt)
  • Added find_package(MPI REQUIRED) for Fortran wrapper (lines 106-111)
  1. Enhanced Unit Tests (wrappers/Fortran/)
  • unit_test.f90: Added barrier calls after commit and forget calls after fetch for 1D, 2D, and 3D interfaces
  • unit_test_multi.f90: Added barrier/forget loops for all dimensions in multi-interface test
  • Tests validate proper parameter passing through actual MUI workflow
  1. Testing:
  • All fixes validated to eliminate segfaults in development code
  • Unit tests successfully exercise barrier and forget functions across all dimensions

Backward Compatibility:
No API changes - this is a pure bug fix correcting the ABI between Fortran and C++.

Resolves issue #115

@Wendi-L Wendi-L self-requested a review April 8, 2026 20:06
@Wendi-L Wendi-L added the bug label Apr 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants