From 2e584b6ec16a4b07645aa52baab16ca216faff73 Mon Sep 17 00:00:00 2001 From: Stephen Copplestone Date: Tue, 19 Apr 2022 01:18:47 +0200 Subject: [PATCH] Created module env script for hopr installation and removed cloning/building hopr for nightly. Only clone/build hopr during weekly now but do not use the resulting executable. Use the module hopr executable on default. --- .gitlab-ci.yml | 26 +- tools/Setup_ModuleEnv/InstallHOPR.sh | 307 ++++++++++++++++++ tools/Setup_ModuleEnv/README.md | 5 +- .../moduletemplates/utilities/hopr/hopr_temp | 30 ++ 4 files changed, 357 insertions(+), 11 deletions(-) create mode 100755 tools/Setup_ModuleEnv/InstallHOPR.sh create mode 100644 tools/Setup_ModuleEnv/moduletemplates/utilities/hopr/hopr_temp diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index e9a5aafb4..253cccd8c 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -173,16 +173,6 @@ build: - mkdir -p build ; cd build - git clone git@gitlab.com:reggie2.0/reggie2.0.git reggie - cmake .. -DLIBS_BUILD_HDF5=OFF -DPICLAS_BUILD_POSTI=ON -DPOSTI_BUILD_SUPERB=ON -DPICLAS_READIN_CONSTANTS=ON ; make -j all - - if [ -n "${DO_NIGHTLY}" ] || [ -n "${DO_WEEKLY}" ]; then - git clone https://github.com/flexi-framework/hopr.git hopr; - cd hopr ; mkdir -p build ; cd build; - echo `pwd`; - cmake .. -DHOPR_BUILD_HDF5=OFF; - make -j all &> output.txt; - tail -n 20 output.txt; - rm output.txt; - ls bin/hopr; - fi build_maxwell: tags: @@ -230,6 +220,22 @@ build_poisson: - git clone git@gitlab.com:reggie2.0/reggie2.0.git reggie - cmake .. -DCMAKE_BUILD_TYPE=Debug -DPICLAS_EQNSYSNAME=poisson -DPICLAS_CODE_ANALYZE=ON -DPICLAS_TIMEDISCMETHOD=RK3 -DLIBS_BUILD_HDF5=OFF ; make -j all +build_hopr: + tags: + - withmodules-concurrent + stage: build + script: + - git clone https://github.com/hopr-framework/hopr.git hopr; + - cd hopr ; mkdir -p build ; cd build; + - echo `pwd`; + - cmake .. -DHOPR_BUILD_HDF5=OFF; + - make -j all &> output.txt; + - tail -n 20 output.txt; + - rm output.txt; + - ls bin/hopr; + rules: + - if: '$DO_WEEKLY' + # ---------------------------------------------------------------------------------------------------------------------------------------------------- # Stage "reggie_checkin": Run most simple reggie with previous builds on check-in # ---------------------------------------------------------------------------------------------------------------------------------------------------- diff --git a/tools/Setup_ModuleEnv/InstallHOPR.sh b/tools/Setup_ModuleEnv/InstallHOPR.sh new file mode 100755 index 000000000..dc3b6ed19 --- /dev/null +++ b/tools/Setup_ModuleEnv/InstallHOPR.sh @@ -0,0 +1,307 @@ +#!/bin/bash -i + +#============================================================================== +# title : InstallHOPR.sh +# description : This script installs HOPR with specific setting in a +# pre-installed module env +# date : Apr 18, 2022 +# version : 1.0 +# usage : bash InstallHOPR.sh +# notes : Bash in run interactively via "-i" to use "module load/purge" +# commands +#============================================================================== + +# Check privilege +if [[ "$EUID" -ne 0 ]]; then + echo "Please run as root" + exit 1 +fi + +# -------------------------------------------------------------------------------------------------- +# Colors +# -------------------------------------------------------------------------------------------------- + +if test -t 1; then # if terminal + NbrOfColors=$(which tput > /dev/null && tput colors) # supports color + if test -n "$NbrOfColors" && test $NbrOfColors -ge 8; then + TERMCOLS=$(tput cols) + BOLD="$(tput bold)" + UNDERLINE="$(tput smul)" + STANDOUT="$(tput smso)" + NORMAL="$(tput sgr0)" + NC="$(tput sgr0)" + BLACK="$(tput setaf 0)" + RED="$(tput setaf 1)" + GREEN="$(tput setaf 2)" + YELLOW="$(tput setaf 3)" + BLUE="$(tput setaf 4)" + MAGENTA="$(tput setaf 5)" + CYAN="$(tput setaf 6)" + WHITE="$(tput setaf 7)" + fi +fi + +# -------------------------------------------------------------------------------------------------- +# Functions +# -------------------------------------------------------------------------------------------------- +# Function for checking modules +check_module () { + if [ -z "${2}" ]; then + echo "module for ${1} not found. Exit" + exit + else + echo "${1}: [${2}]" + fi + } + +# Function for loading modules and checking if they exist in a specific combination +load_module () { + ERROR=$(module load "$1" 2>&1 | grep -in "ERROR") + if [ ! -z "$ERROR" ]; then + echo " " + echo -e "$RED$ERROR$NC" + echo -e "$RED""Failed: [module load $1]. Exit$NC" + exit + else + module load "$1" + fi + } + +# -------------------------------------------------------------------------------------------------- +# Setup +# -------------------------------------------------------------------------------------------------- +# Check command line arguments +RERUNMODE=0 +LOADMODULES=1 +for ARG in "$@" +do + + if [ ${ARG} == "--help" ] || [ ${ARG} == "-h" ]; then + echo "Input arguments:" + echo "--help/-h print help information" + echo "--modules/-m use modules defined in this script by the user." + echo " Otherwise, find modules automatically." + exit + fi + + if [ ${ARG} == "--modules" ] || [ ${ARG} == "-m" ]; then + LOADMODULES=0 + # Set desired versions + #CMAKEVERSION=3.15.3-d + #CMAKEVERSION=3.17.0-d + #CMAKEVERSION=3.20.3 + CMAKEVERSION=3.21.3 + + #GCCVERSION=9.2.0 + #GCCVERSION=9.3.0 + #GCCVERSION=10.1.0 + #GCCVERSION=10.2.0 + GCCVERSION=11.2.0 + + #OPENMPIVERSION=3.1.4 + #OPENMPIVERSION=4.0.1 + #OPENMPIVERSION=4.0.2 + #OPENMPIVERSION=3.1.6 + OPENMPIVERSION=4.1.1 + + #HDF5VERSION=1.10.5 + #HDF5VERSION=1.10.6 + HDF5VERSION=1.12.1 + fi + + # Check if re-run mode is selected by the user + if [[ ${ARG} == "--rerun" ]] || [[ ${ARG} =~ ^-r(erun)?$ ]]; then + RERUNMODE=1 + fi + +done + +HOPRVERSION='master' +HOPRDOWNLOAD='https://github.com/hopr-framework/hopr.git' + +# -------------------------------------------------------------------------------------------------- +# Check pre-requisites +# -------------------------------------------------------------------------------------------------- + +# -------------------------------------------------------------------------------------------------- +# Settings +# -------------------------------------------------------------------------------------------------- + +NBROFCORES=$(grep ^cpu\\scores /proc/cpuinfo | uniq | awk '{print $4}') +#NBROFCORES=1 # set to fixed value when errors are encountered at random (not related to missing packages) +INSTALLDIR=/opt +SOURCESDIR=/opt/sources +MODULESDIR=/opt/modules/modulefiles +TEMPLATEPATH=$(echo `pwd`/moduletemplates/utilities/hopr/hopr_temp) +if [[ ! -f ${TEMPLATEPATH} ]]; then + echo "${RED}ERROR: module template not found under ${TEMPLATEPATH}${NC}. Exit." + exit +fi + +if [ ! -d "${SOURCESDIR}" ]; then + mkdir -p "${SOURCESDIR}" +fi + +# Check if module is available (not required here, but for following libs) +if [[ -n $(module purge 2>&1) ]]; then + echo -e "${RED}module: command not found.\nThis script must be run in an interactive shell (the first line must read '#! /bin/bash' -i)${NC}" + exit +fi + +# take the first gcc compiler installed with first compatible openmpi and hdf5 +echo " " +if [[ $LOADMODULES -eq 1 ]]; then + CMAKEVERSION=$(ls ${MODULESDIR}/utilities/cmake/ | sed 's/ /\n/g' | grep -i "[0-9]\." | head -n 1 | tail -n 1) + GCCVERSION=$(ls ${MODULESDIR}/compilers/gcc/ | sed 's/ /\n/g' | grep -i "[0-9]\." | head -n 1 | tail -n 1) + OPENMPIVERSION=$(ls ${MODULESDIR}/MPI/openmpi/ | sed 's/ /\n/g' | grep -i "[0-9]\." | head -n 1 | tail -n 1) + HDF5VERSION=$(ls ${MODULESDIR}/libraries/hdf5/ | sed 's/ /\n/g' | grep -i "[0-9]\." | head -n 1 | tail -n 1) + echo -e "Modules found automatically.\n\nCMAKEVERSION=${CMAKEVERSION}\nGCCVERSION=${GCCVERSION}\nOPENMPIVERSION=${OPENMPIVERSION}\nHDF5VERSION=${HDF5VERSION}\n\nWARNING: The combination might not be possible!" + if [[ ${RERUNMODE} -eq 0 ]]; then + read -p "Press [Enter] to continue or [Crtl+c] to abort!" + fi +else + echo "Modules defined by user. Check if the combination is possible!" +fi + +check_module "cmake" "${CMAKEVERSION}" +check_module "gcc " "${GCCVERSION}" +check_module "mpi " "${OPENMPIVERSION}" +check_module "hdf5 " "${HDF5VERSION}" + +HOPRMODULEFILEDIR=${MODULESDIR}/utilities/hopr/${HOPRVERSION}/gcc/${GCCVERSION}/openmpi/${OPENMPIVERSION}/hdf5 +MODULEFILE=${HOPRMODULEFILEDIR}/${HDF5VERSION} + +# if no HOPR module for this compiler found, install HOPR and create module +if [ ! -e "${MODULEFILE}" ]; then + echo -e "$GREEN""creating HOPR-${HOPRVERSION} for GCC-${GCCVERSION} under$NC" + echo -e "$GREEN""$MODULEFILE$NC" + echo " " + module purge + load_module "cmake/${CMAKEVERSION}" + load_module "gcc/${GCCVERSION}" + load_module "openmpi/${OPENMPIVERSION}/gcc/${GCCVERSION}" + load_module "hdf5/${HDF5VERSION}/gcc/${GCCVERSION}/openmpi/${OPENMPIVERSION}" + module list + echo " " + echo -e "$GREEN""Important: If the compilation step fails, run the script again and if it still fails \n1) try compiling single, .i.e., remove -j from make -j or \n2) try make -j 2 (not all available threads)$NC" + echo " " + echo -e "This will install HOPR version ${GREEN}${HOPRVERSION}${NC} from ${HOPRDOWNLOAD} \nCompilation in parallel will be executed with ${GREEN}${NBROFCORES} threads${NC}." + if [[ ${RERUNMODE} -eq 0 ]]; then + read -p "Have the correct modules been loaded? If yes, press [Enter] to continue or [Crtl+c] to abort!" + fi + + # Install destination + HOPRINSTALLDIR=/opt/hopr/${HOPRVERSION}/gcc-${GCCVERSION}/openmpi-${OPENMPIVERSION}/hdf5-${HDF5VERSION} + + # Create and change to install directory + mkdir -p ${HOPRINSTALLDIR} + cd ${HOPRINSTALLDIR} + + # Check if repo is already downloaded + CLONEDIR=${HOPRINSTALLDIR}/hopr + if [[ -d ${CLONEDIR} ]]; then + # Inquiry: Continue the installation with the existing files OR remove them all and start fresh + while true; do + echo " " + echo "${YELLOW}${CLONEDIR} already exists.${NC}" + echo "${YELLOW}Do you want to continue the installation (y/n)?${NC}" + # Inquiry + if [[ ${RERUNMODE} -eq 0 ]]; then + read -p "${YELLOW}Otherwise the directory will be removed and a fresh installation will be performed. [Y/n]${NC}" yn + else + yn=y + fi + # Select case + case $yn in + [Yy]* ) echo "Continuing... "; break;; + [Nn]* ) rm -rf ${CLONEDIR} ; break;; + * ) echo "Please answer yes or no.";; + esac + done + fi + + # Check if git repo exists/is available + # echo "Checking git repository ${HOPRDOWNLOAD}" + # wget ${HOPRDOWNLOAD} --no-check-certificate -o /dev/null + # ERRORCODE=$? + # if [ ${ERRORCODE} -ne 0 ]; then + # echo " " + # echo -e "$RED""Failed to find git repository: [wget ${HOPRDOWNLOAD} --no-check-certificate -o /dev/null]$NC" + # exit + # fi + + # Clone git repository + if [[ -d ${CLONEDIR} ]]; then + cd ${CLONEDIR} + git fetch + git pull origin ${HOPRVERSION} + else + git clone ${HOPRDOWNLOAD} + cd ${CLONEDIR} + fi + echo `pwd` + + + # Check if extraction failed + ERRORCODE=$? + if [ ${ERRORCODE} -ne 0 ]; then + echo " " + echo -e "$RED""Failed to download [git clone ${HOPRDOWNLOAD}] or update [git pull origin ${HOPRVERSION}]$NC" + exit + else + HOPRBUILDDIR=${CLONEDIR}/build + rm -rf ${HOPRBUILDDIR} + mkdir -p ${HOPRBUILDDIR} + cd ${HOPRBUILDDIR} + fi + + # CMAKE COMPILE FLAGS DEPEND ON THE CHOSEN HOPR VERSION! + #if [ "$PARAVIEWVERSION" == "5.2.0" ] || [ "$PARAVIEWVERSION" == "5.3.0" ] || [ "$PARAVIEWVERSION" == "5.4.0" ]; then + cmake -DCMAKE_BUILD_TYPE=Release \ + -DLIBS_USE_MPI=ON \ + -DLIBS_BUILD_HDF5=OFF \ + ${CLONEDIR} + #else + #echo -e "$RED""ERROR: Set the correct cmake compile flags for the HOPR version [$HOPRVERSION] in InstallHOPR.sh$NC" + #exit + #fi + + # Compile source files with NBROFCORES threads + make -j${NBROFCORES} 2>&1 | tee make.out + + # Check if compilation failed + if [ ${PIPESTATUS[0]} -ne 0 ]; then + echo " " + echo -e "$RED""Failed: [make -j${NBROFCORES} 2>&1 | tee make.out]$NC" + exit + else + make install 2>&1 | tee install.out + fi + + + #ERRORCODE=$? + #echo ${ERRORCODE} + #echo `pwd` + #ls -l + #read -p "Download okay?" + + + # create modulefile if the installation seems successful (check if mpicc, mpicxx, mpifort exists in installdir) + if [ -e "${HOPRBUILDDIR}/bin/hopr" ]; then + if [ ! -d "${HOPRMODULEFILEDIR}" ]; then + mkdir -p ${HOPRMODULEFILEDIR} + fi + cp ${TEMPLATEPATH} ${MODULEFILE} + sed -i 's/hoprversion/'${HOPRVERSION}'/gI' ${MODULEFILE} + sed -i 's/CMAKEVERSIONFLAG/'${CMAKEVERSION}'/gI' ${MODULEFILE} + sed -i 's/GCCVERSIONFLAG/'${GCCVERSION}'/gI' ${MODULEFILE} + sed -i 's/MPIVERSIONFLAG/'${OPENMPIVERSION}'/gI' ${MODULEFILE} + sed -i 's/HDF5VERSIONFLAG/'${HDF5VERSION}'/gI' ${MODULEFILE} + sed -i 's\HOPRTOPDIR\'${HOPRBUILDDIR}'\gI' ${MODULEFILE} + else + echo -e "$RED""No module file created for HOPR-${HOPRVERSION} for GCC-${GCCVERSION}$NC" + echo -e "$RED""no installation found in ${HOPRBUILDDIR}/bin$NC" + fi +else + echo -e "$YELLOW""HOPR-${HOPRVERSION} already created: module file exists under ${MODULEFILE}$NC" +fi diff --git a/tools/Setup_ModuleEnv/README.md b/tools/Setup_ModuleEnv/README.md index d513c1f0e..ba55ca9d1 100644 --- a/tools/Setup_ModuleEnv/README.md +++ b/tools/Setup_ModuleEnv/README.md @@ -44,7 +44,7 @@ This cleans the created module file and build directory of the version currently ## 6. HDF5 from [https://support.hdfgroup.org/ftp/HDF5/releases/](https://support.hdfgroup.org/ftp/HDF5/releases/) sudo ./InstallHDF5.sh -## 7. ParaViewfrom [https://www.paraview.org/download/](https://www.paraview.org/download/) +## 7. ParaView from [https://www.paraview.org/download/](https://www.paraview.org/download/) The installation of ParaView is not mandatory for piclas/hopr. The pre-requisites for Ubuntu are installed via sudo ./InstallPackagesParaView.sh @@ -53,4 +53,7 @@ and Paraview itself is installed via sudo ./InstallParaview.sh +## 8. HOPR from [https://github.com/hopr-framework/hopr](https://github.com/hopr-framework/hopr) +This installation is optional and creates a module for HOPR by running + sudo ./InstallHOPR.sh diff --git a/tools/Setup_ModuleEnv/moduletemplates/utilities/hopr/hopr_temp b/tools/Setup_ModuleEnv/moduletemplates/utilities/hopr/hopr_temp new file mode 100644 index 000000000..4ee668816 --- /dev/null +++ b/tools/Setup_ModuleEnv/moduletemplates/utilities/hopr/hopr_temp @@ -0,0 +1,30 @@ +#%Module1.0##################################################################### +## +## modules hopr/hoprversion +## +## modulefiles/utilities/hopr/hoprversion +## +proc ModulesHelp { } { + global version modroot + + puts stderr "hopr-hoprversion - sets the Environment for HOPR-hoprversion" +} + +module-whatis "Sets the environment for using hopr-hoprversion" + +conflict hopr + +prereq cmake/CMAKEVERSIONFLAG +prereq gcc/GCCVERSIONFLAG +prereq openmpi/MPIVERSIONFLAG/gcc/GCCVERSIONFLAG +prereq hdf5/HDF5VERSIONFLAG/gcc/GCCVERSIONFLAG/openmpi/MPIVERSIONFLAG + +# for Tcl script use only +set topdir HOPRTOPDIR +set version hoprversion +set sys linux64 + +prepend-path PATH $topdir/bin +prepend-path LD_LIBRARY_PATH $topdir/lib +prepend-path HOPR_PATH $topdir/bin/hopr +#set-alias paraviewmpi "paraview --mpi$