Skip to content
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

Unique symbols per precision #61

Closed
wants to merge 9 commits into from

Conversation

wdeconinck
Copy link
Collaborator

@wdeconinck wdeconinck commented Feb 8, 2024

The libraries trans_sp and trans_dp have duplicated symbols.
This PR uses some kind of preprocessing of original files to generate files with a precision suffix like _sp and _dp, avoiding the same symbol names, so that in the future a library could link to both trans_sp and trans_dp.

The work in this PR is inherited from PR #55 by @piotrows, and tidied up a bit, but does not yet go so far to introduce wrappers that make a unified interface.

Note, commit 5329c07 in this PR changes the API of setup_trans and setup_trans0 to use arguments with KIND=JPRD only. This could be reverted and/or added in a follow-up PR if desired.

When this PR is merged and a new release is to be used in the IFS, an extra commit in ifs-source is required, which I have prepared and would be ready for review. I will update this Issue with ifs-source status.
ifs-source was using some ectrans internal modules or subroutines without including the interface.
So even without API change in setup_trans, the ifs-source commit would be required.

@wdeconinck
Copy link
Collaborator Author

Note, preprocessing is based on sed. On macOS 13 this works but on the CI it does not work yet.
Either a workaround will be needed before merging, or we update the macOS runner. Further investigation needed.

@@ -108,6 +107,7 @@ SUBROUTINE SUGAW(KDGL,KM,KN,PL,PW,PANM,PFN)

! computations in extended precision for alternative root finding
! which also works for associated polynomials (m>0)
INTEGER, PARAMETER :: JPRH = JPRD
Copy link
Collaborator

Choose a reason for hiding this comment

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

This one I need to think about a bit. It looks like we are removing the option to compute the roots in extended precision. If we don't need this anymore, and double precision is fine, better to be transparent and just replace all instances of JPRH with JPRD.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes I don't think we need JPRH. At least parkind1 has not recently compiled JPRH differently.
If agreed by others as well we can follow your proposal.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I can just create an issue so we deal with this in a future PR.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks @samhatfield for creating #62 for follow-up.

@samhatfield
Copy link
Collaborator

samhatfield commented Feb 9, 2024

First read over completed. Here is my summary of what you're proposing, as a sanity check:

  • Where possible, PARKIND1 replaced with EC_PARKIND
  • PWEIGHT and PSTRET arguments to SETUP_TRANS and corresponding module variables in TPM_DISTR, TPM_GEOMETRY made double precision always
  • PRAD argument to SETUP_TRANS0 made double precision always
  • SPECNORM PNORM argument made mandatory - Why is this necessary?
  • ectrans_common library created based on subset of JPRB-agnostic modules
  • ectrans_{sp/dp} "backend libraries" created with JPRB-dependent modules

I'd like some more time to read the new CMake functionality for generating the ectrans_${prec} libraries, but feel free to respond to the above comments in the mean time.

@wdeconinck
Copy link
Collaborator Author

  • Where possible, PARKIND1 replaced with EC_PARKIND

I only applied this to some routines, but we could push this through everywhere JPRB is not needed.

  • PWEIGHT and PSTRET arguments to SETUP_TRANS and corresponding module variables in TPM_DISTR, TPM_GEOMETRY made double precision always

Correct. These are arguments that are only needed to set up the grid point domain decomposition.

  • PRAD argument to SETUP_TRANS0 made double precision always

Yes, this makes TPM_CONSTANTS module independent of JPRB.

  • SPECNORM PNORM argument made mandatory - Why is this necessary?

It is in fact not necessary for this PR, but disambiguates overload on this argument's KIND of this routine in the future. All optional arguments cannot be disambiguated. In practice this argument is always required. Otherwise what's the point. Trying this change in ifs-source proved that this argument is never omitted. This change could be removed from this PR and introduced later, but it's pretty harmless.

  • ectrans_common library created based on subset of JPRB-agnostic modules

It is also enlightening to see which routines and modules are not used for the actual transforms.

  • ectrans_{sp/dp} "backend libraries" created with JPRB-dependent modules

I'd like some more time to read the new CMake functionality for generating the ectrans_${prec} libraries, but feel free to respond to the above comments in the mean time.

