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

CMake: Improve handling of Albany and related packages #5950

Merged
merged 3 commits into from
Sep 26, 2023

Conversation

jgfouca
Copy link
Member

@jgfouca jgfouca commented Sep 22, 2023

Specifically:

  • Albany
  • Trilinos
  • Kokkos

This PR establishes the new paradigm of setting ${Package}_ROOT to find the packages we need. So far, I am very happy with how this is going. You can see how much cleaner it is to do things the CMake-3 so you don't have to micro-manage flags.

This PR is currently WIP because I was not able to fully test it on pm-cpu due to permissions issues with the boost that was used to build Trilinos.

In order to be consistent, changes kokkos override env var from KOKKOS_PATH to Kokkos_ROOT.

Fixes #5786

@jgfouca jgfouca added BFB PR leaves answers BFB CMake build system labels Sep 22, 2023
@jgfouca jgfouca requested review from bartgol and mperego September 22, 2023 21:16
@jgfouca jgfouca self-assigned this Sep 22, 2023
@@ -257,6 +257,8 @@
<env name="PERL5LIB">/global/cfs/cdirs/e3sm/perl/lib/perl5-only-switch</env>
<env name="FI_CXI_RX_MATCH_MODE">software</env>
<env name="MPICH_COLL_SYNC">MPI_Bcast</env>
<env name="Albany_ROOT">$SHELL{if [ -z "$Albany_ROOT" ]; then echo /global/common/software/e3sm/mali_tpls/albany-e3sm-serial-release-gcc; else echo "$Albany_ROOT"; fi}</env>
Copy link
Member Author

Choose a reason for hiding this comment

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

The pattern for setting up ${Package}_ROOT is established here. It's a bit messy so I'm wondering if it would be better to move this login into the cmake macro file for the machine?

Copy link
Contributor

Choose a reason for hiding this comment

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

There's a better bash syntax:

Albany_ROOT=${Albany_ROOT:=/global/common/software/e3sm/mali_tpls/albany-e3sm-serial-release-gcc}

The ${VAR:=default} syntax expands to ${VAR} if VAR is defined, otherwise it expands to default. E.g.:

$ export FOO=foo
$ export BAR=${FOO:=bar} && echo $BAR
foo
$ export BAR={FOOBAR:=bar} && echo $BAR
bar

Copy link
Member Author

Choose a reason for hiding this comment

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

@bartgol , I tried that at first. The problem is that the CIME regex will incorrectly match the first } as terminating the SHELL command, so you can use that character in your syntax.

@jgfouca jgfouca mentioned this pull request Sep 22, 2023
49 tasks
@jgfouca jgfouca requested review from rljacob and jasonb5 September 22, 2023 21:19
Copy link
Contributor

@bartgol bartgol left a comment

Choose a reason for hiding this comment

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

Looks much cleaner. I left a suggestion for the bash env var. I think it may be a bit cleaner, but up to you.

@@ -257,6 +257,8 @@
<env name="PERL5LIB">/global/cfs/cdirs/e3sm/perl/lib/perl5-only-switch</env>
<env name="FI_CXI_RX_MATCH_MODE">software</env>
<env name="MPICH_COLL_SYNC">MPI_Bcast</env>
<env name="Albany_ROOT">$SHELL{if [ -z "$Albany_ROOT" ]; then echo /global/common/software/e3sm/mali_tpls/albany-e3sm-serial-release-gcc; else echo "$Albany_ROOT"; fi}</env>
Copy link
Contributor

Choose a reason for hiding this comment

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

There's a better bash syntax:

Albany_ROOT=${Albany_ROOT:=/global/common/software/e3sm/mali_tpls/albany-e3sm-serial-release-gcc}

The ${VAR:=default} syntax expands to ${VAR} if VAR is defined, otherwise it expands to default. E.g.:

$ export FOO=foo
$ export BAR=${FOO:=bar} && echo $BAR
foo
$ export BAR={FOOBAR:=bar} && echo $BAR
bar

@@ -205,65 +205,6 @@ if (USE_PETSC)
set(PETSC_LIB ${PETSC_LIBRARIES})
endif()

if (USE_TRILINOS)
Copy link
Contributor

Choose a reason for hiding this comment

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

So much better than what we had...

endif()

# Albany depends on Trilinos
if (USE_ALBANY OR USE_TRILINOS)
Copy link
Contributor

Choose a reason for hiding this comment

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

This is fine, but for the record, I think that USE_ALBANY here is redundant. find_package(ALBANY REQUIRED) will also call find_package(Trilinos REQUIRED). If a CMake package is installed well, it is responsible of finding all its TPLs when you call find_package(YOUR_PKG).

Copy link
Member Author

Choose a reason for hiding this comment

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

It looks like this is a deficiency with the Albany cmake system. I tried without USE_ALBANY check for Trilinos and I got this error:

CMake Error at /global/common/software/e3sm/mali_tpls/albany-e3sm-serial-release-gcc/lib64/Albany/cmake/albany-targets.cmake:61 (set_target_properties):
  The link interface of target "albanyLib" contains:

    Panzer::all_libs

  but the target was not found.  Possible reasons include:

    * There is a typo in the target name.
    * A find_package call is missing for an IMPORTED target.
    * An ALIAS target is missing.

