#! /bin/csh # # This is an example job script to configure, build, and execute a tgcm # model on a Linux system. # # To use: # 1) Set script variables below. # 2) Copy to a large working directory on the target machine. # 3) Assuming this script is called "jobfile", then: # a) If on lightning, use "bsub < jobfile" # b) To run interactively on non-lightning Linux system (e.g. at hao), # use "jobfile >&! jobfile.out &" # # See http://www.hao.ucar.edu/modeling/tgcm/doc/userguide for more information. # If you need to customize the configuration beyond the shell vars here, # add or change options to the tgcm_config call below. # #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # USER EDIT BATCH JOB (LSF) RESOURCES (for Linux lightning cluster) # #BSUB -J timegcm # job name #BSUB -x # exclusive use of the node #BSUB -n 16 # number of MPI tasks #BSUB -q regular # queue (premium and regular are available) ##BSUB -q debug # debug queue is available during the day (30 min limit) #BSUB -o timegcm.%J.out # stdout filename #BSUB -e timegcm.%J.out # stderr filename #BSUB -N # send mail when job finishes #BSUB -u $LOGNAME@ucar.edu # email address #BSUB -W 3:00 # wallclock limit (hh:mm) (3 hrs for prem or reg) ##BSUB -W 0:30 # 30 min limit for debug queue # #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # USER EDIT SHELL VARIABLES (for batch and interactive jobs) # # model: Desired model name (Required. Use ListModels to see valid models) # wrkdir: User's working directory (default is `pwd`, i.e., the cwd) # usr_srcdirs: List of user source directories (optional) # input: Namelist input file (if not given, a default will be created) # output: Name of stdout file relative to the wrkdir (default is $model.out) # tgcmroot: Root directory of distribution (default env var $TGCMROOT) # tgcmdata: Root directory containing input data files (default $TGCMDATA) # execdir: Directory in which to build and execute # (default is $wrkdir/$model-$os) # utildir: Directory containing config script and needed utilities # (default is $tgcmroot/$model/scripts) # mpi: Load MPI libraries (can be TRUE, FALSE, or DEFAULT) # (DEFAULT will be TRUE on lightning linux, FALSE otherwise) # hres: Horizontal resolution can be either 5.0 (default), or 2.5 degrees # vres: Vertical resolution can be either 0.5 (default), or 0.25 (ln(p0/p)) # debug: If debug=1, configure Makefile for a debug run (default is 0) # # Model output history files will be written to $execdir. # set model = timegcm_trunk set wrkdir = . #set wrkdir = $model-$$ #set input = $model.inp #set output = $model.out #set usr_srcdirs = modsrc #set tgcmroot = . #set tgcmdata = $TGCMDATA #set execdir = $model-linux #set utildir = $TGCMROOT/$model/scripts #set mpi = FALSE #set nproc = 4 # linux mpi runs only #set hres = 2.5 # horizontal resolution (default is 5.0 deg) #set vres = 0.25 # vertical resolution (default is 0.5) #set debug = 1 # default is 0 # # USER SHOULD NOT HAVE TO EDIT BELOW THIS LINE # (except maybe to customize tgcm_config below) #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # set mycwd = `pwd` echo " " echo "${0}:" echo " Begin execution at `date`" echo " Current working directory: $mycwd" echo " System: `uname -a`" echo " Log name: $LOGNAME" set userguide = http://download.hao.ucar.edu/pub/tgcm/doc/userguide # # Model name is required: # if (! $?model) then echo "" ; echo ">>> Please set desired model (e.g., 'tiegcm' or 'timegcm')" echo " See $userguide for more information." exit 1 endif echo " Model: $model" # if (! $?wrkdir) set wrkdir = `pwd` # default working dir is cwd if (! $?tgcmroot) set tgcmroot = "" if (! $?tgcmdata) set tgcmdata = "" if (! $?usr_srcdirs) set usr_srcdirs = "" if (! $?hres) set hres = 5.0 if (! $?vres) set vres = 0.5 if (! $?mpi) set mpi = "" if (! $?debug) set debug = 0 # # Set utility dir from shell var $tgcmroot, or env var $TGCMROOT: # (must contain Abspath, MakeNamelist, Mklogs, etc) # if (! $?utildir) then if ($tgcmroot != "") then # shell var from above (if set, trumps env var) set utildir = $tgcmroot/$model/scripts else if ($?TGCMROOT) then # env var set utildir = $TGCMROOT/$model/scripts else echo "" ; echo ">>> WARNING: cannot determine utility directory." echo "" ; echo "Please set either shell var tgcmroot, or env var TGCMROOT" echo " such that the directory tgcmroot/$model/scripts contains" echo " the configuration script tgcm_config, and other needed utilities." echo " See $userguide for more information." echo "" ; exit 1 endif else # user provided utildir -- it must exist if (! -d $utildir) then echo ">>> Cannot find utility directory $utildir" && exit 1 endif endif if (! -x $utildir/Abspath) echo ">>> Cannot find command $utildir/Abspath" set utildir = `perl $utildir/Abspath $utildir` # full path to utildir echo " Utildir = $utildir" # set wrkdir = `perl $utildir/Abspath $wrkdir` # full path to wrkdir echo " Wrkdir = $wrkdir" # # Set exec directory if necessary (wrkdir/model-os): # if (! $?execdir) then set os = `uname -s | tr "[A-Z]" "[a-z]"` set execdir = $wrkdir/$model-$os # if does not exist, will be created by config endif set execdir = `perl $utildir/Abspath $execdir` # full path to execdir echo " Execdir = $execdir" if (! -x $utildir/tgcm_config) \ echo ">>> WARNING: Cannot find config script $utildir/tgcm_config" # # Configure (pass shell vars to tgcm_config): # See http://download.hao.ucar.edu/pub/tgcm/doc/userguide for more # options to tgcm_config. # perl $utildir/tgcm_config -model=$model -wrkdir=$wrkdir -execdir=$execdir \ -tgcmroot=$tgcmroot -tgcmdata=$tgcmdata -usr_srcdirs=$usr_srcdirs \ -utildir=$utildir -hres=$hres -vres=$vres -mpi=$mpi -debug=$debug || \ echo ">>> ${0}: Error from tgcm_config" && exit 1 # # Make default namelist input if not provided by user: # if (! $?input) then set input = \ `perl $utildir/Mknamelist -model=$model -hres=$hres -vres=$vres` || \ echo "${0}: Error from Mknamelist: fileout = $input" && exit 1 echo "Made default namelist input file $input" else echo "Using user provided namelist input file $input" endif set namelist = `perl $utildir/Abspath $input` if (! -e $namelist) then echo "${0}: Cannot find namelist input file $namelist" && exit 1 endif # # Build model in execdir: # cd $execdir || echo ">>> Cannot cd to execdir $execdir" && exit 1 echo "" ; echo "Begin building $model in `pwd` at `date`..." gmake -j4 || echo ">>> Error return from gmake" && exit 1 echo "End building $model at `date`..." cd $mycwd # return to original cwd # # Default stdout file is $model.out in the wrkdir: # if (! $?output) then set output = $wrkdir/$model.out else set output = `perl $utildir/Abspath $wrkdir/$output` endif # # Execute from execdir: # cd $execdir || echo ">>> Error from cd to execdir $execdir" && exit 1 echo "" ; echo "Executing model $model from `pwd` at `date`" if (-e dispose.csh) then echo "Removing dispose.csh prior to execution." /bin/rm dispose.csh || echo "WARNING: error removing dispose.csh" endif # # Create machines.ini file: # if ($mpi == TRUE) then if (! $?nproc) then set nproc = 2 endif echo `hostname` >! machines.ini @ i = 1 while ($i < $nproc) echo i = $i echo `hostname` >> machines.ini @ i++ end endif set unamen = `uname -n` # #- - - - - - - - - - - - - - - lightning - - - - - - - - - - - - - - if ($unamen =~ ln*) then # # Must make a separate exec script for the linux cluster "lightning", # so that mpirun.lsf will send stdout to separate files for each mpi task: # cat << EOF > mpiexec.$$ #! /bin/csh set stdin = $namelist set stdout = ${output}_task\$GMPI_ID.out if ($output:e == 'out') then set stdout = $output:r_task\$GMPI_ID.out endif set exec = $execdir/$model \$exec < \$stdin > \$stdout EOF chmod +x mpiexec.$$ # echo "Model output will go to ${output}_task[n].out" mpirun.lsf mpiexec.$$ || \ echo ">>> ${0} Execution of $execdir/$model FAILED at `date`" # #- - - - - - - - - - - - non-lightning linux - - - - - - - - - - - - else # is not lightning # echo "Model output will go to $output" echo "Linux job: mpi = $mpi" # # Execute linux mpi job (s.a., gmake above): if ($mpi == TRUE) then echo "Executing mpirun -np $nproc for Linux MPI run." mpirun -np $nproc -machinefile machines.ini $execdir/$model < $namelist >&! $output || \ echo ">>> ${0} mpirun execution of $execdir/$model FAILED at `date`" && \ echo "See output in $output" echo "Linux MPI run of $model completed at `date`" # # Execute linux non-mpi job: else echo "Executing $model for Linux non-MPI run." $execdir/$model < $namelist >&! $output || \ echo ">>> ${0} Execution of $execdir/$model FAILED at `date`" && \ echo "See output in $output" echo "Linux non-MPI run of $model completed at `date`" endif # # Separate output files by MPI task: # (we are still in $execdir, but $output contains full path to $wrkdir) # perl $utildir/Mklogs $output || \ echo ">>> ${0}: Error from $execdir/Mklogs on output $output" # #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - endif # lightning or non-lightning linux # # Execute dispose.csh, if it exists: # This script was created by the model to dispose history files # to the mss if model namelist DISPOSE=2. # if (-e dispose.csh) then echo "" ; echo "Contents of dispose.csh: " ; cat $execdir/dispose.csh ; echo "" echo "Starting dispose.csh in background.." dispose.csh & endif # cd $mycwd # return to original cwd echo "" ; echo "${0}: Completed execution at `date`" exit 0