Skip to content

Commit

Permalink
Update CDEPS (#2)
Browse files Browse the repository at this point in the history
Update CDEPS to the 20201124 version of the master branch at ESCOMP/CDEPS.
  • Loading branch information
binli2337 authored Dec 9, 2020
1 parent 8e77759 commit 4fd370e
Show file tree
Hide file tree
Showing 72 changed files with 7,976 additions and 4,783 deletions.
115 changes: 115 additions & 0 deletions .github/workflows/extbuild.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
# This is a workflow to compile the cdeps source without cime
name: extbuild
# Controls when the action will run. Triggers the workflow on push or pull request
# events but only for the master branch
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
build-cdeps:
runs-on: ubuntu-latest
env:
CC: mpicc
FC: mpifort
CXX: mpicxx
CPPFLAGS: "-I/usr/include -I/usr/local/include"
# Versions of all dependencies can be updated here
ESMF_VERSION: ESMF_8_1_0_beta_snapshot_25
PNETCDF_VERSION: pnetcdf-1.12.1
NETCDF_FORTRAN_VERSION: v4.5.2
PIO_VERSION: pio-2.5.1
steps:
- uses: actions/checkout@v2
# Build the ESMF library, if the cache contains a previous build
# it will be used instead
- id: cache-esmf
uses: actions/cache@v2
with:
path: ~/ESMF
key: ${{ runner.os }}-${{ env.ESMF_VERSION }}-ESMF
- id: load-env
run: sudo apt-get install gfortran wget openmpi-bin netcdf-bin libopenmpi-dev
- id: build-ESMF
if: steps.cache-esmf.outputs.cache-hit != 'true'
run: |
wget https://github.com/esmf-org/esmf/archive/${{ env.ESMF_VERSION }}.tar.gz
tar -xzvf ${{ env.ESMF_VERSION }}.tar.gz
pushd esmf-${{ env.ESMF_VERSION }}
export ESMF_DIR=`pwd`
export ESMF_COMM=openmpi
export ESMF_YAMLCPP="internal"
export ESMF_INSTALL_PREFIX=$HOME/ESMF
export ESMF_BOPT=g
make
make install
popd
- id: cache-pnetcdf
uses: actions/cache@v2
with:
path: ~/pnetcdf
key: ${{ runner.os }}-${{ env.PNETCDF_VERSION}}-pnetcdf
- name: pnetcdf build
if: steps.cache-pnetcdf.outputs.cache-hit != 'true'
run: |
wget https://parallel-netcdf.github.io/Release/${{ env.PNETCDF_VERSION }}.tar.gz
tar -xzvf ${{ env.PNETCDF_VERSION }}.tar.gz
ls -l
pushd ${{ env.PNETCDF_VERSION }}
./configure --prefix=$HOME/pnetcdf --enable-shared --disable-cxx
make
make install
popd
- name: Cache netcdf-fortran
id: cache-netcdf-fortran
uses: actions/cache@v2
with:
path: ~/netcdf-fortran
key: ${{ runner.os }}-${{ env.NETCDF_FORTRAN_VERSION }}-netcdf-fortran
- name: netcdf fortran build
if: steps.cache-netcdf-fortran.outputs.cache-hit != 'true'
run: |
sudo apt-get install libnetcdf-dev
wget https://github.com/Unidata/netcdf-fortran/archive/${{ env.NETCDF_FORTRAN_VERSION }}.tar.gz
tar -xzvf ${{ env.NETCDF_FORTRAN_VERSION }}.tar.gz
ls -l
pushd netcdf-fortran-*
./configure --prefix=$HOME/netcdf-fortran
make
make install
- name: Cache PIO
id: cache-PIO
uses: actions/cache@v2
with:
path: ~/pio
key: ${{ runner.os }}-${{ env.PIO_VERSION }}.pio
restore-keys: |
${{ runner.os }}-${{ env.NETCDF_FORTRAN_VERSION }}-netcdf-fortran
${{ runner.os }}-${{ env.PNETCDF_VERSION }}-pnetcdf
- name: Build PIO
if: steps.cache-PIO.outputs.cache-hit != 'true'
run: |
wget https://github.com/NCAR/ParallelIO/releases/download/pio_2_5_1/${{ env.PIO_VERSION }}.tar.gz
tar -xzvf ${{ env.PIO_VERSION }}.tar.gz
mkdir build-pio
pushd build-pio
cmake -Wno-dev -DNetCDF_C_LIBRARY=/usr/lib/x86_64-linux-gnu/libnetcdf.so -DNetCDF_C_INCLUDE_DIR=/usr/include -DCMAKE_PREFIX_PATH=/usr -DCMAKE_INSTALL_PREFIX=$HOME/pio -DPIO_HDF5_LOGGING=On -DPIO_USE_MALLOC=On -DPIO_ENABLE_LOGGING=On -DPIO_ENABLE_TIMING=Off -DNetCDF_Fortran_PATH=$HOME/netcdf-fortran -DPnetCDF_PATH=$HOME/pnetcdf ../${{ env.PIO_VERSION }}
make VERBOSE=1
make install
popd
- name: Build CDEPS
run: |
export ESMFMKFILE=$HOME/ESMF/lib/libg/Linux.gfortran.64.openmpi.default/esmf.mk
export PIO=$HOME/pio
git submodule init
git submodule update
mkdir build-cdeps
pushd build-cdeps
cmake -DCMAKE_BUILD_TYPE=DEBUG -DCMAKE_Fortran_FLAGS="-g -Wall -ffree-form -ffree-line-length-none" ../
make VERBOSE=1
popd
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "fox"]
path = fox
url = https://github.com/ESMCI/fox.git
39 changes: 29 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,32 +1,51 @@
cmake_minimum_required(VERSION 3.10)

