#! /bin/csh -f setenv MACH phoenix source env_conf || "problem sourcing env_conf" && exit -1 source env_run || "problem sourcing env_run" && exit -1 source env_mach.$MACH || "problem sourcing env_mach.$MACH" && exit -1 source env_pes.$MACH || "problem sourcing env_pes.$MACH" && exit -1 source /autofs/spin/home/hof/CCSM/ccsm3_1_beta40.bgcmip/scripts/i01.10cn/Tools/env_setcomp || "problem sourcing env_setcomp" && exit -1 echo ------------------------------------------------------------------------- echo " Preparing $GRID component models for execution " echo ------------------------------------------------------------------------- if !($?LID) setenv LID "`date +%y%m%d-%H%M%S`" # ------------------------------------------------------------------------- echo " - Create execution directories for atm,cpl,lnd,ice,ocn" # ------------------------------------------------------------------------- foreach DIR ( $EXEROOT $LIBROOT $INCROOT $OBJROOT) if !(-d $DIR) mkdir -p $DIR || "cannot make $DIR" && exit -1 end rm -rf $EXEROOT/all; mkdir -p $EXEROOT/all || "cannot make $EXEROOT/all" && exit -1 # ------------------------------------------------------------------------- echo " - If a restart run then copy restart files into executable directory " # ------------------------------------------------------------------------- if ($MACH != 'moon') then $UTILROOT/Tools/ccsm_getrestart endif # ------------------------------------------------------------------------- echo " - Check validity of variables" # ------------------------------------------------------------------------- if ($BLDTYPE != 'TRUE' && $BLDTYPE != 'FALSE') then echo "error in BLDTYPE: $BLDTYPE" exit 1 endif echo " - Build flag (BLDTYPE) is $BLDTYPE" if ($SINGLE_EXEC != 'TRUE' && $SINGLE_EXEC != 'FALSE') then echo "error in SINGLE_EXEC: $SINGLE_EXEC" exit 1 endif echo " - Build flag (SINGLE_EXEC) is $SINGLE_EXEC" # ------------------------------------------------------------------------- echo " - Check validity of configuration" # ------------------------------------------------------------------------- set reconfig = FALSE $UTILROOT/Tools/ccsm_listcache > $CASEROOT/.cache/env_conf.checkcache.tmp cmp -s $CASEROOT/.cache/env_conf.checkcache.tmp $CASEROOT/.cache/env_conf.cache || set reconfig = TRUE if ($reconfig == 'TRUE') then echo "ERROR - env_conf has changed since initial configuration" echo "must invoke the following:" echo " configure -cleanall" echo " configure -mach $MACH" echo "Warning: this will delete Buildexe, Buildlib, Buildnml_Prestage" exit -1 endif if (-f $CASEROOT/.cache/env_conf.checkcache.tmp) rm $CASEROOT/.cache/env_conf.checkcache.tmp set reconfig = FALSE cmp -s $CASEROOT/env_pes.$MACH $CASEROOT/.cache/env_pes.$MACH.cache || set reconfig = TRUE if ($reconfig == 'TRUE') then echo "ERROR - tasks and/or threads and/or component layout has changed since initial configuration" echo "must invoke the following:" echo " configure -cleanmach $MACH" echo " configure -mach $MACH " exit -1 endif # ------------------------------------------------------------------------- echo " - Build Libraries: mph, mct" # ------------------------------------------------------------------------- cd $EXEROOT foreach lib (mph mct) set exedir = $EXEROOT/$lib; if !(-d $exedir) mkdir -p $exedir set file = $lib.buildlib.$LID cd $exedir echo `date` $file | tee $file $CASEROOT/Buildlib/$lib.buildlib >>& $file if ($status != 0) then echo ERROR: $lib.buildlib failed, see ${file} echo ERROR: cat $cwd/${file} exit 99 endif end # ------------------------------------------------------------------------- echo " - Determine if models must be rebuilt" # ------------------------------------------------------------------------- #--- note that the variable BLDTYPE is determined at this point but used #--- primarily by the component templates, and just a bit in here if !(-f $CASEROOT/.cache/Macros.$MACH) then cp $CASEROOT/Macros.$MACH $CASEROOT/.cache/Macros.$MACH.cache endif set rebuild = FALSE cmp -s $CASEROOT/Macros.$MACH $CASEROOT/.cache/Macros.$MACH.cache || set rebuild = TRUE if (($BLDTYPE == 'FALSE') && ($rebuild == 'TRUE')) then echo "bldtype is $BLDTYPE and rebuild is $rebuild" echo "Macros.$MACH files differ - must rebuild the ccsm models" exit -1 endif # ------------------------------------------------------------------------- echo " - Create model directories, build model executables, create namelist" echo " files, prestage input data" # ------------------------------------------------------------------------- if ($SINGLE_EXEC == 'TRUE') set COMPLIBS = () foreach n (1 2 3 4 5) #--- Set component specific variables set model = $MODELS[$n] set comp = $COMPONENTS[$n] set nthrd = $NTHRDS[$n] #--- Make necessary directories set objdir = $OBJROOT/$model/obj ; if !(-d $objdir) mkdir -p $objdir set exedir = $EXEROOT/$model ; if !(-d $exedir) mkdir -p $exedir #--- Go into executable directory cd $exedir set file_prestage = $model.log.$LID set file_build = $model.buildexe.$LID echo `date` $exedir/${file_prestage} | tee ${file_prestage} echo `date` $exedir/${file_build} | tee ${file_build} #--- Build Namelists/Prestage component input data set buildonly = false if ($?CCSMBUILDONLY) then if ($CCSMBUILDONLY == 'TRUE') then set buildonly = true endif endif if ($buildonly == 'false') then $CASEROOT/Buildnml_Prestage/$comp.buildnml_prestage.csh >>& ${file_prestage} if ($status != 0) then echo ERROR: $comp.buildnml_prestage.csh failed, see ${file_prestage} echo ERROR: cat $cwd/${file_prestage} exit 99 endif endif #--- Build Model Executables or Libraries $CASEROOT/Buildexe/$comp.buildexe.csh >>& ${file_build} if ($status != 0) then echo ERROR: $comp.buildexe.csh failed, see ${file_build} echo ERROR: cat $cwd/${file_build} exit 99 endif #--- If single executable, add library name to env var COMPLIBS if ($SINGLE_EXEC == 'TRUE') then set COMPLIBS = ($COMPLIBS '-L$(EXEROOT)/'$model '-l'$comp) endif #--- if multiple executable, save the latest executables to the active exe.tar if ($SINGLE_EXEC == 'FALSE') then if ($BLDTYPE == 'TRUE') then if ($n == 1) then tar -cf $EXEROOT/$CASE.exe.$LID.tar $comp else tar -rf $EXEROOT/$CASE.exe.$LID.tar $comp endif if ($n == 5) then cmp -s $EXEROOT/$CASE.exe.tar $EXEROOT/$CASE.exe.$LID.tar if ($status == 0) then rm -f $EXEROOT/$CASE.exe.$LID.tar else cp $EXEROOT/$CASE.exe.$LID.tar $EXEROOT/$CASE.exe.tar endif endif endif endif end #--- If single executable, link all component libraries and se_master.F90 #--- into ccsm_se.exe if ($SINGLE_EXEC == 'TRUE') then echo ------------------------------------------------------------------------- echo " Building a single executable version of CCSM " echo ------------------------------------------------------------------------- cd $EXEROOT/all cat >! Filepath << EOF $CCSMROOT/models/cpl/cpl6/driver_con $CCSMROOT/models/csm_share/shr $CCSMROOT/models/csm_share/cpl EOF if ($OS == 'UNICOS') then if (`uname` == 'Linux') then # cross compiler needs to build dependency program for itself module purge gcc -o makdep $BLDROOT/makdep.c || exit 2 source $CASEROOT/env_mach.$MACH || exit -1 else # makes the build run faster on the Cray X1E cc -h command -o makdep $BLDROOT/makdep.c || exit 2 endif else if ($OS == 'Linux' && $SITE == 'ORNL') then gcc -o makdep $BLDROOT/makdep.c || exit 2 else cc -o makdep $BLDROOT/makdep.c || exit 2 endif set THREAD = FALSE if ($NTHRDS_ATM > 1 || $NTHRDS_CPL > 1 || $NTHRDS_ICE > 1 || \ $NTHRDS_LND > 1 || $NTHRDS_OCN > 1 ) set THREAD = TRUE gmake VPFILE=Filepath EXEC_SE=ccsm_se.exe \ THREAD=$THREAD COMPLIBS="$COMPLIBS" -f $BLDROOT/Makefile \ MACFILE=$CASEROOT/Macros.$MACH deps || exit 2 gmake exec_se -j $GMAKE_J VPFILE=Filepath EXEC_SE=ccsm_se.exe \ THREAD=$THREAD COMPLIBS="$COMPLIBS" -f $BLDROOT/Makefile \ MACFILE=$CASEROOT/Macros.$MACH || exit 2 rm makdep #--- rename and save the latest executable (single_exec only) if ($BLDTYPE == 'TRUE') then cp ccsm_se.exe $EXEROOT/$CASE.exe.$LID cmp -s $EXEROOT/$CASE.exe $EXEROOT/$CASE.exe.$LID if ($status == 0) then rm -f $EXEROOT/$CASE.exe.$LID else cp $EXEROOT/$CASE.exe.$LID $EXEROOT/$CASE.exe endif endif endif # ------------------------------------------------------------------------- echo " - Create MPH input file and link into all model dirs" # ------------------------------------------------------------------------- #--- note that file formats are different for single and multiple executables cd $EXEROOT/all set MPHFILE = mph_processors_map.in if ($SINGLE_EXEC == 'TRUE') then echo "PROCESSORS_MAP" >>! $MPHFILE echo "BEGIN" >>! mph_processors_map.in echo "Multi_Comp_Start" >>! $MPHFILE @ M1 = 0 foreach n (1 2 3 4 5) set comp = $COMPONENTS[$n] set model = $MODELS[$n] set nthrd = $NTHRDS[$n] set ntask = $NTASKS[$n] @ M2 = $M1 + $ntask - 1 echo "$model $M1 $M2 THREADS=$nthrd" >>! $MPHFILE @ M1 = $M2 + 1 end echo "Multi_Comp_End" >>! $MPHFILE echo "END" >>! $MPHFILE endif if ($SINGLE_EXEC == 'FALSE') then cat >! $MPHFILE <! $stdiofile << EOF &stdio dir = "$rundir " stdout = "$stdoutfile " $nl_input = "$stdinfile " / EOF rm -f $exedir/$stdiofile ln -s $EXEROOT/all/$stdiofile $exedir end # ------------------------------------------------------------------------- # Save model output stdout and stderr # ------------------------------------------------------------------------- if ($LOGDIR != "") then cd $EXEROOT gzip */*.buildexe*$LID if (! -d $LOGDIR) mkdir -p $LOGDIR if (! -d $LOGDIR/bld) mkdir -p $LOGDIR/bld cp -p */*buildexe*$LID.* $LOGDIR/bld || echo "Error in copy of build logs " && exit -1 endif echo "-------------------------------------------------------------------------" echo " - CCSM BUILD HAS FINISHED SUCCESSFULLY " echo "-------------------------------------------------------------------------"