diff --git a/build_tsmp2.sh b/build_tsmp2.sh index 9d07bc3..1002637 100755 --- a/build_tsmp2.sh +++ b/build_tsmp2.sh @@ -36,7 +36,7 @@ function help_tsmp2() { echo " --OASIS_SRC Set OASIS3-MCT directory" echo " --PDAF_SRC Set PDAF_SRC directory" echo " --no_update Skip component model download" - echo " --build_type Set build configuration: 'DEBUG' 'RELEASE'" + echo " --build_type Set build configuration: 'DEBUG', 'RELEASE', or 'PROFILE'" echo " --build_dir Set build dir cmake, if not set bld/_ is used. Build artifacts will be generated in this folder." echo " --install_dir Set install dir cmake, if not set bin/_ is used. Model executables and libraries will be installed here" echo " --clean_first Delete build_dir if it already exists" @@ -207,8 +207,19 @@ if [ "${update_compsrc}" != n ]; then dwn_compsrc clm35 clm35_src "CLM3.5" fi +# 2. Determine build configuration +if [[ -z "$build_type" ]];then + build_type="RELEASE" +fi +if [[ ${build_type^^} == "DEBUG" || ${build_type^^} == "RELEASE" || ${build_type^^} == "PROFILE" ]]; then + cmake_build_type="${build_type^^}" +else + echo "ABORT: Unsupported build_type=${build_type}" + exit 1 +fi + # -# 2. Source environment file +# 3. Source environment file # if [[ ! -z "${env}" ]]; then @@ -230,15 +241,23 @@ if [[ ! -f "${env}" ]]; then exit 1 fi + if [[ -n "${env}" ]]; then message "Sourcing environment..." - # TODO: Fix this GPU thing on another PR + # TODO: Env file parameterization is temporary and should be fixed if [[ "$parflowGPU" == "y" ]];then - source "${env}" --parflowgpu - else - source "${env}" + env_gpu_params="--parflowgpu" + fi + if [[ ${build_type^^} == "PROFILE" ]];then + env_profile_params="--profile" + if [[ ":${TSMP2_ENV_FILE}:" != *"jsc.2026.gnu.openmpi"* ]]; then + message "ERROR: Profiling builds are only currently supported on jsc.2026.gnu.openmpi." + exit 1 + fi fi + message "SOURCE command: source ${env} ${env_gpu_params} ${env_profile_params}" + source "${env}" ${env_gpu_params} ${env_profile_params} fi # TSMP2_ENV_FILE should be set either (1) through --env, (2) as a shell variable, @@ -249,9 +268,14 @@ if [[ -z "${TSMP2_ENV_FILE}" ]]; then fi # -# 3. Set CMake build directory +# 4. Set CMake build directory # -BUILD_ID="${SYSTEMNAME^^}_${model_id}" +if [[ ${build_type^^} == "RELEASE" ]]; then + BUILD_ID="${SYSTEMNAME^^}_${model_id}" +else + BUILD_ID="${SYSTEMNAME^^}_${build_type^^}_${model_id}" +fi + if [[ -z "${build_dir}" ]]; then cmake_build_dir="${cmake_tsmp2_dir}/bld/${BUILD_ID}" else @@ -293,18 +317,9 @@ fi build_log="$(dirname ${cmake_build_dir})/${BUILD_ID}_$(date +%Y-%m-%d_%H-%M).log" # -# 4. Set the rest of the CMake options +# 5. Set the rest of the CMake options # message "Setting CMAKE options..." -if [[ -z "$build_type" ]];then - build_type="RELEASE" -fi -if [[ ${build_type^^} == "DEBUG" || ${build_type^^} == "RELEASE" ]]; then - cmake_build_type="${build_type^^}" -else - echo "ABORT: Unsupported build_type=${build_type}" - exit 1 -fi if [ -z "${verbose_makefile}" ]; then cmake_verbose_makefile="OFF" @@ -320,7 +335,7 @@ fi mkdir -p "${cmake_install_dir}" # -# 5. CMake configure +# 6. CMake configure # message "" message "====================" @@ -344,7 +359,7 @@ cmake ${cmake_conf} |& tee -a "${build_log}" message "== CMAKE GENERATE PROJECT finished" # -# 6. CMake build and install +# 7. CMake build and install # message "CMAKE build:" message "cmake --build ${cmake_build_dir} |& tee -a $build_log" @@ -359,7 +374,7 @@ cmake --install ${cmake_build_dir} |& tee -a $build_log message "== CMAKE INSTALL finished" # -# 7. Post-installation steps +# 8. Post-installation steps # message "Copying build log and environment file to ${cmake_install_dir}..." if [[ -n "${env}" ]]; then diff --git a/cmake/BuildOASIS3MCT.cmake b/cmake/BuildOASIS3MCT.cmake index c66840f..f71ec29 100644 --- a/cmake/BuildOASIS3MCT.cmake +++ b/cmake/BuildOASIS3MCT.cmake @@ -4,7 +4,7 @@ find_package(OpenMP REQUIRED) if (CMAKE_BUILD_TYPE STREQUAL "DEBUG") set(OPTIM "-g") set(MCT_DEBUGFLAG "--enable-debugging") -elseif (CMAKE_BUILD_TYPE STREQUAL "RELEASE") +elseif (CMAKE_BUILD_TYPE STREQUAL "RELEASE" OR CMAKE_BUILD_TYPE STREQUAL "PROFILE") set(OPTIM "-O2") set(MCT_DEBUGFLAG "") else() diff --git a/cmake/BuildParFlow.cmake b/cmake/BuildParFlow.cmake index 8171145..f0c9eb8 100644 --- a/cmake/BuildParFlow.cmake +++ b/cmake/BuildParFlow.cmake @@ -41,7 +41,10 @@ endif() # Set compiler flags if(CMAKE_C_COMPILER_ID STREQUAL "GNU") # Flags were based from https://github.com/parflow/parflow/blob/c8aa8d7140db19153194728b8fa9136b95177b6d/.github/workflows/linux.yml#L486 - set(PF_CFLAGS "-Wall -Werror -Wno-unused-result -Wno-unused-function -Wno-stringop-overread") + set(PF_CFLAGS "-Wall -Wno-unused-result -Wno-unused-function -Wno-stringop-overread") + if (NOT CMAKE_BUILD_TYPE STREQUAL "PROFILE") + string(APPEND PF_CFLAGS " -Werror") #compile warnings not ignored for DEBUG and RELEASE builds + endif() if(${PDAF}) # parflow-pdaf fork currently ignores unused variables string(APPEND PF_CFLAGS " -Wno-unused-variable") @@ -75,14 +78,25 @@ if (DEFINED ENV{SUNDIALS_ROOT} AND NOT ${PDAF}) set(PF_SUNDIALS_FLAG "-DSUNDIALS_ROOT=$ENV{SUNDIALS_ROOT}") endif() +# Profiling build (Experimental) +if (CMAKE_BUILD_TYPE STREQUAL "PROFILE") + set(PF_C_COMPILER $ENV{TSMP2_PROFILE_CC}) + set(PF_CXX_COMPILER $ENV{TSMP2_PROFILE_CXX}) + set(PF_Fortran_COMPILER $ENV{TSMP2_PROFILE_FC}) +else() + set(PF_C_COMPILER ${CMAKE_C_COMPILER}) + set(PF_CXX_COMPILER ${CMAKE_CXX_COMPILER}) + set(PF_Fortran_COMPILER ${CMAKE_Fortran_COMPILER}) +endif() + # Pass options to ParFlow CMake ExternalProject_Add(ParFlow PREFIX ParFlow SOURCE_DIR ${PARFLOW_SRC} - CMAKE_ARGS -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER} + CMAKE_ARGS -DCMAKE_C_COMPILER=${PF_C_COMPILER} -DCMAKE_C_FLAGS=${PF_CFLAGS} - -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} - -DCMAKE_Fortran_COMPILER=${CMAKE_Fortran_COMPILER} + -DCMAKE_CXX_COMPILER=${PF_CXX_COMPILER} + -DCMAKE_Fortran_COMPILER=${PF_Fortran_COMPILER} -DCMAKE_Fortran_FLAGS=${PF_FFLAGS} -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} -DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX} diff --git a/cmake/BuildeCLM.cmake b/cmake/BuildeCLM.cmake index 42f0f64..f54c7d3 100644 --- a/cmake/BuildeCLM.cmake +++ b/cmake/BuildeCLM.cmake @@ -14,12 +14,21 @@ if(${PDAF}) list(APPEND PDAF_FLAGS -DUSE_PDAF=True) endif() +# Experimental +if (CMAKE_BUILD_TYPE STREQUAL "PROFILE") + set(eCLM_C_COMPILER $ENV{TSMP2_PROFILE_CC}) + set(eCLM_Fortran_COMPILER $ENV{TSMP2_PROFILE_FC}) +else() + set(eCLM_C_COMPILER ${CMAKE_C_COMPILER}) + set(eCLM_Fortran_COMPILER ${CMAKE_Fortran_COMPILER}) +endif() + ExternalProject_Add(eCLM PREFIX eCLM SOURCE_DIR ${eCLM_SRC} SOURCE_SUBDIR src - CMAKE_ARGS -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER} - -DCMAKE_Fortran_COMPILER=${CMAKE_Fortran_COMPILER} + CMAKE_ARGS -DCMAKE_C_COMPILER=${eCLM_C_COMPILER} + -DCMAKE_Fortran_COMPILER=${eCLM_Fortran_COMPILER} -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} -DCMAKE_PREFIX_PATH=${OASIS_ROOT} -DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX} diff --git a/env/jsc.2026.gnu.openmpi b/env/jsc.2026.gnu.openmpi index d006c93..9b472ab 100644 --- a/env/jsc.2026.gnu.openmpi +++ b/env/jsc.2026.gnu.openmpi @@ -52,6 +52,12 @@ fi module load ecCodes # Set default MPI compilers +if [[ "$1" == "--profile" || "$2" == "--profile" ]]; then + module load Scalasca + export TSMP2_PROFILE_CC=$(which scorep-mpicc) + export TSMP2_PROFILE_FC=$(which scorep-mpif90) + export TSMP2_PROFILE_CXX=$(which scorep-mpicxx) +fi export CC=mpicc export FC=mpif90 export CXX=mpicxx @@ -64,14 +70,17 @@ export SUNDIALS_ROOT=$EBROOTSUNDIALS # Display compiler settings module list echo "=============== COMPILER SETTINGS ===============" -echo " Machine: ${SYSTEMNAME} on Stages/$STAGE" -echo " MPI lib: OpenMPI v$EBVERSIONOPENMPI" -echo " C: $($CC --version | head -n 1)" -echo " C++: $($CXX --version | head -n 1)" -echo " Fortran: $($FC --version | head -n 1)" +echo " Machine: ${SYSTEMNAME} on Stages/$STAGE" +echo " MPI lib: OpenMPI v$EBVERSIONOPENMPI" +echo " C: ${CC} (GCC ${EBVERSIONGCCCORE})" +echo " C++: ${CXX} (GCC ${EBVERSIONGCCCORE})" +echo " Fortran: ${FC} (GCC ${EBVERSIONGCCCORE})" if [[ "$1" == "--parflowgpu" ]]; then - echo " nvcc: $(nvcc --version | tail -n 1 | cut -d" " -f2)" - echo " CUDAARCHS: $CUDAARCHS" + echo " nvcc: $(nvcc --version | tail -n 1 | cut -d" " -f2)" + echo " CUDAARCHS: $CUDAARCHS" +fi +if [[ "$1" == "--profile" || "$2" == "--profile" ]]; then + echo " Profiler: Scalasca v${EBVERSIONSCALASCA}" fi echo "==================================================" echo ""