Skip to content

Commit

Permalink
Nemsfv3gfs master ccpp integration (NCAR#63)
Browse files Browse the repository at this point in the history
This PR enables the integration of ccpp-framework (and ccpp-physics) in the current trunk of FV3 in directories ccpp/{framework,physics}.

Most changes are required for the build system so that it can be used with the existing SCM and with FV3 (current trunk). For the FV3-current trunk, the cmake configuration is cleaner and streamlined between the different CMakeLists.txt (and with ccpp-physics). To avoid introducing all these changes for SCM at the same time, the current - to be improved - cmake config for SCM is retained. A new variable PROJECT is introduced that allows to distinguish between different builds (currently 'CCPP-FV3' for FV3-current trunk and default='unknown' for SCM). The cmake build system needs to be reworked, best would be to introduce project 'CCPP-SCM' for the SCM build and use 'unknown' for building the CCPP standalone.

A new attribute 'initialized' is introduced for type ccpp_t (cdata structure) to test the initialization state of cdata. This is required for calling fast physics in FV3 dynamics through CCPP.

For FV3-current trunk, the list of schemes and their dependencies and their caps is written to makefile and cmakefile snippets and used during the cmake build of ccpp-physics (as opposed to FV3v0, where only the auto-generated list of caps is used, or SCM where all of it is hardcoded). This requires minor changes to the Python prebuild script and configs.

This PR is related to several others listed in a follow-up comment. Results are bit-for-bit identical with FV3v0 and SCM.
  • Loading branch information
climbfuji authored and llpcarson committed May 9, 2018
1 parent ca810d3 commit 527d96f
Show file tree
Hide file tree
Showing 15 changed files with 506 additions and 77 deletions.
51 changes: 29 additions & 22 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
# Set default project to unknown
if(NOT PROJECT)
message(STATUS "Setting CCPP project to 'unknown' as none was specified.")
set(PROJECT "Unknown")
endif (NOT PROJECT)

#------------------------------------------------------------------------------
cmake_minimum_required(VERSION 2.8.11)

# Use rpaths on MacOSX
set(CMAKE_MACOSX_RPATH 1)

if(POLICY CMP0048)
cmake_policy(SET CMP0048 NEW)
project(ccpp VERSION 0.1.0)
project(ccpp VERSION 1.0.0)
else(POLICY CMP0048)
project(ccpp)
set(PROJECT_VERSION 0.1.0)
set(PROJECT_VERSION_MAJOR 0)
set(PROJECT_VERSION_MINOR 1)
set(PROJECT_VERSION 1.0.0)
set(PROJECT_VERSION_MAJOR 1)
set(PROJECT_VERSION_MINOR 0)
set(PROJECT_VERSION_PATCH 0)
endif(POLICY CMP0048)

Expand All @@ -21,19 +31,10 @@ enable_language(Fortran)

#------------------------------------------------------------------------------
# Set package definitions
set(PACKAGE "CCPP")
set(AUTHORS "Timothy Brown" "David Gill" "Dom Heinzeller")
set(PACKAGE "ccpp-framework")
set(AUTHORS "Dom Heinzeller" "Timothy Brown" "David Gill")
string(TIMESTAMP YEAR "%Y")

#------------------------------------------------------------------------------
# The PGI compiler can not find any cap routines in their library.
# This is due to how it labels subroutines within a modules.
# For example the subroutine b() in the moduel a(), gets named a_b.
# GCC and Intel do NOT do this, it is name simply as b.
if ("${CMAKE_Fortran_COMPILER_ID}" STREQUAL "PGI")
message(STATUS "WARNING: PGI compiler is not fully ISO_C compliant; working solution involves a hack pgifix.py")
endif()

#------------------------------------------------------------------------------
# CMake Modules
# Set the CMake module path
Expand Down Expand Up @@ -72,8 +73,16 @@ if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
set(CMAKE_BUILD_TYPE Debug CACHE STRING "Choose the type of build." FORCE)

# Set the possible values of build type for cmake-gui
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release"
"MinSizeRel" "RelWithDebInfo")
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "Coverage")
endif()

#------------------------------------------------------------------------------
# The PGI compiler can not find any cap routines in their library.
# This is due to how it labels subroutines within a modules.
# For example the subroutine b() in the moduel a(), gets named a_b.
# GCC and Intel do NOT do this, it is name simply as b.
if ("${CMAKE_Fortran_COMPILER_ID}" MATCHES "PGI")
message(STATUS "WARNING: PGI compiler is not fully ISO_C compliant; working solution involves a hack pgifix.py")
endif()

#------------------------------------------------------------------------------
Expand All @@ -82,7 +91,7 @@ option(BUILD_SHARED_LIBS "Build a shared library" ON)

