(file) Return to dopowslice CVS log (file) (dir) Up to [Development] / JSOC / proj / globalhs / scripts

File: [Development] / JSOC / proj / globalhs / scripts / dopowslice (download)
Revision: 1.10, Fri Feb 13 01:53:10 2015 UTC (3 years, 8 months ago) by tplarson
Branch: MAIN
CVS Tags: Ver_9-1, Ver_9-0, Ver_8-8, Ver_8-7, Ver_8-12, Ver_8-11, Ver_8-10
Changes since 1.9: +1 -1 lines
change from a.q to k.q

#! /bin/tcsh -f

setenv PATH $JSOCROOT/bin/$JSOC_MACHINE':'$JSOCROOT/proj/globalhs/scripts':'$PATH

# submit njobs jobs at once
if (! $?GLOBALHS_POWNJOBS) then
  set njobs=20
else
  set njobs=$GLOBALHS_POWNJOBS
endif

# submit next batch of jobs when total number of gapfill jobs drops below jobthreshold
if (! $?GLOBALHS_POWJOBTHRESHOLD) then
  set jobthreshold=25
else
  set jobthreshold=$GLOBALHS_POWJOBTHRESHOLD
endif

# if this script inherited a label in its environment, use it as the suffix for job names
if (! $?GLOBALHS_LABEL) then
  set suff=''
else
  set suff=.$GLOBALHS_LABEL
endif

#set qsubtmp=/tmp27/$USER/qsubtmp
#mkdir -p $qsubtmp

set qsubtmp=/dev/null
if (! $?GLOBALHS_POWQUEUE) then
  set q=j.q
else
  set q=$GLOBALHS_POWQUEUE
endif

if ($q == k.q) then
  alias qsub qsub2
  alias qstat qstat2
  alias waittosubmit waittosubmit2
endif

