Skip to content

Fortran configury: Ensure F08 real_kinds are actually valid kinds #5401

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 11, 2025

Conversation

lrbison
Copy link
Contributor

@lrbison lrbison commented Mar 21, 2025

Closes #5090

@brtnfld
Copy link
Collaborator

brtnfld commented Mar 24, 2025

For consistency, the same changes should be made to FC_AVAIL_KINDS.

@brtnfld brtnfld self-assigned this Mar 24, 2025
INTEGER :: num_rkinds, num_ikinds, num_lkinds
logical :: found_rkinds( 1:SIZE(real_kinds) )
Copy link
Collaborator

Choose a reason for hiding this comment

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

please use uppercase keyword intrinsics

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed.

@brtnfld
Copy link
Collaborator

brtnfld commented Mar 24, 2025

I have to ensure this does not suppress detected kinds of other compilers since that scenario would not cause tests to fail.

@vchoi-hdfgroup vchoi-hdfgroup added the Component - Wrappers C++, Java & Fortran wrappers label Mar 24, 2025
@vchoi-hdfgroup vchoi-hdfgroup added Component - Build CMake, Autotools and removed Component - Wrappers C++, Java & Fortran wrappers labels Mar 24, 2025
@lrbison
Copy link
Contributor Author

lrbison commented Mar 24, 2025

please use uppercase keyword intrinsics

Done!

I have to ensure this does not suppress detected kinds of other compilers since that scenario would not cause tests to fail.

Sure. In my testing I saw that GNU Fortran was unaffected. You can see output here.

For these next two points let me clarify that SELECTED_REAL_KIND is correct in ACfL, it is only the F08 ISO_FORTRAN_ENV array REAL_KINDS that was wrong. That array was only used to print the real kinds the compiler supported (not max precision), so I don't think the following comments items require a change:

If the KIND is not supported, then the maximum decimal precision, max_decimal_prec, should not be set for that KIND.

The REAL_KINDS array was not used in the loop to determine max decimal precision, so it is already correct.

For consistency, the same changes should be made to FC_AVAIL_KINDS.

The non-F08 version of this loop builds the list of kinds based on the return values of SELECTED_REAL_KIND, so it never had the problem.

... however it makes me wonder if the preferred fix is just to ignore REAL_KINDS altogether and use FC_AVAIL_KINDS's logic to find real kinds.

@byrnHDF byrnHDF added Component - Wrappers C++, Java & Fortran wrappers Component - Configure and removed Component - Build CMake, Autotools labels Mar 26, 2025
@brtnfld
Copy link
Collaborator

brtnfld commented Mar 28, 2025

The non-F08 version of this loop builds the list of kinds based on the return values of SELECTED_REAL_KIND, so it never had the problem.

I'm not sure the compiler does not also have an issue with SELECTED_REAL_KIND, as from our discussion, #5090,

k = SELECTED_REAL_KIND(19,2)
print*,k
end

Printed -1, so it does not support KIND=16.

@lrbison
Copy link
Contributor Author

lrbison commented Mar 28, 2025

Printed -1, so it does not support KIND=16.

Correct. ACfL does not support KIND=16, yet it includes 16 in REAL_KINDS (a compiler bug). This caused HDF5 configuration to make code with REAL(KIND=16) which then fails to compile. I am suggesting this patch to work around the compiler bug.

@lrbison
Copy link
Contributor Author

lrbison commented Apr 1, 2025

@brtnfld so are there other changes you think are required?

@brtnfld
Copy link
Collaborator

brtnfld commented Apr 3, 2025

num_rkinds gets its value from size(real_kinds), which is going to include KIND=16.
max_decimal_prec is going to be for KIND=16, and not KIND=8, or whatever the highest kind supported.

@lrbison
Copy link
Contributor Author

lrbison commented Apr 3, 2025

@brtnfld Yes, num_rkinds will be size(real_kinds), but in the loop before we print the kinds we check the new logical array with IF(.NOT. found_rkinds(k)) CYCLE. I've also updated the logic to ensure we don't print trailing commas, double commas, or anything like that.

max_decimal_prec is going to be for KIND=16, and not KIND=8, or whatever the highest kind supported.

No. On line 216 k = SELECTED_REAL_KIND(ik,jk) never selects kind=16 in ACfL, therefore the max_precision remains correct. When ik goes above 15 selected_real_kind returns -1 and the existing logic exits the loop and max_decimal_prec is never updated further. This is also seen from the issue where I show the test output has -- ....MAX DECIMAL PRECISION 15 rather than 33 as it does in GFortran.

@brtnfld
Copy link
Collaborator

brtnfld commented Apr 3, 2025

num_rkinds is printed later in the program, so it should reflect the number of real KINDS actually printed.

@lrbison
Copy link
Contributor Author

lrbison commented Apr 4, 2025

num_rkinds is printed later

I see, I had missed that, thank you for pointing it out. Testing with cmake -S ../hdf5 -DCMAKE_Fortran_COMPILER=gfortran/armflang -DHDF5_BUILD_FORTRAN=ON: Gfortran cmake prints:

-- ....NUMBER OF INTEGER KINDS FOUND 5
-- ....REAL KINDS FOUND {4,8,16}
-- ....INTEGER KINDS FOUND {1,2,4,8,16}
-- ....MAX DECIMAL PRECISION 33
-- ....LOGICAL KINDS FOUND {1,2,4,8,16}
-- ....FOUND SIZEOF for REAL KINDs {4,8,16}

and ACfL prints

-- ....NUMBER OF INTEGER KINDS FOUND 4
-- ....REAL KINDS FOUND {4,8}
-- ....INTEGER KINDS FOUND {1,2,4,8}
-- ....MAX DECIMAL PRECISION 15
-- ....LOGICAL KINDS FOUND {1,2,4,8}
-- ....FOUND SIZEOF for REAL KINDs {4,8}

The test program itself prints:

gfortran ./test.f90 && ./a.out
1,2,4,8,16
4,8,16
33
5
3
5
1,2,4,8,16
armflang ./test.f90 && ./a.out
1,2,4,8
4,8
15
4
2
4
1,2,4,8

@lrbison
Copy link
Contributor Author

lrbison commented Apr 4, 2025

@brtnfld fixed and rebased

@lrbison
Copy link
Contributor Author

lrbison commented Apr 10, 2025

@brtnfld can you take another look?

Copy link
Collaborator

@brtnfld brtnfld left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for the fix.!

@brtnfld brtnfld requested a review from epourmal April 10, 2025 23:11
@lrknox lrknox merged commit 09bc016 into HDFGroup:develop Apr 11, 2025
54 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component - Wrappers C++, Java & Fortran wrappers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Compilation failure on aarch64 with Arm Compiler for Linux's flang
6 participants