Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:07:31

0001 #!/bin/bash
0002 #
0003 #  file:        install_openmpi.sh
0004 #  description: BASH script for the installation of the openmpi package,
0005 #               can be used standalone or called from other scripts
0006 #
0007 #  author:      Markus Merschmeyer, RWTH Aachen University
0008 #  date:        2013/07/22
0009 #  version:     1.0
0010 #
0011 
0012 print_help() {
0013     echo "" && \
0014     echo "install_openmpi version 1.0" && echo && \
0015     echo "options: -v  version    define openmpi version ( "${OMVER}" )" && \
0016     echo "         -d  path       define openmpi installation directory" && \
0017     echo "                         -> ( "${IDIR}" )" && \
0018     echo "         -W  location   (web)location of openmpi tarball ( "${OMWEBLOCATION}" )" && \
0019     echo "         -S  filename   file name of openmpi tarball ( "${OMFILE}" )" && \
0020     echo "         -C  level      cleaning level of SHERPA installation ( "${LVLCLEAN}" )" && \
0021     echo "                         -> 0: nothing, 1: +objects (make clean)" && \
0022     echo "         -D             debug flag, compile with '-g' option ( "${FLGDEBUG}" )" && \
0023     echo "         -X             create XML file for tool override in CMSSW ( "${FLGXMLFL}" )" && \
0024     echo "         -Z             use multiple CPU cores if available ( "${FLGMCORE}" )" && \
0025     echo "         -K             keep openmpi source code tree after installation ( "${FGLKEEPT}" )" && \
0026     echo "         -h             display this help and exit" && echo
0027 }
0028 
0029 
0030 # save current path
0031 HDIR=`pwd`
0032 
0033 
0034 # dummy setup (if all options are missing)
0035 IDIR="/tmp"                # installation directory
0036 OMVER="1.6.5"              # version to be installed
0037 OMWEBLOCATION=""           # (web)location of openmpi tarball
0038 OMFILE=""                  # file name of openmpi tarball
0039 LVLCLEAN=0                 # cleaning level (0-2)
0040 FLGDEBUG="FALSE"           # debug flag for compilation
0041 FLGXMLFL="FALSE"           # create XML tool definition file for SCRAM?
0042 FGLKEEPT="FALSE"           # keep the source code tree?
0043 FLGMCORE="FALSE"           # use multiple cores for compilation
0044 
0045 
0046 # get & evaluate options
0047 while getopts :v:d:W:S:C:DXZKh OPT
0048 do
0049   case $OPT in
0050   v) OMVER=$OPTARG ;;
0051   d) IDIR=$OPTARG ;;
0052   W) OMWEBLOCATION=$OPTARG ;;
0053   S) OMFILE=$OPTARG ;;
0054   C) LVLCLEAN=$OPTARG ;;
0055   D) FLGDEBUG=TRUE ;;
0056   X) FLGXMLFL=TRUE ;;
0057   Z) FLGMCORE=TRUE ;;
0058   K) FLGKEEPT=TRUE ;;
0059   h) print_help && exit 0 ;;
0060   \?)
0061     shift `expr $OPTIND - 1`
0062     if [ "$1" = "--help" ]; then print_help && exit 0;
0063     else 
0064       echo -n "install_openmpi: error: unrecognized option "
0065       if [ $OPTARG != "-" ]; then echo "'-$OPTARG'. try '-h'"
0066       else echo "'$1'. try '-h'"
0067       fi
0068       print_help && exit 1
0069     fi
0070 #    shift 1
0071 #    OPTIND=1
0072   esac
0073 done
0074 
0075 
0076 # set openmpi download location
0077 if [ "$OMWEBLOCATION" = "" ]; then
0078   OMWEBLOCATION="http://www.open-mpi.org/software/ompi/v1.6/downloads"
0079 else
0080   if [ -e ${OMWEBLOCATION} ]; then   # is the location a local subdirectory?
0081     if [ -d ${OMWEBLOCATION} ]; then
0082       cd ${OMWEBLOCATION}; OMWEBLOCATION=`pwd`; cd ${HDIR}
0083     fi
0084   fi
0085 fi
0086 if [ "$OMFILE" = "" ]; then
0087   OMFILE="openmpi-${OMVER}.tar.gz"
0088 fi
0089 
0090 
0091 # make openmpi version a global variable
0092 export OMVER=${OMVER}
0093 # always use absolute path name...
0094 cd ${IDIR}; IDIR=`pwd`
0095 
0096 echo " openmpi installation: "
0097 echo "  -> openmpi version: '"${OMVER}"'"
0098 echo "  -> installation directory: '"${IDIR}"'"
0099 echo "  -> openmpi location: '"${OMWEBLOCATION}"'"
0100 echo "  -> openmpi file name: '"${OMFILE}"'"
0101 echo "  -> cleaning level: '"${LVLCLEAN}"'"
0102 echo "  -> debugging mode: '"${FLGDEBUG}"'"
0103 echo "  -> CMSSW override: '"${FLGXMLFL}"'"
0104 echo "  -> keep sources:   '"${FLGKEEPT}"'"
0105 echo "  -> use multiple CPU cores: '"${FLGMCORE}"'"
0106 
0107 
0108 
0109 # set path to local HEPMC2 installation
0110 export OMDIR=${IDIR}"/openmpi-"${OMVER}
0111 export OMIDIR=${IDIR}"/OM_"${OMVER}
0112 
0113 
0114 # add compiler & linker flags
0115 echo "CXX      (old):  "$CXX
0116 echo "CXXFLAGS (old):  "$CXXFLAGS
0117 echo "LDFLAGS  (old):  "$LDFLAGS
0118 ##MM FIXME
0119 #  export CXX=""
0120 #  export CXXFLAGS=""
0121 #  export LDFLAGS=""
0122 ##MM FIXME
0123 if [ "$FLGDEBUG" = "TRUE" ]; then
0124   CFDEBUG="-g"
0125   export CXXFLAGS=${CXXFLAGS}" "${CFDEBUG}
0126 fi
0127 echo "CXX      (new):  "$CXX
0128 echo "CXXFLAGS (new):  "$CXXFLAGS
0129 echo "LDFLAGS  (new):  "$LDFLAGS
0130 
0131 # add compiler & linker flags
0132 COPTS=""
0133 MOPTS=""
0134 POPTS=""
0135 if [ "$FLGMCORE" = "TRUE" ]; then
0136     nprc=`cat /proc/cpuinfo | grep  -c processor`
0137     let nprc=$nprc
0138     if [ $nprc -gt 1 ]; then
0139       echo " <I> multiple CPU cores detected: "$nprc
0140       POPTS=" -j"$nprc" "
0141     fi
0142 fi
0143 
0144 
0145 # download, extract compile/install openmpi
0146 cd ${IDIR}
0147 if [ ! -d ${OMIDIR} ]; then
0148   if [ `echo ${OMWEBLOCATION} | grep -c "http:"` -gt 0 ]; then
0149     echo " -> downloading openmpi "${OMVER}" from "${OMWEBLOCATION}/${OMFILE}
0150     wget ${OMWEBLOCATION}/${OMFILE}
0151   elif [ `echo ${OMWEBLOCATION} | grep -c "srm:"` -gt 0 ]; then
0152     echo " -> srm-copying openmpi "${OMVER}" from "${OMWEBLOCATION}/${OMFILE}
0153     srmcp ${OMWEBLOCATION}/${OMFILE} file:////${OMFILE}
0154   else
0155     echo " -> copying openmpi "${OMVER}" from "${OMWEBLOCATION}/${OMFILE}
0156     cp ${OMWEBLOCATION}/${OMFILE} ./
0157   fi
0158   tar -xzf ${OMFILE}
0159   if [ ! "$FLGKEEPT" = "TRUE" ]; then
0160     rm ${OMFILE}
0161   fi
0162   cd ${OMDIR}
0163 
0164   echo " -> configuring openmpi with options "${COPTS} && \
0165   ./configure --prefix=${OMIDIR} ${momflag} ${lenflag} ${COPTS} && \
0166   echo " -> making openmpi with options "${POPTS} ${MOPTS} && \
0167   make ${POPTS} ${MOPTS} && \
0168   echo " -> installing openmpi with options "${MOPTS} && \
0169   make install ${MOPTS}
0170   if [ ${LVLCLEAN} -gt 0 ]; then 
0171     echo " -> cleaning up openmpi installation, level: "${LVLCLEAN}" ..."
0172     if [ ${LVLCLEAN} -ge 1 ]; then  # normal cleanup (objects)
0173       make clean
0174     fi
0175   fi
0176   cd ${HDIR}
0177   if [ "$FLGKEEPT" = "TRUE" ]; then
0178     echo "-> keeping source code..."
0179   else
0180     rm -rf ${OMDIR}
0181   fi
0182 else
0183   echo " <W> path exists => using already installed openmpi"
0184 fi
0185 export OMDIR=${OMIDIR}
0186 cd ${HDIR}
0187 
0188 
0189 # create XML file fro SCRAM
0190 if [ "${FLGXMLFL}" = "TRUE" ]; then
0191   xmlfile="openmpi_"${OMVER}".xml"
0192   echo " <I>"
0193   echo " <I> creating openmpi tool definition XML file"
0194   if [ -e ${xmlfile} ]; then rm ${xmlfile}; fi; touch ${xmlfile}
0195   echo "  <tool name=\"openmpi\" version=\""${OMVER}"\">" >> ${xmlfile}
0196   tmppath=`find ${OMDIR} -type f -name libopenmpi.so\*`
0197 #
0198         echo "OMDIR: "$OMDIR
0199         echo "TMPPATH: "$tmppath
0200 #
0201   tmpcnt=`echo ${tmppath} | grep -o "/" | grep -c "/"`
0202   tmppath=`echo ${tmppath} | cut -f 1-${tmpcnt} -d "/"`
0203   for LIB in `cd ${tmppath}; ls *.so | cut -f 1 -d "." | sed -e 's/lib//'; cd ${HDIR}`; do
0204     echo "    <lib name=\""${LIB}"\"/>" >> ${xmlfile}
0205   done
0206   echo "    <client>" >> ${xmlfile}
0207   echo "      <Environment name=\"OM_BASE\" value=\""${OMDIR}"\"/>" >> ${xmlfile}
0208   echo "      <Environment name=\"LIBDIR\" default=\"\$OM_BASE/lib\"/>" >> ${xmlfile}
0209   echo "      <Environment name=\"INCLUDE\" default=\"\$OM_BASE/include\"/>" >> ${xmlfile}
0210   echo "    </client>" >> ${xmlfile}
0211   echo "  </tool>" >> ${xmlfile}
0212   if [ ! "$PWD" = "${HDIR}" ]; then
0213     mv ${xmlfile} ${HDIR}/
0214   fi
0215 
0216   if [ ! "$CMSSW_BASE" = "" ]; then
0217     cd $CMSSW_BASE
0218     tmpom=`scramv1 tool info openmpi | grep "OM_BASE" | cut -f2 -d"="`
0219     tmpxml=`find $CMSSW_BASE/config -type f -name qd.xml -printf %h`
0220     echo " <I>"
0221     echo " <I> openmpi version currently being used: "${tmpom}
0222     echo " <I> ...defined in "${tmpxml}
0223     cd ${tmpxml}; tmpxml=$PWD; cd ${HDIR}
0224     echo " <I>"
0225     echo " <I> If you want to override this version with the freshly produced "${xmlfile}","
0226     echo " <I> ...please type the following commands:"
0227     echo " <I>"
0228     echo "       cd $CMSSW_BASE"
0229     echo "       scramv1 tool remove openmpi"
0230     echo "       cp ${HDIR}/${xmlfile} ${tmpxml}/"
0231     echo "       scramv1 setup openmpi"
0232     echo "       cd -"
0233     echo " <I>"
0234   fi
0235 
0236 fi
0237 
0238 
0239 echo " -> openmpi installation directory is: " &&\
0240 echo "  "${OMIDIR} && \
0241 echo "" &&\
0242 echo "   + please make sure to add (prepend)" &&\
0243 echo "       "${OMIDIR}"/lib" &&\
0244 echo "      to LD_LIBRARY_PATH environment variable" &&\
0245 echo "   + please make sure to add (prepend)" &&\
0246 echo "       "${OMIDIR}"/bin" &&\
0247 echo "      to the PATH environment variable" &&\
0248 echo "   + please make sure to create a configuration file '.mpd.conf'" &&\
0249 echo "      in your home directory which at least should contain the line" &&\
0250 echo "       MPD_SECRETWORD=(some 8 character long code)" &&\
0251 echo "      and then to launch 'mpd' in the background before starting:" &&\
0252 echo "       mpd &" &&\
0253 echo "" &&\
0254 echo ""
0255 
0256 
0257 ## update LD_LIBRARY_PATH
0258 ## setup 'mpd' -> configuration file...
0259 ## modify PATH to find current 'mpiexec'/'mpirun' first