IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 42449 for trunk/tools


Ignore:
Timestamp:
Apr 13, 2023, 9:30:40 AM (3 years ago)
Author:
eugene
Message:

split fix_chip_locations into parallel processes by chip

Location:
trunk/tools/eam/rawfix.20230221/src
Files:
3 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/eam/rawfix.20230221/src/advance.rawfix.pl

    r42446 r42449  
    144144    my $Nfail    = $values[14];
    145145   
     146    # in state of 'new', we do not care what the values of the stat fields are.
     147    # they may be NULL, so do not yet try to do math on them here
     148    if ($state eq "new")                                              {           &update_night_state ($dateobs, "ckchip.new", 0);     return "NEW"; }
     149
    146150    my $Ndone = $Ngood + $Ndead + $Ngone + $Nfail;
    147151    my $Nwait = $Nsing + $Ndups + $Nsbck + $Nxbck + $Ncul1 + $Ncul2 + $Ncul3;
     
    151155    # check for completion here first (otherwise, advance fixchip.done below)
    152156    if (($state eq "fixchip.done") and ($iter > 0) and ($Nwait == 0)) {           &update_night_state ($dateobs, "DONE");              return "DONE"; }
    153     if ($state eq "new")                                              {           &update_night_state ($dateobs, "ckchip.new", 0);     return "NEW"; }
    154157    if ($state eq "ckchip.done")                                      {           &update_night_state ($dateobs, "fixchip.new");       return "NEW"; }
    155158    if ($state eq "fixchip.done")                                     {           &update_night_state ($dateobs, "md5sum.new");        return "NEW"; }
  • trunk/tools/eam/rawfix.20230221/src/fix_chip_locations.pl

    r42447 r42449  
    1212use Getopt::Long qw( GetOptions :config auto_help auto_version );
    1313
    14 # USAGE: fix_chip_locations.pl --dateobs (night) --chiplist (file) --stage (0,1,etc)
     14# USAGE: fix_chip_locations.pl --dateobs (night) --stage (0,1,etc) [--chiplist (file) | --chipID (ID)]
    1515
    1616# we need to select targets for ITC copies of files currently only at ATRC:
     
    1818# for each chip, target a single host?
    1919
    20 my ($fulldate, $dateword, $chiplist, $stage, $topdir) = &parse_cmdopts;
     20my ($fulldate, $dateword, $chiplist, $chipID, $stage, $topdir) = &parse_cmdopts;
    2121my ($neb_dbh, $raw_dbh) = &parse_db_config ("$topdir/nebulous.config");
    22 
    23 # read the list of chip_ids:
    24 my @chip_ids = &load_chip_list ($chiplist);
    2522
    2623# choose ITC machines on which to place backup copies:
    2724my @vol_copy = &get_neb_volumes_copy; # array of neb hosts to copy data to at ITC
    2825my %vol_good = &get_neb_volumes_good; # hash of valid neb hosts
    29 my $volnum = 0;
    3026
    3127my $Ngood = 0;
     
    4137my $Ncul3 = 0;
    4238my $Nfail = 0;
     39
     40my $Nchip = 0; # counts the number of instances
    4341
    4442# load the lists of good and fail chips
     
    6967}
    7068
    71 my $Nchip = 0;
    72 
     69# read the list of chip_ids:
     70my @chip_ids = &load_chip_list ($chiplist);
     71
     72my $volnum = 0; # select the volume to be used from the list of @vol_copy
     73
     74# loop over all chip_ids so we can distribute the target volumes
    7375foreach my $chip_id (@chip_ids) {
     76    if (not defined $chipID or ($chipID eq $chip_id)) {
     77        &fix_chip_locations_chipID ($chip_id, $volnum);
     78    }
     79    $volnum ++;
     80    if ($volnum > @vol_copy) { $volnum = 0; }
     81}
     82
     83my $Ntotal = $Ngood + $Ngone + $Ndead + $Nsing + $Ndups + $Nsbck + $Nxbck + $Ncul1 + $Ncul2 + $Ncul3 + $Nfail;
     84if ($Ntotal != $Nchip) { die "ERROR: inconsistent count of chips\n"; }
     85
     86if (not defined $chipID) {
     87    # update the stats in the database
     88    my $sql_update_stats = "UPDATE nights set";
     89    $sql_update_stats .= "  Nchip = $Nchip";
     90    $sql_update_stats .= ", Ngood = $Ngood";
     91    $sql_update_stats .= ", Ndead = $Ndead";
     92    $sql_update_stats .= ", Ngone = $Ngone";
     93    $sql_update_stats .= ", Nsing = $Nsing";
     94    $sql_update_stats .= ", Ndups = $Ndups";
     95    $sql_update_stats .= ", Nsbck = $Nsbck";
     96    $sql_update_stats .= ", Nxbck = $Nxbck";
     97    $sql_update_stats .= ", Ncul1 = $Ncul1";
     98    $sql_update_stats .= ", Ncul2 = $Ncul2";
     99    $sql_update_stats .= ", Ncul3 = $Ncul3";
     100    $sql_update_stats .= ", Nfail = $Nfail";
     101    $sql_update_stats .= " WHERE dateobs = $dateword";
     102   
     103    my $query = $raw_dbh->prepare($sql_update_stats);
     104    $query->execute () or die "invalid response from RAW database\n";
     105} else {
     106
     107    open (OUTFILE, ">$topdir/$dateword/$chipID.stats.$stage.txt");
     108
     109    print OUTFILE "Nchip: $Nchip\n";
     110    print OUTFILE "Ngood: $Ngood\n";
     111    print OUTFILE "Ngone: $Ngone\n";
     112    print OUTFILE "Ndead: $Ndead\n";
     113    print OUTFILE "Nsing: $Nsing\n";
     114    print OUTFILE "Ndups: $Ndups\n";
     115    print OUTFILE "Nsbck: $Nsbck\n";
     116    print OUTFILE "Nxbck: $Nxbck\n";
     117    print OUTFILE "Ncul1: $Ncul1\n";
     118    print OUTFILE "Ncul2: $Ncul2\n";
     119    print OUTFILE "Ncul3: $Ncul3\n";
     120    print OUTFILE "Nfail: $Nfail\n";
     121
     122    close (OUTFILE);
     123}
     124
     125exit 0;
     126
     127sub fix_chip_locations_chipID {
     128
     129    my $chip_id = $_[0];
     130    my $volnum  = $_[1];
    74131
    75132    # read from chip_id file, update to next stage number
     
    216273        }
    217274    }
    218     $volnum ++;
    219 }
    220 
    221 print "Nchip: $Nchip\n";
    222 print "Ngood: $Ngood\n";
    223 print "Ngone: $Ngone\n";
    224 print "Ndead: $Ndead\n";
    225 print "Nsing: $Nsing\n";
    226 print "Ndups: $Ndups\n";
    227 print "Nsbck: $Nsbck\n";
    228 print "Nxbck: $Nxbck\n";
    229 print "Ncul1: $Ncul1\n";
    230 print "Ncul2: $Ncul2\n";
    231 print "Ncul3: $Ncul3\n";
    232 print "Nfail: $Nfail\n";
    233 
    234 my $Ntotal = $Ngood + $Ngone + $Ndead + $Nsing + $Ndups + $Nsbck + $Nxbck + $Ncul1 + $Ncul2 + $Ncul3 + $Nfail;
    235 if ($Ntotal != $Nchip) { die "ERROR: inconsistent count of chips\n"; }
    236 
    237 # update the stats in the database
    238 my $sql_update_stats = "UPDATE nights set";
    239 $sql_update_stats .= "  Nchip = $Nchip";
    240 $sql_update_stats .= ", Ngood = $Ngood";
    241 $sql_update_stats .= ", Ndead = $Ndead";
    242 $sql_update_stats .= ", Ngone = $Ngone";
    243 $sql_update_stats .= ", Nsing = $Nsing";
    244 $sql_update_stats .= ", Ndups = $Ndups";
    245 $sql_update_stats .= ", Nsbck = $Nsbck";
    246 $sql_update_stats .= ", Nxbck = $Nxbck";
    247 $sql_update_stats .= ", Ncul1 = $Ncul1";
    248 $sql_update_stats .= ", Ncul2 = $Ncul2";
    249 $sql_update_stats .= ", Ncul3 = $Ncul3";
    250 $sql_update_stats .= ", Nfail = $Nfail";
    251 $sql_update_stats .= " WHERE dateobs = $dateword";
    252 
    253 my $query = $raw_dbh->prepare($sql_update_stats);
    254 $query->execute () or die "invalid response from RAW database\n";
    255 
    256 exit 0;
     275}
    257276
    258277sub get_new_instance {
     
    412431sub parse_cmdopts {
    413432
    414     my ($dateobs, $chiplist, $stage, $topdir);
    415     GetOptions( 'dateobs=s' => \$dateobs, 'chiplist=s' => \$chiplist, 'topdir=s' => \$topdir, 'stage=s' => \$stage) || pod2usage(2);
     433    my ($dateobs, $chiplist, $chipID, $stage, $topdir);
     434    GetOptions( 'dateobs=s' => \$dateobs, 'chiplist=s' => \$chiplist, 'chipID=s' => \$chipID, 'topdir=s' => \$topdir, 'stage=s' => \$stage) || pod2usage(2);
    416435   
    417436    pod2usage( -msg => "Cannot determine target date, use --dateobs YYYY/MM/DD", -exitval => 2) unless defined $dateobs;
    418     pod2usage( -msg => "Provide a list of chips with --chiplist", -exitval => 2) unless defined $chiplist;
    419437    pod2usage( -msg => "Define the stage (0, 1, etc) with --stage", -exitval => 2) unless defined $stage;
    420438    pod2usage( -msg => "Specify the top-level output directory with --topdir", -exitval => 2) unless defined $topdir;
    421    
     439    pod2usage( -msg => "Provide a list of chips with --chiplist", -exitval => 2) unless defined $chiplist;
     440
    422441    # check that stage is an integer
    423442    unless (is_integer ($stage)) { die "stage must be a non-negative integer\n"; }
     
    435454    my $dateword = sprintf ("%4d%02d%02d", $date_year, $date_month, $date_day);
    436455
    437     return ($fulldate, $dateword, $chiplist, $stage, $topdir);
     456    return ($fulldate, $dateword, $chiplist, $chipID, $stage, $topdir);
    438457}
    439458
  • trunk/tools/eam/rawfix.20230221/src/queue.rawfix.sh

    r42442 r42449  
    2929if ($mode == "night") then
    3030  ## XXX validate the format (YYYYMMDD)?
    31 
    32  XXXXX:
    33 
    3431  set mynight = $2
    3532 
  • trunk/tools/eam/rawfix.20230221/src/rawfix.fixchip.pt

    r42447 r42449  
    99if (not($?RAWFIX_FIXCHIP_INIT))
    1010  book init fixchip.book
     11  book init fixhost.book
    1112  $RAWFIX_FIXCHIP_INIT = 1
    1213end
     
    2728
    2829  task.exec
    29     # command check.rawfix.sh state ckchip.done
    3030    command check.rawfix.sh state fixchip.new
    3131  end
     
    5353end
    5454
    55 task nights.fixchip.run
     55# output: fixhost.book
     56task nights.fixchip.loadhosts
    5657  periods      -poll $RPOLL
    5758  periods      -exec $REXEC
    58   periods      -timeout 1800
    59   host         -required $HOST_FIXCHIP
     59  periods      -timeout 60
     60  host          local
    6061  npending 1
     62  # note: the tasks which return their results via stdout
     63  # seem to fail if run remotely. 
     64
     65  stdout $LOGDIR/fixchip.loadhosts.stdout.log 
     66  stderr $LOGDIR/fixchip.loadhosts.stderr.log
    6167
    6268  task.exec
     
    7682    book getword fixchip.book $pageName iter    -var ITER
    7783    option $pageName
    78 
    79     stdout $pageName/log.fixchip.v$ITER
    80     stderr $pageName/log.fixchip.v$ITER
     84    # save the page so we can use it below
     85
     86    # write an entry point in the log for this night
     87    sprintf tmpline "%s/%s/log.fixchip.runhosts.v%d" $mypath $DATEOBS $ITER
     88    date -var mydate
     89    exec echo "# start runhosts $mydate" >> $tmpline
     90
     91    # the command returns these fields: dateobs stage fixhost chipID
     92    # NOTE: stage == ITER
     93    command $mypath/get_hosts_fixchip.sh $mypath $DATEOBS $ITER
     94  end
     95
     96  task.exit 0
     97    # convert the stdout 'queue' to entries in a book
     98    # fields in the table will become words in the page
     99    queueprint stdout
     100    queuesize stdout -var Nhosts
     101    queue2book -raw-columns -key dateobs:chipID -uniq -setword pantaskState INIT stdout fixhost.book
     102    book setword fixchip.book $options:0 NHOST {$Nhosts - 1}
     103    book setword fixchip.book $options:0 NDONE 0
     104    book list
     105    book listbook fixchip.book
     106    # use the queuesize (Nhosts) to track how many jobs are done / to be done
     107  end
     108
     109  # exit values other than 0:
     110  task.exit    default
     111    showcommand failure
     112    book setword fixchip.book $options:0 pantasksQuality FAIL
     113  end
     114
     115  task.exit    crash
     116    showcommand crash
     117    book setword fixchip.book $options:0 pantasksQuality CRASH
     118  end
     119
     120  # operation times out?
     121  task.exit    timeout
     122    showcommand timeout
     123    book setword fixchip.book $options:0 pantasksQuality TIMEOUT
     124  end
     125end
     126
     127task nights.fixchip.run
     128  periods      -poll $RPOLL
     129  periods      -exec $REXEC
     130  periods      -timeout 1800
     131
     132  task.exec
     133    # if we are unable to run the 'exec', use a long retry time
     134    periods -exec $REXEC
     135
     136    book npages fixhost.book -var N
     137    if ($N == 0) break
     138    if ($NETWORK == 0) break
     139   
     140    # look for new nights in fixhost.book (pantaskState == INIT)
     141    book getpage fixhost.book 0 -var pageName -key pantaskState INIT
     142    if ("$pageName" == "NULL") break
     143
     144    book setword fixhost.book $pageName pantaskState RUN
     145    book getword fixhost.book $pageName dateobs -var DATEOBS
     146    book getword fixhost.book $pageName iter    -var ITER
     147    book getword fixhost.book $pageName fixhost -var FIXHOST
     148    book getword fixhost.book $pageName chipID  -var CHIP_ID
     149    option $pageName $DATEOBS
     150
     151    stdout $pageName/log.fixchip.run.v$ITER
     152    stderr $pageName/log.fixchip.run.v$ITER
    81153
    82154    substr $DATEOBS 0 4 YEAR
     
    85157    sprintf FULLDATE "%s/%s/%s" $YEAR $MONTH $DAY
    86158
    87     command $mypath/fix_chip_locations.pl --topdir $mypath --dateobs $FULLDATE --chiplist gpc1.chips.txt --stage $ITER
    88   end
    89 
    90   ## XX delete the page from the book if done?
    91   task.exit 0
     159    host -required $FIXHOST
     160    ## check if this host needs to be launched
     161    if (not($?host:$FIXHOST))
     162      echo "host not defined, creating : $FIXHOST"
     163      $host:$FIXHOST = 0
     164    end
     165    if (not($host:$FIXHOST))
     166      control host add $FIXHOST
     167      $host:$FIXHOST = 1
     168    end
     169
     170    # if we are able to run the 'exec', use a short retry time to launch all outstanding jobs
     171    periods -exec 0.05
     172    command $mypath/fix_chip_locations.pl --topdir $mypath --dateobs $FULLDATE --chiplist gpc1.chips.txt --chipID $CHIP_ID --stage $ITER
     173  end
     174
     175  task.exit 0
     176    nights.fixchip.exit OK
     177  end
     178
     179  # exit values other than 0:
     180  task.exit    default
     181    nights.fixchip.exit FAIL
     182    showcommand failure
     183  end
     184
     185  task.exit    crash
     186    nights.fixchip.exit CRASH
     187    showcommand crash
     188  end
     189
     190  # operation times out?
     191  task.exit    timeout
     192    nights.fixchip.exit TIMEOUT
     193    showcommand timeout
     194  end
     195end
     196
     197# output: fixhost.book
     198task nights.fixchip.clean
     199
     200  periods      -poll $RPOLL
     201  periods      -exec $REXEC
     202  periods      -timeout 60
     203  npending 1
     204
     205  stdout $LOGDIR/fixchip.clean.stdout.log 
     206  stderr $LOGDIR/fixchip.clean.stderr.log
     207
     208  task.exec
     209    # if we are unable to run the 'exec', use a long retry time
     210    periods -exec $REXEC
     211
     212    book npages fixchip.book -var N
     213    if ($N == 0) break
     214    if ($NETWORK == 0) break
     215   
     216    # look for completed nights in fixchip.book (pantaskState == STOP)
     217    book getpage fixchip.book 0 -var pageName -key pantaskState STOP
     218    if ("$pageName" == "NULL") break
     219
     220    # book listpage fixchip.book $pageName
     221
     222    # book setword fixchip.book $pageName pantaskState RUN
     223    book getword fixchip.book $pageName dateobs -var DATEOBS
     224    book getword fixchip.book $pageName pantasksQuality -var QUALITY
     225
     226    option $pageName
     227    # save the page so we can use it below
     228
     229    if ("$QUALITY" == "OK")
     230      command update.rawfix.sh $DATEOBS fixchip.done
     231    else
     232      command update.rawfix.sh $DATEOBS fixchip.fail
     233    end
     234  end
     235
     236  task.exit 0
     237    # now that the entry is set to done in the db, remove the pantasks book entry
     238    echo "cleaning this page: $options:0"
    92239    book setword fixchip.book $options:0 pantaskState DONE
    93     exec update.rawfix.sh $options:0 fixchip.done
    94240  end
    95241
     
    98244    showcommand failure
    99245    book setword fixchip.book $options:0 pantasksQuality FAIL
    100     exec update.rawfix.sh $options:0 fixchip.fail
    101246  end
    102247
     
    104249    showcommand crash
    105250    book setword fixchip.book $options:0 pantasksQuality CRASH
    106     exec update.rawfix.sh $options:0 fixchip.fail
    107251  end
    108252
     
    111255    showcommand timeout
    112256    book setword fixchip.book $options:0 pantasksQuality TIMEOUT
    113     exec update.rawfix.sh $options:0 fixchip.fail
    114   end
    115 end
    116 
     257  end
     258end
     259
     260######################### UTILITIES #################################
     261
     262macro nights.fixchip.exit
     263  if ($0 != 2)
     264    echo "USAGE: nights.fixchip.exit (quality)"
     265    break
     266  end
     267
     268  book setword fixhost.book $options:0 pantaskState DONE
     269  book getword fixchip.book $options:1 NHOST -var Nhosts
     270  book getword fixchip.book $options:1 NDONE -var Ndone
     271  book getword fixchip.book $options:1 stage -var ITER
     272  $Ndone ++
     273  book setword fixchip.book $options:1 NDONE $Ndone
     274  if ("$1" != "OK")
     275    book setword fixchip.book $options:1 pantasksQuality $1
     276    sprintf tmpline "%s/%s/log.fixchip.runhosts.v%d" $mypath $options:1 $ITER
     277    exec echo "failure $1 $options:0" >> $tmpline
     278  else
     279    exec echo "success $1 $options:0" >> $tmpline
     280  end
     281  if ($Ndone == $Nhosts)
     282    book setword fixchip.book $options:1 pantaskState STOP
     283  end
     284  book delpage fixhost.book $options:0
     285end
     286
  • trunk/tools/eam/rawfix.20230221/src/rawfix.md5sum.pt

    r42445 r42449  
    127127# runs on the hosts identified by get_hosts_md5s.sh
    128128# output: md5host.book
    129 task nights.md5sum.runhosts
     129task nights.md5sum.run
    130130
    131131  periods      -poll $RPOLL
Note: See TracChangeset for help on using the changeset viewer.