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

File: [Development] / JSOC / proj / globalhs / scripts / dopow (download)
Revision: 1.10, Tue Jul 2 19:07:07 2013 UTC (9 years, 11 months ago) by tplarson
Branch: MAIN
CVS Tags: Ver_8-6, Ver_8-5, Ver_8-4, Ver_8-3, Ver_8-2, Ver_8-1
Changes since 1.9: +4 -0 lines
added setting of PATH and checking of data VERSION to scripts

#!/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
if (! $?GLOBALHS_POWQUEUE) then
  set q=j.q
else
  set q=$GLOBALHS_POWQUEUE
endif

if ($q == a.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 (! $?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

date
echo $PWD
echo $0 $argv

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

grep -v "^[[:space:]]*#" pow.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`
set ndtin   = `echo "$totalsecsin / $cadence" | bc`
set ndtout   = `echo "$totalsecsout / $cadence" | bc`
set first = `echo "$offsecs / $cadence" | bc`

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

set firstindex = `echo "($startsecs - $epochsecs)/$tstartstep" | 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 = subpow.$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/g | sed s/FFFF/$first/g > pow.parms.$lfirst-$llast
  echo \(time jtsfiddle @pow.parms.$lfirst-$llast\) '>&' pow.log.$lfirst-$llast >> $subfile
  echo echo \$status '>&' jtsfiddle.exitstatus.$lfirst-$llast >> $subfile

@ lc++
end

waittosubmit $jobthreshold subpow
set q=j.q
set i=0
if ($nlc < $njobs) set njobs=$nlc
while ($i < $njobs)
  set subfile = subpow.$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 subpow.$firstindex | grep $lmin-$lmax | grep "$suff" | wc -l`
while($njobsrunning > 0)
  sleep 60
  set njobsrunning = `qstat -r -u $USER | grep "Full jobname:" | grep subpow.$firstindex | grep $lmin-$lmax | grep "$suff" | wc -l`
end

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

set errlist1 = `grep -Hv 0 jtsfiddle.exitstatus.* | awk -F '[.:]' '{print $3}'`
set errlist2 = `grep -c "successful completion" pow.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`

if ($#list) then
  echo some jobs fail, rerunning
  echo rerunlist: $rerunlist > faillog
  echo errlist1: $errlist1 >> faillog
  echo errlist2: $errlist2 >> faillog
  mkdir -p subsave
  mv subpow.* subsave
  set i=0
  while ($i < $#list)
  @ r = $i % $njobs
    set subfile = subpow.$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 jtsfiddle @pow.parms.$list[$i]\) '>&' pow.log.$list[$i] >> $subfile
    echo echo \$status '>&' jtsfiddle.exitstatus.$list[$i] >> $subfile
  end

  waittosubmit $jobthreshold subpow
  set i=0
  if ($#list < $njobs) set njobs = $#list
  while ($i < $njobs)
    set subfile = subpow.$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 subpow.$firstindex | grep $lmin-$lmax | grep "$suff" | wc -l`
  while($njobsrunning > 0)
    sleep 60
    set njobsrunning = `qstat -r -u $USER | grep "Full jobname:" | grep subpow.$firstindex | grep $lmin-$lmax | grep "$suff" | wc -l`
  end

  set ranlist   = `/bin/ls pow.log.*   | cut -d'.' -f 3`
  set rerunlist = `echo $expectedlist $ranlist | sed s/" "/"\n"/g | sort | uniq -u`
  set errlist1  = `grep -Hv 0 jtsfiddle.exitstatus.* | awk -F '[.:]' '{print $3}'`
  set errlist2  = `grep -c "successful completion" pow.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