#------------------------------------------------------------------------------
# Enable code coverage
if(CMAKE_COMPILER_IS_GNUCC AND (CMAKE_BUILD_TYPE STREQUAL "Coverage"))
if ("${CMAKE_Fortran_COMPILER_ID}" MATCHES "GNU" AND (CMAKE_BUILD_TYPE STREQUAL "Coverage"))
include(code_coverage)
list(APPEND LIBS "gcov")
endif()
Expand All @@ -102,8 +111,8 @@ add_subdirectory(schemes)

#------------------------------------------------------------------------------
# Configure and enable packaging
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Common Community Phyics Package")
set(CPACK_PACKAGE_VENDOR "DTC NCAR")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Common Community Physics Package - Framework")
set(CPACK_PACKAGE_VENDOR "GMTB NOAA/NCAR")
set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/README.md")
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE")
set(CPACK_PACKAGE_VERSION_MAJOR ${PROJECT_VERSION_MAJOR})
Expand All @@ -115,7 +124,5 @@ set(CPACK_SOURCE_PACKAGE_FILE_NAME
"${CMAKE_PROJECT_NAME}-${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}")
set(CPACK_SOURCE_GENERATOR "TBZ2")
set(CPACK_GENERATOR "TBZ2")
#set(CPACK_GENERATOR "DEB")
#set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Timothy Brown")

include(CPack)
4 changes: 0 additions & 4 deletions doc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,5 @@ if(BUILD_DOCUMENTATION)
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Generating API documentation with Doxygen"
VERBATIM)

# Define where to install the documentation
install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/html
DESTINATION share/doc/${PROJECT_NAME})
endif()

11 changes: 11 additions & 0 deletions examples/suite_FV3_test.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>

<suite name="FV3_test" lib="ccppphys" ver="1">
<init>FV3_test_init</init>
<group name="fast_physics">
<subcycle loop="1">
<scheme>FV3_test_run</scheme>
</subcycle>
</group>
<finalize>FV3_test_finalize</finalize>
</suite>
2 changes: 1 addition & 1 deletion examples/suite_scm_GFS_test.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>

<suite name="GFS_operational_2017" lib="ccppphys" ver="0.0.1">
<suite name="GFS_operational_2017" lib="ccppphys" ver="1.0.0">
<init>GFS_initialize_scm_run</init>
<group name="time_vary">
<subcycle loop="1">
Expand Down
7 changes: 7 additions & 0 deletions schemes/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# Set default project to unknown
if(NOT PROJECT)
message(STATUS "Setting CCPP project to 'unknown' as none was specified.")
set(PROJECT "Unknown")
endif (NOT PROJECT)

