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

Summa initial NGen contribution #513

Open
wants to merge 45 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
f519387
needed to get mac build to succeed
ashleymedin Apr 21, 2023
763a55d
add summa submodule branch bmi
ashleymedin Apr 21, 2023
961219a
add files to repository
ashleymedin Apr 21, 2023
b1fff82
updated summa to read forcing
ashleymedin Apr 25, 2023
f5f94f6
Merge remote-tracking branch 'upstream/master'
ashleymedin May 1, 2023
accef38
update submodule
ashleymedin May 1, 2023
147e12a
adding general CMakeLists that works for all builds of Summa, and add…
ashleymedin May 11, 2023
d0920b1
change branch of submodule, eventually change to master when merge
ashleymedin May 11, 2023
2d5bd9e
executable names
ashleymedin May 11, 2023
74d76fc
updating modules, switching to merged master branch
ashleymedin May 13, 2023
5dc9bc5
switch back to github repository, code updated for Actors and KINSOL
ashleymedin Jun 22, 2023
7eeeb8c
Merge remote-tracking branch 'upstream/master'
ashleymedin Jun 22, 2023
653078c
update commit
ashleymedin Jun 23, 2023
d056f81
new commit update
ashleymedin Jul 6, 2023
137233c
updating summa
ashleymedin Aug 15, 2023
cb93224
new version of summa
ashleymedin Aug 17, 2023
604910c
new version of summa
ashleymedin Aug 17, 2023
594f889
update summa commit
ashleymedin Aug 31, 2023
bb63835
update commit
ashleymedin Sep 20, 2023
3628390
update commit
ashleymedin Sep 25, 2023
08981c9
Merge commit '90f6fc9bfa742f63b3d9194843527169b6a0664c'
ashleymedin Sep 25, 2023
72fdaed
updating commit, readme, gitignore
ashleymedin Sep 25, 2023
5c8beb1
summa commit
ashleymedin Sep 28, 2023
97c6e4b
Merge commit '72f121a5d12762d59c3870efd6d0598f2286886c'
ashleymedin Sep 28, 2023
9bbd3ec
update summa commit
ashleymedin Oct 26, 2023
a1dd4a0
update commit
ashleymedin Feb 15, 2024
cacd555
Merge remote-tracking branch 'upstream/master'
ashleymedin Feb 15, 2024
f019ead
merge
ashleymedin Feb 15, 2024
fc8527f
update all submodules
ashleymedin Feb 15, 2024
21b301d
update commit
ashleymedin Feb 15, 2024
c0279d4
update CMakeLists.txt
ashleymedin Feb 21, 2024
1e812ca
update commit
ashleymedin Feb 21, 2024
dd898e3
delete commented lines in CMakeLists
ashleymedin Feb 21, 2024
0e1a7ef
update commit
ashleymedin Apr 29, 2024
d171392
update commit
ashleymedin Apr 29, 2024
ce4e69f
update Cmake
ashleymedin May 24, 2024
783ab48
Merge remote-tracking branch 'upstream/master'
ashleymedin May 24, 2024
ffbeed5
cmake
ashleymedin May 24, 2024
5f00706
cmake
ashleymedin May 24, 2024
08e3f02
update commit
ashleymedin Jun 1, 2024
87291be
Merge remote-tracking branch 'upstream/master'
ashleymedin Jun 1, 2024
c7a9306
Merge remote-tracking branch 'upstream/master'
ashleymedin Jun 4, 2024
1c6da5c
fix Cmake
ashleymedin Jun 4, 2024
add6f43
fixing makelist and update summa commit
ashleymedin Jun 7, 2024
128abc2
Merge upstream/master
ashleymedin Dec 12, 2024
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -135,3 +135,5 @@ include/NGenConfig.h
data/forcing/huc01_demo/
# HUC01 Demo Testing Hydrofabric
data/hydrofabric/huc01_demo/
cat-27.csv
nex-26_output.csv
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@
path = extern/sloth
url = https://github.com/noaa-owp/SLoTH
branch = latest
[submodule "extern/summa"]
path = extern/summa/summa
url = https://github.com/ashleymedin/summa.git
branch = develop
[submodule "extern/netcdf-cxx4"]
path = extern/netcdf-cxx4/netcdf-cxx4
url = https://github.com/Unidata/netcdf-cxx4/
2 changes: 1 addition & 1 deletion extern/bmi-cxx
Submodule bmi-cxx updated 1 files
+0 −2 bmi.hxx
2 changes: 1 addition & 1 deletion extern/pybind11
Submodule pybind11 updated 132 files
2 changes: 1 addition & 1 deletion extern/sloth
254 changes: 254 additions & 0 deletions extern/summa/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,254 @@
cmake_minimum_required(VERSION 3.21 FATAL_ERROR)
project(summa VERSION 4.0.0 LANGUAGES Fortran C CXX)