Call Stack (most recent call first):
  /global/common/software/e3sm/mali_tpls/albany-e3sm-serial-release-gcc/lib64/Albany/cmake/AlbanyConfig.cmake:28 (include)
  cmake/find_dep_packages.cmake:45 (find_package)
  CMakeLists.txt:124 (include)

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, we are probably not packaging albany that well.. :/

Copy link
Contributor

Choose a reason for hiding this comment

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

I am going through our cmake stuff, and indeed we lack a lot of stuff to consider us "good cmake citizens"... I will fix it at some point.

@jgfouca
Copy link
Member Author

jgfouca commented Sep 25, 2023

@mperego , there are some deficiencies in the Albany Cmake system that are causing me problems:

  1. Albany's find_package does not find Trilinos, so E3SM has to do it. It's easy enough for E3SM to do it, so this is not a show stopper.
  2. For some reason, the mpasInterface library is linked via -lmpasInterface instead of just listing the full path to the library like the other Albany libraries do. This causes a failure cannot find -lmpasInterface: No such file or directory since the albany cmake doesn't add that directory via -L

If I fix (2) by manually editing the link line (replace -lmpasInterface with /global/common/software/e3sm/mali_tpls/albany-e3sm-serial-release-gcc/lib64/libmpasInterface.so, then everything works and it builds.

Since these problems aren't related to E3SM, I'm going to push ahead with this PR unless you say otherwise.

@jgfouca
Copy link
Member Author

jgfouca commented Sep 25, 2023

I removed all instances of ALBANY_PATH from the Cmake macros. This means that the BGWCYCL1850 compset will only work on perlmutter currently. Any machine that wants to support this compset will need to follow the pattern in the perlmutter config_machines and add Albany_ROOT and Trilinos_ROOT.

@bartgol
Copy link
Contributor

bartgol commented Sep 25, 2023

@mperego , there are some deficiencies in the Albany Cmake system that are causing me problems:

  1. Albany's find_package does not find Trilinos, so E3SM has to do it. It's easy enough for E3SM to do it, so this is not a show stopper.
  2. For some reason, the mpasInterface library is linked via -lmpasInterface instead of just listing the full path to the library like the other Albany libraries do. This causes a failure cannot find -lmpasInterface: No such file or directory since the albany cmake doesn't add that directory via -L

If I fix (2) by manually editing the link line (replace -lmpasInterface with /global/common/software/e3sm/mali_tpls/albany-e3sm-serial-release-gcc/lib64/libmpasInterface.so, then everything works and it builds.

Since these problems aren't related to E3SM, I'm going to push ahead with this PR unless you say otherwise.

We're fixing other issues with our cmake logic (lots of legacy stuff, and some not-so-great cmake usage here and there). I'll keep in mind these issues in the process.

jgfouca added a commit that referenced this pull request Sep 25, 2023
CMake: Improve handling of Albany and related packages

Specifically:
* Albany
* Trilinos
* Kokkos

This PR establishes the new paradigm of setting ${Package}_ROOT to
find the packages we need. So far, I am very happy with how this is
going. You can see how much cleaner it is to do things the CMake-3 so
you don't have to micro-manage flags.

In order to be consistent, changes kokkos override env var from
KOKKOS_PATH to Kokkos_ROOT.

Fixes #5786

[BFB]

* jgfouca/cmake_albany:
  Remove obsolete references to ALBANY_PATH in cmake macros
  Improve Kokkos handling
  CMake: Improve handling of Albany and related packages
@jgfouca
Copy link
Member Author

jgfouca commented Sep 25, 2023

Thanks, @bartgol ! Merged to next.

@mperego
Copy link
Contributor

mperego commented Sep 25, 2023

Thanks a lot @jgfouca! This looks so much cleaner. Looking forward to trying this out.

@jgfouca jgfouca merged commit ffc0e2b into master Sep 26, 2023
2 checks passed
@jgfouca jgfouca deleted the jgfouca/cmake_albany branch September 26, 2023 16:22
@bartgol
Copy link
Contributor

bartgol commented Nov 3, 2023

@mperego , there are some deficiencies in the Albany Cmake system that are causing me problems:

  1. Albany's find_package does not find Trilinos, so E3SM has to do it. It's easy enough for E3SM to do it, so this is not a show stopper.
  2. For some reason, the mpasInterface library is linked via -lmpasInterface instead of just listing the full path to the library like the other Albany libraries do. This causes a failure cannot find -lmpasInterface: No such file or directory since the albany cmake doesn't add that directory via -L

If I fix (2) by manually editing the link line (replace -lmpasInterface with /global/common/software/e3sm/mali_tpls/albany-e3sm-serial-release-gcc/lib64/libmpasInterface.so, then everything works and it builds.

Since these problems aren't related to E3SM, I'm going to push ahead with this PR unless you say otherwise.

I found the culprit. Albany was not exporting the mpasInterface target (unlike the other libs), so it was not available as a CMake target to downstream projects. Will fix it in Albany.

bartgol added a commit to sandialabs/Albany that referenced this pull request Nov 3, 2023
The lack of export was causing link errors in E3SM,
as noted in E3SM-Project/E3SM#5950.
mperego pushed a commit to sandialabs/Albany that referenced this pull request Nov 3, 2023
The lack of export was causing link errors in E3SM,
as noted in E3SM-Project/E3SM#5950.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BFB PR leaves answers BFB CMake build system
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Import cmake file from Albany
3 participants