Noteworthy is that neither backend libraries ectrans_sp and ectrans_dp link with parkind_sp or parkind_dp because the preprocessor step replaces parkind1 with ec_parkind and JPRB with JPRD or JPRM.

@wdeconinck wdeconinck force-pushed the feature/unique_precision_symbols branch from fe646ab to e87e825 Compare February 13, 2024 15:15
@wdeconinck
Copy link
Collaborator Author

Rebased on recently merged CY49R1 sync branch

@wdeconinck wdeconinck force-pushed the feature/unique_precision_symbols branch from e87e825 to 3f3ca55 Compare February 13, 2024 20:27
@wdeconinck
Copy link
Collaborator Author

I added commit f77550c to develop branch which updates the macOS runner to macos-13. Having rebased this branch on develop now fixes the 'sed' issues previously present.

Co-authored-by: Sam Hatfield <samhatfield@users.noreply.github.com>
@RyadElKhatibMF
Copy link
Contributor

RyadElKhatibMF commented Feb 15, 2024 via email

Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we pass setup_trans0.h through configure? Is it meant to "do nothing" in this case?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good observation! I used this to copy files from source dir to build-dir, and indeed in this case changes nothing of the content.

Copy link
Contributor

Choose a reason for hiding this comment

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

So maybe this deserves a comment in the cmake script?

@samhatfield
Copy link
Collaborator

I finally read through the CMake changes and that looks good to me! I think I'm starting to like CMake.

Can internal/sutrle_mod.F90 be added to the common library?

Also external/setup_trans.F90?

@wdeconinck
Copy link
Collaborator Author

I finally read through the CMake changes and that looks good to me! I think I'm starting to like CMake.

Can internal/sutrle_mod.F90 be added to the common library?

Also external/setup_trans.F90?

Hi @samhatfield these files unfortunately cannot be added to the common library because they USE modules that have themselves JPRB. e.g. TPM_FIELDS

@samhatfield
Copy link
Collaborator

Right that makes sense. That also answers the other question I had, which was why we can't automatically build the list of common files. Because that would require code introspection rather than a simple grep.

@samhatfield
Copy link
Collaborator

Good to merge for me.

Copy link
Collaborator

@marsdeno marsdeno left a comment

Choose a reason for hiding this comment

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

This looks good to me.

wdeconinck added a commit that referenced this pull request Feb 28, 2024
* feature/unique_precision_symbols:
  Add setup_trans0 to ectrans_common
  setup_trans, setup_trans0 API change, using JPRD kind for arguments
  Add the new precision independent routines to ectrans_common
  Make some internal modules and routines precision independent
  Remove sugawc from compilation
  Generate libraries with unique symbols
  Code changes related to unused PARKIND1 JPRB
@wdeconinck
Copy link
Collaborator Author

Merged in develop now! Thanks everyone, especially @piotrows for the majority of all work included in this PR. 🙏

@wdeconinck wdeconinck closed this Feb 28, 2024
set(backend ${_PAR_BACKEND})

file(MAKE_DIRECTORY ${destination})
file(MAKE_DIRECTORY ${destination}/${backend})
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this line (132) is not needed.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

You are right, something fishy here, that should be

file(MAKE_DIRECTORY ${destination}/trans_${backend})

This is now added to develop with commit 91a51b1

src/trans/CMakeLists.txt Show resolved Hide resolved
get_filename_component(outfile_ext ${file_i} EXT)
get_filename_component(outfile_dir ${file_i} DIRECTORY)
set(outfile "${destination}/${file_i}")
ecbuild_debug("Generate ${outfile}")
Copy link
Contributor

Choose a reason for hiding this comment

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

Same comment here ("Invoking ...)

src/trans/CMakeLists.txt Show resolved Hide resolved
src/trans/CMakeLists.txt Show resolved Hide resolved
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/src/trans/include/ectrans>
$<INSTALL_INTERFACE:include/ectrans>
SOURCES ${ectrans_${prec}_src}
PUBLIC_INCLUDES $<INSTALL_INTERFACE:include/ectrans>
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this unspecialised path still valid?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes it is still valid as the "common" includes should be there.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes but I mean the install include files, don't they need a subdirectory per variant?

Copy link
Contributor

Choose a reason for hiding this comment

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

So maybe this deserves a comment in the cmake script?

wdeconinck added a commit that referenced this pull request Feb 29, 2024
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.

5 participants