if(DEFINED ENV{FC})
set (CMAKE_Fortran_COMPILER $ENV{FC}) #for NextGen need, works for others
else()
set (CMAKE_Fortran_COMPILER gfortran)
endif()

#=========================================================================================
# SUMMA can be compiled with debug flags by specifiying -DCMAKE_BUILD_TYPE=Debug
#
# There are multiple options for building SUMMA, including using the
# Sundials suite of solvers, the C++ Actor framework, and the NextGen framework.
# The options are set by specifying -DOPTION=ON when running cmake.
# For example to compile SUMMA with Sundials, use
# cmake -B ../cmake_build -S ../. -DUSE_SUNDIALS=ON
# cmake --build ../cmake_build --target all -j
#
# To compile SUMMA with Actors, see the Summa-Actors repo:
# https://github.com/uofs-simlab/Summa-Actors
#=========================================================================================

# Add options for build type
set(CMAKE_CONFIGURATION_TYPES Release Debug)

# Options: Enable each with cmake -DOPTION=ON
option(USE_SUNDIALS "Use IDA solver from SUNDIALS suite" OFF)
option(USE_ACTORS "Use Actors Framework" OFF)
option(USE_NEXTGEN "Use NextGen Framework" OFF)
set(EXT_TARGETS) # list of external targets to link to

# Set Default Executable Name
set(EXEC_NAME summa.exe)
# Set top-level directory
if (USE_NEXTGEN)
set(F_MASTER "${CMAKE_CURRENT_SOURCE_DIR}/summa")
else()
set(F_MASTER "${CMAKE_CURRENT_SOURCE_DIR}/..")
endif()

set(PARENT_DIR "${F_MASTER}")
set(EXEC_DIR "${F_MASTER}/bin")

# Handle optional external libraries
if (USE_SUNDIALS)
message("ENABLING SUNDIALS")
find_package(SUNDIALS REQUIRED)
list(APPEND EXT_TARGETS SUNDIALS::fida_mod_shared
SUNDIALS::fkinsol_mod_shared)
add_compile_definitions(SUNDIALS_ACTIVE)
set(EXEC_NAME summa_sundials.exe)
endif()

if (USE_ACTORS)
message("ENABLING ACTORS")
find_package(CAF 0.18.3 QUIET) # Cluster has 0.18.3, but we can use 0.18.6
if(NOT CAF_FOUND)
find_package(CAF 0.18.6 REQUIRED)
endif()
list(APPEND EXT_TARGETS CAF::core CAF::io)
add_compile_definitions(ACTORS_ACTIVE V4_ACTIVE)

include(FortranCInterface)
FortranCInterface_VERIFY(CXX)

set(PARENT_DIR "${F_MASTER}/..")
set(EXEC_DIR "${PARENT_DIR}/../bin")
set(EXEC_NAME summa_actors.exe)
endif()

if (USE_NEXTGEN)
message("ENABLING NEXTGEN")
if (USE_ACTORS)
message(FATAL_ERROR "NextGen incompatible with Summa-Actors")
endif()
add_compile_definitions(NGEN_ACTIVE BMI_ACTIVE NGEN_FORCING_ACTIVE
NGEN_OUTPUT_ACTIVE)
add_subdirectory(../iso_c_fortran_bmi ${CMAKE_BINARY_DIR}/iso_c_bmi)
list(INSERT CMAKE_MODULE_PATH 0 "${CMAKE_CURRENT_LIST_DIR}/summa/build/cmake/")
list(INSERT CMAKE_PREFIX_PATH 0 "${CMAKE_CURRENT_LIST_DIR}/summa/build/cmake/")
set(CMAKE_Fortran_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/fortran)
set(SUMMA_LIB_NAME_CMAKE summabmi)
set(SUMMA_LIB_DESC_CMAKE "Summa-Sundials BMI Module Shared Library")
else()
LIST(INSERT CMAKE_MODULE_PATH 0 "${CMAKE_SOURCE_DIR}/cmake/")
LIST(INSERT CMAKE_PREFIX_PATH 0 "${CMAKE_SOURCE_DIR}/cmake/")
endif()

get_filename_component(F_MASTER "${F_MASTER}" REALPATH)
get_filename_component(PARENT_DIR "${PARENT_DIR}" REALPATH)
get_filename_component(EXEC_DIR "${EXEC_DIR}" REALPATH)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${EXEC_DIR})

