From 016267eccfee0c80bd5f8ea06be4f3782cec315e Mon Sep 17 00:00:00 2001 From: Jim Edwards Date: Mon, 25 Apr 2022 16:08:30 -0600 Subject: [PATCH 01/17] cmake build working on cheyenne --- tools/mksurfdata_esmf/cmake/FindESMF.cmake | 130 +++++++ tools/mksurfdata_esmf/cmake/FindNetCDF.cmake | 347 ++++++++++++++++++ tools/mksurfdata_esmf/cmake/FindPnetCDF.cmake | 68 ++++ tools/mksurfdata_esmf/src/CMakeLists.txt | 38 +- 4 files changed, 561 insertions(+), 22 deletions(-) create mode 100644 tools/mksurfdata_esmf/cmake/FindESMF.cmake create mode 100644 tools/mksurfdata_esmf/cmake/FindNetCDF.cmake create mode 100644 tools/mksurfdata_esmf/cmake/FindPnetCDF.cmake diff --git a/tools/mksurfdata_esmf/cmake/FindESMF.cmake b/tools/mksurfdata_esmf/cmake/FindESMF.cmake new file mode 100644 index 0000000000..e67e45c489 --- /dev/null +++ b/tools/mksurfdata_esmf/cmake/FindESMF.cmake @@ -0,0 +1,130 @@ +# - Try to find ESMF +# +# Requires setting ESMFMKFILE to the filepath of esmf.mk. If this is NOT set, +# then ESMF_FOUND will always be FALSE. If ESMFMKFILE exists, then ESMF_FOUND=TRUE +# and all ESMF makefile variables will be set in the global scope. Optionally, +# set ESMF_MKGLOBALS to a string list to filter makefile variables. For example, +# to globally scope only ESMF_LIBSDIR and ESMF_APPSDIR variables, use this CMake +# command in CMakeLists.txt: +# +# set(ESMF_MKGLOBALS "LIBSDIR" "APPSDIR") + + +# Add the ESMFMKFILE path to the cache if defined as system env variable +if (DEFINED ENV{ESMFMKFILE} AND NOT DEFINED ESMFMKFILE) + set(ESMFMKFILE $ENV{ESMFMKFILE} CACHE FILEPATH "Path to ESMF mk file") +endif () + +# Found the mk file and ESMF exists on the system +if (EXISTS ${ESMFMKFILE}) + set(ESMF_FOUND TRUE CACHE BOOL "ESMF mk file found" FORCE) + # Did not find the ESMF mk file +else() + set(ESMF_FOUND FALSE CACHE BOOL "ESMF mk file NOT found" FORCE) + # Best to warn users that without the mk file there is no way to find ESMF + if (NOT DEFINED ESMFMKFILE) + message(FATAL_ERROR "ESMFMKFILE not defined. This is the path to esmf.mk file. \ +Without this filepath, ESMF_FOUND will always be FALSE.") + endif () +endif() + +# Only parse the mk file if it is found +if (ESMF_FOUND) + # Read the mk file + file(STRINGS "${ESMFMKFILE}" esmfmkfile_contents) + # Parse each line in the mk file + foreach(str ${esmfmkfile_contents}) + # Only consider uncommented lines + string(REGEX MATCH "^[^#]" def ${str}) + # Line is not commented + if (def) + # Extract the variable name + string(REGEX MATCH "^[^=]+" esmf_varname ${str}) + # Extract the variable's value + string(REGEX MATCH "=.+$" esmf_vardef ${str}) + # Only for variables with a defined value + if (esmf_vardef) + # Get rid of the assignment string + string(SUBSTRING ${esmf_vardef} 1 -1 esmf_vardef) + # Remove whitespace + string(STRIP ${esmf_vardef} esmf_vardef) + # A string or single-valued list + if(NOT DEFINED ESMF_MKGLOBALS) + # Set in global scope + set(${esmf_varname} ${esmf_vardef}) + # Don't display by default in GUI + mark_as_advanced(esmf_varname) + else() # Need to filter global promotion + foreach(m ${ESMF_MKGLOBALS}) + string(FIND ${esmf_varname} ${m} match) + # Found the string + if(NOT ${match} EQUAL -1) + # Promote to global scope + set(${esmf_varname} ${esmf_vardef}) + # Don't display by default in the GUI + mark_as_advanced (esmf_varname) + # No need to search for the current string filter + break() + endif() + endforeach() + endif() + endif() + endif() + endforeach() + + # Construct ESMF_VERSION from ESMF_VERSION_STRING_GIT + if(ESMF_FOUND) + # ESMF_VERSION_MAJOR and ESMF_VERSION_MINOR are defined in ESMFMKFILE + set(ESMF_VERSION 0) + set(ESMF_VERSION_PATCH ${ESMF_VERSION_REVISION}) + set(ESMF_BETA_RELEASE FALSE) + if(ESMF_VERSION_BETASNAPSHOT MATCHES "^('T')$") + set(ESMF_BETA_RELEASE TRUE) + string(REGEX REPLACE ".*beta_snapshot_*\([0-9]*\).*" "\\1" ESMF_BETA_SNAPSHOT "${ESMF_VERSION_STRING_GIT}") + endif() + set(ESMF_VERSION "${ESMF_VERSION_MAJOR}.${ESMF_VERSION_MINOR}.${ESMF_VERSION_PATCH}") + endif() + + separate_arguments(ESMF_F90COMPILEPATHS NATIVE_COMMAND ${ESMF_F90COMPILEPATHS}) + foreach (ITEM ${ESMF_F90COMPILEPATHS}) + string(REGEX REPLACE "^-I" "" ITEM "${ITEM}") + list(APPEND tmp ${ITEM}) + endforeach() + set(ESMF_F90COMPILEPATHS ${tmp}) + + add_library(esmf UNKNOWN IMPORTED) + # Look for static library, if not found try dynamic library + find_library(esmf_lib NAMES libesmf.a PATHS ${ESMF_LIBSDIR}) + if(esmf_lib MATCHES "esmf_lib-NOTFOUND") + message(STATUS "Static ESMF library not found, searching for dynamic library instead") + find_library(esmf_lib NAMES esmf_fullylinked PATHS ${ESMF_LIBSDIR}) + if(esmf_lib MATCHES "esmf_lib-NOTFOUND") + message(FATAL_ERROR "Neither the dynamic nor the static ESMF library was found") + endif() + set(ESMF_INTERFACE_LINK_LIBRARIES "") + else() + # When linking the static library, also need the ESMF linker flags; strip any leading/trailing whitespaces + string(STRIP "${ESMF_F90ESMFLINKRPATHS} ${ESMF_F90ESMFLINKPATHS} ${ESMF_F90LINKPATHS} ${ESMF_F90LINKLIBS} ${ESMF_F90LINKOPTS}" ESMF_INTERFACE_LINK_LIBRARIES) + endif() + + message(STATUS "Found ESMF library: ${esmf_lib}") + if(ESMF_BETA_RELEASE) + message(STATUS "Detected ESMF Beta snapshot ${ESMF_BETA_SNAPSHOT}") + endif() + + set_target_properties(esmf PROPERTIES + IMPORTED_LOCATION ${esmf_lib} + INTERFACE_INCLUDE_DIRECTORIES "${ESMF_F90COMPILEPATHS}" + INTERFACE_LINK_LIBRARIES "${ESMF_INTERFACE_LINK_LIBRARIES}") + +endif() + +## Finalize find_package +include(FindPackageHandleStandardArgs) + +find_package_handle_standard_args( ${CMAKE_FIND_PACKAGE_NAME} + REQUIRED_VARS ESMF_LIBSDIR + ESMF_INTERFACE_LINK_LIBRARIES + ESMF_F90COMPILEPATHS + VERSION_VAR ESMF_VERSION + HANDLE_COMPONENTS ) \ No newline at end of file diff --git a/tools/mksurfdata_esmf/cmake/FindNetCDF.cmake b/tools/mksurfdata_esmf/cmake/FindNetCDF.cmake new file mode 100644 index 0000000000..e335b95bd5 --- /dev/null +++ b/tools/mksurfdata_esmf/cmake/FindNetCDF.cmake @@ -0,0 +1,347 @@ +# (C) Copyright 2011- ECMWF. +# +# This software is licensed under the terms of the Apache Licence Version 2.0 +# which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. +# In applying this licence, ECMWF does not waive the privileges and immunities +# granted to it by virtue of its status as an intergovernmental organisation nor +# does it submit to any jurisdiction. + +# Try to find NetCDF includes and library. +# Supports static and shared libaries and allows each component to be found in sepearte prefixes. +# +# This module defines +# +# - NetCDF_FOUND - System has NetCDF +# - NetCDF_INCLUDE_DIRS - the NetCDF include directories +# - NetCDF_VERSION - the version of NetCDF +# - NetCDF_CONFIG_EXECUTABLE - the netcdf-config executable if found +# - NetCDF_PARALLEL - Boolean True if NetCDF4 has parallel IO support via hdf5 and/or pnetcdf +# - NetCDF_HAS_PNETCDF - Boolean True if NetCDF4 has pnetcdf support +# +# Deprecated Defines +# - NetCDF_LIBRARIES - [Deprecated] Use NetCDF::NetCDF_ targets instead. +# +# +# Following components are available: +# +# - C - C interface to NetCDF (netcdf) +# - CXX - CXX4 interface to NetCDF (netcdf_c++4) +# - Fortran - Fortran interface to NetCDF (netcdff) +# +# For each component the following are defined: +# +# - NetCDF__FOUND - whether the component is found +# - NetCDF__LIBRARIES - the libraries for the component +# - NetCDF__LIBRARY_SHARED - Boolean is true if libraries for component are shared +# - NetCDF__INCLUDE_DIRS - the include directories for specified component +# - NetCDF::NetCDF_ - target of component to be used with target_link_libraries() +# +# The following paths will be searched in order if set in CMake (first priority) or environment (second priority) +# +# - NetCDF_ROOT - root of NetCDF installation +# - NetCDF_PATH - root of NetCDF installation +# +# The search process begins with locating NetCDF Include headers. If these are in a non-standard location, +# set one of the following CMake or environment variables to point to the location: +# +# - NetCDF_INCLUDE_DIR or NetCDF_${comp}_INCLUDE_DIR +# - NetCDF_INCLUDE_DIRS or NetCDF_${comp}_INCLUDE_DIR +# +# Notes: +# +# - Use "NetCDF::NetCDF_" targets only. NetCDF_LIBRARIES exists for backwards compatibility and should not be used. +# - These targets have all the knowledge of include directories and library search directories, and a single +# call to target_link_libraries will provide all these transitive properties to your target. Normally all that is +# needed to build and link against NetCDF is, e.g.: +# target_link_libraries(my_c_tgt PUBLIC NetCDF::NetCDF_C) +# - "NetCDF" is always the preferred naming for this package, its targets, variables, and environment variables +# - For compatibility, some variables are also set/checked using alternate names NetCDF4, NETCDF, or NETCDF4 +# - Environments relying on these older environment variable names should move to using a "NetCDF_ROOT" environment variable +# - Preferred component capitalization follows the CMake LANGUAGES variables: i.e., C, Fortran, CXX +# - For compatibility, alternate capitalizations are supported but should not be used. +# - If no components are defined, all components will be searched +# + +list( APPEND _possible_components C CXX Fortran ) + +## Include names for each component +set( NetCDF_C_INCLUDE_NAME netcdf.h ) +set( NetCDF_CXX_INCLUDE_NAME netcdf ) +set( NetCDF_Fortran_INCLUDE_NAME netcdf.mod ) + +## Library names for each component +set( NetCDF_C_LIBRARY_NAME netcdf ) +set( NetCDF_CXX_LIBRARY_NAME netcdf_c++4 ) +set( NetCDF_Fortran_LIBRARY_NAME netcdff ) + +## Enumerate search components +foreach( _comp ${_possible_components} ) + string( TOUPPER "${_comp}" _COMP ) + set( _arg_${_COMP} ${_comp} ) + set( _name_${_COMP} ${_comp} ) +endforeach() + +set( _search_components C) +foreach( _comp ${${CMAKE_FIND_PACKAGE_NAME}_FIND_COMPONENTS} ) + string( TOUPPER "${_comp}" _COMP ) + set( _arg_${_COMP} ${_comp} ) + list( APPEND _search_components ${_name_${_COMP}} ) + if( NOT _name_${_COMP} ) + message(SEND_ERROR "Find${CMAKE_FIND_PACKAGE_NAME}: COMPONENT ${_comp} is not a valid component. Valid components: ${_possible_components}" ) + endif() +endforeach() +list( REMOVE_DUPLICATES _search_components ) + +## Search hints for finding include directories and libraries +foreach( _comp IN ITEMS "_" "_C_" "_Fortran_" "_CXX_" ) + foreach( _name IN ITEMS NetCDF4 NetCDF NETCDF4 NETCDF ) + foreach( _var IN ITEMS ROOT PATH ) + list(APPEND _search_hints ${${_name}${_comp}${_var}} $ENV{${_name}${_comp}${_var}} ) + list(APPEND _include_search_hints + ${${_name}${_comp}INCLUDE_DIR} $ENV{${_name}${_comp}INCLUDE_DIR} + ${${_name}${_comp}INCLUDE_DIRS} $ENV{${_name}${_comp}INCLUDE_DIRS} ) + endforeach() + endforeach() +endforeach() +#Old-school HPC module env variable names +foreach( _name IN ITEMS NetCDF4 NetCDF NETCDF4 NETCDF ) + foreach( _comp IN ITEMS "_C" "_Fortran" "_CXX" ) + list(APPEND _search_hints ${${_name}} $ENV{${_name}}) + list(APPEND _search_hints ${${_name}${_comp}} $ENV{${_name}${_comp}}) + endforeach() +endforeach() + +## Find headers for each component +set(NetCDF_INCLUDE_DIRS) +set(_new_search_components) +foreach( _comp IN LISTS _search_components ) + if(NOT ${PROJECT_NAME}_NetCDF_${_comp}_FOUND) + list(APPEND _new_search_components ${_comp}) + endif() + find_file(NetCDF_${_comp}_INCLUDE_FILE + NAMES ${NetCDF_${_comp}_INCLUDE_NAME} + DOC "NetCDF ${_comp} include directory" + HINTS ${_include_search_hints} ${_search_hints} + PATH_SUFFIXES include include/netcdf + ) + mark_as_advanced(NetCDF_${_comp}_INCLUDE_FILE) + message(DEBUG "NetCDF_${_comp}_INCLUDE_FILE: ${NetCDF_${_comp}_INCLUDE_FILE}") + if( NetCDF_${_comp}_INCLUDE_FILE ) + get_filename_component(NetCDF_${_comp}_INCLUDE_FILE ${NetCDF_${_comp}_INCLUDE_FILE} ABSOLUTE) + get_filename_component(NetCDF_${_comp}_INCLUDE_DIR ${NetCDF_${_comp}_INCLUDE_FILE} DIRECTORY) + list(APPEND NetCDF_INCLUDE_DIRS ${NetCDF_${_comp}_INCLUDE_DIR}) + endif() +endforeach() +if(NetCDF_INCLUDE_DIRS) + list(REMOVE_DUPLICATES NetCDF_INCLUDE_DIRS) +endif() +set(NetCDF_INCLUDE_DIRS "${NetCDF_INCLUDE_DIRS}" CACHE STRING "NetCDF Include directory paths" FORCE) + +## Find n*-config executables for search components +foreach( _comp IN LISTS _search_components ) + if( _comp MATCHES "^(C)$" ) + set(_conf "c") + elseif( _comp MATCHES "^(Fortran)$" ) + set(_conf "f") + elseif( _comp MATCHES "^(CXX)$" ) + set(_conf "cxx4") + endif() + find_program( NetCDF_${_comp}_CONFIG_EXECUTABLE + NAMES n${_conf}-config + HINTS ${NetCDF_INCLUDE_DIRS} ${_include_search_hints} ${_search_hints} + PATH_SUFFIXES bin Bin ../bin ../../bin + DOC "NetCDF n${_conf}-config helper" ) + message(DEBUG "NetCDF_${_comp}_CONFIG_EXECUTABLE: ${NetCDF_${_comp}_CONFIG_EXECUTABLE}") +endforeach() + +set(_C_libs_flag --libs) +set(_Fortran_libs_flag --flibs) +set(_CXX_libs_flag --libs) +set(_C_includes_flag --includedir) +set(_Fortran_includes_flag --includedir) +set(_CXX_includes_flag --includedir) +function(netcdf_config exec flag output_var) + set(${output_var} False PARENT_SCOPE) + if( exec ) + execute_process( COMMAND ${exec} ${flag} RESULT_VARIABLE _ret OUTPUT_VARIABLE _val) + if( _ret EQUAL 0 ) + string( STRIP ${_val} _val ) + set( ${output_var} ${_val} PARENT_SCOPE ) + endif() + endif() +endfunction() + +## Detect additional package properties +netcdf_config(${NetCDF_C_CONFIG_EXECUTABLE} --has-parallel4 _val) +if( NOT _val MATCHES "^(yes|no)$" ) + netcdf_config(${NetCDF_C_CONFIG_EXECUTABLE} --has-parallel _val) +endif() +if( _val MATCHES "^(yes)$" ) + set(NetCDF_PARALLEL TRUE CACHE STRING "NetCDF has parallel IO capability via pnetcdf or hdf5." FORCE) +else() + set(NetCDF_PARALLEL FALSE CACHE STRING "NetCDF has no parallel IO capability." FORCE) +endif() + +if(NetCDF_PARALLEL) + find_package(MPI REQUIRED) +endif() + +## Find libraries for each component +set( NetCDF_LIBRARIES ) +foreach( _comp IN LISTS _search_components ) + string( TOUPPER "${_comp}" _COMP ) + + find_library( NetCDF_${_comp}_LIBRARY + NAMES ${NetCDF_${_comp}_LIBRARY_NAME} + DOC "NetCDF ${_comp} library" + HINTS ${NetCDF_${_comp}_INCLUDE_DIRS} ${_search_hints} + PATH_SUFFIXES lib64 lib ../lib64 ../lib ../../lib64 ../../lib ) + mark_as_advanced( NetCDF_${_comp}_LIBRARY ) + get_filename_component(NetCDF_${_comp}_LIBRARY ${NetCDF_${_comp}_LIBRARY} ABSOLUTE) + set(NetCDF_${_comp}_LIBRARY ${NetCDF_${_comp}_LIBRARY} CACHE STRING "NetCDF ${_comp} library" FORCE) + message(DEBUG "NetCDF_${_comp}_LIBRARY: ${NetCDF_${_comp}_LIBRARY}") + + if( NetCDF_${_comp}_LIBRARY ) + if( NetCDF_${_comp}_LIBRARY MATCHES ".a$" ) + set( NetCDF_${_comp}_LIBRARY_SHARED FALSE ) + set( _library_type STATIC) + else() + list( APPEND NetCDF_LIBRARIES ${NetCDF_${_comp}_LIBRARY} ) + set( NetCDF_${_comp}_LIBRARY_SHARED TRUE ) + set( _library_type SHARED) + endif() + endif() + + #Use nc-config to set per-component LIBRARIES variable if possible + netcdf_config( ${NetCDF_${_comp}_CONFIG_EXECUTABLE} ${_${_comp}_libs_flag} _val ) + if( _val ) + set( NetCDF_${_comp}_LIBRARIES ${_val} ) + if(NOT NetCDF_${_comp}_LIBRARY_SHARED AND NOT NetCDF_${_comp}_FOUND) #Static targets should use nc_config to get a proper link line with all necessary static targets. + list( APPEND NetCDF_LIBRARIES ${NetCDF_${_comp}_LIBRARIES} ) + endif() + else() + set( NetCDF_${_comp}_LIBRARIES ${NetCDF_${_comp}_LIBRARY} ) + if(NOT NetCDF_${_comp}_LIBRARY_SHARED) + message(SEND_ERROR "Unable to properly find NetCDF. Found static libraries at: ${NetCDF_${_comp}_LIBRARY} but could not run nc-config: ${NetCDF_CONFIG_EXECUTABLE}") + endif() + endif() + + #Use nc-config to set per-component INCLUDE_DIRS variable if possible + netcdf_config( ${NetCDF_${_comp}_CONFIG_EXECUTABLE} ${_${_comp}_includes_flag} _val ) + if( _val ) + string( REPLACE " " ";" _val ${_val} ) + set( NetCDF_${_comp}_INCLUDE_DIRS ${_val} ) + else() + set( NetCDF_${_comp}_INCLUDE_DIRS ${NetCDF_${_comp}_INCLUDE_DIR} ) + endif() + + if( NetCDF_${_comp}_LIBRARIES AND NetCDF_${_comp}_INCLUDE_DIRS ) + set( ${CMAKE_FIND_PACKAGE_NAME}_${_arg_${_COMP}}_FOUND TRUE ) + if (NOT TARGET NetCDF::NetCDF_${_comp}) + add_library(NetCDF::NetCDF_${_comp} ${_library_type} IMPORTED) + set_target_properties(NetCDF::NetCDF_${_comp} PROPERTIES + IMPORTED_LOCATION ${NetCDF_${_comp}_LIBRARY} + INTERFACE_INCLUDE_DIRECTORIES "${NetCDF_${_comp}_INCLUDE_DIRS}" + INTERFACE_LINK_LIBRARIES ${NetCDF_${_comp}_LIBRARIES} ) + if( NOT _comp MATCHES "^(C)$" ) + target_link_libraries(NetCDF::NetCDF_${_comp} INTERFACE NetCDF::NetCDF_C) + endif() + if(MPI_${_comp}_FOUND) + target_link_libraries(NetCDF::NetCDF_${_comp} INTERFACE MPI::MPI_${_comp}) + endif() + endif() + endif() +endforeach() +if(NetCDF_LIBRARIES AND NetCDF_${_comp}_LIBRARY_SHARED) + list(REMOVE_DUPLICATES NetCDF_LIBRARIES) +endif() +set(NetCDF_LIBRARIES "${NetCDF_LIBRARIES}" CACHE STRING "NetCDF library targets" FORCE) + +## Find version via netcdf-config if possible +if (NetCDF_INCLUDE_DIRS) + if( NetCDF_C_CONFIG_EXECUTABLE ) + netcdf_config( ${NetCDF_C_CONFIG_EXECUTABLE} --version _vers ) + if( _vers ) + string(REGEX REPLACE ".* ((([0-9]+)\\.)+([0-9]+)).*" "\\1" NetCDF_VERSION "${_vers}" ) + endif() + else() + foreach( _dir IN LISTS NetCDF_INCLUDE_DIRS) + if( EXISTS "${_dir}/netcdf_meta.h" ) + file(STRINGS "${_dir}/netcdf_meta.h" _netcdf_version_lines + REGEX "#define[ \t]+NC_VERSION_(MAJOR|MINOR|PATCH|NOTE)") + string(REGEX REPLACE ".*NC_VERSION_MAJOR *\([0-9]*\).*" "\\1" _netcdf_version_major "${_netcdf_version_lines}") + string(REGEX REPLACE ".*NC_VERSION_MINOR *\([0-9]*\).*" "\\1" _netcdf_version_minor "${_netcdf_version_lines}") + string(REGEX REPLACE ".*NC_VERSION_PATCH *\([0-9]*\).*" "\\1" _netcdf_version_patch "${_netcdf_version_lines}") + string(REGEX REPLACE ".*NC_VERSION_NOTE *\"\([^\"]*\)\".*" "\\1" _netcdf_version_note "${_netcdf_version_lines}") + set(NetCDF_VERSION "${_netcdf_version_major}.${_netcdf_version_minor}.${_netcdf_version_patch}${_netcdf_version_note}") + unset(_netcdf_version_major) + unset(_netcdf_version_minor) + unset(_netcdf_version_patch) + unset(_netcdf_version_note) + unset(_netcdf_version_lines) + endif() + endforeach() + endif() +endif () + +## Finalize find_package +include(FindPackageHandleStandardArgs) + +if(NOT NetCDF_FOUND OR _new_search_components) + find_package_handle_standard_args( ${CMAKE_FIND_PACKAGE_NAME} + REQUIRED_VARS NetCDF_INCLUDE_DIRS NetCDF_LIBRARIES + VERSION_VAR NetCDF_VERSION + HANDLE_COMPONENTS ) +endif() + +foreach( _comp IN LISTS _search_components ) + if( NetCDF_${_comp}_FOUND ) + #Record found components to avoid duplication in NetCDF_LIBRARIES for static libraries + set(NetCDF_${_comp}_FOUND ${NetCDF_${_comp}_FOUND} CACHE BOOL "NetCDF ${_comp} Found" FORCE) + #Set a per-package, per-component found variable to communicate between multiple calls to find_package() + set(${PROJECT_NAME}_NetCDF_${_comp}_FOUND True) + endif() +endforeach() + +if( ${CMAKE_FIND_PACKAGE_NAME}_FOUND AND NOT ${CMAKE_FIND_PACKAGE_NAME}_FIND_QUIETLY AND _new_search_components) + message( STATUS "Find${CMAKE_FIND_PACKAGE_NAME} defines targets:" ) + message( STATUS " - NetCDF_VERSION [${NetCDF_VERSION}]") + message( STATUS " - NetCDF_PARALLEL [${NetCDF_PARALLEL}]") + foreach( _comp IN LISTS _new_search_components ) + string( TOUPPER "${_comp}" _COMP ) + message( STATUS " - NetCDF_${_comp}_CONFIG_EXECUTABLE [${NetCDF_${_comp}_CONFIG_EXECUTABLE}]") + if( ${CMAKE_FIND_PACKAGE_NAME}_${_arg_${_COMP}}_FOUND ) + get_filename_component(_root ${NetCDF_${_comp}_INCLUDE_DIR}/.. ABSOLUTE) + if( NetCDF_${_comp}_LIBRARY_SHARED ) + message( STATUS " - NetCDF::NetCDF_${_comp} [SHARED] [Root: ${_root}] Lib: ${NetCDF_${_comp}_LIBRARY} ") + else() + message( STATUS " - NetCDF::NetCDF_${_comp} [STATIC] [Root: ${_root}] Lib: ${NetCDF_${_comp}_LIBRARY} ") + endif() + endif() + endforeach() +endif() + +foreach( _prefix NetCDF NetCDF4 NETCDF NETCDF4 ${CMAKE_FIND_PACKAGE_NAME} ) + set( ${_prefix}_INCLUDE_DIRS ${NetCDF_INCLUDE_DIRS} ) + set( ${_prefix}_LIBRARIES ${NetCDF_LIBRARIES}) + set( ${_prefix}_VERSION ${NetCDF_VERSION} ) + set( ${_prefix}_FOUND ${${CMAKE_FIND_PACKAGE_NAME}_FOUND} ) + set( ${_prefix}_CONFIG_EXECUTABLE ${NetCDF_CONFIG_EXECUTABLE} ) + set( ${_prefix}_PARALLEL ${NetCDF_PARALLEL} ) + + foreach( _comp ${_search_components} ) + string( TOUPPER "${_comp}" _COMP ) + set( _arg_comp ${_arg_${_COMP}} ) + set( ${_prefix}_${_comp}_FOUND ${${CMAKE_FIND_PACKAGE_NAME}_${_arg_comp}_FOUND} ) + set( ${_prefix}_${_COMP}_FOUND ${${CMAKE_FIND_PACKAGE_NAME}_${_arg_comp}_FOUND} ) + set( ${_prefix}_${_arg_comp}_FOUND ${${CMAKE_FIND_PACKAGE_NAME}_${_arg_comp}_FOUND} ) + + set( ${_prefix}_${_comp}_LIBRARIES ${NetCDF_${_comp}_LIBRARIES} ) + set( ${_prefix}_${_COMP}_LIBRARIES ${NetCDF_${_comp}_LIBRARIES} ) + set( ${_prefix}_${_arg_comp}_LIBRARIES ${NetCDF_${_comp}_LIBRARIES} ) + + set( ${_prefix}_${_comp}_INCLUDE_DIRS ${NetCDF_${_comp}_INCLUDE_DIRS} ) + set( ${_prefix}_${_COMP}_INCLUDE_DIRS ${NetCDF_${_comp}_INCLUDE_DIRS} ) + set( ${_prefix}_${_arg_comp}_INCLUDE_DIRS ${NetCDF_${_comp}_INCLUDE_DIRS} ) + endforeach() +endforeach() \ No newline at end of file diff --git a/tools/mksurfdata_esmf/cmake/FindPnetCDF.cmake b/tools/mksurfdata_esmf/cmake/FindPnetCDF.cmake new file mode 100644 index 0000000000..b87d245cd1 --- /dev/null +++ b/tools/mksurfdata_esmf/cmake/FindPnetCDF.cmake @@ -0,0 +1,68 @@ +# - Try to find PnetCDF +# +# This can be controlled by setting the PnetCDF_PATH (or, equivalently, the +# PNETCDF environment variable), or PnetCDF__PATH CMake variables, where +# is the COMPONENT language one needs. +# +# Once done, this will define: +# +# PnetCDF__FOUND (BOOL) - system has PnetCDF +# PnetCDF__IS_SHARED (BOOL) - whether library is shared/dynamic +# PnetCDF__INCLUDE_DIR (PATH) - Location of the C header file +# PnetCDF__INCLUDE_DIRS (LIST) - the PnetCDF include directories +# PnetCDF__LIBRARY (FILE) - Path to the C library file +# PnetCDF__LIBRARIES (LIST) - link these to use PnetCDF +# +# The available COMPONENTS are: C, Fortran +# If no components are specified, it assumes only C +include (LibFind) +include (LibCheck) + +# Define PnetCDF C Component +define_package_component (PnetCDF DEFAULT + COMPONENT C + INCLUDE_NAMES pnetcdf.h + LIBRARY_NAMES pnetcdf) + +# Define PnetCDF Fortran Component +define_package_component (PnetCDF + COMPONENT Fortran + INCLUDE_NAMES pnetcdf.mod pnetcdf.inc + LIBRARY_NAMES pnetcdf) + +# Search for list of valid components requested +find_valid_components (PnetCDF) + +#============================================================================== +# SEARCH FOR VALIDATED COMPONENTS +foreach (PNCDFcomp IN LISTS PnetCDF_FIND_VALID_COMPONENTS) + + # If not found already, search... + if (NOT PnetCDF_${PNCDFcomp}_FOUND) + + # Manually add the MPI include and library dirs to search paths + # and search for the package component + if (MPI_${PNCDFcomp}_FOUND) + initialize_paths (PnetCDF_${PNCDFcomp}_PATHS + INCLUDE_DIRECTORIES ${MPI_${PNCDFcomp}_INCLUDE_PATH} + LIBRARIES ${MPI_${PNCDFcomp}_LIBRARIES}) + find_package_component(PnetCDF COMPONENT ${PNCDFcomp} + PATHS ${PnetCDF_${PNCDFcomp}_PATHS}) + else () + find_package_component(PnetCDF COMPONENT ${PNCDFcomp}) + endif () + + # Continue only if component found + if (PnetCDF_${PNCDFcomp}_FOUND) + + # Check version + check_version (PnetCDF + NAME "pnetcdf.h" + HINTS ${PnetCDF_${PNCDFcomp}_INCLUDE_DIR} + MACRO_REGEX "PNETCDF_VERSION_") + + endif () + + endif () + +endforeach () diff --git a/tools/mksurfdata_esmf/src/CMakeLists.txt b/tools/mksurfdata_esmf/src/CMakeLists.txt index 597dadaf9e..be8da28083 100644 --- a/tools/mksurfdata_esmf/src/CMakeLists.txt +++ b/tools/mksurfdata_esmf/src/CMakeLists.txt @@ -1,20 +1,9 @@ cmake_minimum_required(VERSION 3.10) project(mksurfdata Fortran) -set (ESMFMKFILE /glade/work/oehmke/ESMF/scalable_mesh_from_file/lib/libg/Linux.intel.64.mpt.default/esmf.mk) - -file(STRINGS ${ESMFMKFILE} esmf_mk_text) -foreach(line ${esmf_mk_text}) - string(REGEX REPLACE "^[ ]+" "" line ${line}) # strip leading spaces - if (line MATCHES "^ESMF_*") # process only line starting with ESMF_ - string(REGEX MATCH "^ESMF_[^=]+" esmf_name ${line}) - string(REPLACE "${esmf_name}=" "" emsf_value ${line}) - set(${esmf_name} "${emsf_value}") - endif() -endforeach() -string(REPLACE "-I" "" ESMF_F90COMPILEPATHS ${ESMF_F90COMPILEPATHS}) -string(REPLACE " " ";" ESMF_F90COMPILEPATHS ${ESMF_F90COMPILEPATHS}) -message("ESMF_F90COMPILEPATHS: ${ESMF_F90COMPILEPATHS}") +list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../cmake") +find_package(NetCDF 4.8.1 REQUIRED Fortran) +find_package(ESMF 8.3.0 REQUIRED ) set(SRCFILES mkagfirepkmonthMod.F90 mkchecksMod.F90 @@ -52,18 +41,23 @@ set(SRCFILES mkagfirepkmonthMod.F90 shr_const_mod.F90 shr_kind_mod.F90 shr_string_mod.F90 - shr_sys_mod.F90) - -add_library(mksurfdata ${SRCFILES}) + shr_sys_mod.F90 + mksurfdata.F90) add_compile_definitions(PIO2) -message("CMAKE_CURRENT_BINARY_DIR is ${CMAKE_CURRENT_BINARY_DIR}") -message("PROJECT_BINARY_DIR is ${PROJECT_BINARY_DIR}") +add_library(pnetcdf STATIC IMPORTED) +set_property(TARGET pnetcdf PROPERTY IMPORTED_LOCATION $ENV{PNETCDF}) +add_library(pioc STATIC IMPORTED) +add_library(piof STATIC IMPORTED) +set_property(TARGET pioc PROPERTY IMPORTED_LOCATION $ENV{PIO}/lib/libpioc.a) +set_property(TARGET piof PROPERTY IMPORTED_LOCATION $ENV{PIO}/lib/libpiof.a) +add_executable(mksurfdata ${SRCFILES}) +target_link_libraries(mksurfdata PRIVATE esmf pioc piof) target_include_directories (mksurfdata PRIVATE ${ESMF_F90COMPILEPATHS}) -target_include_directories (mksurfdata PRIVATE /glade/work/jedwards/tools/pio/2.5.5/intel/19.1.1/mpt/2.22/include) -target_include_directories (mksurfdata PRIVATE /glade/u/apps/ch/opt/pnetcdf/1.12.2/mpt/2.22/intel/19.1.1//include) -target_include_directories (mksurfdata PRIVATE /glade/u/apps/ch/opt/netcdf-mpi/4.8.1/mpt/2.22/intel/19.1.1//include) +target_include_directories (mksurfdata PRIVATE ${PIO}/include) +target_include_directories (mksurfdata PRIVATE ${PNETCDF}/include) +target_include_directories (mksurfdata PRIVATE ${NETCDF}/include) install(TARGETS mksurfdata) From 50a1c5fce0fc678ea930905c8c094822a16f6690 Mon Sep 17 00:00:00 2001 From: Jim Edwards Date: Mon, 25 Apr 2022 16:12:36 -0600 Subject: [PATCH 02/17] remove unused files --- tools/mksurfdata_esmf/cmake/FindPnetCDF.cmake | 68 ------------------- tools/mksurfdata_esmf/src/Makefile | 67 ------------------ 2 files changed, 135 deletions(-) delete mode 100644 tools/mksurfdata_esmf/cmake/FindPnetCDF.cmake delete mode 100644 tools/mksurfdata_esmf/src/Makefile diff --git a/tools/mksurfdata_esmf/cmake/FindPnetCDF.cmake b/tools/mksurfdata_esmf/cmake/FindPnetCDF.cmake deleted file mode 100644 index b87d245cd1..0000000000 --- a/tools/mksurfdata_esmf/cmake/FindPnetCDF.cmake +++ /dev/null @@ -1,68 +0,0 @@ -# - Try to find PnetCDF -# -# This can be controlled by setting the PnetCDF_PATH (or, equivalently, the -# PNETCDF environment variable), or PnetCDF__PATH CMake variables, where -# is the COMPONENT language one needs. -# -# Once done, this will define: -# -# PnetCDF__FOUND (BOOL) - system has PnetCDF -# PnetCDF__IS_SHARED (BOOL) - whether library is shared/dynamic -# PnetCDF__INCLUDE_DIR (PATH) - Location of the C header file -# PnetCDF__INCLUDE_DIRS (LIST) - the PnetCDF include directories -# PnetCDF__LIBRARY (FILE) - Path to the C library file -# PnetCDF__LIBRARIES (LIST) - link these to use PnetCDF -# -# The available COMPONENTS are: C, Fortran -# If no components are specified, it assumes only C -include (LibFind) -include (LibCheck) - -# Define PnetCDF C Component -define_package_component (PnetCDF DEFAULT - COMPONENT C - INCLUDE_NAMES pnetcdf.h - LIBRARY_NAMES pnetcdf) - -# Define PnetCDF Fortran Component -define_package_component (PnetCDF - COMPONENT Fortran - INCLUDE_NAMES pnetcdf.mod pnetcdf.inc - LIBRARY_NAMES pnetcdf) - -# Search for list of valid components requested -find_valid_components (PnetCDF) - -#============================================================================== -# SEARCH FOR VALIDATED COMPONENTS -foreach (PNCDFcomp IN LISTS PnetCDF_FIND_VALID_COMPONENTS) - - # If not found already, search... - if (NOT PnetCDF_${PNCDFcomp}_FOUND) - - # Manually add the MPI include and library dirs to search paths - # and search for the package component - if (MPI_${PNCDFcomp}_FOUND) - initialize_paths (PnetCDF_${PNCDFcomp}_PATHS - INCLUDE_DIRECTORIES ${MPI_${PNCDFcomp}_INCLUDE_PATH} - LIBRARIES ${MPI_${PNCDFcomp}_LIBRARIES}) - find_package_component(PnetCDF COMPONENT ${PNCDFcomp} - PATHS ${PnetCDF_${PNCDFcomp}_PATHS}) - else () - find_package_component(PnetCDF COMPONENT ${PNCDFcomp}) - endif () - - # Continue only if component found - if (PnetCDF_${PNCDFcomp}_FOUND) - - # Check version - check_version (PnetCDF - NAME "pnetcdf.h" - HINTS ${PnetCDF_${PNCDFcomp}_INCLUDE_DIR} - MACRO_REGEX "PNETCDF_VERSION_") - - endif () - - endif () - -endforeach () diff --git a/tools/mksurfdata_esmf/src/Makefile b/tools/mksurfdata_esmf/src/Makefile deleted file mode 100644 index dc3570168d..0000000000 --- a/tools/mksurfdata_esmf/src/Makefile +++ /dev/null @@ -1,67 +0,0 @@ -# GNU Makefile template for user ESMF application - -################################################################################ -################################################################################ -## This Makefile must be able to find the "esmf.mk" Makefile fragment in the ## -## 'include' line below. Following the ESMF User's Guide, a complete ESMF ## -## installation should ensure that a single environment variable "ESMFMKFILE" ## -## is made available on the system. This variable should point to the ## -## "esmf.mk" file. ## -## ## -## This example Makefile uses the "ESMFMKFILE" environment variable. ## -## ## -## If you notice that this Makefile cannot find variable ESMFMKFILE then ## -## please contact the person responsible for the ESMF installation on your ## -## system. ## -## As a work-around you can simply hardcode the path to "esmf.mk" in the ## -## include line below. However, doing so will render this Makefile a lot less ## -## flexible and non-portable. ## -################################################################################ - - -COMPILEPATH = -I$(MKSURFDATA_BLD) -I/glade/u/apps/ch/opt/pio/2.5.5/mpt/2.22/intel/19.1.1/include -LINKPATH = -L$(MKSURFDATA_BLD) -PIO_LINKPATH = -L/glade/work/jedwards/tools/pio/2.5.5/intel/19.1.1/mpt/2.22/lib -L/glade/u/apps/ch/opt/pnetcdf/1.12.2/mpt/2.22/intel/19.1.1//lib -L/glade/u/apps/ch/opt/netcdf/4.7.3/intel/19.0.5/lib - -ESMFMKFILE=/glade/work/oehmke/ESMF/scalable_mesh_from_file/lib/libg/Linux.intel.64.mpt.default/esmf.mk -include $(ESMFMKFILE) - -################################################################################ -################################################################################ - -.SUFFIXES: .f90 .F90 .c .C - -%.o : %.f90 - $(ESMF_F90COMPILER) -c $(ESMF_F90COMPILEOPTS) $(ESMF_F90COMPILEPATHS) $(ESMF_F90COMPILEFREENOCPP) $(COMPILEPATH) $< - -%.o : %.F90 - $(ESMF_F90COMPILER) -c $(ESMF_F90COMPILEOPTS) $(ESMF_F90COMPILEPATHS) $(ESMF_F90COMPILEFREECPP) $(ESMF_F90COMPILECPPFLAGS) $(COMPILEPATH) $< - -%.o : %.c - $(ESMF_CXXCOMPILER) -c $(ESMF_CXXCOMPILEOPTS) $(ESMF_CXXCOMPILEPATHSLOCAL) $(ESMF_CXXCOMPILEPATHS) $(ESMF_CXXCOMPILECPPFLAGS) $< - -%.o : %.C - $(ESMF_CXXCOMPILER) -c $(ESMF_CXXCOMPILEOPTS) $(ESMF_CXXCOMPILEPATHSLOCAL) $(ESMF_CXXCOMPILEPATHS) $(ESMF_CXXCOMPILECPPFLAGS) $< - -# ----------------------------------------------------------------------------- -mksurfdata: mksurfdata.o - $(ESMF_F90LINKER) -g $(LINKPATH) $(PIO_LINKPATH) $(ESMF_F90LINKOPTS) $(ESMF_F90LINKPATHS) $(ESMF_F90LINKRPATHS) -o $@ $^ $(ESMF_F90ESMFLINKLIBS) -l mksurfdata -l piof -l pnetcdf -lnetcdf - -# ----------------------------------------------------------------------------- -# ----------------------------------------------------------------------------- -.PHONY: dust clean distclean info edit -dust: - rm -f PET*.ESMF_LogFile *.nc *.stdout -clean: - rm -f esmApp *.o *.mod -distclean: dust clean - -info: - @echo ================================================================== - @echo ESMFMKFILE=$(ESMFMKFILE) - @echo ================================================================== - @cat $(ESMFMKFILE) - @echo ================================================================== - -run: - $(ESMF_INTERNAL_MPIRUN) -np 4 ./esmApp From 3496e14d594879def6dffe24e8591c3e0faadf9a Mon Sep 17 00:00:00 2001 From: Jim Edwards Date: Tue, 26 Apr 2022 16:50:19 -0600 Subject: [PATCH 03/17] builds on izumi with $PIO --- tools/mksurfdata_esmf/src/CMakeLists.txt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tools/mksurfdata_esmf/src/CMakeLists.txt b/tools/mksurfdata_esmf/src/CMakeLists.txt index be8da28083..8720f3188a 100644 --- a/tools/mksurfdata_esmf/src/CMakeLists.txt +++ b/tools/mksurfdata_esmf/src/CMakeLists.txt @@ -2,8 +2,8 @@ cmake_minimum_required(VERSION 3.10) project(mksurfdata Fortran) list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../cmake") -find_package(NetCDF 4.8.1 REQUIRED Fortran) -find_package(ESMF 8.3.0 REQUIRED ) +find_package(NetCDF 4.7.4 REQUIRED Fortran) +find_package(ESMF 8.2.0 REQUIRED ) set(SRCFILES mkagfirepkmonthMod.F90 mkchecksMod.F90 @@ -54,9 +54,9 @@ add_library(piof STATIC IMPORTED) set_property(TARGET pioc PROPERTY IMPORTED_LOCATION $ENV{PIO}/lib/libpioc.a) set_property(TARGET piof PROPERTY IMPORTED_LOCATION $ENV{PIO}/lib/libpiof.a) add_executable(mksurfdata ${SRCFILES}) -target_link_libraries(mksurfdata PRIVATE esmf pioc piof) +target_link_libraries(mksurfdata PRIVATE esmf piof pioc) target_include_directories (mksurfdata PRIVATE ${ESMF_F90COMPILEPATHS}) -target_include_directories (mksurfdata PRIVATE ${PIO}/include) +target_include_directories (mksurfdata PRIVATE $ENV{PIO}/include) target_include_directories (mksurfdata PRIVATE ${PNETCDF}/include) target_include_directories (mksurfdata PRIVATE ${NETCDF}/include) From 3dd40425078df86da9fd562617dea58a581193c6 Mon Sep 17 00:00:00 2001 From: Mariana Vertenstein Date: Wed, 27 Apr 2022 23:05:38 -0600 Subject: [PATCH 04/17] updated README --- tools/mksurfdata_esmf/README | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/tools/mksurfdata_esmf/README b/tools/mksurfdata_esmf/README index c719e0df74..fb40164865 100644 --- a/tools/mksurfdata_esmf/README +++ b/tools/mksurfdata_esmf/README @@ -15,26 +15,28 @@ Getting the code ======================= building the executable ======================= +> bash + +> module load intel +> module load python +> module load cmake +> module use /glade/p/cesmdata/cseg/PROGS/modulefiles/esmfpkgs/intel/19.1.1/ +> module load esmf-8.3.0b13-ncdfio-mpt-O +> module unload netcdf/4.8.1 +> module load netcdf-mpi/4.8.1 +> module load pnetcdf/1.12.2 +> module load pio/2.5.7 +> module list + > cd tools/mksurfdata_esmf > rm -rf bld # (or the contents of /bld) before rerunning CC=... > mkdir ./bld > cd bld -> module load intel # I found I need the latest version of intel -> module load python # in case need latest version of python -> module load cmake -> bash > CC=mpicc FC=mpif90 cmake -DCMAKE_BUILD_TYPE=debug ../src/ > make VERBOSE=1 -> export MKSURFDATA_BLD=`pwd` # needed once; execute in /bld - -# IF YOU MODIFY .F90 files, start here first, though more than once -# I have found it necessary to go back to the "rm -rf bld" step -> cd ../src -> make clean # REMEMBER to be in bash -> make VERBOSE=1 ======================= -running for a single submission: +running for a single submission: ======================= > cd ../ # to generate your target namelist: From 4dd0eb667b8b119bf304c3ba70c46052b0101f05 Mon Sep 17 00:00:00 2001 From: Jim Edwards Date: Thu, 28 Apr 2022 11:18:08 -0600 Subject: [PATCH 05/17] update README --- tools/mksurfdata_esmf/README | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/tools/mksurfdata_esmf/README b/tools/mksurfdata_esmf/README index c719e0df74..4bd139e2bb 100644 --- a/tools/mksurfdata_esmf/README +++ b/tools/mksurfdata_esmf/README @@ -7,7 +7,7 @@ Getting the code > cd > git clone https://github.com/ESCOMP/CTSM.git > cd -> git checkout feature/new_mksurfdata +> git checkout ctsm5.2.mksurfdata # Save time by checking out ccs_config only > ./manage_externals/checkout_externals ccs_config @@ -22,7 +22,14 @@ building the executable > module load intel # I found I need the latest version of intel > module load python # in case need latest version of python > module load cmake -> bash +> module load mpt/2.25 +> module use /glade/p/cesmdata/cseg/PROGS/modulefiles/esmfpkgs/intel/19.1.1/ +> module load esmf-8.3.0b13-ncdfio-mpt-O +> module unload netcdf/4.8.1 +> module load netcdf-mpi/4.8.1 +> module load pnetcdf/1.12.2 +> module load pio/2.5.7 +> bash #If you are not already using the bash shell > CC=mpicc FC=mpif90 cmake -DCMAKE_BUILD_TYPE=debug ../src/ > make VERBOSE=1 > export MKSURFDATA_BLD=`pwd` # needed once; execute in /bld From 47bfd6d3398fd8fe31550f33c5f7642362890791 Mon Sep 17 00:00:00 2001 From: Jim Edwards Date: Thu, 28 Apr 2022 11:35:26 -0600 Subject: [PATCH 06/17] fix merge issue --- tools/mksurfdata_esmf/README | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/tools/mksurfdata_esmf/README b/tools/mksurfdata_esmf/README index 6e5649619a..75be0c0afa 100644 --- a/tools/mksurfdata_esmf/README +++ b/tools/mksurfdata_esmf/README @@ -15,18 +15,6 @@ Getting the code ======================= building the executable ======================= -> bash - -> module load intel -> module load python -> module load cmake -> module use /glade/p/cesmdata/cseg/PROGS/modulefiles/esmfpkgs/intel/19.1.1/ -> module load esmf-8.3.0b13-ncdfio-mpt-O -> module unload netcdf/4.8.1 -> module load netcdf-mpi/4.8.1 -> module load pnetcdf/1.12.2 -> module load pio/2.5.7 -> module list > cd tools/mksurfdata_esmf > rm -rf bld # (or the contents of /bld) before rerunning CC=... From ca8a7a92b181c3d972b98863304c608ccd155e85 Mon Sep 17 00:00:00 2001 From: Erik Kluzek Date: Mon, 2 May 2022 12:00:43 -0600 Subject: [PATCH 07/17] Get build script working again --- tools/mksurfdata_esmf/gen_mksurfdata_build.sh | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/tools/mksurfdata_esmf/gen_mksurfdata_build.sh b/tools/mksurfdata_esmf/gen_mksurfdata_build.sh index 645645a47f..b41d0548fb 100755 --- a/tools/mksurfdata_esmf/gen_mksurfdata_build.sh +++ b/tools/mksurfdata_esmf/gen_mksurfdata_build.sh @@ -1,17 +1,14 @@ #! /bin/bash -f -module load cmake - export MACH="cheyenne" export COMPILER="intel" -export OS="LINUX" -export ESMFMKFILE="/glade/work/oehmke/ESMF/scalable_mesh_from_file/lib/libg/Linux.intel.64.mpt.default/esmf.mk" +export MPILIB="mpt" cwd=`pwd` rm -rf bld mkdir bld cd bld -../../../cime/tools/configure --macros-format CMake --machine cheyenne --compiler intel --mpilib mpt +../../../cime/tools/configure --macros-format CMake --machine $MACH --compiler $COMPILER --mpilib $MPILIB ls -l source ./.env_mach_specific.sh CC=mpicc FC=mpif90 cmake -DCMAKE_BUILD_TYPE=debug ../src From 333fb214c2ce8de13330f500ebd59b75441227da Mon Sep 17 00:00:00 2001 From: Erik Kluzek Date: Mon, 2 May 2022 13:07:26 -0600 Subject: [PATCH 08/17] Make some changes to the README and build script that Sam and I discussed --- tools/mksurfdata_esmf/README | 35 ++++--------------- tools/mksurfdata_esmf/gen_mksurfdata_build.sh | 6 +++- 2 files changed, 12 insertions(+), 29 deletions(-) diff --git a/tools/mksurfdata_esmf/README b/tools/mksurfdata_esmf/README index 75be0c0afa..a7ef872c48 100644 --- a/tools/mksurfdata_esmf/README +++ b/tools/mksurfdata_esmf/README @@ -1,38 +1,17 @@ -Most recent update of README: -4/6/2022 slevis +For users working on cime machines you can use the build +script to build the tool for you. On other machines you'll need to do port to cime +and tell how to build for that machine. That's talked about in the cime documentation. +And you'll have to make some modifications to the build script. -================ -Getting the code -================ -> cd -> git clone https://github.com/ESCOMP/CTSM.git -> cd -> git checkout ctsm5.2.mksurfdata - -# Save time by checking out ccs_config only -> ./manage_externals/checkout_externals ccs_config +Machines that are already run CTSM or CESM have been ported to cime. So if you can run the model +on your machine you will be able to build the tool there. ======================= building the executable ======================= > cd tools/mksurfdata_esmf -> rm -rf bld # (or the contents of /bld) before rerunning CC=... -> mkdir ./bld -> cd bld -> module load intel # I found I need the latest version of intel -> module load python # in case need latest version of python -> module load cmake -> module load mpt/2.25 -> module use /glade/p/cesmdata/cseg/PROGS/modulefiles/esmfpkgs/intel/19.1.1/ -> module load esmf-8.3.0b13-ncdfio-mpt-O -> module unload netcdf/4.8.1 -> module load netcdf-mpi/4.8.1 -> module load pnetcdf/1.12.2 -> module load pio/2.5.7 -> bash #If you are not already using the bash shell -> CC=mpicc FC=mpif90 cmake -DCMAKE_BUILD_TYPE=debug ../src/ -> make VERBOSE=1 +> ./gen_mksurfdata_build.sh # For machines with a cime build ======================= running for a single submission: diff --git a/tools/mksurfdata_esmf/gen_mksurfdata_build.sh b/tools/mksurfdata_esmf/gen_mksurfdata_build.sh index b41d0548fb..2333ff3483 100755 --- a/tools/mksurfdata_esmf/gen_mksurfdata_build.sh +++ b/tools/mksurfdata_esmf/gen_mksurfdata_build.sh @@ -1,16 +1,20 @@ #! /bin/bash -f +# Define what machine to use that's been ported to cime export MACH="cheyenne" export COMPILER="intel" export MPILIB="mpt" +# Create a build directory cwd=`pwd` rm -rf bld mkdir bld cd bld +# Run the cime configure tool to figure out what modules need to be loaded ../../../cime/tools/configure --macros-format CMake --machine $MACH --compiler $COMPILER --mpilib $MPILIB -ls -l source ./.env_mach_specific.sh +# Build the cmake files CC=mpicc FC=mpif90 cmake -DCMAKE_BUILD_TYPE=debug ../src +# Build the actual executable make VERBOSE=1 From 2e5af3f90aac49f4fdafd239af1b367f10bb7e48 Mon Sep 17 00:00:00 2001 From: Erik Kluzek Date: Mon, 2 May 2022 14:25:14 -0600 Subject: [PATCH 09/17] Have the build script figure out it's cheyenne or some other machine, add error checking after each step, and print a success at the end --- tools/mksurfdata_esmf/gen_mksurfdata_build.sh | 39 ++++++++++++++++--- 1 file changed, 34 insertions(+), 5 deletions(-) diff --git a/tools/mksurfdata_esmf/gen_mksurfdata_build.sh b/tools/mksurfdata_esmf/gen_mksurfdata_build.sh index 2333ff3483..d2b09bab7a 100755 --- a/tools/mksurfdata_esmf/gen_mksurfdata_build.sh +++ b/tools/mksurfdata_esmf/gen_mksurfdata_build.sh @@ -1,20 +1,49 @@ #! /bin/bash -f +hostname=`hostname --short` + # Define what machine to use that's been ported to cime -export MACH="cheyenne" -export COMPILER="intel" -export MPILIB="mpt" +case $hostname in + ##cheyenne + cheyenne* | r* ) + export MACH="cheyenne" + ;; + ## Other machines + *) + export MACH="$hostname" + ;; +esac # Create a build directory +echo "cime Machine is: $MACH..." +echo "Remove the old bld directory and create a new one..." cwd=`pwd` rm -rf bld mkdir bld cd bld # Run the cime configure tool to figure out what modules need to be loaded -../../../cime/tools/configure --macros-format CMake --machine $MACH --compiler $COMPILER --mpilib $MPILIB -source ./.env_mach_specific.sh +echo "Run cime configure for machine $MACH..." +# You can specify the non-default compiler and mpi-library by adding --compiler and --mpilib settings +../../../cime/tools/configure --macros-format CMake --machine $MACH +if [ $? != 0 ]; then + echo "Error doing configure for machine name: $MACH" + exit 1 +fi +. .env_mach_specific.sh +echo "COMPILER = $COMPILER, MPILIB = $MPILIB, DEBUG = $DEBUG, OS = $OS" # Build the cmake files +echo "Do the cmake build..." CC=mpicc FC=mpif90 cmake -DCMAKE_BUILD_TYPE=debug ../src +if [ $? != 0 ]; then + echo "Error doing cmake for $MACH $MPILIB $COMPILER" + exit 1 +fi # Build the actual executable +echo "Build the mksurfdata_esmf build..." make VERBOSE=1 +if [ $? != 0 ]; then + echo "Error doing make for $MACH $MPILIB $COMPILER" + exit 1 +fi +echo "\n\n\nSuccessfully created mksurfdata_esmf executable for: ${MACH}_${COMPILER} for $MPILIB library" From 3ed08f8dbae5fb76a45cc6e6279fd08b86993abe Mon Sep 17 00:00:00 2001 From: Erik Kluzek Date: Mon, 2 May 2022 14:51:15 -0600 Subject: [PATCH 10/17] Add a check if the build directory already exists and abort if so --- tools/mksurfdata_esmf/gen_mksurfdata_build.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tools/mksurfdata_esmf/gen_mksurfdata_build.sh b/tools/mksurfdata_esmf/gen_mksurfdata_build.sh index d2b09bab7a..2471ea9c29 100755 --- a/tools/mksurfdata_esmf/gen_mksurfdata_build.sh +++ b/tools/mksurfdata_esmf/gen_mksurfdata_build.sh @@ -16,7 +16,10 @@ esac # Create a build directory echo "cime Machine is: $MACH..." -echo "Remove the old bld directory and create a new one..." +if [ -d "bld" ]; then + echo "An existing bld directory exists already remove it, if you want to do a clean build..." + exit 1 +fi cwd=`pwd` rm -rf bld mkdir bld From af2d5ea27d18c9fda077da8a91515321f56c22c2 Mon Sep 17 00:00:00 2001 From: Erik Kluzek Date: Mon, 2 May 2022 16:07:47 -0600 Subject: [PATCH 11/17] Update to ccs_config branch --- Externals.cfg | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Externals.cfg b/Externals.cfg index 239e8e9d89..986dfa92cb 100644 --- a/Externals.cfg +++ b/Externals.cfg @@ -34,9 +34,11 @@ hash = 34723c2 required = True [ccs_config] -tag = ccs_config_cesm0.0.15 +#tag = ccs_config_cesm0.0.15 +branch = update_for_mksurfdata_esmf_build protocol = git -repo_url = https://github.com/ESMCI/ccs_config_cesm.git +#repo_url = https://github.com/ESMCI/ccs_config_cesm.git +repo_url = git@github.com:ekluzek/ccs_config_cesm.git local_path = ccs_config required = True From c309d82aa13d807da89fb2e409b8f5c2957a7a41 Mon Sep 17 00:00:00 2001 From: Erik Kluzek Date: Mon, 2 May 2022 16:18:11 -0600 Subject: [PATCH 12/17] Add some empty lines at the end --- tools/mksurfdata_esmf/gen_mksurfdata_build.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tools/mksurfdata_esmf/gen_mksurfdata_build.sh b/tools/mksurfdata_esmf/gen_mksurfdata_build.sh index 2471ea9c29..9e046a2240 100755 --- a/tools/mksurfdata_esmf/gen_mksurfdata_build.sh +++ b/tools/mksurfdata_esmf/gen_mksurfdata_build.sh @@ -48,5 +48,8 @@ if [ $? != 0 ]; then echo "Error doing make for $MACH $MPILIB $COMPILER" exit 1 fi -echo "\n\n\nSuccessfully created mksurfdata_esmf executable for: ${MACH}_${COMPILER} for $MPILIB library" +echo "" +echo "" +echo "" +echo "Successfully created mksurfdata_esmf executable for: ${MACH}_${COMPILER} for $MPILIB library" From f04ab5e5e3dc502e5293edfb4e178683fa5ddff0 Mon Sep 17 00:00:00 2001 From: Erik Kluzek Date: Mon, 2 May 2022 16:21:54 -0600 Subject: [PATCH 13/17] Point to a specific hash on the ccs_config branch --- Externals.cfg | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Externals.cfg b/Externals.cfg index 986dfa92cb..4e0998372a 100644 --- a/Externals.cfg +++ b/Externals.cfg @@ -35,7 +35,8 @@ required = True [ccs_config] #tag = ccs_config_cesm0.0.15 -branch = update_for_mksurfdata_esmf_build +#branch = update_for_mksurfdata_esmf_build +hash = e79eafcda096d20d41e7ef4921ac484215ed3d38 protocol = git #repo_url = https://github.com/ESMCI/ccs_config_cesm.git repo_url = git@github.com:ekluzek/ccs_config_cesm.git From ecb9f71eaaa33b492a41b11a518843e5b51c451d Mon Sep 17 00:00:00 2001 From: Erik Kluzek Date: Mon, 2 May 2022 17:09:10 -0600 Subject: [PATCH 14/17] Update ccs_config hash with changes needed to build on izumi with intel and mvapich2 --- Externals.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Externals.cfg b/Externals.cfg index 4e0998372a..c7cdf64fce 100644 --- a/Externals.cfg +++ b/Externals.cfg @@ -36,7 +36,7 @@ required = True [ccs_config] #tag = ccs_config_cesm0.0.15 #branch = update_for_mksurfdata_esmf_build -hash = e79eafcda096d20d41e7ef4921ac484215ed3d38 +hash = 29a06a80a5f411f3ed001d5b2cb34d2aab685cbe protocol = git #repo_url = https://github.com/ESMCI/ccs_config_cesm.git repo_url = git@github.com:ekluzek/ccs_config_cesm.git From 668bbd692c3dd9b23c4c2ee1d7bc5cd79e3d3d2f Mon Sep 17 00:00:00 2001 From: Erik Kluzek Date: Mon, 2 May 2022 18:52:35 -0600 Subject: [PATCH 15/17] Add handling for specifying MPILIB and COMPILER as env variables and abort if the PIO env variable is not set after configure --- tools/mksurfdata_esmf/gen_mksurfdata_build.sh | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/tools/mksurfdata_esmf/gen_mksurfdata_build.sh b/tools/mksurfdata_esmf/gen_mksurfdata_build.sh index 2471ea9c29..bfe0665df9 100755 --- a/tools/mksurfdata_esmf/gen_mksurfdata_build.sh +++ b/tools/mksurfdata_esmf/gen_mksurfdata_build.sh @@ -27,13 +27,25 @@ cd bld # Run the cime configure tool to figure out what modules need to be loaded echo "Run cime configure for machine $MACH..." # You can specify the non-default compiler and mpi-library by adding --compiler and --mpilib settings -../../../cime/tools/configure --macros-format CMake --machine $MACH +if [ -z "$COMPILER" ] && [ -z "$MPILIB" ]; then + echo "configure for the default MPI-library and compiler..." + ../../../cime/tools/configure --macros-format CMake --machine $MACH +else + echo "configure for the specific MPILIB=$MPILIB and COMPILER=$COMPILER..." + ../../../cime/tools/configure --macros-format CMake --machine $MACH --compiler $COMPILER --mpilib $MPILIB +fi + if [ $? != 0 ]; then echo "Error doing configure for machine name: $MACH" exit 1 fi . .env_mach_specific.sh echo "COMPILER = $COMPILER, MPILIB = $MPILIB, DEBUG = $DEBUG, OS = $OS" +if [ -z "$PIO" ]; then + echo "The PIO directory for the PIO build is required and was not set in the configure" + echo "Make sure a PIO build is provided for $MACH_$COMPILER with $MPILIB in config_machines" + exit 1 +fi # Build the cmake files echo "Do the cmake build..." CC=mpicc FC=mpif90 cmake -DCMAKE_BUILD_TYPE=debug ../src @@ -49,4 +61,3 @@ if [ $? != 0 ]; then exit 1 fi echo "\n\n\nSuccessfully created mksurfdata_esmf executable for: ${MACH}_${COMPILER} for $MPILIB library" - From 5898e5c150a95f8bc0a1241edcdde3a359fecca4 Mon Sep 17 00:00:00 2001 From: Erik Kluzek Date: Mon, 2 May 2022 23:14:36 -0600 Subject: [PATCH 16/17] Add some notes on requirements and point to some web addresses for that --- tools/mksurfdata_esmf/README | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/tools/mksurfdata_esmf/README b/tools/mksurfdata_esmf/README index a7ef872c48..6b85b7564d 100644 --- a/tools/mksurfdata_esmf/README +++ b/tools/mksurfdata_esmf/README @@ -1,11 +1,43 @@ +=================== +Build Requirements: +=================== + +mksurfdata_esmf is an distributed memory parallel program (using Message Passing Interface -- MPI) that utilizes +both ESMF (Earth System Modelling Framework) for regridding as well as PIO (Parallel I/O) and NetCDF output. As +such libraries must be built for the following: + +1) MPI +2) NetCDF +3) ParallelIO +4) ESMF + +These libraries need to be built such that they can all work together in the same executable. Hence, the above +order may be required in building them. + +========================================= +Use cime to manage the build requirements +========================================= + For users working on cime machines you can use the build -script to build the tool for you. On other machines you'll need to do port to cime +script to build the tool for you. On other machines you'll need to do a port to cime and tell how to build for that machine. That's talked about in the cime documentation. And you'll have to make some modifications to the build script. -Machines that are already run CTSM or CESM have been ported to cime. So if you can run the model +https://github.com/ESMCI/cime/wiki/Porting-Overview + +Machines that already run CTSM or CESM have been ported to cime. So if you can run the model on your machine you will be able to build the tool there. +To get a list of the machines that have been ported to cime: + +cd ../../cime/scripts +./query_config --machines + +NOTE: +In addition to having a port to cime, the machine also needs to have PIO built and able +to be referenced with the env variable PIO which will need to be in the porting instructions +for the machine. Currently an independent PIO library is not available on cime ported machines. + ======================= building the executable ======================= From 309a8dcb121e2ba16dfdd182e7358da021ce6934 Mon Sep 17 00:00:00 2001 From: Erik Kluzek Date: Mon, 2 May 2022 23:40:19 -0600 Subject: [PATCH 17/17] Add a note about the build --- tools/mksurfdata_esmf/README | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/mksurfdata_esmf/README b/tools/mksurfdata_esmf/README index 6b85b7564d..f2d61e2539 100644 --- a/tools/mksurfdata_esmf/README +++ b/tools/mksurfdata_esmf/README @@ -11,6 +11,8 @@ such libraries must be built for the following: 3) ParallelIO 4) ESMF +In addition for the build: python, bash-shell, CMake and GNU-Make are required + These libraries need to be built such that they can all work together in the same executable. Hence, the above order may be required in building them.