From 3fa6b4cd51d584b27526e64071d118a46d181a2f Mon Sep 17 00:00:00 2001 From: Dom Heinzeller Date: Mon, 19 Jul 2021 12:02:37 -0600 Subject: [PATCH 01/11] Detect missing scheme requested by suite in physics library --- scripts/ccpp_prebuild.py | 18 ++++++++++++++++++ scripts/mkstatic.py | 7 +++++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/scripts/ccpp_prebuild.py b/scripts/ccpp_prebuild.py index c1fea0a0..59d61d0f 100755 --- a/scripts/ccpp_prebuild.py +++ b/scripts/ccpp_prebuild.py @@ -326,6 +326,19 @@ def collect_physics_subroutines(scheme_files): os.chdir(BASEDIR) return (success, metadata_request, arguments_request, dependencies_request, schemes_in_files) +def check_schemes_in_suites(arguments, suites): + """Check that all schemes that are requested in the suites exist""" + success = True + logging.info("Checking for existence of schemes in suites ...") + for suite in suites: + for group in suite.groups: + for subcycle in group.subcycles: + for scheme_name in subcycle.schemes: + if not scheme_name in arguments.keys(): + success = False + logging.critical("Scheme {} in suite {} cannot be found".format(scheme_name, suite.name)) + return success + def filter_metadata(metadata, arguments, dependencies, schemes_in_files, suites): """Remove all variables from metadata that are not used in the given suite; also remove information on argument lists, dependencies and schemes in files""" @@ -782,6 +795,11 @@ def main(): if not success: raise Exception('Call to collect_physics_subroutines failed.') + # Check that the schemes requested in the suites exist + success = check_schemes_in_suites(arguments_request, suites) + if not success: + raise Exception('Call to check_schemes_in_suites failed.') + # Filter metadata/arguments - remove whatever is not included in suite definition files (success, metadata_request, arguments_request, dependencies_request, schemes_in_files) = filter_metadata( metadata_request, arguments_request, dependencies_request, schemes_in_files, suites) diff --git a/scripts/mkstatic.py b/scripts/mkstatic.py index 5064bb50..65010d8a 100755 --- a/scripts/mkstatic.py +++ b/scripts/mkstatic.py @@ -899,7 +899,10 @@ def write(self, metadata_request, metadata_define, arguments): standard_name_by_local_name_define[metadata_define[standard_name][0].local_name] = standard_name # First get target names of standard CCPP variables for subcycling and error handling - ccpp_loop_counter_target_name = metadata_request[CCPP_LOOP_COUNTER][0].target + if CCPP_LOOP_COUNTER in metadata_request.keys(): + ccpp_loop_counter_target_name = metadata_request[CCPP_LOOP_COUNTER][0].target + else: + ccpp_loop_counter_target_name = None if CCPP_LOOP_EXTENT in metadata_request.keys(): ccpp_loop_extent_target_name = metadata_request[CCPP_LOOP_EXTENT][0].target else: @@ -1385,7 +1388,7 @@ def write(self, metadata_request, metadata_define, arguments): end do end associate ''' - else: + elif ccpp_loop_counter_target_name: subcycle_body_prefix += ''' {loop_var_name} = 1\n'''.format(loop_var_name=ccpp_loop_counter_target_name) From d8d98a27bde7a6b04060015ca2d05f989089f0e1 Mon Sep 17 00:00:00 2001 From: Dom Heinzeller Date: Thu, 2 Sep 2021 10:17:37 -0600 Subject: [PATCH 02/11] Update scripts/ccpp_prebuild.py and scripts/mkstatic.py to create shell and cmake include files for the static API --- scripts/ccpp_prebuild.py | 21 +++++++++++++-------- scripts/mkstatic.py | 22 +++++++++++++++++++--- 2 files changed, 32 insertions(+), 11 deletions(-) diff --git a/scripts/ccpp_prebuild.py b/scripts/ccpp_prebuild.py index 59d61d0f..af7d69a7 100755 --- a/scripts/ccpp_prebuild.py +++ b/scripts/ccpp_prebuild.py @@ -93,14 +93,15 @@ def import_config(configfile, builddir): config['caps_cmakefile'] = ccpp_prebuild_config.CAPS_CMAKEFILE.format(build_dir=builddir) config['caps_sourcefile'] = ccpp_prebuild_config.CAPS_SOURCEFILE.format(build_dir=builddir) config['caps_dir'] = ccpp_prebuild_config.CAPS_DIR.format(build_dir=builddir) - config['suites_dir'] = ccpp_prebuild_config.SUITES_DIR + config['suites_dir'] = ccpp_prebuild_config.SUITES_DIR.format(build_dir=builddir) config['optional_arguments'] = ccpp_prebuild_config.OPTIONAL_ARGUMENTS config['host_model'] = ccpp_prebuild_config.HOST_MODEL_IDENTIFIER config['html_vartable_file'] = ccpp_prebuild_config.HTML_VARTABLE_FILE.format(build_dir=builddir) config['latex_vartable_file'] = ccpp_prebuild_config.LATEX_VARTABLE_FILE.format(build_dir=builddir) - # Location of static API file, and shell script to source + # Location of static API file, shell script to source, cmake include file config['static_api_dir'] = ccpp_prebuild_config.STATIC_API_DIR.format(build_dir=builddir) - config['static_api_srcfile'] = ccpp_prebuild_config.STATIC_API_SRCFILE.format(build_dir=builddir) + config['static_api_sourcefile'] = ccpp_prebuild_config.STATIC_API_SOURCEFILE.format(build_dir=builddir) + config['static_api_cmakefile'] = ccpp_prebuild_config.STATIC_API_CMAKEFILE.format(build_dir=builddir) # Add model-independent, CCPP-internal variable definition files config['variable_definition_files'].append(CCPP_INTERNAL_VARIABLE_DEFINITON_FILE) @@ -148,7 +149,7 @@ def clean_files(config): config['latex_vartable_file'], os.path.join(config['caps_dir'], 'ccpp_*_cap.F90'), os.path.join(config['static_api_dir'], '{api}.F90'.format(api=CCPP_STATIC_API_MODULE)), - config['static_api_srcfile'], + config['static_api_sourcefile'], ] # Not very pythonic, but the easiest way w/o importing another Python module cmd = 'rm -vf {0}'.format(' '.join(files_to_remove)) @@ -847,12 +848,16 @@ def main(): raise Exception('Call to generate_suite_and_group_caps failed.') (success, api) = generate_static_api(suites, config['static_api_dir']) - if not success: + if not success: raise Exception('Call to generate_static_api failed.') - success = api.write_sourcefile(config['static_api_srcfile']) - if not success: - raise Exception("Writing API sourcefile {sourcefile} failed".format(sourcefile=config['static_api_srcfile'])) + success = api.write_includefile(config['static_api_sourcefile'], type='shell') + if not success: + raise Exception("Writing API sourcefile {sourcefile} failed".format(sourcefile=config['static_api_sourcefile'])) + + success = api.write_includefile(config['static_api_cmakefile'], type='cmake') + if not success: + raise Exception("Writing API cmakefile {cmakefile} failed".format(cmakefile=config['static_api_cmakefile'])) # Add filenames of caps to makefile/cmakefile/shell script all_caps = suite_and_group_caps diff --git a/scripts/mkstatic.py b/scripts/mkstatic.py index 65010d8a..16eae36d 100755 --- a/scripts/mkstatic.py +++ b/scripts/mkstatic.py @@ -406,7 +406,7 @@ def write(self): self.update_api = True return - def write_sourcefile(self, source_filename): + def write_includefile(self, source_filename, type): success = True filepath = os.path.split(source_filename)[0] if filepath and not os.path.isdir(filepath): @@ -422,14 +422,30 @@ def write_sourcefile(self, source_filename): else: write_to_test_file = False f = open(source_filename, 'w') - # Contents of shell/source file - contents = """# The CCPP static API is defined here. + + if type == 'shell': + # Contents of shell/source file + contents = """# The CCPP static API is defined here. # # This file is auto-generated using ccpp_prebuild.py # at compile time, do not edit manually. # export CCPP_STATIC_API=\"{filename}\" """.format(filename=os.path.abspath(os.path.join(self.directory,self.filename))) + elif type == 'cmake': + # Contents of cmake include file + contents = """# The CCPP static API is defined here. +# +# This file is auto-generated using ccpp_prebuild.py +# at compile time, do not edit manually. +# +set(API \"{filename}\") +""".format(filename=os.path.abspath(os.path.join(self.directory,self.filename))) + else: + logging.error('Encountereed unknown type of file "{type}" when writing include file for static API'.format(type=type)) + success = False + return + f.write(contents) f.close() # See comment above on updating the API or not From 2adecf3ad93ebcdd39f6d16cc8dceba6931be761 Mon Sep 17 00:00:00 2001 From: Dom Heinzeller Date: Thu, 2 Sep 2021 10:17:50 -0600 Subject: [PATCH 03/11] Add CCPP stub --- stub/CMakeLists.txt | 362 +++++++++++++++++++++++++++++++++++ stub/ccpp_prebuild_config.py | 77 ++++++++ stub/data.F90 | 17 ++ stub/data.meta | 14 ++ stub/stub.F90 | 35 ++++ stub/stub.meta | 48 +++++ stub/suite_stub.xml | 9 + 7 files changed, 562 insertions(+) create mode 100644 stub/CMakeLists.txt create mode 100755 stub/ccpp_prebuild_config.py create mode 100644 stub/data.F90 create mode 100644 stub/data.meta create mode 100644 stub/stub.F90 create mode 100644 stub/stub.meta create mode 100644 stub/suite_stub.xml diff --git a/stub/CMakeLists.txt b/stub/CMakeLists.txt new file mode 100644 index 00000000..5b4dd8ea --- /dev/null +++ b/stub/CMakeLists.txt @@ -0,0 +1,362 @@ +#------------------------------------------------------------------------------ +cmake_minimum_required(VERSION 3.0) + +project(ccppstub + VERSION 1.0.0 + LANGUAGES Fortran) +# +# # Use rpaths on MacOSX +# set(CMAKE_MACOSX_RPATH 1) +# if(POLICY CMP0042) +# cmake_policy(SET CMP0042 NEW) +# endif(POLICY CMP0042) +# +# # CMP0057: Support new IN_LIST if() operator +# if(POLICY CMP0057) +# cmake_policy(SET CMP0057 NEW) +# endif(POLICY CMP0057) + +##------------------------------------------------------------------------------ +#set(PACKAGE "ccpp-physics") +#set(AUTHORS "Grant Firl" "Dom Heinzeller" "Man Zhang" "Laurie Carson") +# +##------------------------------------------------------------------------------ +## Set OpenMP flags for C/C++/Fortran +#if (OPENMP) +# include(detect_openmp) +# detect_openmp() +# #set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}") +# #set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}") +# #set (CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} ${OpenMP_Fortran_FLAGS}") +# message(STATUS "Enable OpenMP support for C/C++/Fortran compiler") +#else (OPENMP) +# message (STATUS "Disable OpenMP support for C/C++/Fortran compiler") +#endif() + +##------------------------------------------------------------------------------ +## The Fortran compiler/linker flag inserted by cmake to create shared libraries +## with the Intel compiler is deprecated (-i_dynamic), correct here. +## CMAKE_Fortran_COMPILER_ID = {"Intel", "PGI", "GNU", "Clang", "MSVC", ...} +#if ("${CMAKE_Fortran_COMPILER_ID}" STREQUAL "Intel") +# string(REPLACE "-i_dynamic" "-shared-intel" +# CMAKE_SHARED_LIBRARY_CREATE_Fortran_FLAGS +# "${CMAKE_SHARED_LIBRARY_CREATE_Fortran_FLAGS}") +# string(REPLACE "-i_dynamic" "-shared-intel" +# CMAKE_SHARED_LIBRARY_LINK_Fortran_FLAGS +# "${CMAKE_SHARED_LIBRARY_LINK_Fortran_FLAGS}") +#endif() +# +##------------------------------------------------------------------------------ +## Set a default build type if none was specified +#if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) +# message(STATUS "Setting build type to 'Release' as none was specified.") +# set(CMAKE_BUILD_TYPE Release 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" "Bitforbit" "Release" "Coverage") +#endif() + +#------------------------------------------------------------------------------ +# Request a static build +option(BUILD_SHARED_LIBS "Build a shared library" OFF) + +#------------------------------------------------------------------------------ +# Set the sources: physics type definitions +set(TYPEDEFS $ENV{CCPP_TYPEDEFS}) +if(TYPEDEFS) + message(STATUS "Got CCPP TYPEDEFS from environment variable: ${TYPEDEFS}") +else(TYPEDEFS) + include(${CMAKE_CURRENT_SOURCE_DIR}/CCPP_TYPEDEFS.cmake) + message(STATUS "Got CCPP TYPEDEFS from cmakefile include file: ${TYPEDEFS}") +endif(TYPEDEFS) + +# Generate list of Fortran modules from the CCPP type +# definitions that need need to be installed +foreach(typedef_module ${TYPEDEFS}) + list(APPEND MODULES_F90 ${CMAKE_CURRENT_BINARY_DIR}/${typedef_module}) +endforeach() + +#------------------------------------------------------------------------------ +# Set the sources: physics schemes +set(SCHEMES $ENV{CCPP_SCHEMES}) +if(SCHEMES) + message(STATUS "Got CCPP SCHEMES from environment variable: ${SCHEMES}") +else(SCHEMES) + include(${CMAKE_CURRENT_SOURCE_DIR}/CCPP_SCHEMES.cmake) + message(STATUS "Got CCPP SCHEMES from cmakefile include file: ${SCHEMES}") +endif(SCHEMES) + +# Set the sources: physics scheme caps +set(CAPS $ENV{CCPP_CAPS}) +if(CAPS) + message(STATUS "Got CCPP CAPS from environment variable: ${CAPS}") +else(CAPS) + include(${CMAKE_CURRENT_SOURCE_DIR}/CCPP_CAPS.cmake) + message(STATUS "Got CCPP CAPS from cmakefile include file: ${CAPS}") +endif(CAPS) + +# Set the sources: physics scheme caps +set(API $ENV{CCPP_API}) +if(API) + message(STATUS "Got CCPP API from environment variable: ${API}") +else(API) + include(${CMAKE_CURRENT_SOURCE_DIR}/CCPP_API.cmake) + message(STATUS "Got CCPP API from cmakefile include file: ${API}") +endif(API) + +### # Schemes and caps from the CCPP code generator use full paths with symlinks +### # resolved, we need to do the same here for the below logic to work +### get_filename_component(FULL_PATH_TO_CMAKELISTS CMakeLists.txt REALPATH BASE_DIR ${LOCAL_CURRENT_SOURCE_DIR}) +### get_filename_component(LOCAL_CURRENT_SOURCE_DIR ${FULL_PATH_TO_CMAKELISTS} DIRECTORY) +### +### # List of files that need to be compiled without OpenMP +### set(SCHEMES_OPENMP_OFF ${LOCAL_CURRENT_SOURCE_DIR}/physics/rte-rrtmgp/rrtmgp/mo_gas_optics.F90 +### ${LOCAL_CURRENT_SOURCE_DIR}/physics/rte-rrtmgp/rrtmgp/mo_rrtmgp_constants.F90 +### ${LOCAL_CURRENT_SOURCE_DIR}/physics/rte-rrtmgp/rrtmgp/mo_rrtmgp_util_reorder.F90 +### ${LOCAL_CURRENT_SOURCE_DIR}/physics/rte-rrtmgp/rrtmgp/mo_gas_concentrations.F90 +### ${LOCAL_CURRENT_SOURCE_DIR}/physics/rte-rrtmgp/rrtmgp/kernels-openacc/mo_gas_optics_kernels.F90 +### ${LOCAL_CURRENT_SOURCE_DIR}/physics/rte-rrtmgp/rrtmgp/mo_rrtmgp_util_string.F90 +### ${LOCAL_CURRENT_SOURCE_DIR}/physics/rte-rrtmgp/rrtmgp/kernels/mo_gas_optics_kernels.F90 +### ${LOCAL_CURRENT_SOURCE_DIR}/physics/rte-rrtmgp/rrtmgp/kernels/mo_rrtmgp_util_reorder_kernels.F90 +### ${LOCAL_CURRENT_SOURCE_DIR}/physics/rte-rrtmgp/rrtmgp/mo_gas_optics_rrtmgp.F90 +### ${LOCAL_CURRENT_SOURCE_DIR}/physics/rte-rrtmgp/tests/mo_testing_io.F90 +### ${LOCAL_CURRENT_SOURCE_DIR}/physics/rte-rrtmgp/tests/clear_sky_regression.F90 +### ${LOCAL_CURRENT_SOURCE_DIR}/physics/rte-rrtmgp/extensions/mo_rrtmgp_clr_all_sky.F90 +### ${LOCAL_CURRENT_SOURCE_DIR}/physics/rte-rrtmgp/extensions/mo_fluxes_byband_kernels.F90 +### ${LOCAL_CURRENT_SOURCE_DIR}/physics/rte-rrtmgp/extensions/mo_fluxes_byband.F90 +### ${LOCAL_CURRENT_SOURCE_DIR}/physics/rte-rrtmgp/extensions/solar_variability/mo_solar_variability.F90 +### ${LOCAL_CURRENT_SOURCE_DIR}/physics/rte-rrtmgp/extensions/mo_heating_rates.F90 +### ${LOCAL_CURRENT_SOURCE_DIR}/physics/rte-rrtmgp/extensions/mo_fluxes_bygpoint.F90 +### ${LOCAL_CURRENT_SOURCE_DIR}/physics/rte-rrtmgp/extensions/mo_compute_bc.F90 +### ${LOCAL_CURRENT_SOURCE_DIR}/physics/rte-rrtmgp/extensions/cloud_optics/mo_cloud_sampling.F90 +### ${LOCAL_CURRENT_SOURCE_DIR}/physics/rte-rrtmgp/extensions/cloud_optics/mo_cloud_optics.F90 +### ${LOCAL_CURRENT_SOURCE_DIR}/physics/rte-rrtmgp/examples/mo_load_coefficients.F90 +### ${LOCAL_CURRENT_SOURCE_DIR}/physics/rte-rrtmgp/examples/rfmip-clear-sky/rrtmgp_rfmip_sw.F90 +### ${LOCAL_CURRENT_SOURCE_DIR}/physics/rte-rrtmgp/examples/rfmip-clear-sky/mo_rfmip_io.F90 +### ${LOCAL_CURRENT_SOURCE_DIR}/physics/rte-rrtmgp/examples/rfmip-clear-sky/rrtmgp_rfmip_lw.F90 +### ${LOCAL_CURRENT_SOURCE_DIR}/physics/rte-rrtmgp/examples/mo_simple_netcdf.F90 +### ${LOCAL_CURRENT_SOURCE_DIR}/physics/rte-rrtmgp/examples/all-sky/rrtmgp_allsky.F90 +### ${LOCAL_CURRENT_SOURCE_DIR}/physics/rte-rrtmgp/examples/all-sky/mo_load_cloud_coefficients.F90 +### ${LOCAL_CURRENT_SOURCE_DIR}/physics/rte-rrtmgp/examples/all-sky/mo_garand_atmos_io.F90 +### ${LOCAL_CURRENT_SOURCE_DIR}/physics/rte-rrtmgp/rte/mo_rte_config.F90 +### ${LOCAL_CURRENT_SOURCE_DIR}/physics/rte-rrtmgp/rte/mo_source_functions.F90 +### ${LOCAL_CURRENT_SOURCE_DIR}/physics/rte-rrtmgp/rte/mo_rte_sw.F90 +### ${LOCAL_CURRENT_SOURCE_DIR}/physics/rte-rrtmgp/rte/mo_fluxes.F90 +### ${LOCAL_CURRENT_SOURCE_DIR}/physics/rte-rrtmgp/rte/mo_rte_lw.F90 +### ${LOCAL_CURRENT_SOURCE_DIR}/physics/rte-rrtmgp/rte/kernels-openacc/mo_rte_solver_kernels.F90 +### ${LOCAL_CURRENT_SOURCE_DIR}/physics/rte-rrtmgp/rte/kernels-openacc/mo_optical_props_kernels.F90 +### ${LOCAL_CURRENT_SOURCE_DIR}/physics/rte-rrtmgp/rte/mo_rte_util_array.F90 +### ${LOCAL_CURRENT_SOURCE_DIR}/physics/rte-rrtmgp/rte/kernels/mo_rte_solver_kernels.F90 +### ${LOCAL_CURRENT_SOURCE_DIR}/physics/rte-rrtmgp/rte/kernels/mo_optical_props_kernels.F90 +### ${LOCAL_CURRENT_SOURCE_DIR}/physics/rte-rrtmgp/rte/kernels/mo_fluxes_broadband_kernels.F90 +### ${LOCAL_CURRENT_SOURCE_DIR}/physics/rte-rrtmgp/rte/mo_rte_kind.F90 +### ${LOCAL_CURRENT_SOURCE_DIR}/physics/rte-rrtmgp/rte/mo_optical_props.F90) +### +### #------------------------------------------------------------------------------ +### if (${CMAKE_Fortran_COMPILER_ID} STREQUAL "GNU") +### +### set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -ffree-line-length-none") +### +### SET_SOURCE_FILES_PROPERTIES(${LOCAL_CURRENT_SOURCE_DIR}/physics/module_bfmicrophysics.f +### ${LOCAL_CURRENT_SOURCE_DIR}/physics/sflx.f +### ${LOCAL_CURRENT_SOURCE_DIR}/physics/sfc_diff.f +### ${LOCAL_CURRENT_SOURCE_DIR}/physics/sfc_diag.f +### ${LOCAL_CURRENT_SOURCE_DIR}/physics/module_nst_model.f90 +### ${LOCAL_CURRENT_SOURCE_DIR}/physics/calpreciptype.f90 +### ${LOCAL_CURRENT_SOURCE_DIR}/physics/mersenne_twister.f +### ${LOCAL_CURRENT_SOURCE_DIR}/physics/module_nst_water_prop.f90 +### ${LOCAL_CURRENT_SOURCE_DIR}/physics/aer_cloud.F +### ${LOCAL_CURRENT_SOURCE_DIR}/physics/wv_saturation.F +### ${LOCAL_CURRENT_SOURCE_DIR}/physics/cldwat2m_micro.F +### ${LOCAL_CURRENT_SOURCE_DIR}/physics/surface_perturbation.F90 +### ${LOCAL_CURRENT_SOURCE_DIR}/physics/module_mp_thompson_make_number_concentrations.F90 +### ${LOCAL_CURRENT_SOURCE_DIR}/physics/module_SF_JSFC.F90 +### ${LOCAL_CURRENT_SOURCE_DIR}/physics/module_BL_MYJPBL.F90 +### PROPERTIES COMPILE_FLAGS "-fdefault-real-8 -fdefault-double-8 ${OpenMP_Fortran_FLAGS}") +### +### if (PROJECT STREQUAL "CCPP-FV3") +### # Set 32-bit floating point precision flags for certain files +### # that are executed in the dynamics (fast physics part) +### if (DYN32) +### if (${LOCAL_CURRENT_SOURCE_DIR}/physics/gfdl_fv_sat_adj.F90 IN_LIST SCHEMES) +### # Reduce floating point precision from 64-bit to 32-bit, if necessary +### set(CMAKE_Fortran_FLAGS_PREC32 ${CMAKE_Fortran_FLAGS_DEFAULT_PREC}) +### string(REPLACE "-fdefault-real-8" "" +### CMAKE_Fortran_FLAGS_PREC32 "${CMAKE_Fortran_FLAGS_PREC32}") +### string(REPLACE "-fdefault-double-8" "" +### CMAKE_Fortran_FLAGS_PREC32 "${CMAKE_Fortran_FLAGS_PREC32}") +### SET_PROPERTY(SOURCE ${LOCAL_CURRENT_SOURCE_DIR}/physics/gfdl_fv_sat_adj.F90 +### APPEND_STRING PROPERTY COMPILE_FLAGS " ${CMAKE_Fortran_FLAGS_PREC32} ${OpenMP_Fortran_FLAGS} ") +### # Add all of the above files to the list of schemes with special floating point precision flags +### list(APPEND SCHEMES_SFX_PREC ${LOCAL_CURRENT_SOURCE_DIR}/physics/gfdl_fv_sat_adj.F90) +### endif() +### endif() +### +### # Remove files with special floating point precision flags from list +### # of files with standard floating point precision flags +### if (SCHEMES_SFX_PREC) +### list(REMOVE_ITEM SCHEMES2 ${SCHEMES_SFX_PREC}) +### endif () +### +### if (PROJECT STREQUAL "CCPP-FV3") +### # Remove files that need to be compiled without OpenMP from list +### # of files with standard compiler flags, and assign no-OpenMP flags +### if (SCHEMES_OPENMP_OFF) +### list(REMOVE_ITEM SCHEMES2 ${SCHEMES_OPENMP_OFF}) +### endif () +### # Assign standard floating point precision flags to all remaining schemes and caps +### SET_PROPERTY(SOURCE ${SCHEMES_OPENMP_OFF} +### APPEND_STRING PROPERTY COMPILE_FLAGS " ${CMAKE_Fortran_FLAGS_DEFAULT_PREC} ") +### endif() +### +### # Assign standard floating point precision flags to all remaining schemes and caps +### SET_PROPERTY(SOURCE ${SCHEMES2} ${CAPS} +### APPEND_STRING PROPERTY COMPILE_FLAGS " ${CMAKE_Fortran_FLAGS_DEFAULT_PREC} ${OpenMP_Fortran_FLAGS} ") +### +### endif (PROJECT STREQUAL "CCPP-FV3") +### +### elseif (${CMAKE_Fortran_COMPILER_ID} STREQUAL "Intel") +### # Adjust settings for bit-for-bit reproducibility of NEMSfv3gfs +### if (PROJECT STREQUAL "CCPP-FV3") +### +### if (${LOCAL_CURRENT_SOURCE_DIR}/physics/module_sf_mynn.F90 IN_LIST SCHEMES) +### # Reduce optimization for module_sf_mynn.F90 (to avoid an apparent compiler bug with Intel 18 on Hera) +### SET_SOURCE_FILES_PROPERTIES(${LOCAL_CURRENT_SOURCE_DIR}/physics/module_sf_mynn.F90 +### PROPERTIES COMPILE_FLAGS "${CMAKE_Fortran_FLAGS_OPT} -O1") +### list(APPEND SCHEMES_SFX_OPT ${LOCAL_CURRENT_SOURCE_DIR}/physics/module_sf_mynn.F90) +### endif() +### +### if (${LOCAL_CURRENT_SOURCE_DIR}/physics/radiation_aerosols.f IN_LIST SCHEMES) +### # Replace -xHost or -xCORE-AVX2 with -xCORE-AVX-I for certain files +### set(CMAKE_Fortran_FLAGS_LOPT1 ${CMAKE_Fortran_FLAGS_OPT}) +### string(REPLACE "-xHOST" "-xCORE-AVX-I" +### CMAKE_Fortran_FLAGS_LOPT1 +### "${CMAKE_Fortran_FLAGS_LOPT1}") +### string(REPLACE "-xCORE-AVX2" "-xCORE-AVX-I" +### CMAKE_Fortran_FLAGS_LOPT1 +### "${CMAKE_Fortran_FLAGS_LOPT1}") +### string(REPLACE "-axSSE4.2,CORE-AVX2" "-axSSE4.2,CORE-AVX-I" +### CMAKE_Fortran_FLAGS_LOPT1 +### "${CMAKE_Fortran_FLAGS_LOPT1}") +### SET_SOURCE_FILES_PROPERTIES(${LOCAL_CURRENT_SOURCE_DIR}/physics/radiation_aerosols.f +### PROPERTIES COMPILE_FLAGS "${CMAKE_Fortran_FLAGS_LOPT1}") +### # Add all of the above files to the list of schemes with special compiler flags +### list(APPEND SCHEMES_SFX_OPT ${LOCAL_CURRENT_SOURCE_DIR}/physics/radiation_aerosols.f) +### endif() +### +### # Remove files with special compiler flags from list of files with standard compiler flags +### if (SCHEMES_SFX_OPT) +### list(REMOVE_ITEM SCHEMES ${SCHEMES_SFX_OPT}) +### endif(SCHEMES_SFX_OPT) +### # Assign standard compiler flags to all remaining schemes and caps +### SET_SOURCE_FILES_PROPERTIES(${SCHEMES} ${CAPS} +### PROPERTIES COMPILE_FLAGS "${CMAKE_Fortran_FLAGS_OPT}") +### +### # Set 32-bit floating point precision flags for certain files +### # that are executed in the dynamics (fast physics part) +### if (DYN32) +### if (${LOCAL_CURRENT_SOURCE_DIR}/physics/gfdl_fv_sat_adj.F90 IN_LIST SCHEMES) +### # Reduce floating point precision from 64-bit to 32-bit, if necessary +### set(CMAKE_Fortran_FLAGS_PREC32 ${CMAKE_Fortran_FLAGS_DEFAULT_PREC}) +### string(REPLACE "-real-size 64" "-real-size 32" +### CMAKE_Fortran_FLAGS_PREC32 "${CMAKE_Fortran_FLAGS_PREC32}") +### SET_PROPERTY(SOURCE ${LOCAL_CURRENT_SOURCE_DIR}/physics/gfdl_fv_sat_adj.F90 +### APPEND_STRING PROPERTY COMPILE_FLAGS " ${CMAKE_Fortran_FLAGS_PREC32} ${OpenMP_Fortran_FLAGS} ") +### # Add all of the above files to the list of schemes with special floating point precision flags +### list(APPEND SCHEMES_SFX_PREC ${LOCAL_CURRENT_SOURCE_DIR}/physics/gfdl_fv_sat_adj.F90) +### endif() +### endif() +### +### # Remove files with special floating point precision flags from list +### # of files with standard floating point precision flags flags +### if (SCHEMES_SFX_PREC) +### list(REMOVE_ITEM SCHEMES2 ${SCHEMES_SFX_PREC}) +### endif (SCHEMES_SFX_PREC) +### +### # Remove files that need to be compiled without OpenMP from list +### # of files with standard compiler flags, and assign no-OpenMP flags +### if (SCHEMES_OPENMP_OFF) +### list(REMOVE_ITEM SCHEMES2 ${SCHEMES_OPENMP_OFF}) +### # Assign standard floating point precision flags to all remaining schemes and caps +### SET_PROPERTY(SOURCE ${SCHEMES_OPENMP_OFF} +### APPEND_STRING PROPERTY COMPILE_FLAGS " ${CMAKE_Fortran_FLAGS_DEFAULT_PREC} ") +### endif () +### +### # Assign standard floating point precision flags to all remaining schemes and caps +### SET_PROPERTY(SOURCE ${SCHEMES2} ${CAPS} +### APPEND_STRING PROPERTY COMPILE_FLAGS " ${CMAKE_Fortran_FLAGS_DEFAULT_PREC} ${OpenMP_Fortran_FLAGS} ") +### +### else (PROJECT STREQUAL "CCPP-FV3") +### SET_SOURCE_FILES_PROPERTIES(${LOCAL_CURRENT_SOURCE_DIR}/physics/module_bfmicrophysics.f +### ${LOCAL_CURRENT_SOURCE_DIR}/physics/sflx.f +### ${LOCAL_CURRENT_SOURCE_DIR}/physics/sfc_diff.f +### ${LOCAL_CURRENT_SOURCE_DIR}/physics/sfc_diag.f +### PROPERTIES COMPILE_FLAGS "-r8 ${OpenMP_Fortran_FLAGS} ") +### SET_SOURCE_FILES_PROPERTIES(${LOCAL_CURRENT_SOURCE_DIR}/physics/module_nst_model.f90 +### ${LOCAL_CURRENT_SOURCE_DIR}/physics/calpreciptype.f90 +### PROPERTIES COMPILE_FLAGS "-r8 -free ${OpenMP_Fortran_FLAGS} ") +### SET_SOURCE_FILES_PROPERTIES(${LOCAL_CURRENT_SOURCE_DIR}/physics/mersenne_twister.f +### PROPERTIES COMPILE_FLAGS "-r8 -ftz ${OpenMP_Fortran_FLAGS} ") +### SET_SOURCE_FILES_PROPERTIES(${LOCAL_CURRENT_SOURCE_DIR}/physics/module_nst_water_prop.f90 +### PROPERTIES COMPILE_FLAGS "-extend-source 132 -r8 -free ${OpenMP_Fortran_FLAGS} ") +### SET_SOURCE_FILES_PROPERTIES(${LOCAL_CURRENT_SOURCE_DIR}/physics/aer_cloud.F +### ${LOCAL_CURRENT_SOURCE_DIR}/physics/wv_saturation.F +### ${LOCAL_CURRENT_SOURCE_DIR}/physics/cldwat2m_micro.F +### ${LOCAL_CURRENT_SOURCE_DIR}/physics/surface_perturbation.F90 +### PROPERTIES COMPILE_FLAGS "-r8 ${OpenMP_Fortran_FLAGS} ") +### SET_SOURCE_FILES_PROPERTIES(${LOCAL_CURRENT_SOURCE_DIR}/physics/module_mp_thompson_make_number_concentrations.F90 +### PROPERTIES COMPILE_FLAGS "-r8 ${OpenMP_Fortran_FLAGS} ") +### SET_SOURCE_FILES_PROPERTIES(${LOCAL_CURRENT_SOURCE_DIR}/physics/module_SF_JSFC.F90 +### ${LOCAL_CURRENT_SOURCE_DIR}/physics/module_BL_MYJPBL.F90 +### PROPERTIES COMPILE_FLAGS "-r8 ${OpenMP_Fortran_FLAGS} ") +### endif (PROJECT STREQUAL "CCPP-FV3") +### +### else() +### message ("CMAKE_Fortran_COMPILER full path: " ${CMAKE_Fortran_COMPILER}) +### message ("Fortran compiler: " ${CMAKE_Fortran_COMPILER_ID}) +### message (FATAL_ERROR "This program has only been compiled with gfortran, pgf90 and ifort. If another compiler is needed, the appropriate flags must be added in ${GFS_PHYS_SRC}/CMakeLists.txt") +### endif() +### +### # The auto-generated caps can contain calls to physics schemes in +### # which some of the arguments (pointers, arrays) are not associated/allocated. +### # This is on purpose to avoid allocating fields that are not used inside the +### # scheme if, for example, certain conditions are not met. To avoid +### # Fortran runtime errors, it is necessary to remove checks for pointers +### # that are not associated and for array bounds from the caps ONLY. For the +### # physics schemes, these checks can and should remain enabled. Overwriting +### # the pointer check flags explicitly works for Intel and GNU, but not for PGI. +### if (${CMAKE_Fortran_COMPILER_ID} STREQUAL "GNU") +### set_property(SOURCE ${CAPS} APPEND_STRING PROPERTY COMPILE_FLAGS " -fcheck=no-pointer,no-bounds ") +### elseif (${CMAKE_Fortran_COMPILER_ID} STREQUAL "Intel") +### set_property(SOURCE ${CAPS} APPEND_STRING PROPERTY COMPILE_FLAGS " -check nopointers,nobounds ") +### endif () + +#------------------------------------------------------------------------------ +add_library(ccppstub STATIC ${SCHEMES} ${CAPS} ${API}) +# Generate list of Fortran modules from defined sources +foreach(source_f90 ${CAPS} ${API}) + get_filename_component(tmp_source_f90 ${source_f90} NAME) + string(REGEX REPLACE ".F90" ".mod" tmp_module_f90 ${tmp_source_f90}) + string(TOLOWER ${tmp_module_f90} module_f90) + list(APPEND MODULES_F90 ${CMAKE_CURRENT_BINARY_DIR}/${module_f90}) +endforeach() + +set_target_properties(ccppstub PROPERTIES VERSION ${PROJECT_VERSION} + SOVERSION ${PROJECT_VERSION_MAJOR}) + +# Define where to install the library +install(TARGETS ccppstub + EXPORT ccppstub-targets + ARCHIVE DESTINATION lib + LIBRARY DESTINATION lib + RUNTIME DESTINATION lib +) +# Export our configuration +install(EXPORT ccppstub-targets + FILE ccppstub-config.cmake + DESTINATION lib/cmake +) +# Define where to install the C headers and Fortran modules +#install(FILES ${HEADERS_C} DESTINATION include) +install(FILES ${MODULES_F90} DESTINATION include) + diff --git a/stub/ccpp_prebuild_config.py b/stub/ccpp_prebuild_config.py new file mode 100755 index 00000000..5ee15b05 --- /dev/null +++ b/stub/ccpp_prebuild_config.py @@ -0,0 +1,77 @@ +#!/usr/bin/env python + +# CCPP prebuild config for GFDL Finite-Volume Cubed-Sphere Model (FV3) + + +############################################################################### +# Definitions # +############################################################################### + +HOST_MODEL_IDENTIFIER = "FV3" + +# Add all files with metadata tables on the host model side and in CCPP, +# relative to basedir = top-level directory of host model. This includes +# kind and type definitions used in CCPP physics. Also add any internal +# dependencies of these files to the list. +VARIABLE_DEFINITION_FILES = [ + # actual variable definition files + 'data.F90', + ] + +TYPEDEFS_NEW_METADATA = { + 'ccpp_types' : { + 'ccpp_types' : '', + 'ccpp_t' : 'ccpp_data', + }, + } + +# Add all physics scheme files relative to basedir +SCHEME_FILES = [ + 'stub.F90', + ] + +# Default build dir, relative to current working directory, +# if not specified as command-line argument +DEFAULT_BUILD_DIR = '.' + +# Auto-generated makefile/cmakefile snippets that contain all type definitions +TYPEDEFS_MAKEFILE = '{build_dir}/CCPP_TYPEDEFS.mk' +TYPEDEFS_CMAKEFILE = '{build_dir}/CCPP_TYPEDEFS.cmake' +TYPEDEFS_SOURCEFILE = '{build_dir}/CCPP_TYPEDEFS.sh' + +# Auto-generated makefile/cmakefile snippets that contain all schemes +SCHEMES_MAKEFILE = '{build_dir}/CCPP_SCHEMES.mk' +SCHEMES_CMAKEFILE = '{build_dir}/CCPP_SCHEMES.cmake' +SCHEMES_SOURCEFILE = '{build_dir}/CCPP_SCHEMES.sh' + +# Auto-generated makefile/cmakefile snippets that contain all caps +CAPS_MAKEFILE = '{build_dir}/CCPP_CAPS.mk' +CAPS_CMAKEFILE = '{build_dir}/CCPP_CAPS.cmake' +CAPS_SOURCEFILE = '{build_dir}/CCPP_CAPS.sh' + +# Directory where to put all auto-generated physics caps +CAPS_DIR = '{build_dir}' + +# Directory where the suite definition files are stored +SUITES_DIR = '{build_dir}' + +# Optional arguments - only required for schemes that use +# optional arguments. ccpp_prebuild.py will throw an exception +# if it encounters a scheme subroutine with optional arguments +# if no entry is made here. Possible values are: 'all', 'none', +# or a list of standard_names: [ 'var1', 'var3' ]. +OPTIONAL_ARGUMENTS = {} + +# Directory where to write static API to +STATIC_API_DIR = '{build_dir}' +STATIC_API_CMAKEFILE = '{build_dir}/CCPP_API.cmake' +STATIC_API_SOURCEFILE = '{build_dir}/CCPP_API.sh' + +# Directory for writing HTML pages generated from metadata files +METADATA_HTML_OUTPUT_DIR = '{build_dir}' + +# HTML document containing the model-defined CCPP variables +HTML_VARTABLE_FILE = '{build_dir}/CCPP_VARIABLES_STUB.html' + +# LaTeX document containing the provided vs requested CCPP variables +LATEX_VARTABLE_FILE = '{build_dir}/CCPP_VARIABLES_STUB.tex' diff --git a/stub/data.F90 b/stub/data.F90 new file mode 100644 index 00000000..d2a21c15 --- /dev/null +++ b/stub/data.F90 @@ -0,0 +1,17 @@ +module data + +!! \section arg_table_data Argument Table +!! \htmlinclude data.html +!! + + use ccpp_types, only: ccpp_t + + implicit none + + private + + public ccpp_data + + type(ccpp_t), save, target :: ccpp_data + +end module data diff --git a/stub/data.meta b/stub/data.meta new file mode 100644 index 00000000..55600b1a --- /dev/null +++ b/stub/data.meta @@ -0,0 +1,14 @@ +[ccpp-table-properties] + name = data + type = module + dependencies = + +[ccpp-arg-table] + name = data + type = module +[ccpp_data] + standard_name = ccpp_t_instance + long_name = instance of derived data type ccpp_t + units = DDT + dimensions = () + type = ccpp_t diff --git a/stub/stub.F90 b/stub/stub.F90 new file mode 100644 index 00000000..0b392daa --- /dev/null +++ b/stub/stub.F90 @@ -0,0 +1,35 @@ +!>\file stub.F90 +!! This file contains a stub CCPP scheme that does nothing +!! except requesting the minimum, mandatory variables. + +module stub + + implicit none + private + public :: stub_init, stub_finalize + + contains + +!! \section arg_table_stub_init Argument Table +!! \htmlinclude stub_init.html +!! + subroutine stub_init(errmsg, errflg) + character(len=*), intent(out) :: errmsg + integer, intent(out) :: errflg + ! Initialize CCPP error handling variables + errmsg = '' + errflg = 0 + end subroutine stub_init + +!! \section arg_table_stub_finalize Argument Table +!! \htmlinclude stub_finalize.html +!! + subroutine stub_finalize(errmsg, errflg) + character(len=*), intent(out) :: errmsg + integer, intent(out) :: errflg + ! Initialize CCPP error handling variables + errmsg = '' + errflg = 0 + end subroutine stub_finalize + +end module stub diff --git a/stub/stub.meta b/stub/stub.meta new file mode 100644 index 00000000..46d1303a --- /dev/null +++ b/stub/stub.meta @@ -0,0 +1,48 @@ +[ccpp-table-properties] + name = stub + type = scheme + dependencies = + +######################################################################## +[ccpp-arg-table] + name = stub_init + type = scheme +[errmsg] + standard_name = ccpp_error_message + long_name = error message for error handling in CCPP + units = none + dimensions = () + type = character + kind = len=* + intent = out + optional = F +[errflg] + standard_name = ccpp_error_flag + long_name = error flag for error handling in CCPP + units = flag + dimensions = () + type = integer + intent = out + optional = F + +######################################################################## +[ccpp-arg-table] + name = stub_finalize + type = scheme +[errmsg] + standard_name = ccpp_error_message + long_name = error message for error handling in CCPP + units = none + dimensions = () + type = character + kind = len=* + intent = out + optional = F +[errflg] + standard_name = ccpp_error_flag + long_name = error flag for error handling in CCPP + units = flag + dimensions = () + type = integer + intent = out + optional = F diff --git a/stub/suite_stub.xml b/stub/suite_stub.xml new file mode 100644 index 00000000..46d25f9f --- /dev/null +++ b/stub/suite_stub.xml @@ -0,0 +1,9 @@ + + + + + + stub + + + From 958b284854385845dafc8f7adca990c7aac563d8 Mon Sep 17 00:00:00 2001 From: Dom Heinzeller Date: Thu, 2 Sep 2021 10:21:13 -0600 Subject: [PATCH 04/11] Add stub/README.md --- stub/README.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 stub/README.md diff --git a/stub/README.md b/stub/README.md new file mode 100644 index 00000000..e641aece --- /dev/null +++ b/stub/README.md @@ -0,0 +1,12 @@ +# How to build the stub + +Note: build is in-source for now + +1. Set compiler environment as appropriate for your system +2. Run the following commands: +``` +cd stub +../scripts/ccpp_prebuild.py --config=ccpp_prebuild_config.py +cmake . 2>&1 | tee log.cmake +make 2>&1 | tee log.make +``` From 566916dcf628ad009430c0365c372501249a5703 Mon Sep 17 00:00:00 2001 From: Dom Heinzeller Date: Wed, 2 Feb 2022 20:56:20 -0700 Subject: [PATCH 05/11] Update stub code to reflect recent changes in ccpp-framework --- stub/CMakeLists.txt | 278 ----------------------------------- stub/ccpp_prebuild_config.py | 1 + stub/stub.meta | 5 +- 3 files changed, 2 insertions(+), 282 deletions(-) diff --git a/stub/CMakeLists.txt b/stub/CMakeLists.txt index 5b4dd8ea..9ee7ce9f 100644 --- a/stub/CMakeLists.txt +++ b/stub/CMakeLists.txt @@ -4,57 +4,6 @@ cmake_minimum_required(VERSION 3.0) project(ccppstub VERSION 1.0.0 LANGUAGES Fortran) -# -# # Use rpaths on MacOSX -# set(CMAKE_MACOSX_RPATH 1) -# if(POLICY CMP0042) -# cmake_policy(SET CMP0042 NEW) -# endif(POLICY CMP0042) -# -# # CMP0057: Support new IN_LIST if() operator -# if(POLICY CMP0057) -# cmake_policy(SET CMP0057 NEW) -# endif(POLICY CMP0057) - -##------------------------------------------------------------------------------ -#set(PACKAGE "ccpp-physics") -#set(AUTHORS "Grant Firl" "Dom Heinzeller" "Man Zhang" "Laurie Carson") -# -##------------------------------------------------------------------------------ -## Set OpenMP flags for C/C++/Fortran -#if (OPENMP) -# include(detect_openmp) -# detect_openmp() -# #set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}") -# #set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}") -# #set (CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} ${OpenMP_Fortran_FLAGS}") -# message(STATUS "Enable OpenMP support for C/C++/Fortran compiler") -#else (OPENMP) -# message (STATUS "Disable OpenMP support for C/C++/Fortran compiler") -#endif() - -##------------------------------------------------------------------------------ -## The Fortran compiler/linker flag inserted by cmake to create shared libraries -## with the Intel compiler is deprecated (-i_dynamic), correct here. -## CMAKE_Fortran_COMPILER_ID = {"Intel", "PGI", "GNU", "Clang", "MSVC", ...} -#if ("${CMAKE_Fortran_COMPILER_ID}" STREQUAL "Intel") -# string(REPLACE "-i_dynamic" "-shared-intel" -# CMAKE_SHARED_LIBRARY_CREATE_Fortran_FLAGS -# "${CMAKE_SHARED_LIBRARY_CREATE_Fortran_FLAGS}") -# string(REPLACE "-i_dynamic" "-shared-intel" -# CMAKE_SHARED_LIBRARY_LINK_Fortran_FLAGS -# "${CMAKE_SHARED_LIBRARY_LINK_Fortran_FLAGS}") -#endif() -# -##------------------------------------------------------------------------------ -## Set a default build type if none was specified -#if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) -# message(STATUS "Setting build type to 'Release' as none was specified.") -# set(CMAKE_BUILD_TYPE Release 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" "Bitforbit" "Release" "Coverage") -#endif() #------------------------------------------------------------------------------ # Request a static build @@ -104,233 +53,6 @@ else(API) message(STATUS "Got CCPP API from cmakefile include file: ${API}") endif(API) -### # Schemes and caps from the CCPP code generator use full paths with symlinks -### # resolved, we need to do the same here for the below logic to work -### get_filename_component(FULL_PATH_TO_CMAKELISTS CMakeLists.txt REALPATH BASE_DIR ${LOCAL_CURRENT_SOURCE_DIR}) -### get_filename_component(LOCAL_CURRENT_SOURCE_DIR ${FULL_PATH_TO_CMAKELISTS} DIRECTORY) -### -### # List of files that need to be compiled without OpenMP -### set(SCHEMES_OPENMP_OFF ${LOCAL_CURRENT_SOURCE_DIR}/physics/rte-rrtmgp/rrtmgp/mo_gas_optics.F90 -### ${LOCAL_CURRENT_SOURCE_DIR}/physics/rte-rrtmgp/rrtmgp/mo_rrtmgp_constants.F90 -### ${LOCAL_CURRENT_SOURCE_DIR}/physics/rte-rrtmgp/rrtmgp/mo_rrtmgp_util_reorder.F90 -### ${LOCAL_CURRENT_SOURCE_DIR}/physics/rte-rrtmgp/rrtmgp/mo_gas_concentrations.F90 -### ${LOCAL_CURRENT_SOURCE_DIR}/physics/rte-rrtmgp/rrtmgp/kernels-openacc/mo_gas_optics_kernels.F90 -### ${LOCAL_CURRENT_SOURCE_DIR}/physics/rte-rrtmgp/rrtmgp/mo_rrtmgp_util_string.F90 -### ${LOCAL_CURRENT_SOURCE_DIR}/physics/rte-rrtmgp/rrtmgp/kernels/mo_gas_optics_kernels.F90 -### ${LOCAL_CURRENT_SOURCE_DIR}/physics/rte-rrtmgp/rrtmgp/kernels/mo_rrtmgp_util_reorder_kernels.F90 -### ${LOCAL_CURRENT_SOURCE_DIR}/physics/rte-rrtmgp/rrtmgp/mo_gas_optics_rrtmgp.F90 -### ${LOCAL_CURRENT_SOURCE_DIR}/physics/rte-rrtmgp/tests/mo_testing_io.F90 -### ${LOCAL_CURRENT_SOURCE_DIR}/physics/rte-rrtmgp/tests/clear_sky_regression.F90 -### ${LOCAL_CURRENT_SOURCE_DIR}/physics/rte-rrtmgp/extensions/mo_rrtmgp_clr_all_sky.F90 -### ${LOCAL_CURRENT_SOURCE_DIR}/physics/rte-rrtmgp/extensions/mo_fluxes_byband_kernels.F90 -### ${LOCAL_CURRENT_SOURCE_DIR}/physics/rte-rrtmgp/extensions/mo_fluxes_byband.F90 -### ${LOCAL_CURRENT_SOURCE_DIR}/physics/rte-rrtmgp/extensions/solar_variability/mo_solar_variability.F90 -### ${LOCAL_CURRENT_SOURCE_DIR}/physics/rte-rrtmgp/extensions/mo_heating_rates.F90 -### ${LOCAL_CURRENT_SOURCE_DIR}/physics/rte-rrtmgp/extensions/mo_fluxes_bygpoint.F90 -### ${LOCAL_CURRENT_SOURCE_DIR}/physics/rte-rrtmgp/extensions/mo_compute_bc.F90 -### ${LOCAL_CURRENT_SOURCE_DIR}/physics/rte-rrtmgp/extensions/cloud_optics/mo_cloud_sampling.F90 -### ${LOCAL_CURRENT_SOURCE_DIR}/physics/rte-rrtmgp/extensions/cloud_optics/mo_cloud_optics.F90 -### ${LOCAL_CURRENT_SOURCE_DIR}/physics/rte-rrtmgp/examples/mo_load_coefficients.F90 -### ${LOCAL_CURRENT_SOURCE_DIR}/physics/rte-rrtmgp/examples/rfmip-clear-sky/rrtmgp_rfmip_sw.F90 -### ${LOCAL_CURRENT_SOURCE_DIR}/physics/rte-rrtmgp/examples/rfmip-clear-sky/mo_rfmip_io.F90 -### ${LOCAL_CURRENT_SOURCE_DIR}/physics/rte-rrtmgp/examples/rfmip-clear-sky/rrtmgp_rfmip_lw.F90 -### ${LOCAL_CURRENT_SOURCE_DIR}/physics/rte-rrtmgp/examples/mo_simple_netcdf.F90 -### ${LOCAL_CURRENT_SOURCE_DIR}/physics/rte-rrtmgp/examples/all-sky/rrtmgp_allsky.F90 -### ${LOCAL_CURRENT_SOURCE_DIR}/physics/rte-rrtmgp/examples/all-sky/mo_load_cloud_coefficients.F90 -### ${LOCAL_CURRENT_SOURCE_DIR}/physics/rte-rrtmgp/examples/all-sky/mo_garand_atmos_io.F90 -### ${LOCAL_CURRENT_SOURCE_DIR}/physics/rte-rrtmgp/rte/mo_rte_config.F90 -### ${LOCAL_CURRENT_SOURCE_DIR}/physics/rte-rrtmgp/rte/mo_source_functions.F90 -### ${LOCAL_CURRENT_SOURCE_DIR}/physics/rte-rrtmgp/rte/mo_rte_sw.F90 -### ${LOCAL_CURRENT_SOURCE_DIR}/physics/rte-rrtmgp/rte/mo_fluxes.F90 -### ${LOCAL_CURRENT_SOURCE_DIR}/physics/rte-rrtmgp/rte/mo_rte_lw.F90 -### ${LOCAL_CURRENT_SOURCE_DIR}/physics/rte-rrtmgp/rte/kernels-openacc/mo_rte_solver_kernels.F90 -### ${LOCAL_CURRENT_SOURCE_DIR}/physics/rte-rrtmgp/rte/kernels-openacc/mo_optical_props_kernels.F90 -### ${LOCAL_CURRENT_SOURCE_DIR}/physics/rte-rrtmgp/rte/mo_rte_util_array.F90 -### ${LOCAL_CURRENT_SOURCE_DIR}/physics/rte-rrtmgp/rte/kernels/mo_rte_solver_kernels.F90 -### ${LOCAL_CURRENT_SOURCE_DIR}/physics/rte-rrtmgp/rte/kernels/mo_optical_props_kernels.F90 -### ${LOCAL_CURRENT_SOURCE_DIR}/physics/rte-rrtmgp/rte/kernels/mo_fluxes_broadband_kernels.F90 -### ${LOCAL_CURRENT_SOURCE_DIR}/physics/rte-rrtmgp/rte/mo_rte_kind.F90 -### ${LOCAL_CURRENT_SOURCE_DIR}/physics/rte-rrtmgp/rte/mo_optical_props.F90) -### -### #------------------------------------------------------------------------------ -### if (${CMAKE_Fortran_COMPILER_ID} STREQUAL "GNU") -### -### set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -ffree-line-length-none") -### -### SET_SOURCE_FILES_PROPERTIES(${LOCAL_CURRENT_SOURCE_DIR}/physics/module_bfmicrophysics.f -### ${LOCAL_CURRENT_SOURCE_DIR}/physics/sflx.f -### ${LOCAL_CURRENT_SOURCE_DIR}/physics/sfc_diff.f -### ${LOCAL_CURRENT_SOURCE_DIR}/physics/sfc_diag.f -### ${LOCAL_CURRENT_SOURCE_DIR}/physics/module_nst_model.f90 -### ${LOCAL_CURRENT_SOURCE_DIR}/physics/calpreciptype.f90 -### ${LOCAL_CURRENT_SOURCE_DIR}/physics/mersenne_twister.f -### ${LOCAL_CURRENT_SOURCE_DIR}/physics/module_nst_water_prop.f90 -### ${LOCAL_CURRENT_SOURCE_DIR}/physics/aer_cloud.F -### ${LOCAL_CURRENT_SOURCE_DIR}/physics/wv_saturation.F -### ${LOCAL_CURRENT_SOURCE_DIR}/physics/cldwat2m_micro.F -### ${LOCAL_CURRENT_SOURCE_DIR}/physics/surface_perturbation.F90 -### ${LOCAL_CURRENT_SOURCE_DIR}/physics/module_mp_thompson_make_number_concentrations.F90 -### ${LOCAL_CURRENT_SOURCE_DIR}/physics/module_SF_JSFC.F90 -### ${LOCAL_CURRENT_SOURCE_DIR}/physics/module_BL_MYJPBL.F90 -### PROPERTIES COMPILE_FLAGS "-fdefault-real-8 -fdefault-double-8 ${OpenMP_Fortran_FLAGS}") -### -### if (PROJECT STREQUAL "CCPP-FV3") -### # Set 32-bit floating point precision flags for certain files -### # that are executed in the dynamics (fast physics part) -### if (DYN32) -### if (${LOCAL_CURRENT_SOURCE_DIR}/physics/gfdl_fv_sat_adj.F90 IN_LIST SCHEMES) -### # Reduce floating point precision from 64-bit to 32-bit, if necessary -### set(CMAKE_Fortran_FLAGS_PREC32 ${CMAKE_Fortran_FLAGS_DEFAULT_PREC}) -### string(REPLACE "-fdefault-real-8" "" -### CMAKE_Fortran_FLAGS_PREC32 "${CMAKE_Fortran_FLAGS_PREC32}") -### string(REPLACE "-fdefault-double-8" "" -### CMAKE_Fortran_FLAGS_PREC32 "${CMAKE_Fortran_FLAGS_PREC32}") -### SET_PROPERTY(SOURCE ${LOCAL_CURRENT_SOURCE_DIR}/physics/gfdl_fv_sat_adj.F90 -### APPEND_STRING PROPERTY COMPILE_FLAGS " ${CMAKE_Fortran_FLAGS_PREC32} ${OpenMP_Fortran_FLAGS} ") -### # Add all of the above files to the list of schemes with special floating point precision flags -### list(APPEND SCHEMES_SFX_PREC ${LOCAL_CURRENT_SOURCE_DIR}/physics/gfdl_fv_sat_adj.F90) -### endif() -### endif() -### -### # Remove files with special floating point precision flags from list -### # of files with standard floating point precision flags -### if (SCHEMES_SFX_PREC) -### list(REMOVE_ITEM SCHEMES2 ${SCHEMES_SFX_PREC}) -### endif () -### -### if (PROJECT STREQUAL "CCPP-FV3") -### # Remove files that need to be compiled without OpenMP from list -### # of files with standard compiler flags, and assign no-OpenMP flags -### if (SCHEMES_OPENMP_OFF) -### list(REMOVE_ITEM SCHEMES2 ${SCHEMES_OPENMP_OFF}) -### endif () -### # Assign standard floating point precision flags to all remaining schemes and caps -### SET_PROPERTY(SOURCE ${SCHEMES_OPENMP_OFF} -### APPEND_STRING PROPERTY COMPILE_FLAGS " ${CMAKE_Fortran_FLAGS_DEFAULT_PREC} ") -### endif() -### -### # Assign standard floating point precision flags to all remaining schemes and caps -### SET_PROPERTY(SOURCE ${SCHEMES2} ${CAPS} -### APPEND_STRING PROPERTY COMPILE_FLAGS " ${CMAKE_Fortran_FLAGS_DEFAULT_PREC} ${OpenMP_Fortran_FLAGS} ") -### -### endif (PROJECT STREQUAL "CCPP-FV3") -### -### elseif (${CMAKE_Fortran_COMPILER_ID} STREQUAL "Intel") -### # Adjust settings for bit-for-bit reproducibility of NEMSfv3gfs -### if (PROJECT STREQUAL "CCPP-FV3") -### -### if (${LOCAL_CURRENT_SOURCE_DIR}/physics/module_sf_mynn.F90 IN_LIST SCHEMES) -### # Reduce optimization for module_sf_mynn.F90 (to avoid an apparent compiler bug with Intel 18 on Hera) -### SET_SOURCE_FILES_PROPERTIES(${LOCAL_CURRENT_SOURCE_DIR}/physics/module_sf_mynn.F90 -### PROPERTIES COMPILE_FLAGS "${CMAKE_Fortran_FLAGS_OPT} -O1") -### list(APPEND SCHEMES_SFX_OPT ${LOCAL_CURRENT_SOURCE_DIR}/physics/module_sf_mynn.F90) -### endif() -### -### if (${LOCAL_CURRENT_SOURCE_DIR}/physics/radiation_aerosols.f IN_LIST SCHEMES) -### # Replace -xHost or -xCORE-AVX2 with -xCORE-AVX-I for certain files -### set(CMAKE_Fortran_FLAGS_LOPT1 ${CMAKE_Fortran_FLAGS_OPT}) -### string(REPLACE "-xHOST" "-xCORE-AVX-I" -### CMAKE_Fortran_FLAGS_LOPT1 -### "${CMAKE_Fortran_FLAGS_LOPT1}") -### string(REPLACE "-xCORE-AVX2" "-xCORE-AVX-I" -### CMAKE_Fortran_FLAGS_LOPT1 -### "${CMAKE_Fortran_FLAGS_LOPT1}") -### string(REPLACE "-axSSE4.2,CORE-AVX2" "-axSSE4.2,CORE-AVX-I" -### CMAKE_Fortran_FLAGS_LOPT1 -### "${CMAKE_Fortran_FLAGS_LOPT1}") -### SET_SOURCE_FILES_PROPERTIES(${LOCAL_CURRENT_SOURCE_DIR}/physics/radiation_aerosols.f -### PROPERTIES COMPILE_FLAGS "${CMAKE_Fortran_FLAGS_LOPT1}") -### # Add all of the above files to the list of schemes with special compiler flags -### list(APPEND SCHEMES_SFX_OPT ${LOCAL_CURRENT_SOURCE_DIR}/physics/radiation_aerosols.f) -### endif() -### -### # Remove files with special compiler flags from list of files with standard compiler flags -### if (SCHEMES_SFX_OPT) -### list(REMOVE_ITEM SCHEMES ${SCHEMES_SFX_OPT}) -### endif(SCHEMES_SFX_OPT) -### # Assign standard compiler flags to all remaining schemes and caps -### SET_SOURCE_FILES_PROPERTIES(${SCHEMES} ${CAPS} -### PROPERTIES COMPILE_FLAGS "${CMAKE_Fortran_FLAGS_OPT}") -### -### # Set 32-bit floating point precision flags for certain files -### # that are executed in the dynamics (fast physics part) -### if (DYN32) -### if (${LOCAL_CURRENT_SOURCE_DIR}/physics/gfdl_fv_sat_adj.F90 IN_LIST SCHEMES) -### # Reduce floating point precision from 64-bit to 32-bit, if necessary -### set(CMAKE_Fortran_FLAGS_PREC32 ${CMAKE_Fortran_FLAGS_DEFAULT_PREC}) -### string(REPLACE "-real-size 64" "-real-size 32" -### CMAKE_Fortran_FLAGS_PREC32 "${CMAKE_Fortran_FLAGS_PREC32}") -### SET_PROPERTY(SOURCE ${LOCAL_CURRENT_SOURCE_DIR}/physics/gfdl_fv_sat_adj.F90 -### APPEND_STRING PROPERTY COMPILE_FLAGS " ${CMAKE_Fortran_FLAGS_PREC32} ${OpenMP_Fortran_FLAGS} ") -### # Add all of the above files to the list of schemes with special floating point precision flags -### list(APPEND SCHEMES_SFX_PREC ${LOCAL_CURRENT_SOURCE_DIR}/physics/gfdl_fv_sat_adj.F90) -### endif() -### endif() -### -### # Remove files with special floating point precision flags from list -### # of files with standard floating point precision flags flags -### if (SCHEMES_SFX_PREC) -### list(REMOVE_ITEM SCHEMES2 ${SCHEMES_SFX_PREC}) -### endif (SCHEMES_SFX_PREC) -### -### # Remove files that need to be compiled without OpenMP from list -### # of files with standard compiler flags, and assign no-OpenMP flags -### if (SCHEMES_OPENMP_OFF) -### list(REMOVE_ITEM SCHEMES2 ${SCHEMES_OPENMP_OFF}) -### # Assign standard floating point precision flags to all remaining schemes and caps -### SET_PROPERTY(SOURCE ${SCHEMES_OPENMP_OFF} -### APPEND_STRING PROPERTY COMPILE_FLAGS " ${CMAKE_Fortran_FLAGS_DEFAULT_PREC} ") -### endif () -### -### # Assign standard floating point precision flags to all remaining schemes and caps -### SET_PROPERTY(SOURCE ${SCHEMES2} ${CAPS} -### APPEND_STRING PROPERTY COMPILE_FLAGS " ${CMAKE_Fortran_FLAGS_DEFAULT_PREC} ${OpenMP_Fortran_FLAGS} ") -### -### else (PROJECT STREQUAL "CCPP-FV3") -### SET_SOURCE_FILES_PROPERTIES(${LOCAL_CURRENT_SOURCE_DIR}/physics/module_bfmicrophysics.f -### ${LOCAL_CURRENT_SOURCE_DIR}/physics/sflx.f -### ${LOCAL_CURRENT_SOURCE_DIR}/physics/sfc_diff.f -### ${LOCAL_CURRENT_SOURCE_DIR}/physics/sfc_diag.f -### PROPERTIES COMPILE_FLAGS "-r8 ${OpenMP_Fortran_FLAGS} ") -### SET_SOURCE_FILES_PROPERTIES(${LOCAL_CURRENT_SOURCE_DIR}/physics/module_nst_model.f90 -### ${LOCAL_CURRENT_SOURCE_DIR}/physics/calpreciptype.f90 -### PROPERTIES COMPILE_FLAGS "-r8 -free ${OpenMP_Fortran_FLAGS} ") -### SET_SOURCE_FILES_PROPERTIES(${LOCAL_CURRENT_SOURCE_DIR}/physics/mersenne_twister.f -### PROPERTIES COMPILE_FLAGS "-r8 -ftz ${OpenMP_Fortran_FLAGS} ") -### SET_SOURCE_FILES_PROPERTIES(${LOCAL_CURRENT_SOURCE_DIR}/physics/module_nst_water_prop.f90 -### PROPERTIES COMPILE_FLAGS "-extend-source 132 -r8 -free ${OpenMP_Fortran_FLAGS} ") -### SET_SOURCE_FILES_PROPERTIES(${LOCAL_CURRENT_SOURCE_DIR}/physics/aer_cloud.F -### ${LOCAL_CURRENT_SOURCE_DIR}/physics/wv_saturation.F -### ${LOCAL_CURRENT_SOURCE_DIR}/physics/cldwat2m_micro.F -### ${LOCAL_CURRENT_SOURCE_DIR}/physics/surface_perturbation.F90 -### PROPERTIES COMPILE_FLAGS "-r8 ${OpenMP_Fortran_FLAGS} ") -### SET_SOURCE_FILES_PROPERTIES(${LOCAL_CURRENT_SOURCE_DIR}/physics/module_mp_thompson_make_number_concentrations.F90 -### PROPERTIES COMPILE_FLAGS "-r8 ${OpenMP_Fortran_FLAGS} ") -### SET_SOURCE_FILES_PROPERTIES(${LOCAL_CURRENT_SOURCE_DIR}/physics/module_SF_JSFC.F90 -### ${LOCAL_CURRENT_SOURCE_DIR}/physics/module_BL_MYJPBL.F90 -### PROPERTIES COMPILE_FLAGS "-r8 ${OpenMP_Fortran_FLAGS} ") -### endif (PROJECT STREQUAL "CCPP-FV3") -### -### else() -### message ("CMAKE_Fortran_COMPILER full path: " ${CMAKE_Fortran_COMPILER}) -### message ("Fortran compiler: " ${CMAKE_Fortran_COMPILER_ID}) -### message (FATAL_ERROR "This program has only been compiled with gfortran, pgf90 and ifort. If another compiler is needed, the appropriate flags must be added in ${GFS_PHYS_SRC}/CMakeLists.txt") -### endif() -### -### # The auto-generated caps can contain calls to physics schemes in -### # which some of the arguments (pointers, arrays) are not associated/allocated. -### # This is on purpose to avoid allocating fields that are not used inside the -### # scheme if, for example, certain conditions are not met. To avoid -### # Fortran runtime errors, it is necessary to remove checks for pointers -### # that are not associated and for array bounds from the caps ONLY. For the -### # physics schemes, these checks can and should remain enabled. Overwriting -### # the pointer check flags explicitly works for Intel and GNU, but not for PGI. -### if (${CMAKE_Fortran_COMPILER_ID} STREQUAL "GNU") -### set_property(SOURCE ${CAPS} APPEND_STRING PROPERTY COMPILE_FLAGS " -fcheck=no-pointer,no-bounds ") -### elseif (${CMAKE_Fortran_COMPILER_ID} STREQUAL "Intel") -### set_property(SOURCE ${CAPS} APPEND_STRING PROPERTY COMPILE_FLAGS " -check nopointers,nobounds ") -### endif () - #------------------------------------------------------------------------------ add_library(ccppstub STATIC ${SCHEMES} ${CAPS} ${API}) # Generate list of Fortran modules from defined sources diff --git a/stub/ccpp_prebuild_config.py b/stub/ccpp_prebuild_config.py index 5ee15b05..31aeccfb 100755 --- a/stub/ccpp_prebuild_config.py +++ b/stub/ccpp_prebuild_config.py @@ -15,6 +15,7 @@ # dependencies of these files to the list. VARIABLE_DEFINITION_FILES = [ # actual variable definition files + '../src/ccpp_types.F90', 'data.F90', ] diff --git a/stub/stub.meta b/stub/stub.meta index 46d1303a..29bba80a 100644 --- a/stub/stub.meta +++ b/stub/stub.meta @@ -15,7 +15,6 @@ type = character kind = len=* intent = out - optional = F [errflg] standard_name = ccpp_error_flag long_name = error flag for error handling in CCPP @@ -23,7 +22,6 @@ dimensions = () type = integer intent = out - optional = F ######################################################################## [ccpp-arg-table] @@ -37,7 +35,6 @@ type = character kind = len=* intent = out - optional = F [errflg] standard_name = ccpp_error_flag long_name = error flag for error handling in CCPP @@ -45,4 +42,4 @@ dimensions = () type = integer intent = out - optional = F + From 503f43d27a7cf7f27f1cae9412a510c7f28f0f2e Mon Sep 17 00:00:00 2001 From: Dom Heinzeller Date: Sun, 6 Feb 2022 20:23:18 -0700 Subject: [PATCH 06/11] Fix problems with ccpp loop counter/max variables not being in list of required variables --- scripts/ccpp_prebuild.py | 17 ++++++++++++++ scripts/metadata_parser.py | 45 +++++++++++++++++++------------------- scripts/mkdoc.py | 2 +- scripts/mkstatic.py | 45 ++++++++++++++++++++++++++++---------- 4 files changed, 74 insertions(+), 35 deletions(-) diff --git a/scripts/ccpp_prebuild.py b/scripts/ccpp_prebuild.py index 25858930..23bf610c 100755 --- a/scripts/ccpp_prebuild.py +++ b/scripts/ccpp_prebuild.py @@ -3,6 +3,7 @@ # Standard modules import argparse import collections +import copy import filecmp import importlib import itertools @@ -23,6 +24,7 @@ TypedefsMakefile, TypedefsCMakefile, TypedefsSourcefile from mkdoc import metadata_to_html, metadata_to_latex from mkstatic import API, Suite, Group +from mkstatic import CCPP_SUITE_VARIABLES ############################################################################### # Set up the command line argument parser and other global variables # @@ -389,6 +391,16 @@ def filter_metadata(metadata, arguments, dependencies, schemes_in_files, suites) schemes_in_files_filtered[scheme] = schemes_in_files[scheme] return (success, metadata_filtered, arguments_filtered, dependencies_filtered, schemes_in_files_filtered) +def add_ccpp_suite_variables(metadata): + """ Add variables that are required to construct CCPP suites to the list of requested variables""" + success = True + logging.info("Adding CCPP suite variables to list of requested variables") + for var_name in CCPP_SUITE_VARIABLES.keys(): + if not var_name in metadata.keys(): + metadata[var_name] = [copy.deepcopy(CCPP_SUITE_VARIABLES[var_name])] + logging.debug("Adding CCPP suite variable {0} to list of requested variables".format(var_name)) + return (success, metadata) + def generate_list_of_schemes_and_dependencies_to_compile(schemes_in_files, dependencies1, dependencies2): """Generate a flat list of schemes and dependencies in two dependency dictionaries to compile""" success = True @@ -723,6 +735,11 @@ def main(): if not success: raise Exception('Call to filter_metadata failed.') + # Add variables that are required to construct CCPP suites to the list of requested variables + (success, metadata_request) = add_ccpp_suite_variables(metadata_request) + if not success: + raise Exception('Call to add_ccpp_suite_variables failed.') + (success, schemes_and_dependencies_to_compile) = generate_list_of_schemes_and_dependencies_to_compile( schemes_in_files, dependencies_request, dependencies_define) if not success: diff --git a/scripts/metadata_parser.py b/scripts/metadata_parser.py index 56778f98..c7bdb797 100755 --- a/scripts/metadata_parser.py +++ b/scripts/metadata_parser.py @@ -9,6 +9,7 @@ from xml.etree import ElementTree as ET from common import encode_container, CCPP_STAGES +from common import CCPP_ERROR_FLAG_VARIABLE, CCPP_ERROR_MSG_VARIABLE from mkcap import Var sys.path.append(os.path.join(os.path.split(__file__)[0], 'fortran_tools')) @@ -37,28 +38,28 @@ # Mandatory variables that every scheme needs to have CCPP_MANDATORY_VARIABLES = { - 'ccpp_error_message' : Var(local_name = 'errmsg', - standard_name = 'ccpp_error_message', - long_name = 'error message for error handling in CCPP', - units = 'none', - type = 'character', - dimensions = [], - rank = '', - kind = 'len=*', - intent = 'out', - active = 'T', - ), - 'ccpp_error_flag' : Var(local_name = 'ierr', - standard_name = 'ccpp_error_flag', - long_name = 'error flag for error handling in CCPP', - units = 'flag', - type = 'integer', - dimensions = [], - rank = '', - kind = '', - intent = 'out', - active = 'T', - ), + CCPP_ERROR_MSG_VARIABLE : Var(local_name = 'errmsg', + standard_name = CCPP_ERROR_MSG_VARIABLE, + long_name = 'error message for error handling in CCPP', + units = 'none', + type = 'character', + dimensions = [], + rank = '', + kind = 'len=*', + intent = 'out', + active = 'T', + ), + CCPP_ERROR_FLAG_VARIABLE : Var(local_name = 'ierr', + standard_name = CCPP_ERROR_FLAG_VARIABLE, + long_name = 'error flag for error handling in CCPP', + units = 'flag', + type = 'integer', + dimensions = [], + rank = '', + kind = '', + intent = 'out', + active = 'T', + ), } # Save metadata to avoid repeated parsing of type/variable definition files diff --git a/scripts/mkdoc.py b/scripts/mkdoc.py index 39a2ea83..e6692f63 100755 --- a/scripts/mkdoc.py +++ b/scripts/mkdoc.py @@ -124,7 +124,7 @@ def metadata_to_latex(metadata_define, metadata_request, model, filename): target = 'MISSING' local_name = 'MISSING' if var_name in metadata_request.keys(): - requested_list = [ escape_tex(decode_container(v.container)) for v in metadata_request[var_name] ] + requested_list = [ escape_tex(decode_container(v.container)) if v.container else 'none' for v in metadata_request[var_name] ] # for the purpose of the table, just output the name of the subroutine for i in range(len(requested_list)): entry = requested_list[i] diff --git a/scripts/mkstatic.py b/scripts/mkstatic.py index ea269d2e..10fcd576 100755 --- a/scripts/mkstatic.py +++ b/scripts/mkstatic.py @@ -20,6 +20,7 @@ from common import FORTRAN_CONDITIONAL_REGEX_WORDS, FORTRAN_CONDITIONAL_REGEX from common import CCPP_TYPE, STANDARD_VARIABLE_TYPES, STANDARD_CHARACTER_TYPE from common import CCPP_STATIC_API_MODULE, CCPP_STATIC_SUBROUTINE_NAME +from metadata_parser import CCPP_MANDATORY_VARIABLES from mkcap import Var ############################################################################### @@ -27,6 +28,32 @@ # Maximum number of dimensions of an array allowed by the Fortran 2008 standard FORTRAN_ARRAY_MAX_DIMS = 15 +# These variables always need to be present for creating suite and group caps +CCPP_SUITE_VARIABLES = { **CCPP_MANDATORY_VARIABLES, + CCPP_LOOP_COUNTER : Var(local_name = 'loop_cnt', + standard_name = CCPP_LOOP_COUNTER, + long_name = 'loop counter for subcycling loops in CCPP', + units = 'index', + type = 'integer', + dimensions = [], + rank = '', + kind = '', + intent = 'in', + active = 'T', + ), + CCPP_LOOP_EXTENT : Var(local_name = 'loop_max', + standard_name = CCPP_LOOP_EXTENT, + long_name = 'loop counter for subcycling loops in CCPP', + units = 'count', + type = 'integer', + dimensions = [], + rank = '', + kind = '', + intent = 'in', + active = 'T', + ), + } + ############################################################################### def extract_parents_and_indices_from_local_name(local_name): @@ -919,14 +946,8 @@ def write(self, metadata_request, metadata_define, arguments, debug): standard_name_by_local_name_define[metadata_define[standard_name][0].local_name] = standard_name # First get target names of standard CCPP variables for subcycling and error handling - if CCPP_LOOP_COUNTER in metadata_request.keys(): - ccpp_loop_counter_target_name = metadata_request[CCPP_LOOP_COUNTER][0].target - else: - ccpp_loop_counter_target_name = None - if CCPP_LOOP_EXTENT in metadata_request.keys(): - ccpp_loop_extent_target_name = metadata_request[CCPP_LOOP_EXTENT][0].target - else: - ccpp_loop_extent_target_name = None + ccpp_loop_counter_target_name = metadata_request[CCPP_LOOP_COUNTER][0].target + ccpp_loop_extent_target_name = metadata_request[CCPP_LOOP_EXTENT][0].target ccpp_error_flag_target_name = metadata_request[CCPP_ERROR_FLAG_VARIABLE][0].target ccpp_error_msg_target_name = metadata_request[CCPP_ERROR_MSG_VARIABLE][0].target # @@ -1480,14 +1501,14 @@ def write(self, metadata_request, metadata_define, arguments, debug): ''' subcycle_body_suffix = '' if self.parents[ccpp_stage]: - # Set subcycle loop extent if requested by any scheme - if ccpp_loop_extent_target_name and ccpp_stage == 'run': + # Set subcycle loop extent + if ccpp_stage == 'run': subcycle_body_prefix += ''' ! Set loop extent variable for the following subcycle {loop_extent_var_name} = {loop_cnt_max} '''.format(loop_extent_var_name=ccpp_loop_extent_target_name, loop_cnt_max=subcycle.loop) - elif ccpp_loop_extent_target_name: + else: subcycle_body_prefix += ''' ! Set loop extent variable for the following subcycle {loop_extent_var_name} = 1 @@ -1502,7 +1523,7 @@ def write(self, metadata_request, metadata_define, arguments, debug): end do end associate ''' - elif ccpp_loop_counter_target_name: + else: subcycle_body_prefix += ''' {loop_var_name} = 1\n'''.format(loop_var_name=ccpp_loop_counter_target_name) From 6c840e2fdda7d207ef1192ec8db067614d83bf24 Mon Sep 17 00:00:00 2001 From: uturuncoglu Date: Mon, 7 Feb 2022 23:44:58 -0700 Subject: [PATCH 07/11] fix namespace collision for static api --- scripts/ccpp_prebuild.py | 16 ++++++++++++---- scripts/mkstatic.py | 4 ++++ 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/scripts/ccpp_prebuild.py b/scripts/ccpp_prebuild.py index 23bf610c..f826781d 100755 --- a/scripts/ccpp_prebuild.py +++ b/scripts/ccpp_prebuild.py @@ -37,6 +37,7 @@ parser.add_argument('--debug', action='store_true', help='enable debugging features in auto-generated code', default=False) parser.add_argument('--suites', action='store', help='suite definition files to use (comma-separated, without path)', default='') parser.add_argument('--builddir', action='store', help='relative path to CCPP build directory', required=False, default=None) +parser.add_argument('--suffix', action='store', help='suffix to be added to the name of static api module', required=False, default='') # BASEDIR is the current directory where this script is executed BASEDIR = os.getcwd() @@ -58,7 +59,8 @@ def parse_arguments(): else: sdfs = None builddir = args.builddir - return (success, configfile, clean, verbose, debug, sdfs, builddir) + suffix = args.suffix + return (success, configfile, clean, verbose, debug, sdfs, builddir, suffix) def import_config(configfile, builddir): """Import the configuration from a given configuration file""" @@ -514,7 +516,7 @@ def generate_suite_and_group_caps(suites, metadata_request, metadata_define, arg success = False return (success, suite_and_group_caps) -def generate_static_api(suites, static_api_dir): +def generate_static_api(suites, static_api_dir, suffix): """Generate static API for given suite(s)""" success = True # Change to caps directory, create if necessary @@ -522,6 +524,12 @@ def generate_static_api(suites, static_api_dir): os.makedirs(static_api_dir) os.chdir(static_api_dir) api = API(suites=suites, directory=static_api_dir) + if suffix: + base = os.path.splitext(os.path.basename(api.filename))[0] + logging.info('Static API file name is ''{}'''.format(api.filename)) + api.filename = base+'_'+suffix+'.F90' + api.module = base+'_'+suffix + logging.info('Static API file name is changed to ''{}'''.format(api.filename)) logging.info('Generating static API {0} in {1} ...'.format(api.filename, static_api_dir)) api.write() os.chdir(BASEDIR) @@ -680,7 +688,7 @@ def generate_caps_makefile(caps, caps_makefile, caps_cmakefile, caps_sourcefile, def main(): """Main routine that handles the CCPP prebuild for different host models.""" # Parse command line arguments - (success, configfile, clean, verbose, debug, sdfs, builddir) = parse_arguments() + (success, configfile, clean, verbose, debug, sdfs, builddir, suffix) = parse_arguments() if not success: raise Exception('Call to parse_arguments failed.') @@ -774,7 +782,7 @@ def main(): if not success: raise Exception('Call to generate_suite_and_group_caps failed.') - (success, api) = generate_static_api(suites, config['static_api_dir']) + (success, api) = generate_static_api(suites, config['static_api_dir'], suffix) if not success: raise Exception('Call to generate_static_api failed.') diff --git a/scripts/mkstatic.py b/scripts/mkstatic.py index 09e556d6..a95f9e63 100755 --- a/scripts/mkstatic.py +++ b/scripts/mkstatic.py @@ -279,6 +279,10 @@ def module(self): '''Get the module name of the API.''' return self._module + @module.setter + def module(self, value): + self._module = value + @property def subroutines(self): '''Get the subroutines names of the API to.''' From 302cb1e2513af842216e65b1b1e04fe56db9507d Mon Sep 17 00:00:00 2001 From: uturuncoglu Date: Tue, 8 Feb 2022 10:17:39 -0700 Subject: [PATCH 08/11] update new option name and fix clean option --- scripts/ccpp_prebuild.py | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/scripts/ccpp_prebuild.py b/scripts/ccpp_prebuild.py index f826781d..7b4e62d7 100755 --- a/scripts/ccpp_prebuild.py +++ b/scripts/ccpp_prebuild.py @@ -37,7 +37,7 @@ parser.add_argument('--debug', action='store_true', help='enable debugging features in auto-generated code', default=False) parser.add_argument('--suites', action='store', help='suite definition files to use (comma-separated, without path)', default='') parser.add_argument('--builddir', action='store', help='relative path to CCPP build directory', required=False, default=None) -parser.add_argument('--suffix', action='store', help='suffix to be added to the name of static api module', required=False, default='') +parser.add_argument('--namespace', action='store', help='namespace suffix to be added to the name of static api module', required=False, default='') # BASEDIR is the current directory where this script is executed BASEDIR = os.getcwd() @@ -59,8 +59,8 @@ def parse_arguments(): else: sdfs = None builddir = args.builddir - suffix = args.suffix - return (success, configfile, clean, verbose, debug, sdfs, builddir, suffix) + namespace = args.namespace + return (success, configfile, clean, verbose, debug, sdfs, builddir, namespace) def import_config(configfile, builddir): """Import the configuration from a given configuration file""" @@ -132,10 +132,14 @@ def setup_logging(verbose): logging.info('Logging level set to INFO') return success -def clean_files(config): +def clean_files(config, namespace): """Clean files created by ccpp_prebuild.py""" success = True logging.info('Performing clean ....') + if namespace: + static_api_file = '{api}.F90'.format(api=CCPP_STATIC_API_MODULE+'_'+namespace) + else: + static_api_file = '{api}.F90'.format(api=CCPP_STATIC_API_MODULE) # Create list of files to remove, use wildcards where necessary files_to_remove = [ config['typedefs_makefile'], @@ -150,7 +154,7 @@ def clean_files(config): config['html_vartable_file'], config['latex_vartable_file'], os.path.join(config['caps_dir'], 'ccpp_*_cap.F90'), - os.path.join(config['static_api_dir'], '{api}.F90'.format(api=CCPP_STATIC_API_MODULE)), + os.path.join(config['static_api_dir'], static_api_file), config['static_api_sourcefile'], ] # Not very pythonic, but the easiest way w/o importing another Python module @@ -516,7 +520,7 @@ def generate_suite_and_group_caps(suites, metadata_request, metadata_define, arg success = False return (success, suite_and_group_caps) -def generate_static_api(suites, static_api_dir, suffix): +def generate_static_api(suites, static_api_dir, namespace): """Generate static API for given suite(s)""" success = True # Change to caps directory, create if necessary @@ -524,11 +528,11 @@ def generate_static_api(suites, static_api_dir, suffix): os.makedirs(static_api_dir) os.chdir(static_api_dir) api = API(suites=suites, directory=static_api_dir) - if suffix: + if namespace: base = os.path.splitext(os.path.basename(api.filename))[0] logging.info('Static API file name is ''{}'''.format(api.filename)) - api.filename = base+'_'+suffix+'.F90' - api.module = base+'_'+suffix + api.filename = base+'_'+namespace+'.F90' + api.module = base+'_'+namespace logging.info('Static API file name is changed to ''{}'''.format(api.filename)) logging.info('Generating static API {0} in {1} ...'.format(api.filename, static_api_dir)) api.write() @@ -688,7 +692,7 @@ def generate_caps_makefile(caps, caps_makefile, caps_cmakefile, caps_sourcefile, def main(): """Main routine that handles the CCPP prebuild for different host models.""" # Parse command line arguments - (success, configfile, clean, verbose, debug, sdfs, builddir, suffix) = parse_arguments() + (success, configfile, clean, verbose, debug, sdfs, builddir, namespace) = parse_arguments() if not success: raise Exception('Call to parse_arguments failed.') @@ -702,7 +706,7 @@ def main(): # Perform clean if requested, then exit if clean: - success = clean_files(config) + success = clean_files(config, namespace) logging.info('CCPP prebuild clean completed successfully, exiting.') sys.exit(0) @@ -782,7 +786,7 @@ def main(): if not success: raise Exception('Call to generate_suite_and_group_caps failed.') - (success, api) = generate_static_api(suites, config['static_api_dir'], suffix) + (success, api) = generate_static_api(suites, config['static_api_dir'], namespace) if not success: raise Exception('Call to generate_static_api failed.') From 5c213062ca95a1fa7ca05fa1999dd5e218363a80 Mon Sep 17 00:00:00 2001 From: Dom Heinzeller Date: Sat, 16 Apr 2022 10:51:38 -0600 Subject: [PATCH 09/11] Update CCPP error code variable in stub/stub.meta --- stub/stub.meta | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/stub/stub.meta b/stub/stub.meta index 29bba80a..3cc30d59 100644 --- a/stub/stub.meta +++ b/stub/stub.meta @@ -16,9 +16,9 @@ kind = len=* intent = out [errflg] - standard_name = ccpp_error_flag - long_name = error flag for error handling in CCPP - units = flag + standard_name = ccpp_error_code + long_name = error code for error handling in CCPP + units = 1 dimensions = () type = integer intent = out @@ -36,9 +36,9 @@ kind = len=* intent = out [errflg] - standard_name = ccpp_error_flag - long_name = error flag for error handling in CCPP - units = flag + standard_name = ccpp_error_code + long_name = error code for error handling in CCPP + units = 1 dimensions = () type = integer intent = out From f694a99b60b3493f56e0fa0bdf12fe5bdc9163dc Mon Sep 17 00:00:00 2001 From: Dom Heinzeller Date: Thu, 9 Jun 2022 07:37:05 -0600 Subject: [PATCH 10/11] Update scripts/mkstatic.py --- scripts/mkstatic.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/mkstatic.py b/scripts/mkstatic.py index a95f9e63..2722388e 100755 --- a/scripts/mkstatic.py +++ b/scripts/mkstatic.py @@ -473,7 +473,7 @@ def write_includefile(self, source_filename, type): set(API \"{filename}\") """.format(filename=os.path.abspath(os.path.join(self.directory,self.filename))) else: - logging.error('Encountereed unknown type of file "{type}" when writing include file for static API'.format(type=type)) + logging.error('Encountered unknown type of file "{type}" when writing include file for static API'.format(type=type)) success = False return From e1075421ccde907a1dab2a20be0a19ef42968e02 Mon Sep 17 00:00:00 2001 From: Dom Heinzeller Date: Thu, 9 Jun 2022 07:37:25 -0600 Subject: [PATCH 11/11] Update scripts/metadata_parser.py --- scripts/metadata_parser.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/metadata_parser.py b/scripts/metadata_parser.py index 11d93288..00a0acd7 100755 --- a/scripts/metadata_parser.py +++ b/scripts/metadata_parser.py @@ -52,7 +52,7 @@ ), CCPP_ERROR_CODE_VARIABLE : Var(local_name = 'ierr', standard_name = CCPP_ERROR_CODE_VARIABLE, - long_name = 'error flag for error handling in CCPP', + long_name = 'error code for error handling in CCPP', units = '1', type = 'integer', dimensions = [],