#=========================================================================================
# SET THE PATHS TO THE LIBRARIES AND INCLUDE FILES
#=========================================================================================

# NetCDF is found with a custom FindNetCDF.cmake file
find_package(NetCDF REQUIRED)
list(APPEND EXT_TARGETS NetCDF::NetCDF)

# OpenBLAS
set(BLA_VENDOR OpenBLAS) # MKL
find_package(OpenBLAS REQUIRED)
list(APPEND EXT_TARGETS OpenBLAS::OpenBLAS)

# Set compiler flags
set(FLAGS_OPT $ENV{FLAGS_OPT}) # get optional user-specified flags from environment variables
if(CMAKE_BUILD_TYPE MATCHES Debug)
message("\nSetting SUMMA Debug Options")
add_compile_definitions(DEBUG)
set(FLAGS_NOAH -g -O0 -fbacktrace -fbounds-check -ffree-form -ffree-line-length-none -fmax-errors=0 -fPIC -Wfatal-errors ${FLAGS_OPT})
set(FLAGS_ALL -g -O0 -fbacktrace -fbounds-check -ffree-line-length-none -fmax-errors=0 -fPIC -Wfatal-errors -cpp ${FLAGS_OPT})
set(FLAGS_CXX -g -O0 -fbounds-check -Wfatal-errors -std=c++17 ${FLAGS_OPT})
else()
message("\nSetting SUMMA Release Options")
set(FLAGS_NOAH -O3 -ffree-form -ffree-line-length-none -fmax-errors=0 -fPIC -Wfatal-errors ${FLAGS_OPT})
set(FLAGS_ALL -O3 -ffree-line-length-none -fmax-errors=0 -fPIC -Wfatal-errors -cpp ${FLAGS_OPT})
set(FLAGS_CXX -O3 -Wfatal-errors -std=c++17 ${FLAGS_OPT})
endif()

#=========================================================================================
# COMPILE PART 1: Define directory paths
#=========================================================================================

# Define directories that contains source code
set(DRIVER_DIR ${F_MASTER}/build/source/driver)
set(DSHARE_DIR ${F_MASTER}/build/source/dshare)
set(ENGINE_DIR ${F_MASTER}/build/source/engine)
set(HOOKUP_DIR ${F_MASTER}/build/source/hookup)
set(NETCDF_DIR ${F_MASTER}/build/source/netcdf)
set(NOAHMP_DIR ${F_MASTER}/build/source/noah-mp)

# Define Actors specific directories
set(ACTORS_DIR ${PARENT_DIR}/source)
set(SYS_INIT_DIR ${ACTORS_DIR}/system_initialization)
set(FILE_ACCESS_DIR ${ACTORS_DIR}/file_access_actor)
set(JOB_ACTOR_DIR ${ACTORS_DIR}/job_actor)
set(GRU_ACTOR_DIR ${ACTORS_DIR}/gru_actor)
set(HRU_ACTOR_DIR ${ACTORS_DIR}/hru_actor)

#=========================================================================================
# COMPILE PART 2: Assemble all of the SUMMA sub-routines
#=========================================================================================

# SUMMA Source Files are defined in the CMakeLists.txt file in the subdirectory
add_subdirectory(${F_MASTER}/build/source/)


#=========================================================================================
# COMPILE PART 3: Collect the subroutines into build groups depending on build type
#=========================================================================================

set(COMM_ALL ${NRPROC} ${HOOKUP} ${DATAMS} ${UTILMS})

set(SUMMA_ALL ${NETCDF} ${PRELIM} ${MODRUN} ${SOLVER} ${DRIVER})

if (USE_ACTORS)
set(COMM_ALL ${COMM_ALL} ${DATAMS_ACTORS} ${INTERFACE})
set(SUMMA_ALL ${SUMMA_ALL} ${SYS_INIT_INTERFACE} ${FILE_ACCESS_INTERFACE}
${JOB_INTERFACE} ${GRU_INTERFACE} ${HRU_INTERFACE})
set(MAIN_SUMMA ${ACTORS_DIR}/main.cpp)
else()
set(SUMMA_ALL ${SUMMA_ALL} ${PRELIM_NOT_ACTORS} ${MODRUN_NOT_ACTORS}
${SOLVER_NOT_ACTORS} ${DRIVER_NOT_ACTORS})
set(MAIN_SUMMA ${DRIVER_DIR}/summa_driver.f90)
endif()

if (USE_NEXTGEN)
set(SUMMA_ALL ${SUMMA_ALL} ${DRIVER_NEXTGEN})
endif()