#------------------------------------------------------------------------------
# Add all the physics schemes in their own sub-directory (a.k.a repos)
#------------------------------------------------------------------------------
Expand All @@ -16,6 +22,7 @@ ExternalProject_Add(
INSTALL_COMMAND ""
CMAKE_ARGS -DCCPP_INCLUDE_DIRS=${CCPP_INCLUDE_DIRS}
-DCCPP_LIB_DIRS=${CCPP_LIB_DIRS}
-DPROJECT=${PROJECT}
-DCCPP_MKCAP=${CMAKE_CURRENT_SOURCE_DIR}/mkcap.py
-DCMAKE_Fortran_FLAGS=${CMAKE_Fortran_FLAGS}
-DCMAKE_SHARED_LIBRARY_CREATE_Fortran_FLAGS=${CMAKE_SHARED_LIBRARY_CREATE_Fortran_FLAGS}
Expand Down
36 changes: 27 additions & 9 deletions schemes/check/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
# Set default project to unknown
if(NOT PROJECT)
message(STATUS "Setting CCPP project to 'unknown' as none was specified.")
set(PROJECT "Unknown")
endif (NOT PROJECT)

# Use rpaths on MacOSX
set(CMAKE_MACOSX_RPATH 1)

message (INFO "CMAKE_CURRENT_SOURCE_DIR: ${CMAKE_CURRENT_SOURCE_DIR}")
message (INFO "CMAKE_CURRENT_BINARY_DIR: ${CMAKE_CURRENT_BINARY_DIR}")
#message (FATAL_ERROR "BLA")

#------------------------------------------------------------------------------
cmake_minimum_required(VERSION 2.8.11)

Expand Down Expand Up @@ -34,15 +44,23 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../cmake")
option(BUILD_SHARED_LIBS "Build a shared library" ON)

#------------------------------------------------------------------------------
# Add the CCPP include/module directory
set(CCPP_INCLUDE_DIRS "" CACHE FILEPATH "Path to ccpp includes")
set_property(DIRECTORY PROPERTY INCLUDE_DIRECTORIES ${CCPP_INCLUDE_DIRS})

#------------------------------------------------------------------------------
# Add the CCPP library
set(CCPP_LIB_DIRS "" CACHE FILEPATH "Path to ccpp library")
link_directories(${CCPP_LIB_DIRS})
list(APPEND LIBS "ccpp")
# Add the CCPP include/module directory and libraries, currently depends on build
# see FV3_current_trunk/ccpp/CMakeLists.txt on how to set CCPP_INCLUDE_DIRS etc.
if (PROJECT MATCHES "CCPP-FV3")
# Add the CCPP include/module directory
set(CCPP_INCLUDE_DIRS "" CACHE FILEPATH "Path to ccpp includes")
set_property(DIRECTORY PROPERTY INCLUDE_DIRECTORIES ${CCPP_INCLUDE_DIRS})
# Add the CCPP library
set(CCPP_LIB_DIRS "" CACHE FILEPATH "Path to ccpp library")
link_directories(${CCPP_LIB_DIRS})
list(APPEND LIBS "ccpp")
else (PROJECT MATCHES "CCPP-FV3")
# Add the CCPP include/module directory
INCLUDE_DIRECTORIES("${CMAKE_CURRENT_BINARY_DIR}/../../../../src")
# Add the CCPP library
LINK_DIRECTORIES("${CMAKE_CURRENT_BINARY_DIR}/../../../../src")
list(APPEND LIBS "ccpp")
endif (PROJECT MATCHES "CCPP-FV3")

#------------------------------------------------------------------------------
# Set the sources
Expand Down
34 changes: 23 additions & 11 deletions scripts/ccpp_prebuild.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
# Local modules
from common import encode_container, execute
from metadata_parser import merge_metadata_dicts, parse_scheme_tables, parse_variable_tables
from mkcap import Cap, CapsMakefile, SchemesMakefile
from mkcap import Cap, CapsMakefile, CapsCMakefile, SchemesMakefile, SchemesCMakefile
from mkdoc import metadata_to_html, metadata_to_latex

###############################################################################
# User definitions #
###############################################################################

# List of configured host models
HOST_MODELS = ["FV3", "SCM"]
HOST_MODELS = ["FV3v0", "FV3v1", "SCM"]

###############################################################################
# Set up the command line argument parser and other global variables #
Expand Down Expand Up @@ -60,9 +60,12 @@ def import_config(host_model):
# Definitions in host-model dependent CCPP prebuild config script
config['variable_definition_files'] = ccpp_prebuild_config.VARIABLE_DEFINITION_FILES
config['scheme_files'] = ccpp_prebuild_config.SCHEME_FILES
config['scheme_files_dependencies'] = ccpp_prebuild_config.SCHEME_FILES_DEPENDENCIES
config['schemes_makefile'] = ccpp_prebuild_config.SCHEMES_MAKEFILE
config['schemes_cmakefile'] = ccpp_prebuild_config.SCHEMES_CMAKEFILE
config['target_files'] = ccpp_prebuild_config.TARGET_FILES
config['caps_makefile'] = ccpp_prebuild_config.CAPS_MAKEFILE
config['caps_cmakefile'] = ccpp_prebuild_config.CAPS_CMAKEFILE
config['caps_dir'] = ccpp_prebuild_config.CAPS_DIR
config['optional_arguments'] = ccpp_prebuild_config.OPTIONAL_ARGUMENTS
config['module_include_file'] = ccpp_prebuild_config.MODULE_INCLUDE_FILE
Expand Down Expand Up @@ -327,11 +330,13 @@ def generate_scheme_caps(metadata, arguments, caps_dir, module_use_template_sche
os.chdir(BASEDIR)
return (success, scheme_caps)

def generate_schemes_makefile(schemes, schemes_makefile):
logging.info('Generating schemes makefile snippet ...')
def generate_schemes_makefile(schemes, schemes_makefile, schemes_cmakefile):
logging.info('Generating schemes makefile/cmakefile snippet ...')
success = True
makefile = SchemesMakefile()
makefile.filename = schemes_makefile
cmakefile = SchemesCMakefile()
cmakefile.filename = schemes_cmakefile
# Adjust relative file path to schemes from caps makefile
schemes_with_path = []
schemes_makefile_dir = os.path.split(os.path.abspath(schemes_makefile))[0]
Expand All @@ -340,20 +345,26 @@ def generate_schemes_makefile(schemes, schemes_makefile):
relative_path = './{0}'.format(os.path.relpath(scheme_filepath, schemes_makefile_dir))
schemes_with_path.append(os.path.join(relative_path, scheme_filename))
makefile.write(schemes_with_path)
logging.info('Added {0} schemes to makefile {1}'.format(len(schemes_with_path), makefile.filename))
cmakefile.write(schemes_with_path)
logging.info('Added {0} schemes to makefile/cmakefile {1}/{2}'.format(
len(schemes_with_path), makefile.filename, cmakefile.filename))
return success

def generate_caps_makefile(caps, caps_makefile, caps_dir):
logging.info('Generating caps makefile snippet ...')
def generate_caps_makefile(caps, caps_makefile, caps_cmakefile, caps_dir):
logging.info('Generating caps makefile/cmakefile snippet ...')
success = True
makefile = CapsMakefile()
makefile.filename = caps_makefile
cmakefile = CapsCMakefile()
cmakefile.filename = caps_cmakefile
# Adjust relative file path to schemes from caps makefile
caps_makefile_dir = os.path.split(os.path.abspath(caps_makefile))[0]
relative_path = './{0}'.format(os.path.relpath(caps_dir, caps_makefile_dir))
caps_with_path = [ os.path.join(relative_path, cap) for cap in caps]
makefile.write(caps_with_path)
logging.info('Added {0} auto-generated caps to makefile {1}'.format(len(caps_with_path), makefile.filename))
cmakefile.write(caps_with_path)
logging.info('Added {0} auto-generated caps to makefile/cmakefile {1}/{2}'.format(
len(caps_with_path), makefile.filename, cmakefile.filename))
return success

def main():
Expand Down Expand Up @@ -423,13 +434,14 @@ def main():
if not success:
raise Exception('Call to generate_scheme_caps failed.')

# Add filenames of schemes to makefile
success = generate_schemes_makefile(config['scheme_files'], config['schemes_makefile'])
# Add filenames of schemes to makefile - add dependencies for schemes
success = generate_schemes_makefile(config['scheme_files_dependencies'] + config['scheme_files'],
config['schemes_makefile'], config['schemes_cmakefile'])
if not success:
raise Exception('Call to generate_schemes_makefile failed.')

# Add filenames of scheme caps to makefile
success = generate_caps_makefile(scheme_caps, config['caps_makefile'], config['caps_dir'])
success = generate_caps_makefile(scheme_caps, config['caps_makefile'], config['caps_cmakefile'], config['caps_dir'])
if not success:
raise Exception('Call to generate_caps_makefile failed.')

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python

# CCPP prebuild config for GFDL Finite-Volume Cubed-Sphere Model (FV3) v0.0
# CCPP prebuild config for GFDL Finite-Volume Cubed-Sphere Model (FV3) v0


###############################################################################
Expand All @@ -14,6 +14,11 @@
'FV3/gfsphysics/physics/physcons.f90',
]

# Can be empty, since all physics schemes and their
# dependencies are hardcoded in the makefile in
# FV3/gfsphysics - will be fixed in FV3 v1
SCHEME_FILES_DEPENDENCIES = []

# Add all physics scheme files relative to basedir
SCHEME_FILES = [
'FV3/gfsphysics/physics/GFS_DCNV_generic.f90',
Expand All @@ -22,7 +27,7 @@
'FV3/gfsphysics/physics/GFS_PBL_generic.f90',
'FV3/gfsphysics/physics/GFS_SCNV_generic.f90',
'FV3/gfsphysics/physics/GFS_calpreciptype.f90',
'FV3/gfsphysics/physics/GFS_debug.f90',
'FV3/gfsphysics/physics/GFS_debug.F90',
'FV3/gfsphysics/physics/GFS_rrtmg_post.F90',
'FV3/gfsphysics/physics/GFS_rrtmg_pre.F90',
'FV3/gfsphysics/physics/GFS_stochastics.f90',
Expand Down Expand Up @@ -55,17 +60,19 @@
'FV3/gfsphysics/physics/sfc_sice.f',
]

# Auto-generated makefile snippet that contains all schemes
# Auto-generated makefile/cmakefile snippets that contain all schemes
SCHEMES_MAKEFILE = 'FV3/gfsphysics/CCPP_SCHEMES.mk'
SCHEMES_CMAKEFILE = 'FV3/gfsphysics/CCPP_SCHEMES.cmake'

# CCPP host cap in which to insert the ccpp_field_add statements;
# determines the directory to place ccpp_{modules,fields}.inc
TARGET_FILES = [
'FV3/gfsphysics/IPD_layer/IPD_CCPP_Driver.F90',
]

# Auto-generated makefile snippet that contains all caps
# Auto-generated makefile/cmakefile snippets that contain all caps
CAPS_MAKEFILE = 'FV3/gfsphysics/CCPP_CAPS.mk'
CAPS_CMAKEFILE = 'FV3/gfsphysics/CCPP_CAPS.cmake'

# Directory where to put all auto-generated physics caps
CAPS_DIR = 'FV3/gfsphysics/physics'
Expand Down
Loading

0 comments on commit 527d96f

Please sign in to comment.