Skip to content

ABI: Changes to Fortran-related get/set routines - #7942

Open
dalcinl wants to merge 2 commits into
pmodels:mainfrom
dalcinl:fix-fortran-logical128
Open

ABI: Changes to Fortran-related get/set routines#7942
dalcinl wants to merge 2 commits into
pmodels:mainfrom
dalcinl:fix-fortran-logical128

Conversation

@dalcinl

@dalcinl dalcinl commented Aug 26, 2026

Copy link
Copy Markdown
Collaborator

Pull Request Description

Changes to Fortran ABI get/set routines. Some bits may be controversial. this is a middle ground of my interpretation of the standard and what Open MPI has implemented (note: not by me). Split in two commits to help review, can be squashed.

Partially addresses #7938, remove symbol visibility MPIR_fortran_true/false from the MPI libraries.

Commit messages pasted below for the reviewer convenience:

  • bindings/c/abi: Refactor bindings generation for Fortran APIs

    • Implement MPI_Abi_get_fortran_booleans in the MPIR layer
    • Implement MPI_Abi_get_fortran_info in the MPIR layer
    • Support Fortran booleans of size 16
    • Use MPI_ERR_ARG to signal bad logical_size
    • Do not expose MPIR_fortran_true/false as a visible symbol.
  • bindings/c/abi: Implement Fortran get/set booleans with the C preprocessor

    • Allow for get/set Fortran booleans in arbitrary and thus possibly
      unaligned memory locations by using an intermediate value and memcpy.
    • Refactor repetitive code using C preprocessor macros.

Author Checklist

  • Provide Description
    Particularly focus on why, not what. Reference background, issues, test failures, xfail entries, etc.
  • Commits Follow Good Practice
    Commits are self-contained and do not do two things at once.
    Commit message is of the form: module: short description
    Commit message explains what's in the commit.
  • Passes All Tests
    Whitespace checker. Warnings test. Additional tests via comments.
  • Contribution Agreement
    For non-Argonne authors, check contribution agreement.
    If necessary, request an explicit comment from your companies PR approval manager.

Comment thread src/mpi/datatype/typeutil.c Outdated
@dalcinl
dalcinl force-pushed the fix-fortran-logical128 branch 3 times, most recently from 26546f3 to 2934406 Compare September 1, 2026 19:05
@dalcinl

dalcinl commented Sep 1, 2026

Copy link
Copy Markdown
Collaborator Author

@hzhou I have not looked at #7803 yet. Can this PR be merged first? Or after? Or somehow merged?

* Implement MPI_Abi_get_fortran_booleans in the MPIR layer
* Implement MPI_Abi_get_fortran_info  in the MPIR layer
* Support Fortran booleans of size 16
* Use MPI_ERR_ARG to signal bad logical_size
* Do not expose MPIR_fortran_true/false as a visible symbol.
…essor

* Allow for get/set Fortran booleans in arbitrary and thus possibly
  unaligned  memory locations by using an intermediate value and memcpy.
* Refactor repetitive code using C preprocessor macros.
@dalcinl
dalcinl force-pushed the fix-fortran-logical128 branch from 2934406 to 859a7c9 Compare September 1, 2026 19:13
@hzhou

hzhou commented Sep 1, 2026

Copy link
Copy Markdown
Collaborator

@hzhou I have not looked at #7803 yet. Can this PR be merged first? Or after? Or somehow merged?

Yes, this can be merged first. If there are compatibility issue we will find out after the merge and deal with it then

@hzhou hzhou left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

intN_t true_value = (intN_t) MPIR_fortran_true; \
intN_t false_value = (intN_t) MPIR_fortran_false; \
(void) memcpy(logical_true, &true_value, sizeof(intN_t)); \
(void) memcpy(logical_false, &false_value, sizeof(intN_t)); \

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Wait. We need consider endian to use memcpy

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

What do you mean? The C compiler and the Fortran compiler would use the same endianness. The use of memcpy here preserves endianness. I'm using memcpy to avoid alignment issues, in case the user is trying to get/set the booleans from unaligned memory (e.g. members of a packed struct or something like that, or even maybe a byte array).

Am I missing something obvious?

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.

2 participants