Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmake build working on cheyenne for mksurfdata_esmf #1721

Merged
merged 19 commits into from
May 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions Externals.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,12 @@ hash = 34723c2
required = True

[ccs_config]
tag = ccs_config_cesm0.0.15
#tag = ccs_config_cesm0.0.15
#branch = update_for_mksurfdata_esmf_build
hash = 29a06a80a5f411f3ed001d5b2cb34d2aab685cbe
protocol = git
repo_url = https://github.com/ESMCI/ccs_config_cesm.git
#repo_url = https://github.com/ESMCI/ccs_config_cesm.git
repo_url = [email protected]:ekluzek/ccs_config_cesm.git
local_path = ccs_config
required = True

Expand Down
70 changes: 42 additions & 28 deletions tools/mksurfdata_esmf/README
Original file line number Diff line number Diff line change
@@ -1,40 +1,54 @@
Most recent update of README:
4/6/2022 slevis
===================
Build Requirements:
===================

================
Getting the code
================
> cd <user/work/area>
> git clone https://github.com/ESCOMP/CTSM.git <dir_name>
> cd <dir_name>
> git checkout feature/new_mksurfdata
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

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.

=========================================
Use cime to manage the build requirements
=========================================

# Save time by checking out ccs_config only
> ./manage_externals/checkout_externals ccs_config
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 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.

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
=======================

> 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
> ./gen_mksurfdata_build.sh # For machines with a cime build

=======================
running for a single submission:
running for a single submission:
=======================
> cd ../
# to generate your target namelist:
Expand Down
130 changes: 130 additions & 0 deletions tools/mksurfdata_esmf/cmake/FindESMF.cmake
Original file line number Diff line number Diff line change
@@ -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 )
Loading