if (USE_SUNDIALS)
set(COMM_ALL ${COMM_ALL} ${DATAMS_SUNDIALS} ${UTILMS_SUNDIALS})
set(SUMMA_ALL ${SUMMA_ALL} ${MODRUN_SUNDIALS} ${SOLVER_SUNDIALS})
endif()


# Define version number, not working correctly
set(VERSIONFILE ${DRIVER_DIR}/summaversion.inc)
execute_process(COMMAND " ${GIT_EXECUTABLE} tag | tail -n 1" OUTPUT_VARIABLE VERSION)
execute_process(COMMAND "date" OUTPUT_VARIABLE BULTTIM)
execute_process(COMMAND " ${GIT_EXECUTABLE} describe --long --all --always | sed -e's/heads\///'" OUTPUT_VARIABLE GITBRCH)
execute_process(COMMAND " ${GIT_EXECUTABLE} rev-parse HEAD" OUTPUT_VARIABLE GITHASH)


#=========================================================================================
# COMPILE PART 4: Do the compilation
#=========================================================================================

# update version information, not working correctly
file(WRITE ${VERSIONFILE} "character(len=64), parameter :: summaVersion = '${VERSION}'\n")
file(APPEND ${VERSIONFILE} "character(len=64), parameter :: buildTime = ''\n")
file(APPEND ${VERSIONFILE} "character(len=64), parameter :: gitBranch = '${GITBRCH}'\n")
file(APPEND ${VERSIONFILE} "character(len=64), parameter :: gitHash = '${GITHASH}'")

# Build SUMMA_NOAHMP Object
add_library(SUMMA_NOAHMP OBJECT ${NOAHMP} ${NRUTIL})
target_compile_options(SUMMA_NOAHMP PRIVATE ${FLAGS_NOAH})

# Build SUMMA_COMM Object
add_library(SUMMA_COMM OBJECT ${COMM_ALL})
target_compile_options(SUMMA_COMM PRIVATE ${FLAGS_ALL})
target_link_libraries(SUMMA_COMM PUBLIC SUMMA_NOAHMP ${EXT_TARGETS}) # added flags to the link step

# For NextGen, build SUMMA Shared Library and add the outside BMI libraries
if(USE_NEXTGEN)
if(WIN32)
add_library(summabmi ${SUMMA_ALL})
else()
add_library(summabmi SHARED ${SUMMA_ALL})
endif()
target_compile_options(summabmi PRIVATE ${FLAGS_ALL})
target_link_libraries(summabmi PUBLIC ${EXT_TARGETS} iso_c_bmi SUMMA_NOAHMP SUMMA_COMM)

set_target_properties(summabmi PROPERTIES VERSION ${PROJECT_VERSION})
include(GNUInstallDirs)

install(TARGETS summabmi
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
configure_file(summabmi.pc.in summabmi.pc @ONLY)
install(FILES ${CMAKE_BINARY_DIR}/summabmi.pc DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/pkgconfig)

else()
add_library(summa SHARED ${SUMMA_ALL})
target_compile_options(summa PRIVATE ${FLAGS_ALL})
target_link_libraries(summa PUBLIC ${EXT_TARGETS} SUMMA_NOAHMP SUMMA_COMM)

# For Actors, build SUMMA Shared Library add the actors libraries and add the executable
if(USE_ACTORS)
add_executable(${EXEC_NAME} ${MAIN_SUMMA} ${ACTORS_GLOBAL}
${FILE_ACCESS_ACTOR} ${JOB_ACTOR} ${GRU_ACTOR} ${HRU_ACTOR}
${SYS_INIT} ${SUMMA_CLIENT} ${SUMMA_SERVER})

set_property(TARGET ${EXEC_NAME} PROPERTY LINKER_LANGUAGE Fortran)
target_compile_options(${EXEC_NAME} PUBLIC ${FLAGS_CXX})
target_include_directories(${EXEC_NAME} PUBLIC
${PARENT_DIR}/includes/global
${PARENT_DIR}/includes/summa_actor
${PARENT_DIR}/includes/job_actor
${PARENT_DIR}/includes/file_access_actor
${PARENT_DIR}/includes/gru_actor
${PARENT_DIR}/includes/hru_actor)
target_link_libraries( ${EXEC_NAME} ${EXT_TARGETS} summa)

# For other cases, build SUMMA Shared Library and add the executable
else()
add_executable(${EXEC_NAME} ${MAIN_SUMMA})
set_property(TARGET ${EXEC_NAME} PROPERTY LINKER_LANGUAGE Fortran)
target_link_libraries(${EXEC_NAME} summa ${EXT_TARGETS}) # added flags to the link step
endif()
endif()
Loading