-
Notifications
You must be signed in to change notification settings - Fork 718
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
Adjust #defines to accommodate future CMake build #1910
Conversation
@dudhia @weiwangncar |
@@ -15,7 +15,8 @@ SUBROUTINE init_module_scalar_tables | |||
END SUBROUTINE init_module_scalar_tables | |||
END MODULE module_scalar_tables | |||
|
|||
#if( WRF_CHEM == 1 && WRF_KPP == 1 ) | |||
#ifdef WRF_CHEM | |||
#ifdef WRF_KPP |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps hypothetically, but without duplicating the enclosed code, how would one transform the original directive here if it involved an or instead of and relationship? Inability to process logical expressions in #if directives might be an issue to raise with the CMake developers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be impossible, and the current guidance (from CMake developers) is to (1) switch to Ninja or (2) rewrite the code - both of which at times are nonstarters.
This is a huge annoyance that has been noted to the CMake developers in https://gitlab.kitware.com/cmake/cmake/-/issues/17398 (which coincidentally happens to be a derivative issue spawned from https://github.com/WRF-CMake/wrf that helped me find out this limitation).
There are a few instances in WRF already that run into this scenario, and the solution there is to do neither (1) or (2) but instead do traditional C preprocessing and generate an intermediate file. The makefile system already does this for everything; moving away from this to do native Fortran preprocessing through the respective compiler would be ideal.
As a middle ground compromise limiting two-step intermediate file C preprocessing to only those files which absolutely need it has been an okay solution.
The regression test results:
|
Would it be worth splitting the changes for the I'll give it some thought, but perhaps there's a way to describe the changes in this PR differently. Looking through the diffs, my take-away is that (1) CMake doesn't support compound preprocessor conditionals, and (2) to enable CMake to generate a correct dependency graph we need to define stub modules in cases where those modules wouldn't otherwise be defined (because they had been pre-processed out). |
4908aac
to
fc27eaf
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've visually verified that the revised preprocessing directives are logically equivalent to those they replace.
@weiwangncar or @dudhia would you give this a second review? |
Can you explain why some physics have stub modules? |
@dudhia Since sometimes multiple modules exist within one file, they are considered "compiled" regardless of preprocessor directive conditional compilation to CMake. This is due to how CMake generates interdependencies for files and when conditionally compiled out, if CMake cannot process the |
@islas Thanks |
To use a specific example, the #if( BUILD_SBM_FAST != 1)
MODULE module_mp_SBM_polar_radar
CONTAINS
SUBROUTINE SBM_polar_radar
REAL :: dummy
dummy = 1
END SUBROUTINE SBM_polar_radar
END MODULE module_mp_SBM_polar_radar
#else
! ... other code ...
! +----------------------------------------------------------------------------+
! +----------------------------------------------------------------------------+
MODULE module_mp_SBM_polar_radar
! Kind paramater
INTEGER, PARAMETER, PRIVATE:: R8SIZE = 8
INTEGER, PARAMETER, PRIVATE:: R4SIZE = 4
private
public polar_hucm
! ... code ...
END MODULE module_mp_SBM_polar_radar
!**** **************************************************************** &
#endif The first If I understand correctly, the additional stub modules are there to ensure that the same set of Fortran |
@mgduda Even more clear now. Thanks. |
@mgduda That is correct. This was only done for modules where rewriting the defines+directives for CMake to understand was not possible without greater modification to the code. In the above example |
TYPE: bug fix
KEYWORDS: defines, cmake
SOURCE: internal
DESCRIPTION OF CHANGES:
Problem:
Certain #define constructs prove to be challenging for CMake to process automatically into a dependency graph.
Solution:
Reduce complexity for #defines that can be rewritten. For those that cannot, create stub modules.
LIST OF MODIFIED FILES:
M dyn_em/module_advect_em.F
M external/atm_ocn/cmpcomm.F
M external/io_adios2/wrf_io.F90
M external/io_netcdf/wrf_io.F90
M external/io_netcdfpar/wrf_io.F90
M external/io_pnetcdf/wrf_io.F90
M frame/module_configure.F
M phys/module_mp_SBM_polar_radar.F
M phys/module_mp_fast_sbm.F
TESTS CONDUCTED:
RELEASE NOTE:
Adjust #defines to accommodate future CMake build