@ i = 1
while ($i <= $#argv )
  set $argv[$i]
@ i++
end

if (! $?starttime) then
  echo must specify parameter starttime
  exit 1
endif

if (! $?totaltimein) then
  echo must specify parameter totaltimein
  exit 1
endif

set totalsecsin = `durcon $totaltimein`
if ($status) then
  echo incorrect format for parameter totaltimein
  exit 1
endif

if (! $?slicestep) then
  echo must specify parameter slicestep
  exit 1
endif

set stepsecs = `durcon $slicestep`
if ($status) then
  echo incorrect format for parameter slicestep
  exit 1
endif

if (! $?lmin) set lmin = 0
if (! $?lmax) set lmax = 300
if (! $?lchunk) set lchunk = 10

if (! $?startoffset) set startoffset = 0d
set offsecs = `durcon $startoffset`
if ($status) then
  echo incorrect format for parameter startoffset
  exit 1
endif

if (! $?totaltimeout) set totaltimeout = $totaltimein
set totalsecsout = `durcon $totaltimeout`
if ($status) then
  echo incorrect format for parameter totaltimeout
  exit 1
endif

echo `date` on $HOST
echo $PWD
echo $0 $argv

if (! -es slc.parms.blank) then
  echo parameter file blank missing: slc.parms.blank is required
  exit 1
endif

grep -v "^[[:space:]]*#" slc.parms.blank | sed s@"[[:space:]]"@"\n"@g | grep -v '^[[:space:]]*$'  > parms.tmp

set in = `cat parms.tmp | grep ^in= | sed s/\'//g | sed s/\"//g | awk -F '[=[]' '{print $2}'`
set epoch = `show_info -j $in | grep -i '^keyword:t_start_epoch' | cut -d, -f5`
set epochsecs = `time_convert o=jsoc time=$epoch`
set tstartstep = `show_info -j $in | grep -i '^keyword:t_start_step' | cut -d, -f5`
set cadence = `show_info -j $in | grep -i '^keyword:t_step' | cut -d, -f5`

durcon $starttime >& /dev/null
if ($status) then
  set startsecs = `time_convert o=jsoc time=$starttime`
else
  set startsecs = `durcon $starttime`
  set startsecs = `echo "$startsecs + $epochsecs" | bc`
endif

set firstindex = `echo "($startsecs - $epochsecs)/$tstartstep" | bc`
set ndtin   = `echo "$totalsecsin / $cadence" | bc`
set ndtout   = `echo "$stepsecs / $cadence" | bc`
set first = `echo "$offsecs / $cadence" | bc`

@ lchunkfirst = $lmin / $lchunk
@ lchunklast  = $lmax / $lchunk
@ nlc = ($lchunklast - $lchunkfirst) + 1

@ lc = $lchunkfirst
while ($lc <= $lchunklast)
@ lfirst = $lc * $lchunk
@ llast  = $lfirst + $lchunk - 1
  if ($lfirst < $lmin) set lfirst = $lmin
  if ($llast  > $lmax) set llast  = $lmax

@ r = ( $lc - $lchunkfirst ) % $njobs
  set subfile = subslc.$firstindex.$lmin-$lmax.$r$suff
  if ( ( $lc - $lchunkfirst ) < $njobs) then
    echo '#\!/bin/csh' > $subfile
    echo 'setenv PATH' $JSOCROOT'/bin/$JSOC_MACHINE' >> $subfile
    echo 'cd' $PWD >> $subfile
  endif

  cat parms.tmp | sed s@XXXX@$starttime@ | sed s/MMMM/$llast/g | sed s/NNNN/$lfirst/g | sed s/SSSS/$ndtin/g | sed s/TTTT/$ndtout/ | sed s/FFFF/$first/g | sed s/OOOO/$totaltimeout/g > slc.parms.$lfirst-$llast
  echo \(time jtsslice @slc.parms.$lfirst-$llast\) '>&' slc.log.$lfirst-$llast >> $subfile
  echo echo \$status '>&' jtsslice.exitstatus.$lfirst-$llast >> $subfile

@ lc++
end

waittosubmit $jobthreshold subslc
set q=j.q
set i=0
if ($nlc < $njobs) set njobs=$nlc
while ($i < $njobs)
  set subfile = subslc.$firstindex.$lmin-$lmax.$i$suff
  qsub -q $q -e $qsubtmp -o $qsubtmp $subfile
@ i++
end

echo jobs submitted, start waiting

set njobsrunning = `qstat -r -u $USER | grep "Full jobname:" | grep subslc.$firstindex | grep $lmin-$lmax | grep "$suff" | wc -l`
while($njobsrunning > 0)
  sleep 60
  set njobsrunning = `qstat -r -u $USER | grep "Full jobname:" | grep subslc.$firstindex | grep $lmin-$lmax | grep "$suff" | wc -l`
end

#check for errors here
set expectedlist = `/bin/ls slc.parms.[0-9]* | cut -d'.' -f 3`
set ranlist      = `/bin/ls slc.log.*   | cut -d'.' -f 3`
set rerunlist = `echo $expectedlist $ranlist | sed s/" "/"\n"/g | sort -n | uniq -u`

set errlist1 = `grep -Hv 0 jtsslice.exitstatus.* | awk -F '[.:]' '{print $3}'`
set errlist2 = `grep -c "successful completion" slc.log.* | grep -v :1 | awk -F '[.:]' '{print $3}'`
set errlist = `echo $errlist1 $errlist2 | sed s/" "/"\n"/g | sort | uniq`
set list = `echo $rerunlist $errlist | sed s/" "/"\n"/g | sort -n`

if ($#list) then
  echo some jobs fail, rerunning
  echo rerunlist: $rerunlist > faillog
  echo errlist1: $errlist1 >> faillog
  echo errlist2: $errlist2 >> faillog
  mkdir subsave
  mv subslc.* subsave
  set i=0
  while ($i < $#list)
  @ r = $i % $njobs
    set subfile = subslc.$firstindex.$lmin-$lmax.$r$suff
    if ( $i < $njobs) then
      echo '#\!/bin/csh' > $subfile
      echo 'setenv PATH' $JSOCROOT'/bin/$JSOC_MACHINE' >> $subfile
      echo 'cd' $PWD >> $subfile
    endif
  @ i++
    echo \(time jtsslice @slc.parms.$list[$i]\) '>&' slc.log.$list[$i] >> $subfile
    echo echo \$status '>&' jtsslice.exitstatus.$list[$i] >> $subfile
  end

  waittosubmit $jobthreshold subslc
  set i=0
  if ($#list < $njobs) set njobs=$#list
  while ($i < $njobs)
    set subfile = subslc.$firstindex.$lmin-$lmax.$i$suff
    qsub -q $q -e $qsubtmp -o $qsubtmp $subfile
  @ i++
  end

  set njobsrunning = `qstat -r -u $USER | grep "Full jobname:" | grep subslc.$firstindex | grep $lmin-$lmax | grep "$suff" | wc -l`
  while($njobsrunning > 0)
    sleep 60
    set njobsrunning = `qstat -r -u $USER | grep "Full jobname:" | grep subslc.$firstindex | grep $lmin-$lmax | grep "$suff" | wc -l`
  end

  set ranlist   = `/bin/ls slc.log.*   | cut -d'.' -f 3`
  set rerunlist = `echo $expectedlist $ranlist | sed s/" "/"\n"/g | sort -n | uniq -u`
  set errlist1  = `grep -Hv 0 jtsslice.exitstatus.* | awk -F '[.:]' '{print $3}'`
  set errlist2  = `grep -c "successful completion" slc.log.* | grep -v :1 | awk -F '[.:]' '{print $3}'`

  if ($#errlist1 || $#errlist2 || $#rerunlist) then
    echo some jobs still fail, i give up
    exit 1
  endif
endif

echo successful completion

rm -rf subsave parms.tmp

exit 0

Karen Tian
Powered by
ViewCVS 0.9.4