project(NUOPC_DATA_MODELS LANGUAGES Fortran VERSION 0.1)
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
include(ExternalProject)
find_package(ESMF REQUIRED)

if (DEFINED CIMEROOT)
message("Using CIME in ${CIMEROOT} with compiler ${COMPILER}")
include(${CASEROOT}/Macros.cmake)
if (${PIO_VERSION} LESS 2)
message( FATAL_ERROR "Version 2 of the PIO library required")
endif()
set(FOX ${LIBROOT})
if (${MPILIB} STREQUAL "mpi-serial")
set(CMAKE_C_COMPILER ${SCC})
set(CMAKE_Fortran_COMPILER ${SFC})
set(CMAKE_CXX_COMPILER ${SCXX})
else()
set(CMAKE_C_COMPILER ${MPICC})
set(CMAKE_Fortran_COMPILER ${MPIFC})
set(CMAKE_CXX_COMPILER ${MPICXX})
endif()
set(CMAKE_Fortran_FLAGS "${FFLAGS} -I${LIBROOT}/include -I${LIBROOT}/finclude -I${LIBROOT}/nuopc/esmf/${NINST_VALUE}/include")
else ()
else()
set(BLD_STANDALONE TRUE)
endif ()
endif()

project(NUOPC_DATA_MODELS LANGUAGES Fortran VERSION 0.1)

list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)

message("CMAKE_MODULE_PATH is ${CMAKE_MODULE_PATH}")

find_package(ESMF REQUIRED)
if (DEFINED PIO)
set(PIO_PATH ${PIO})
else()
set(PIO_PATH $ENV{PIO})
endif()
find_package(PIO REQUIRED COMPONENT C Fortran PATH ${PIO_PATH})

if (NOT DEFINED MPILIB OR NOT ${MPILIB} STREQUAL "mpi-serial")
find_package(MPI REQUIRED)
endif()

