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

Add CMake build to WW3 #533

Merged
merged 199 commits into from
Feb 24, 2022
Merged

Add CMake build to WW3 #533

merged 199 commits into from
Feb 24, 2022

Conversation

kgerheiser
Copy link
Contributor

@kgerheiser kgerheiser commented Nov 15, 2021

Pull Request Summary

PR to add a CMake build to WW3

See documentation here

Description

The CMake build handles the build a bit differently than the current build. It builds all available files/executables it can.

The build starts with a base set of files that have no dependencies (see https://github.com/kgerheiser/WW3/blob/feature/cmake/model/src/cmake/src_list.cmake) and then based on switches adds more files to the library (i.e. SCRIP, SCRIPNC, etc). It builds up a ww3_lib library and then links each executable to that library.

The switch file options been extracted from the build system into model/bin/switches.json, which CMake parses at build time to check for necessary files/conflicts. This is meant to be a self-documenting way to add switches. Any new switches only have to be updated in this one location.

See: https://github.com/kgerheiser/WW3/blob/feature/cmake/model/bin/switches.json

Each category is an element in the JSON array which contains a name, description, type, and an array of valid options.

Each valid option object can contain an array build files associated with the given switch. It also has an optional requires and conflicts member to handle conflicting required and conflicting switches. Elements in requires: can be either a string or an array. If a string then that switch is required, if an array then one of those elements is required.

To build:

mkdir build && cd build
cmake .. -DSWITCH=<switch_file> -DCMAKE_INSTALL_PREFIX=install 
make -jn
make install

The build type can be set with -DCMAKE_BUILD_TYPE=<type> where type can be Debug or Release (case-sensitive)

Based on the switches
This will put all executables in the install directory under bin and the library in lib.

Issue(s) addressed

Fixes #139

Check list

  • Is your feature branch up to date with the authoritative repository (NOAA/develop)?

Yes

  • Please list appropriate labels code managers should add for this PR:
    documentation, enhancement, new feature, ..

  • Reviewers: @mentions of suggested reviewers of the proposed changes
    @JessicaMeixner-NOAA

Commit Message

Add a CMake build to WW3

CMake provides a portable and standardized build system and out-of-source builds. This means a faster and simpler build system. See README for more documentation.

Testing

Testing has been done on Hera and Datarmor, and the build contains a Github Actions build to test on each PR/Push.

VERSION Outdated Show resolved Hide resolved
math(EXPR len "${len} - 1")

# Loop over switch categories
set(switch_files "")
Copy link
Contributor

Choose a reason for hiding this comment

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

You have a clever solution to a complex problem, but I suspect the problem is more complex than it needs to be. It's unlikely that all these compiler switches are really needed. Most packages get by without anything like this level of complexity of build switches.

I would suggest that the coding team not get too comfortable with the JSON solution, and instead seek to reduce the number of switches to a manageable level (less than 5 or 6), and then handle them in the usual way in CMake. This will take some time, no doubt.

In the meantime, there should be very strict review of attempts to add more switches.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Fair enough @edwardhartnett but we need to be able to compile the code as it is now, in all its complexity. The solution @kgerheiser came up with is greatly appreciated.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree @edwardhartnett. It's a very unusual build with a lot of complexity, but I didn't want to touch any code, and let the build compile as is.

Copy link
Contributor

Choose a reason for hiding this comment

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

I totally agree that @kgerheiser cannot resolve these issues, and the build has to cope with them right now. His solution is elegant.

It's an unfortunate side effect of Kyle's clever solution that it's now easier than ever for the development team to add new switches. However, as we have seen, switches cause build system complexity and test difficulties. Better that if-statements are used in the code then #ifdef in the pre-processor, except for certainly well-understood cases, like whether or not a library is present at build-time.

@JessicaMeixner-NOAA perhaps you should consider some overall configuration namelist that can be read at application startup and can carry the switch settings for those switches that can be handled by code, instead of by the build.

Ideally, at some future point, Kyle's JSON solution could be removed, and the remaining switches handled by CMake command line switches, in the typical manner.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes the switch file has become a proxy to create multiple combinations of possibilities within the wave model without a review of it being needed or not. The wave model will have to carry out a longer term refactoring/restrategizing on reducing the number of switch options. That will probably take a while :)

@aliabdolali aliabdolali self-requested a review November 15, 2021 16:07
@kgerheiser
Copy link
Contributor Author

@mickaelaccensi my develop was out of date. Do a git fetch and try again.

@JessicaMeixner-NOAA
Copy link
Collaborator

@mickaelaccensi you moved the prep.sh files in ww3_tp2.14 in different directories and both this branch and PR changed them. Do we just need to move the prep.sh in this branch to the new locations? Or are there some of the changes you made that also need to be included, etc?

@mickaelaccensi
Copy link
Collaborator

ok I'm solving the conflicts then I try to make a PR

@mickaelaccensi
Copy link
Collaborator

@kgerheiser , I still can't make a PR on your github branch. It seems your visibility is not fully public for PR or contribution...
Because I can select a lot of people github repos but I can't find yours

@kgerheiser
Copy link
Contributor Author

@mickaelaccensi I'm not sure what that's about. I added you as a collaborator on the repo.

@mickaelaccensi
Copy link
Collaborator

@mickaelaccensi you moved the prep.sh files in ww3_tp2.14 in different directories and both this branch and PR changed them. Do we just need to move the prep.sh in this branch to the new locations? Or are there some of the changes you made that also need to be included, etc?
@JessicaMeixner-NOAA , if you can solve the conflicts, you just need to delete prep_env.sh from ww3_tp2.14/input directory.

@JessicaMeixner-NOAA
Copy link
Collaborator

@mickaelaccensi you moved the prep.sh files in ww3_tp2.14 in different directories and both this branch and PR changed them. Do we just need to move the prep.sh in this branch to the new locations? Or are there some of the changes you made that also need to be included, etc?
@JessicaMeixner-NOAA , if you can solve the conflicts, you just need to delete prep_env.sh from ww3_tp2.14/input directory.

But @kgerheiser made changes to prep_env.sh to work with cmake. Then you also changed the file itself + changed its locations. I don't know if I should just take the prep_evn.sh in this branch and move it to each of the files or if there needs to be some sort of changes. If you can tell me that I can make the changes, but I don't know the answer to this question to do it myself.

@mickaelaccensi
Copy link
Collaborator

@mickaelaccensi I'm not sure what that's about. I added you as a collaborator on the repo.

it works ! thanks

@JessicaMeixner-NOAA
Copy link
Collaborator

@kgerheiser I'm starting the final set of regression tests for this and hope to post the results at the end of today and then be able to merge this tomorrow. If there is any needed updates to the PR description, we should do those today.

@JessicaMeixner-NOAA
Copy link
Collaborator

When comparing this branch to itself, we get the following diff:

**********************************************************************
********************* non-identical cases ****************************
**********************************************************************
mww3_test_03/./work_PR2_UQ_MPI_d2                     (8 files differ)
mww3_test_03/./work_PR3_UNO_MPI_d2_c                     (6 files differ)
mww3_test_03/./work_PR3_UNO_MPI_d2                     (8 files differ)
mww3_test_03/./work_PR2_UNO_MPI_d2                     (8 files differ)
mww3_test_03/./work_PR1_MPI_d2                     (10 files differ)
mww3_test_03/./work_PR3_UQ_MPI_d2_c                     (8 files differ)
mww3_test_03/./work_PR3_UQ_MPI_d2                     (9 files differ)
ww3_ta1/./work_UPD0F_U                     (0 files differ)
ww3_tp2.10/./work_MPI_OMPH                     (4 files differ)
ww3_tp2.16/./work_MPI_OMPH                     (2 files differ)
ww3_ufs1.3/./work_a                     (1 files differ)

Full matrix:

matrixCompFull.txt
matrixCompSummary.txt
matrixDiff.txt

@JessicaMeixner-NOAA
Copy link
Collaborator

When comparing this branch to develop,
matrixCompSummary.txt
matrixCompFull.txt
we get a few more diffs (ignoring all 0 files diff):

**********************************************************************
********************* non-identical cases ****************************
**********************************************************************
mww3_test_03/./work_PR2_UQ_MPI_d2                     (8 files differ)
mww3_test_03/./work_PR3_UNO_MPI_d2_c                     (7 files differ)
mww3_test_03/./work_PR3_UNO_MPI_d2                     (8 files differ)
mww3_test_03/./work_PR2_UNO_MPI_d2                     (6 files differ)
mww3_test_03/./work_PR1_MPI_d2                     (9 files differ)
mww3_test_03/./work_PR3_UQ_MPI_d2_c                     (8 files differ)
mww3_test_03/./work_PR3_UQ_MPI_d2                     (8 files differ)
ww3_tp2.10/./work_MPI_OMPH                     (4 files differ)
ww3_tp2.14/./work_OASACM4                     (6 files differ)
ww3_tp2.14/./work_OASICM                     (2 files differ)
ww3_tp2.14/./work_OASOCM                     (9 files differ)
ww3_tp2.14/./work_OASACM2                     (6 files differ)
ww3_tp2.14/./work_OASACM5                     (6 files differ)
ww3_tp2.14/./work_OASACM                     (6 files differ)
ww3_tp2.16/./work_MPI_OMPH                     (16 files differ)
ww3_tp2.5/./work_PR1_MPI                     (5 files differ)
ww3_tp2.5/./work_PR1                     (5 files differ)
ww3_ufs1.3/./work_a                     (1 files differ)

The diffs in tp2.5 are "good" diffs:


/scratch2/NCEPDEV/climate/Jessica.Meixner/PR_WW3/pr533/regtests/output/ww3_tp2.5/work_PR1/ww3.08052210.hs_diff.txt
***
16082c16082
<         -999        -999        -999           0        -999        -999
---
>         -999        -999        -999 -2147483648        -999        -999

in which we get a 0 instead of -2147483648. The tp2.14 tests are likely because a different flag is used in compilation, but we get the same answers on those tests moving forward, so this seems likely okay. The matrixDiff.txt file will not upload for whatever reason.

@aliabdolali
Copy link
Contributor

When comparing this branch to develop, matrixCompSummary.txt matrixCompFull.txt we get a few more diffs (ignoring all 0 files diff):

**********************************************************************
********************* non-identical cases ****************************
**********************************************************************
mww3_test_03/./work_PR2_UQ_MPI_d2                     (8 files differ)
mww3_test_03/./work_PR3_UNO_MPI_d2_c                     (7 files differ)
mww3_test_03/./work_PR3_UNO_MPI_d2                     (8 files differ)
mww3_test_03/./work_PR2_UNO_MPI_d2                     (6 files differ)
mww3_test_03/./work_PR1_MPI_d2                     (9 files differ)
mww3_test_03/./work_PR3_UQ_MPI_d2_c                     (8 files differ)
mww3_test_03/./work_PR3_UQ_MPI_d2                     (8 files differ)
ww3_tp2.10/./work_MPI_OMPH                     (4 files differ)
ww3_tp2.14/./work_OASACM4                     (6 files differ)
ww3_tp2.14/./work_OASICM                     (2 files differ)
ww3_tp2.14/./work_OASOCM                     (9 files differ)
ww3_tp2.14/./work_OASACM2                     (6 files differ)
ww3_tp2.14/./work_OASACM5                     (6 files differ)
ww3_tp2.14/./work_OASACM                     (6 files differ)
ww3_tp2.16/./work_MPI_OMPH                     (16 files differ)
ww3_tp2.5/./work_PR1_MPI                     (5 files differ)
ww3_tp2.5/./work_PR1                     (5 files differ)
ww3_ufs1.3/./work_a                     (1 files differ)

The diffs in tp2.5 are "good" diffs:

/scratch2/NCEPDEV/climate/Jessica.Meixner/PR_WW3/pr533/regtests/output/ww3_tp2.5/work_PR1/ww3.08052210.hs_diff.txt
***
16082c16082
<         -999        -999        -999           0        -999        -999
---
>         -999        -999        -999 -2147483648        -999        -999

in which we get a 0 instead of -2147483648. The tp2.14 tests are likely because a different flag is used in compilation, but we get the same answers on those tests moving forward, so this seems likely okay. The matrixDiff.txt file will not upload for whatever reason.

When the matrixDiff is very large, github does not allow you to upload it.

@JessicaMeixner-NOAA
Copy link
Collaborator

@aliabdolali good to know. I'm happy to post any portion of the matrixdiff if anyone is curious.

@JessicaMeixner-NOAA JessicaMeixner-NOAA merged commit cfcd089 into NOAA-EMC:develop Feb 24, 2022
@aliabdolali
Copy link
Contributor

thanks @kgerheiser for this great development.

@arunchawla-NOAA
Copy link
Contributor

hurrah !!!!!!!

@edwardhartnett
Copy link
Contributor

Good work @kgerheiser , this was a lot more complex than I anticipated!

aliabdolali pushed a commit that referenced this pull request Mar 16, 2022
CMake provides a portable and standardized build system and out-of-source builds. This means a faster and simpler build system. See README for more documentation.
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.

CMAKE
10 participants