#! /bin/csh # # User set shell variables for TIEGCM Linux job: # (modeldir, execdir, and utildir may be relative or absolute paths) # # modeldir: Root directory to model source (may be an SVN working dir) # execdir: Directory in which to build and execute (will be created if necessary) # input: Namelist input file (will use default if not provided) # output: Stdout file from model execution (will be created) # make: Build file with platform-specific compile parameters (in scripts dir) # mpi: TRUE/FALSE for MPI or non-MPI run # nproc: Number of processors for 64-bit Linux MPI run # modelres: Model resolution (5.0 or 2.5) # debug: If TRUE, build and execute a "debug" run # exec: If TRUE, execute the model (build only if FALSE) # utildir: Dir containing supporting scripts (usually $modeldir/scripts) # set modeldir = tiegcm_ktrunk set execdir = tiegcm-linux set input = tiegcm_superdarn.inp set output = tiegcm.out set make = Make.intel_hao64 #set modelres = 5.0 set modelres = 2.5 set mpi = TRUE #set nproc = 1 set nproc = 4 set debug = FALSE set exec = TRUE set utildir = $modeldir/scripts # #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # Shell Script for TIEGCM Linux job #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # set mycwd = `pwd` echo "" ; echo "${0}:" echo " Begin execution at `date`" echo " Current working directory: $mycwd" echo " System: `uname -a`" echo "" # # Verify directories and make_machine file (make execdir if necessary). # Get absolute path for dirs that are accessed from the execdir. # if (! -d $modeldir) then echo ">>> Cannot find model directory $modeldir <<<" exit 1 endif set model = $modeldir:t if (! -d $utildir) then echo ">>> Cannot find model scripts directory $utildir <<<" exit 1 endif set srcdir = $modeldir/src if (! -d $srcdir) then echo ">>> Cannot find model source directory $srcdir <<<" exit 1 endif set srcdir = `perl $utildir/abspath $srcdir` if (! -d $execdir) then echo "Making exec directory $execdir" mkdir -p $execdir endif if ($modelres != 5.0 && $modelres != 2.5) then echo ">>> Unknown model resolution $modelres <<<" exit 1 endif # # Copy make files to execdir if necessary: # if (! -f $execdir/$make) cp $utildir/$make $execdir if (! -f $execdir/Makefile) cp $utildir/Makefile $execdir if (! -f $execdir/mkdepends) cp $utildir/mkdepends $execdir # # Make default namelist input file if not provided by user: # if ($?input) then if (! -f $input) then echo ">>> Cannot find namelist input file $input <<<" exit 1 endif else set input = \ `perl $utildir/mknamelist -model=$model -modelres=$modelres` || \ echo ">>> Error from mknamelist: fileout = $input" && exit 1 endif set input = `perl $utildir/abspath $input` set output = `perl $utildir/abspath $output` set mklogs = `perl $utildir/abspath $utildir` set mklogs = $mklogs/mklogs # # Report to stdout: # set svnversion = `svnversion $modeldir` || set svnversion = "[none]" echo -n " Model directory: $modeldir" && echo " (SVN revision $svnversion)" echo " Exec directory: $execdir" echo " Source directory: $srcdir" echo " Make machine file: $make" echo " Namelist input: $input" echo " Model resolution: $modelres" echo " Debug flag: $debug" # # If debug flag has changed from last gmake, clean execdir # and reset debug file: # if (-f $execdir/debug) then set lastdebug = `cat $execdir/debug` if ($lastdebug != $debug) then echo "Clean execdir $execdir because debug flag switched from $lastdebug to $debug" set mycwd = `pwd` ; cd $execdir ; gmake clean ; cd $mycwd echo $debug >! $execdir/debug endif else echo $debug >! $execdir/debug echo "Created file debug with debug flag = $debug" endif # # Copy defs header file to execdir, if necessary, according to # requested resolution. This should seamlessly switch between # resolutions according to $modelres. # set defs = $srcdir/defs5.0 if ($modelres == 2.5) set defs = $srcdir/defs2.5 if (-f $execdir/defs.h) then cmp -s $execdir/defs.h $defs if ($status == 1) then # files differ -> switch resolutions echo "Switching defs.h for model resolution $modelres" cp $defs $execdir/defs.h else echo "defs.h already set for model resolution $modelres" endif else # defs.h does not exist in execdir -> copy appropriate defs file echo "Copying $defs to $execdir/defs.h for resolution $modelres" cp $defs $execdir/defs.h endif # # cd to execdir and run make: # cd $execdir || echo ">>> Cannot cd to execdir $execdir" && exit 1 echo "" echo "Begin building $model in `pwd`" # # Build Make.env file in exec dir, containing needed env vars for Makefile: # cat << EOF >! Make.env MAKE_MACHINE = $make DIRS = . $srcdir MPI = $mpi NPROC = $nproc EXECNAME = $model NAMELIST = $input OUTPUT = $output DEBUG = $debug SVN_VERSION = $svnversion EOF # # Build the model: gmake -j4 all || echo ">>> Error return from gmake all" && exit 1 # # Execute Linux job (MPI or non-MPI run): # if ($exec == "TRUE") then set model = ./$model echo "$model output will go to $output" if ($mpi == "TRUE") then # # Files machines.ini and mpirun.command are made by the Make.machines file. gmake machines.ini gmake mpirun.command set mpirun = `cat mpirun.command` echo "Executing $mpirun with -np $nproc for Linux MPI run." # # Execute mpirun (Intel or PGI) for MPI run: $mpirun -machinefile machines.ini -np $nproc $model < $input >&! $output || \ echo ">>> ${0} mpirun execution of $model FAILED at `date`" && \ echo "See output in $output" echo "Linux MPI run of $model completed at `date`" perl $mklogs $output else # MPI is FALSE echo "Executing $model for Linux non-MPI run." $model < $input >&! $output || \ echo ">>> ${0} Execution of $model FAILED at `date`" && \ echo "See output in $output" echo "Linux non-MPI run of $model completed at `date`" endif else echo "I am NOT executing $model (exec was not set)" endif exit 0