if(BLD_STANDALONE)
add_subdirectory(share)
list(APPEND EXTRA_LIBS cdeps_share)
list(APPEND EXTRA_INCLUDES "${PIO_INCDIR}" "${CMAKE_BINARY_DIR}/share" )
list(APPEND EXTRA_INCLUDES "${CMAKE_BINARY_DIR}/share" )
endif()


add_subdirectory(fox)
add_subdirectory(streams)
add_subdirectory(dshr)

Expand All @@ -35,4 +54,4 @@ foreach(COMP datm dice dlnd docn drof dwav)
endforeach(COMP)

install(TARGETS streams dshr
LIBRARY DESTINATION lib)
LIBRARY DESTINATION lib)
80 changes: 57 additions & 23 deletions cime_config/buildlib
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,16 @@
build cime component model library. This buildlib script is used by all CDEPS components.
"""

import sys, os
import sys, os, time

_CIMEROOT = os.path.join(os.path.dirname(os.path.abspath(__file__)), "..","..","..","..", "..")
_CIMEROOT = os.environ.get("CIMEROOT")
if _CIMEROOT is None:
raise SystemExit("ERROR: must set CIMEROOT environment variable")
sys.path.append(os.path.join(_CIMEROOT, "scripts", "Tools"))

_LIBDIR = os.path.join(_CIMEROOT, "scripts", "Tools")
sys.path.append(_LIBDIR)

from standard_script_setup import *
from CIME.buildlib import parse_input
from CIME.case import Case
Expand All @@ -22,7 +27,6 @@ logger = logging.getLogger(__name__)
def buildlib(bldroot, libroot, case, compname=None):
if bldroot.endswith("obj") and not compname:
compname = os.path.basename(os.path.abspath(os.path.join(bldroot,os.pardir)))
print "HERE compname is {} libroot={} bldroot={}".format(compname, libroot, bldroot)

if case.get_value("DEBUG"):
strdebug = "debug"
Expand All @@ -37,6 +41,7 @@ def buildlib(bldroot, libroot, case, compname=None):
sharedpath = os.path.join(case.get_value("COMPILER"),mpilib,
strdebug, strthread, "nuopc")

exe_root = case.get_value("EXEROOT")

if compname:
s, o, e = run_cmd("make d{}".format(compname), from_dir=bldroot, verbose=True)
Expand All @@ -49,24 +54,44 @@ def buildlib(bldroot, libroot, case, compname=None):
expect(False, "ERROR in {} build {} {}".format(compname,o,e))
else:
logger.info("Running cmake for CDEPS")
srcpath = os.path.join(case.get_value("CIMEROOT"),"src","components","cdeps")

srcpath = os.path.abspath(os.path.join(os.path.dirname(__file__),os.pardir))
cmake_flags = get_standard_cmake_args(case, os.path.join(sharedpath,"cdeps"), shared_lib=True)
ccomp, cxxcomp, fcomp = get_compiler_names(case)

cmake_flags += " -DCMAKE_C_COMPILER={} -DCMAKE_CXX_COMPILER={} -DCMAKE_Fortran_COMPILER={}".format(ccomp, cxxcomp, fcomp)
cmake_flags += " -DCMAKE_INSTALL_PREFIX={} ".format(libroot)
cmake_flags += " -DLIBROOT={} ".format(libroot) + srcpath
# base path of install to be completed by setting DESTDIR in make install
cmake_flags += " -DCMAKE_INSTALL_PREFIX:PATH=/"
cmake_flags += " -DLIBROOT={} ".format(libroot)
cmake_flags += " -DMPILIB={} ".format(mpilib)
cmake_flags += " -DPIO_C_LIBRARY={path}/lib -DPIO_C_INCLUDE_DIR={path}/include ".format(path=os.path.join(case.get_value("EXEROOT"),sharedpath))
cmake_flags += " -DPIO_Fortran_LIBRARY={path}/lib -DPIO_Fortran_INCLUDE_DIR={path}/include ".format(path=os.path.join(case.get_value("EXEROOT"),sharedpath))
cmake_flags += srcpath

latest_src_file = max(all_files_under(srcpath), key=os.path.getmtime)
src_time = os.path.getmtime(latest_src_file)
if os.path.exists(os.path.join(bldroot,"CMakeFiles")):
bld_time = os.path.getmtime(os.path.join(bldroot,"CMakeFiles"))
else:
bld_time = src_time - 1

logger.info("cmake_flags {}".format(cmake_flags))
s,o,e = run_cmd("cmake {} ".format(cmake_flags), from_dir=bldroot, verbose=True)
expect(not s,"ERROR from cmake output={}, error={}".format(o,e))

s,o,e = run_cmd("make install", from_dir=bldroot, verbose=True)
# if any file in src is newer than CmakeFiles in the build directory, rerun cmake
if src_time > bld_time:
logger.info("cmake_flags {}".format(cmake_flags))
s,o,e = run_cmd("cmake {} ".format(cmake_flags), from_dir=bldroot, verbose=True)
expect(not s,"ERROR from cmake output={}, error={}".format(o,e))
else:
# The dwav_lib is the last file built in cdeps, wait for it to be built
dwav_lib = os.path.join(bldroot,"dwav","libdwav.a")
time_to_wait = 300
time_counter = 0
while not os.path.exists(dwav_lib):
time.sleep(1)
time_counter += 1
if time_counter > time_to_wait:
break
expect(time_counter <= time_to_wait," Timeout waiting for {}".format(dwav_lib))
print("HERE exeroot {} bldroot {}".format(exe_root, bldroot))

s,o,e = run_cmd("make install DESTDIR={}".format(libroot), from_dir=bldroot, verbose=True)
expect(not s,"ERROR from make output={}, error={}".format(o,e))


# Link the CDEPS component directories to the location expected by cime
for comp in ("atm", "lnd", "ice", "ocn", "rof", "wav"):
compname = case.get_value("COMP_{}".format(comp.upper()))
Expand All @@ -76,18 +101,27 @@ def buildlib(bldroot, libroot, case, compname=None):
os.rmdir(comppath)
symlink_force(os.path.join(bldroot,compname), comppath)

def all_files_under(path):
"""Iterates through all files that are under the given path."""
for cur_path, dirnames, filenames in os.walk(path):
for filename in filenames:
yield os.path.join(cur_path, filename)

def get_compiler_names(case):
machobj = Machines(machine=case.get_value("MACH"))
machine=case.get_value("MACH")
machobj = Machines(machine=machine)
compobj = Compilers(machobj)
compiler = case.get_value("COMPILER")
if case.get_value("MPILIB") == 'mpi-serial':
ccomp = compobj.get_value("SCC").strip()
cxxcomp = compobj.get_value("SCXX").strip()
fcomp = compobj.get_value("SFC").strip()
print("HERE Compiler {} mach={}".format(compiler, machine))
ccomp = compobj.get_value("SCC",{"COMPILER":compiler,"MACH":machine}).strip()
cxxcomp = compobj.get_value("SCXX",{"COMPILER":compiler}).strip()
fcomp = compobj.get_value("SFC",{"COMPILER":compiler}).strip()
print("HERE the compilers are {} {} {}".format(ccomp,cxxcomp, fcomp))
else:
ccomp = compobj.get_value("MPICC").strip()
cxxcomp = compobj.get_value("MPICXX").strip()
fcomp = compobj.get_value("MPIFC").strip()
ccomp = compobj.get_value("MPICC",{"COMPILER":compiler}).strip()
cxxcomp = compobj.get_value("MPICXX",{"COMPILER":compiler}).strip()
fcomp = compobj.get_value("MPIFC",{"COMPILER":compiler}).strip()

return ccomp, cxxcomp, fcomp

Expand Down
Loading

0 comments on commit 4fd370e

Please sign in to comment.