Skip to content

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

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

Fix Fortran Wrapper Parameter Passing Bug in barrier and forget Functions#116
kellih wants to merge 3 commits into
MxUI: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
@Wendi-L
Copy link
Copy Markdown
Member

Wendi-L commented Jun 1, 2026

Hi @kellih,

Many thanks for your contribution! Overall, the PR looks good to me.

I just have one comment regarding the removal of the following lines in ‎src/mui.h:

  • #include "samplers/temporal/temporal_sampler_linear.h" (line 68)
  • DECLARE_SAMPLER_0ARG(temporal_sampler_linear,SUFFIX,config_##SUFFIX); (line 123)
  • DECLARE_SAMPLER_0ARG(temporal_sampler_linear,SUFFIX,CONFIG); (line 165)

These should be kept. I believe the temporal_sampler_linear implementation was still being merged when you created this PR, so removing these lines was understandable at that time. This piece of work on temporal_sampler_linear has now been completed, and these declarations are required.

If you could revert these changes, I will carry out a final round of testing and then proceed with the merge.

Thanks again for your contribution!

Comment thread src/mui.h
#include "samplers/temporal/temporal_sampler_gauss_adaptive.h"
#include "samplers/temporal/temporal_sampler_mean.h"
#include "samplers/temporal/temporal_sampler_sum.h"
#include "samplers/temporal/temporal_sampler_linear.h"
Copy link
Copy Markdown
Member

@Wendi-L Wendi-L Jun 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please keep this include. temporal_sampler_linear has now been merged and is required.

Comment thread src/mui.h
DECLARE_SAMPLER_0ARG(temporal_sampler_gauss,SUFFIX,config_##SUFFIX);\
DECLARE_SAMPLER_0ARG(temporal_sampler_sum,SUFFIX,config_##SUFFIX);\
DECLARE_SAMPLER_0ARG(temporal_sampler_mean,SUFFIX,config_##SUFFIX);\
DECLARE_SAMPLER_0ARG(temporal_sampler_linear,SUFFIX,config_##SUFFIX);\
Copy link
Copy Markdown
Member

@Wendi-L Wendi-L Jun 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please keep this declaration. temporal_sampler_linear is now part of the main codebase.

Comment thread src/mui.h
DECLARE_SAMPLER_0ARG(temporal_sampler_gauss,SUFFIX,CONFIG);\
DECLARE_SAMPLER_0ARG(temporal_sampler_sum,SUFFIX,CONFIG);\
DECLARE_SAMPLER_0ARG(temporal_sampler_mean,SUFFIX,CONFIG);\
DECLARE_SAMPLER_0ARG(temporal_sampler_linear,SUFFIX,CONFIG);\
Copy link
Copy Markdown
Member

@Wendi-L Wendi-L Jun 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please keep this declaration. temporal_sampler_linear is now part of the main codebase.

Comment thread src/mui.h
//Include temporal samplers
#include "samplers/temporal/temporal_sampler_exact.h"
#include "samplers/temporal/temporal_sampler_gauss.h"
#include "samplers/temporal/temporal_sampler_gauss_adaptive.h"
Copy link
Copy Markdown
Member

@Wendi-L Wendi-L Jun 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think temporal_sampler_gauss_adaptive is a part of the code base. Suggest removing this include

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