IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 37291


Ignore:
Timestamp:
Aug 22, 2014, 4:49:46 PM (12 years ago)
Author:
eugene
Message:

scripts are all converted

Location:
tags/ipp-pv3-20140717/ippScripts/scripts
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • tags/ipp-pv3-20140717/ippScripts/scripts/sc_prepare_camera.pl

    r37126 r37291  
    11#! /usr/bin/env perl
     2
     3# generate the input & output files lists and commands for a single camRun
    24
    35use Carp;
     
    1618use Pod::Usage qw( pod2usage );
    1719
    18 
    1920# Hard coded values
    20 # my $remote_root   = '/scratch3/watersc1/';  # Far side destination base location
    21 my $remote_root   = '/lustre/scratch1/turquoise/watersc1/ps1/'; # Far side destination base location
    22 $remote_root = '/scratch3/watersc1/';
    23 my $threads       = 2;                      # How many threads are we going to use?
    24 my $job_cost      = 1700 / 60 / 60;         # Estimate of how long a job runs, in hours.
    25 my $proc_per_node = 24;                     # processors per node
    26 my $min_nodes     = 1;                      # smallest allocation to ask for
    27 my $max_nodes     = 1000;                   # largest allocation to ask for
    28 my $min_time      = 1;                      # shortest allocation to ask for
    29 my $max_time      = 8;                      # longest allocation to ask for
    30 my $remote_hostname= "LANL/Mustang";         # Name of the remote node.
    31 my @return_component_list = ("DBINFO.EXP", "PSASTRO.CONFIG", "PSASTRO.OUTPUT", "LOG.EXP", "PSASTRO.STATS");
     21# my $remote_root   = '/lustre/scratch1/turquoise/watersc1/ps1/'; # Far side destination base location
     22my $remote_root   = '/scratch3/watersc1/';  # Far side destination base location
     23my $threads_req   = 0;                      # How many threads are we going to use?
     24
     25my $fail_state = "prep_fail";
     26
    3227# Look for programs we need
    3328my $missing_tools;
    34 
    3529my $remotetool = can_run('remotetool') or (warn "Can't find remotetool" and $missing_tools = 1);
    3630my $camtool    = can_run('camtool') or (warn "Can't find camtool" and $missing_tools = 1);
     
    4135}
    4236
    43 my ($remote_id,$cam_id,,$camera,$dbname,$verbose,$path_base,$no_update);
     37my ($remote_id,$cam_id,$camera,$dbname,$verbose,$path_base,$no_update);
    4438GetOptions(
    4539    'remote_id=s'    => \$remote_id,
     40    'cam_d=s'        => \$cam_id,
    4641    'camera|c=s'     => \$camera,
    4742    'dbname|d=s'     => \$dbname,
     
    5247
    5348pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV;
    54 pod2usage( -msg => "Required options: --remote_id --camera --dbname --path_base", -exitval => 3) unless
     49pod2usage( -msg => "Required options: --remote_id --cam_id --camera --dbname --path_base", -exitval => 3) unless
    5550    defined($remote_id) and
     51    defined($cam_id) and
    5652    defined($camera) and
    5753    defined($path_base) and
    5854    defined($dbname);
    59 my $ipprc = PS::IPP::Config->new( $camera ) or my_die( "Unable to set up", $remote_id);
     55
     56my $ipprc = PS::IPP::Config->new( $camera ) or &my_die( "Unable to set up", $remote_id, $cam_id, $PS_EXIT_CONFIG_ERROR, $fail_state);
    6057
    6158my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files
    6259
    63 #
    64 # Step 1: Get a list of the components that make up this remoteRun
    65 
    66 # SHould this call listrun to ensure we're in state new?
    67 my $rt_cmd = "$remotetool -listcomponent -remote_id $remote_id";
    68 $rt_cmd   .= " -dbname $dbname " if defined($dbname);
    69 
    70 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    71     run(command => $rt_cmd, verbose => $verbose);
    72 unless ($success) {
    73     $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    74     &my_die("Unable to run remotetool to determine stage parameters.",
    75             $remote_id,$error_code);
    76 }
    77 my $compData = $mdcParser->parse(join "", @$stdout_buf) or
    78     &my_die("Unable to determine component information.",
    79             $remote_id,$PS_EXIT_PROG_ERROR);
    80 my $compData2= parse_md_list($compData);
    81 
    82 #
    83 # Step 1b: Open output files
    84 my $uri_command = $path_base . ".cmd";
     60my @return_component_list = ("DBINFO.EXP", "PSASTRO.CONFIG", "PSASTRO.OUTPUT", "LOG.EXP", "PSASTRO.STATS");
     61
     62# STEP 0: Open output files
    8563my $uri_transfer= $path_base . ".transfer";
    8664my $uri_check   = $path_base . ".check";
     
    8967my $uri_return  = $path_base . ".return";
    9068
    91 my $disk_command = $ipprc->file_resolve($uri_command,1);
    9269my $disk_transfer= $ipprc->file_resolve($uri_transfer,1);
    9370my $disk_check   = $ipprc->file_resolve($uri_check,1);
     
    9875my (undef, $remote_config) = uri_convert($uri_config); # Needs to be done after we've created it.
    9976
    100 open(TRANSFER, ">$disk_transfer")  || &my_die("Couldn't open file? $disk_transfer",$remote_id,$PS_EXIT_SYS_ERROR);
    101 open(CHECK,    ">$disk_check")  || &my_die("Couldn't open file? $disk_check",$remote_id,$PS_EXIT_SYS_ERROR);
    102 open(CONFIG,   ">$disk_config")  || &my_die("Couldn't open file? $disk_config",$remote_id,$PS_EXIT_SYS_ERROR);
    103 open(GENERATE, ">$disk_generate") || &my_die("Couldn't open file? $disk_generate",$remote_id,$PS_EXIT_SYS_ERROR);
    104 open(RETURN,   ">$disk_return") || &my_die("Couldn't open file? $disk_return", $remote_id, $PS_EXIT_SYS_ERROR);
     77open(TRANSFER, ">$disk_transfer")  || &my_die("Couldn't open file? $disk_transfer",$remote_id, $cam_id, $PS_EXIT_SYS_ERROR, $fail_state);
     78open(CHECK,    ">$disk_check")     || &my_die("Couldn't open file? $disk_check",   $remote_id, $cam_id, $PS_EXIT_SYS_ERROR, $fail_state);
     79open(CONFIG,   ">$disk_config")    || &my_die("Couldn't open file? $disk_config",  $remote_id, $cam_id, $PS_EXIT_SYS_ERROR, $fail_state);
     80open(GENERATE, ">$disk_generate")  || &my_die("Couldn't open file? $disk_generate",$remote_id, $cam_id, $PS_EXIT_SYS_ERROR, $fail_state);
     81open(RETURN,   ">$disk_return")    || &my_die("Couldn't open file? $disk_return",  $remote_id, $cam_id, $PS_EXIT_SYS_ERROR, $fail_state);
    10582my %file_filter = ();
    10683
    107 #
    108 # Step 2: Iterate over all componenets in this remote run.
    10984my $job_index = 0;
    110 my @pre_commands = ();
    111 my @main_commands = ();
    112 my @post_commands = ();
    113 
    114 foreach my $compEntry (@$compData2) {
    115     my $cam_id = $compEntry->{stage_id};
    116 
    117 # Get exposure level information from the camRun we're working from.
    118    
     85
     86# STEP 1: Get exposure level information for this camRun
     87my ($workdir,$exp_tag);
     88{   
    11989    my $command = "$camtool -pendingexp -cam_id $cam_id ";
    12090    $command   .= " -dbname $dbname " if defined($dbname);
     
    12595        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    12696       
    127         &my_die("Unable to run camtool to determine stage parameters.",
    128                 $cam_id,$error_code);
    129     }
    130 
    131     my $camData = $mdcParser->parse(join "", @$stdout_buf) or
    132         &my_die("Unable to determine cam component information.",
    133                 $cam_id,$PS_EXIT_PROG_ERROR);
    134     my $camData2= parse_md_list($camData);
    135     my $camEntry = ${ $camData2 }[0];
    136    
    137     my $workdir = $camEntry->{workdir};
    138     my $exp_tag = $camEntry->{exp_tag};
     97        &my_die("Unable to run camtool to determine stage parameters.", $remote_id, $cam_id, $error_code, $fail_state);
     98    }
     99   
     100    my $MDlist = $mdcParser->parse(join "", @$stdout_buf) or
     101        &my_die("Unable to determine cam component information.", $remote_id, $cam_id, $PS_EXIT_PROG_ERROR, $fail_state);
     102    my $metadata = parse_md_list($MDlist);
     103    my $camEntry = $metadata->[0];
     104   
     105    $workdir = $camEntry->{workdir};
     106    $exp_tag = $camEntry->{exp_tag};
    139107    unless (defined($workdir)) {
    140108        while( my ($k, $v) = each %$camEntry ) {
    141109            print "key: $k, value: $v.\n";
    142110        }
    143 
    144111        print "%{ $camEntry }\n";
    145112        die;
    146113    }
    147     my $ipp_outroot = "${workdir}/${exp_tag}/${exp_tag}.cm.${cam_id}";
    148     my $remote_outroot = uri_local_to_remote($ipp_outroot);
    149 
    150 
    151 #
     114}
     115
     116my $ipp_outroot = "${workdir}/${exp_tag}/${exp_tag}.cm.${cam_id}";
     117my $remote_outroot = uri_local_to_remote($ipp_outroot);
     118
    152119# Step 3: Iterate over the sub-components
    153 
    154     my $reg_command = "$camtool -pendingimfile -cam_id $cam_id ";
    155     $reg_command   .= " -dbname $dbname " if defined($dbname);
     120{
     121    my $command = "$camtool -pendingimfile -cam_id $cam_id ";
     122    $command   .= " -dbname $dbname " if defined($dbname);
    156123
    157124    ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    158         run(command => $reg_command, verbose => 0);
     125        run(command => $command, verbose => 0);
    159126    unless ($success) {
    160127        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    161         &my_die("Unable to run camtool -pendingimfile ",
    162                 $cam_id,$error_code);
    163     }
    164    
     128        &my_die("Unable to run camtool -pendingimfile ", $remote_id, $cam_id, $error_code, $fail_state);
     129    }
    165130
    166131    # We don't actually care about the input cam data other than to know which mask files to instantiate.
    167     my $inpData = $mdcParser->parse(join "", @$stdout_buf) or
    168         &my_die("Unable to determine cam component information.",
    169                 $cam_id, $PS_EXIT_PROG_ERROR);
    170     my $inpData2=parse_md_list($inpData);
    171     my $chipProto= ${ $inpData2 }[0];
     132    my $MDlist = $mdcParser->parse(join "", @$stdout_buf) or
     133        &my_die("Unable to determine cam component information.", $remote_id, $cam_id, $PS_EXIT_PROG_ERROR, $fail_state);
     134
     135    my $metadata = parse_md_list($MDlist);
     136    my $chipProto = $metadata->[0];
    172137    my $chip_path = $chipProto->{path_base};
    173138    my $remote_chip_path = uri_local_to_remote( $chip_path );
     
    180145    my $psastro_command = " psastro -list ${remote_outroot}.cmflist ";
    181146    $psastro_command   .= " -masklist ${remote_outroot}.masklist ${remote_outroot} ";
    182 #    $psastro_command   .= " -refmasklist ${remote_outroot}.masklist ${remote_outroot} "; # This is used to do edge calculations.  It should probably be smart enough to know that it can just use the masks I just specified, but it's not.
     147#   $psastro_command   .= " -refmasklist ${remote_outroot}.masklist ${remote_outroot} ";
     148# This is used to do edge calculations.  It should probably be smart enough to know that it can just use the masks I just specified, but it's not.
    183149    # Uncomment when remote psastro supports this
    184150    $psastro_command   .= " -kh-correct /turquoise/usr/projects/ps1/watersc1/references/khcorrect.20140606.v0.fits ";
    185151    $psastro_command   .= " -refmasklist /turquoise/usr/projects/ps1/watersc1/references/gpc1.refmask.list ";
    186 #    $psastro_command   .= " -astrommodel /turquoise/usr/projects/ps1/watersc1/references/gpc1.20080909.asm ";
     152#   $psastro_command   .= " -astrommodel /turquoise/usr/projects/ps1/watersc1/references/gpc1.20080909.asm ";
    187153    $psastro_command   .= " -astrommodel /turquoise/usr/projects/ps1/watersc1/references/gpc1.20140505.asm ";
    188154    $psastro_command   .= " -recipe PSASTRO $recipe_psastro ";
     
    192158   
    193159    my $camtool_post_cmd = "camtool -cam_id $cam_id -addprocessedexp -uri UNKNOWN ";
    194     $camtool_post_cmd  .=  " -dbname $dbname " if defined $dbname;                                                                                                            $camtool_post_cmd  .=  " -path_base $ipp_outroot -hostname $remote_hostname -dtime_script 0 ";
     160    $camtool_post_cmd  .=  " -dbname $dbname " if defined $dbname;
     161    $camtool_post_cmd  .=  " -path_base $ipp_outroot -hostname $remote_hostname -dtime_script 0 ";
    195162    my $post_cmd_echo = " echo -n \"$camtool_post_cmd\" > ${remote_outroot}.dbinfo ";
    196163    my $post_cmd_SfM  = " ppStatsFromMetadata ${remote_outroot}.stats - CAMERA_EXP_FPA >> ${remote_outroot}.dbinfo ";
     
    206173        print CONFIG " && mkdir -p ${remote_root}/tmp/${remote_outroot_dir} && ln -sf $remote_disk ${remote_root}/tmp/${ipp_disk} && touch $remote_disk ";
    207174    }
    208     foreach my $chipInfo (@{ $inpData2 }) {
     175    foreach my $chipInfo (@{ $metadata }) {
    209176        my $filename = $ipprc->filename("PSASTRO.OUTPUT.MASK",$ipp_outroot,$chipInfo->{class_id});
    210177        my ($ipp_disk, $remote_disk) = uri_to_outputs_for_return( $filename);
     
    220187close(GENERATE);
    221188
    222 #
    223 # Construct the moab command last, so we can use the job_index counter to estimate resources.  Somehow.
    224 my $proc_need = $job_index * $threads;       # how many total processors do we need?
    225 my $node_need = $proc_need / $proc_per_node; # this equals how many nodes?
    226 my $time_need = $job_index * $job_cost;      # How many seconds will this take?
    227 
    228 my $fill_factor = 0.8;  # This is the factor of how much of the time allocation we'd like to fill
    229 my ($time_req,$node_req);
    230 if ($node_need * $job_cost < $fill_factor * $min_nodes * $min_time) {
    231     $time_req = $min_time;
    232     $node_req = $min_nodes;
    233 }
    234 elsif ($node_need * $job_cost > $fill_factor * $max_nodes * $max_time) {
    235     $time_req = $max_time;
    236     $node_req = $max_nodes;
    237     print STDERR "You've requested the construction of a bundle that appears to need $node_need nodes and $job_cost time per job.  This exceeds the max limits ($max_nodes, $max_time).  Using those max values instead.  Good luck.\n";
    238 }
    239 else {
    240     $time_req = int(($node_need * $job_cost) / ($fill_factor * $max_nodes)) + 1;
    241     $node_req = int(($node_need * $job_cost) / ($fill_factor * $time_req)) + 1;
    242 }
    243 $time_req += 1; # Safety addition.
    244 
    245 open(COMMAND,  ">$disk_command") || &my_die("Couldn't open file? $disk_command",$remote_id,$PS_EXIT_SYS_ERROR);
    246 print COMMAND "#!/bin/tcsh\n";
    247 print COMMAND "##### Moab controll lines\n";
    248 print COMMAND "#MSUB -l nodes=${node_req}:ppn=${proc_per_node},walltime=${time_req}:00:00\n"; ## CHECK RESOURCES
    249 print COMMAND "#MSUB -j oe\n";
    250 print COMMAND "#MSUB -V\n";
    251 print COMMAND "#MSUB -o ${remote_root}cam.${remote_id}.out\n";
    252 print COMMAND "date\n";
    253 print COMMAND 'srun -n $SLURM_JOB_NUM_NODES -m cyclic -l /bin/hostname | sort -n | awk \'{printf "%s\n", $2}\' > hosts.${SLURM_JOB_ID}' . "\n";
    254 print COMMAND "${remote_root}/stask_chip.py $remote_config " . 'hosts.${SLURM_JOB_ID} 1' . "\n";
    255 print COMMAND "date\n";
    256 close(COMMAND);
    257 
    258189unless($no_update) {
    259     my $command = "remotetool -updaterun -remote_id $remote_id ";
    260     $command .= " -set_state pending ";
    261     $command .= " -dbname $dbname " if defined $dbname;
    262 
     190    my $command = "remotetool -updatecomponent -remote_id $remote_id -stage_id $cam_id ";
     191    $command   .= " -set_jobs $job_index";
     192    $command   .= " -set_path_base $path_base";
     193    $command   .= " -set_state prep_done";
     194    $command   .= " -dbname $dbname " if defined $dbname;
    263195    system($command);
    264196}
    265197
     198exit (0);
    266199
    267200## Common SC routines
     
    273206   
    274207    unless(defined($ipp_disk)) {
    275         my_die();
     208        &my_die( "Unable to generate file for $neb_uri ", $remote_id, $cam_id, $PS_EXIT_SYS_ERROR, $fail_state);
    276209    }
    277210
     
    289222   
    290223    unless(defined($ipp_disk)) {
    291         my_die();
     224        &my_die( "Unable to generate file for $neb_uri ", $remote_id, $cam_id, $PS_EXIT_SYS_ERROR, $fail_state);
    292225    }
    293226
     
    345278sub my_die { # exit with status; my_die(message,stage_id,exit_code,exit_status);
    346279    my $msg = shift;
    347     my $id  = shift;
     280    my $remote_id  = shift;
     281    my $stage_id  = shift;
    348282    my $exit_code = shift;
    349283    my $exit_state = shift;
     
    353287    carp($msg);
    354288   
    355     if (defined $id and not $no_update) {
    356         my $command = "remotetool -updaterun -remote_id $id";
    357         $command .= " -fault $exit_code " if defined $exit_code;
     289    if (defined $remote_id and defined $stage_id and not $no_update) {
     290        my $command = "remotetool -updatecomponent -remote_id $id -stage_id $stage_id";
    358291        $command .= " -set_state $exit_state " if defined $exit_state;
    359292        $command .= " -dbname $dbname " if defined $dbname;
  • tags/ipp-pv3-20140717/ippScripts/scripts/sc_prepare_chip.pl

    r37280 r37291  
    5858    defined($dbname);
    5959
    60 my $ipprc = PS::IPP::Config->new( $camera ) or my_die( "Unable to set up", $remote_id, $chip_id, $PS_EXIT_CONFIG_ERROR, $fail_state);
     60my $ipprc = PS::IPP::Config->new( $camera ) or &my_die( "Unable to set up", $remote_id, $chip_id, $PS_EXIT_CONFIG_ERROR, $fail_state);
    6161
    6262my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files
     
    304304    system($command);
    305305}
    306 
    307306exit (0);
    308307
     
    313312
    314313    unless(defined($ipp_disk)) {
    315         my_die( "Unable to generate file for $neb_uri ", $remote_id, $chip_id, $PS_EXIT_SYS_ERROR, $fail_state);
     314        &my_die( "Unable to generate file for $neb_uri ", $remote_id, $chip_id, $PS_EXIT_SYS_ERROR, $fail_state);
    316315    }
    317316
     
    329328
    330329    unless(defined($ipp_disk)) {
    331         my_die( "Unable to generate file for $neb_uri ", $remote_id, $chip_id, $PS_EXIT_SYS_ERROR, $fail_state);
     330        &my_die( "Unable to generate file for $neb_uri ", $remote_id, $chip_id, $PS_EXIT_SYS_ERROR, $fail_state);
    332331    }
    333332
  • tags/ipp-pv3-20140717/ippScripts/scripts/sc_prepare_run.pl

    r37284 r37291  
    2626my $remote_raw    = "${remote_root}/raw/";  # Directory to find raw data in.
    2727
    28 # value for chip:
    2928my $threads       = 2;                      # How many threads are we going to use?
    30 my $job_cost      = 150 / 60 / 60;          # Estimate of how long a job runs, in hours.
     29
     30my $fail_state = "prep_fail";
     31
     32# Estimate of how long a job runs, in hours (depends on stage)
     33my %job_cost = ();
     34$job_cost{"camera"} = 1700 / 60 / 60;
     35$job_cost{"chip"}   = 150 / 60 / 60;
     36$job_cost{"warp"}   = 110 / 60 / 60;
     37$job_cost{"stack"}  = 1500 / 60 / 60;
    3138
    3239my $proc_per_node = 24;                     # processors per node
     
    3542my $min_time      = 1;                      # shortest allocation to ask for
    3643my $max_time      = 8;                      # longest allocation to ask for
     44my $remote_hostname= "LANL/Mustang";         # Name of the remote node.
    3745
    3846# We need to ensure we only ever try to transfer a file once.
     
    4149# Look for programs we need
    4250my $missing_tools;
    43 my $chiptool = can_run('chiptool') or (warn "Can't find chiptool" and $missing_tools = 1);
    44 my $detselect= can_run('detselect') or (warn "Can't find detselect" and $missing_tools = 1);
    4551my $remotetool = can_run('remotetool') or (warn "Can't find remotetool" and $missing_tools = 1);
    4652
     
    5157
    5258# Options
    53 my ($exp_id,$exp_name,$remote_id,$chip_id,$detrends,$camera,$dbname,$verbose,$path_base,$no_update);
     59my ($remote_id,$stage,$camera,$path_base,$dbname,$verbose,$no_update);
    5460GetOptions(
    5561    'remote_id=s'    => \$remote_id,
     62    'stage=s'        => \$stage,
    5663    'camera|c=s'     => \$camera,
     64    'path_base=s'    => \$path_base,
    5765    'dbname|d=s'     => \$dbname,
    58     'path_base=s'    => \$path_base,
     66    'verbose'        => \$verbose,
    5967    'no_update'      => \$no_update,
    60     'verbose'        => \$verbose,
    6168    ) or pod2usage( 2 );
    6269
    6370pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV;
    64 pod2usage( -msg => "Required options: --remote_id --camera --dbname --path_base", -exitval => 3) unless
     71pod2usage( -msg => "Required options: --remote_id --stage --camera --dbname --path_base", -exitval => 3) unless
    6572    defined($remote_id) and
     73    defined($stage) and
    6674    defined($camera) and
    6775    defined($path_base) and
    6876    defined($dbname);
    69 my $ipprc = PS::IPP::Config->new( $camera ) or my_die( "Unable to set up", $exp_id);
     77
     78my $ipprc = PS::IPP::Config->new( $camera ) or &my_die( "Unable to set up", $remote_id, $PS_EXIT_CONFIG_ERROR, $fail_state);
    7079
    7180my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files
     
    8291        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    8392
    84         &my_die("Unable to run chiptool to determine stage parameters.", $remote_id, $error_code);
     93        &my_die("Unable to run remotetool to determine stage parameters.", $remote_id, $error_code, $fail_state);
    8594    }
    8695    my $MDlist = $mdcParser->parse(join "", @$stdout_buf) or
    87         &my_die("Unable to determine component information.", $remote_id,$PS_EXIT_PROG_ERROR);
     96        &my_die("Unable to determine component information.", $remote_id, $PS_EXIT_PROG_ERROR, $fail_state);
    8897    $compData = parse_md_list($MDlist);
    8998}
     
    112121my (undef, $remote_config) = uri_convert($uri_config); # Needs to be done after we've created it.
    113122
    114 open(TRANSFER, ">$disk_transfer")  || &my_die("Couldn't open file? $disk_transfer",$chip_id,$PS_EXIT_SYS_ERROR);
    115 open(CHECK,    ">$disk_check")     || &my_die("Couldn't open file? $disk_check",   $chip_id,$PS_EXIT_SYS_ERROR);
    116 open(CONFIG,   ">$disk_config")    || &my_die("Couldn't open file? $disk_config",  $chip_id,$PS_EXIT_SYS_ERROR);
    117 open(GENERATE, ">$disk_generate")  || &my_die("Couldn't open file? $disk_generate",$chip_id,$PS_EXIT_SYS_ERROR);
    118 open(RETURN,   ">$disk_return")    || &my_die("Couldn't open file? $disk_return",  $chip_id,$PS_EXIT_SYS_ERROR);
     123open(TRANSFER, ">$disk_transfer")  || &my_die("Couldn't open file? $disk_transfer",$remote_id, $PS_EXIT_SYS_ERROR, $fail_state);
     124open(CHECK,    ">$disk_check")     || &my_die("Couldn't open file? $disk_check",   $remote_id, $PS_EXIT_SYS_ERROR, $fail_state);
     125open(CONFIG,   ">$disk_config")    || &my_die("Couldn't open file? $disk_config",  $remote_id, $PS_EXIT_SYS_ERROR, $fail_state);
     126open(GENERATE, ">$disk_generate")  || &my_die("Couldn't open file? $disk_generate",$remote_id, $PS_EXIT_SYS_ERROR, $fail_state);
     127open(RETURN,   ">$disk_return")    || &my_die("Couldn't open file? $disk_return",  $remote_id, $PS_EXIT_SYS_ERROR, $fail_state);
    119128
    120129# Step 2: Iterate over all componenets in this remote run.
     
    194203my $proc_need = $job_index * $threads;       # how many total processors do we need?
    195204my $node_need = $proc_need / $proc_per_node; # this equals how many nodes?
    196 my $time_need = $job_index * $job_cost;      # How many seconds will this take?
     205my $time_need = $job_index * $job_cost{$stage};      # How many seconds will this take?
    197206
    198207my $fill_factor = 0.8;  # This is the factor of how much of the time allocation we'd like to fill
    199208my ($time_req,$node_req);
    200 if ($node_need * $job_cost < $fill_factor * $min_nodes * $min_time) {
     209if ($node_need * $job_cost{$stage} < $fill_factor * $min_nodes * $min_time) {
    201210    $time_req = $min_time;
    202211    $node_req = $min_nodes;
    203212}
    204 elsif ($node_need * $job_cost > $fill_factor * $max_nodes * $max_time) {
     213elsif ($node_need * $job_cost{$stage} > $fill_factor * $max_nodes * $max_time) {
    205214    $time_req = $max_time;
    206215    $node_req = $max_nodes;
    207     print STDERR "You've requested the construction of a bundle that appears to need $node_need nodes and $job_cost time per job.  This exceeds the max limits ($max_nodes, $max_time).  Using those max values instead.  Good luck.\n";
     216    print STDERR "You've requested the construction of a bundle that appears to need $node_need nodes and $job_cost{$stage} time per job.  This exceeds the max limits ($max_nodes, $max_time).  Using those max values instead.  Good luck.\n";
    208217}
    209218else {
    210     $time_req = int(($node_need * $job_cost) / ($fill_factor * $max_nodes)) + 1;
    211     $node_req = int(($node_need * $job_cost) / ($fill_factor * $time_req)) + 1;
    212 }
    213 $time_req += 1; # Safety addition.
    214 
    215 open(COMMAND,  ">$disk_command") || &my_die("Couldn't open file? $disk_command",$chip_id,$PS_EXIT_SYS_ERROR);
     219    $time_req = int(($node_need * $job_cost{$stage}) / ($fill_factor * $max_nodes)) + 1;
     220    $node_req = int(($node_need * $job_cost{$stage}) / ($fill_factor * $time_req)) + 1;
     221}
     222
     223if ($stage eq "stack") {
     224    $time_req += 2;
     225    $node_req *= 3;
     226} else {
     227    $time_req += 1; # Safety addition.
     228}
     229
     230open(COMMAND,  ">$disk_command") || &my_die("Couldn't open file? $disk_command", $remote_id, $PS_EXIT_SYS_ERROR, $fail_state);
    216231print COMMAND "#!/bin/tcsh\n";
    217232print COMMAND "##### Moab controll lines\n";
     
    219234print COMMAND "#MSUB -j oe\n";
    220235print COMMAND "#MSUB -V\n";
    221 print COMMAND "#MSUB -o ${remote_root}chip.${remote_id}.out\n";
     236print COMMAND "#MSUB -o ${remote_root}/${stage}.${remote_id}.out\n";
    222237print COMMAND "date\n";
    223238print COMMAND 'srun -n $SLURM_JOB_NUM_NODES -m cyclic -l /bin/hostname | sort -n | awk \'{printf "%s\n", $2}\' > hosts.${SLURM_JOB_ID}' . "\n";
     
    246261
    247262    unless(defined($ipp_disk)) {
    248         my_die();
     263        &my_die( "Unable to generate file for $neb_uri ", $remote_id, $PS_EXIT_SYS_ERROR, $fail_state);
    249264    }
    250265
     
    258273sub my_die {
    259274    my $msg = shift;
    260     my $id  = shift;
     275    my $remote_id  = shift;
    261276    my $exit_code = shift;
    262277    my $exit_state = shift;
     
    266281    carp($msg);
    267282
    268     if (defined $id and not $no_update) {
    269         my $command = "remotetool -updaterun -remote_id $id";
     283    if (defined $remote_id and not $no_update) {
     284        my $command = "remotetool -updaterun -remote_id $remote_id";
    270285        $command .= " -fault $exit_code " if defined $exit_code;
    271286        $command .= " -set_state $exit_state " if defined $exit_state;
  • tags/ipp-pv3-20140717/ippScripts/scripts/sc_prepare_stack.pl

    r37196 r37291  
    11#! /usr/bin/env perl
     2
     3# generate the input & output files lists and commands for a single stackRun
    24
    35use Carp;
     
    1618use Pod::Usage qw( pod2usage );
    1719
    18 
    1920# Hard coded values
    20 #my $remote_root   = '/scratch3/watersc1/';  # Far side destination base location
    21 my $remote_root   = '/lustre/scratch1/turquoise/watersc1/ps1/'; # Far side destination base location
    22 $remote_root = '/scratch3/watersc1/';
    23 my $threads       = 2;                      # How many threads are we going to use?
    24 my $job_cost      = 1500 / 60 / 60;           # Estimate of how long a job runs, in hours.
    25 my $proc_per_node = 24;                     # processors per node
    26 my $min_nodes     = 1;                      # smallest allocation to ask for
    27 my $max_nodes     = 1000;                   # largest allocation to ask for
    28 my $min_time      = 1;                      # shortest allocation to ask for
    29 my $max_time      = 8;                      # longest allocation to ask for
    30 my $remote_hostname   = "LANL/Mustang";         # Name of the remote node.
    31 my @return_component_list = ("DBINFO.EXP", "PPSTACK.UNCONV","PPSTACK.UNCONV.MASK","PPSTACK.UNCONV.VARIANCE",
    32                              "PPSTACK.UNCONV.EXP","PPSTACK.UNCONV.EXPWT","PPSTACK.UNCONV.EXPNUM","PSPHOT.OUTPUT",
    33                              "LOG.EXP", "PSASTRO.STATS",
    34                              "PPSTACK.CONFIG","PPSTACK.TARGET.PSF","PSPHOT.STACK.PSF.SAVE");
    35 #,"PPSTACK.CONV.KERNEL");
     21# my $remote_root   = '/lustre/scratch1/turquoise/watersc1/ps1/'; # Far side destination base location
     22my $remote_root   = '/scratch3/watersc1/';  # Far side destination base location
     23my $threads_req   = 4;                      # How many threads are we going to use?
     24
     25my $fail_state = "prep_fail";
     26
    3627# Look for programs we need
    3728my $missing_tools;
    38 
    3929my $remotetool = can_run('remotetool') or (warn "Can't find remotetool" and $missing_tools = 1);
    40 my $stacktool    = can_run('stacktool') or (warn "Can't find warptool" and $missing_tools = 1);
     30my $stacktool    = can_run('stacktool') or (warn "Can't find stacktool" and $missing_tools = 1);
    4131
    4232if ($missing_tools) {
     
    4838GetOptions(
    4939    'remote_id=s'    => \$remote_id,
     40    'stack_id=s'     => \$stack_id,
    5041    'camera|c=s'     => \$camera,
    5142    'dbname|d=s'     => \$dbname,
     
    5647
    5748pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV;
    58 pod2usage( -msg => "Required options: --remote_id --camera --dbname --path_base", -exitval => 3) unless
     49pod2usage( -msg => "Required options: --remote_id --stack_id --camera --dbname --path_base", -exitval => 3) unless
    5950    defined($remote_id) and
     51    defined($stack_id) and
    6052    defined($camera) and
    6153    defined($path_base) and
    6254    defined($dbname);
    63 my $ipprc = PS::IPP::Config->new( $camera ) or my_die( "Unable to set up", $remote_id);
     55
     56my $ipprc = PS::IPP::Config->new( $camera ) or &my_die( "Unable to set up", $remote_id, $stack_id, $PS_EXIT_CONFIG_ERROR, $fail_state);
    6457
    6558my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files
    6659
    67 #
    68 # Step 1: Get a list of the components that make up this remoteRun
    69 
    70 # SHould this call listrun to ensure we're in state new?
    71 my $rt_cmd = "$remotetool -listcomponent -remote_id $remote_id";
    72 $rt_cmd   .= " -dbname $dbname " if defined($dbname);
    73 
    74 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    75     run(command => $rt_cmd, verbose => $verbose);
    76 unless ($success) {
    77     $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    78     &my_die("Unable to run remotetool to determine stage parameters.",
    79             $remote_id,$error_code);
    80 }
    81 my $compData = $mdcParser->parse(join "", @$stdout_buf) or
    82     &my_die("Unable to determine component information.",
    83             $remote_id,$PS_EXIT_PROG_ERROR);
    84 my $compData2= parse_md_list($compData);
    85 
    86 #
    87 # Step 1b: Open output files
    88 my $uri_command = $path_base . ".cmd";
     60my @return_component_list = ("DBINFO.EXP", "PPSTACK.UNCONV","PPSTACK.UNCONV.MASK","PPSTACK.UNCONV.VARIANCE",
     61                             "PPSTACK.UNCONV.EXP","PPSTACK.UNCONV.EXPWT","PPSTACK.UNCONV.EXPNUM","PSPHOT.OUTPUT",
     62                             "LOG.EXP", "PSASTRO.STATS",
     63                             "PPSTACK.CONFIG","PPSTACK.TARGET.PSF","PSPHOT.STACK.PSF.SAVE");
     64#,"PPSTACK.CONV.KERNEL");
     65
     66# STEP 0: Open output files
    8967my $uri_transfer= $path_base . ".transfer";
    9068my $uri_check   = $path_base . ".check";
     
    9371my $uri_return  = $path_base . ".return";
    9472
    95 my $disk_command = $ipprc->file_resolve($uri_command,1);
    9673my $disk_transfer= $ipprc->file_resolve($uri_transfer,1);
    9774my $disk_check   = $ipprc->file_resolve($uri_check,1);
     
    10279my (undef, $remote_config) = uri_convert($uri_config); # Needs to be done after we've created it.
    10380
    104 open(TRANSFER, ">$disk_transfer")  || &my_die("Couldn't open file? $disk_transfer",$remote_id,$PS_EXIT_SYS_ERROR);
    105 open(CHECK,    ">$disk_check")  || &my_die("Couldn't open file? $disk_check",$remote_id,$PS_EXIT_SYS_ERROR);
    106 open(CONFIG,   ">$disk_config")  || &my_die("Couldn't open file? $disk_config",$remote_id,$PS_EXIT_SYS_ERROR);
    107 open(GENERATE, ">$disk_generate") || &my_die("Couldn't open file? $disk_generate",$remote_id,$PS_EXIT_SYS_ERROR);
    108 open(RETURN,   ">$disk_return") || &my_die("Couldn't open file? $disk_return", $remote_id, $PS_EXIT_SYS_ERROR);
    109 
    110 
    111 #
    112 # Step 2: Iterate over all componenets in this remote run.
     81open(TRANSFER, ">$disk_transfer")  || &my_die("Couldn't open file? $disk_transfer",$remote_id, $stack_id, $PS_EXIT_SYS_ERROR, $fail_state);
     82open(CHECK,    ">$disk_check")     || &my_die("Couldn't open file? $disk_check",   $remote_id, $stack_id, $PS_EXIT_SYS_ERROR, $fail_state);
     83open(CONFIG,   ">$disk_config")    || &my_die("Couldn't open file? $disk_config",  $remote_id, $stack_id, $PS_EXIT_SYS_ERROR, $fail_state);
     84open(GENERATE, ">$disk_generate")  || &my_die("Couldn't open file? $disk_generate",$remote_id, $stack_id, $PS_EXIT_SYS_ERROR, $fail_state);
     85open(RETURN,   ">$disk_return")    || &my_die("Couldn't open file? $disk_return",  $remote_id, $stack_id, $PS_EXIT_SYS_ERROR, $fail_state);
     86
    11387my $job_index = 0;
    114 my @pre_commands = ();
    115 my @main_commands = ();
    116 my @post_commands = ();
    117 my %file_filter = ();
    118 
    119 
    120 foreach my $compEntry (@$compData2) {
    121     my $stack_id = $compEntry->{stage_id};
    122 
    123 # Get exposure level information from the stackRun we're working from.
    124     my $run_command = "$stacktool -tosum -stack_id $stack_id";
    125     $run_command .= " -dbname $dbname " if defined($dbname);
     88
     89# STEP 1: Get exposure level information from the stackRun we're working from.
     90my ($reduction, $workdir, $tess_id, $skycell_id);
     91{
     92    my $command = "$stacktool -tosum -stack_id $stack_id";
     93    $command .= " -dbname $dbname " if defined($dbname);
    12694    ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    127         run(command => $run_command, verbose => 0);
     95        run(command => $command, verbose => 0);
    12896    unless ($success) {
    12997        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    130         &my_die("Unable to run stacktool -tosum ",
    131                 $stack_id,$error_code);
    132     }
    133 
    134     my $stackData = $mdcParser->parse(join "", @$stdout_buf) or
    135         &my_die("Unable to determine stack component information.",
    136                 $stack_id,$PS_EXIT_PROG_ERROR);
    137     my $stackData2= parse_md_list($stackData);
    138 
    139     my $stack = ${ $stackData2 }[0];
    140     my $reduction = $stack->{reduction};
     98        &my_die("Unable to run stacktool -tosum ", $remote_id, $stack_id, $error_code, $fail_state);
     99    }
     100
     101    my $MDlist = $mdcParser->parse(join "", @$stdout_buf) or
     102        &my_die("Unable to determine stack component information.", $remote_id, $stack_id, $PS_EXIT_PROG_ERROR, $fail_state);
     103    my $metadata = parse_md_list($MDlist);
     104
     105    my $stack = $metadata->[0];
     106
     107    $reduction = $stack->{reduction};
    141108    $reduction = 'DEFAULT' unless defined($reduction);
    142     my $workdir   = $stack->{workdir};
    143     my $tess_id   = $stack->{tess_id};
    144     my $skycell_id= $stack->{skycell_id};
    145 
    146     my $ipp_outroot    = "${workdir}/${tess_id}/${skycell_id}/${tess_id}.${skycell_id}.stk.${stack_id}";   
    147     my $remote_outroot = uri_local_to_remote($ipp_outroot);   
    148     my $remote_outdir  = uri_local_to_remote("${workdir}/${tess_id}/${skycell_id}");
     109    $workdir   = $stack->{workdir};
     110    $tess_id   = $stack->{tess_id};
     111    $skycell_id= $stack->{skycell_id};
     112}
     113my $ipp_outroot    = "${workdir}/${tess_id}/${skycell_id}/${tess_id}.${skycell_id}.stk.${stack_id}";   
     114my $remote_outroot = uri_local_to_remote($ipp_outroot);   
     115my $remote_outdir  = uri_local_to_remote("${workdir}/${tess_id}/${skycell_id}");
     116
     117# STEP 2: Get the list of input warps
     118my ($warpData);
     119{
    149120    # This actually returns all the individual stack/skyfiles that comprise this run.  Because consistency.
    150121    my $command = "$stacktool -inputskyfile -stack_id $stack_id ";
     
    154125    unless ($success) {
    155126        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    156         &my_die("Unable to run stacktool -inputskyfile ",
    157                 $stack_id,$error_code);
    158     }
    159 
    160     my $warpData = $mdcParser->parse(join "", @$stdout_buf) or
    161         &my_die("Unable to determine stack component information.",
    162                 $stack_id,$PS_EXIT_PROG_ERROR);
    163     my $warpData2= parse_md_list($warpData);
    164 
    165 #
    166 # Step 3: Iterate over the sub-components
     127        &my_die("Unable to run stacktool -inputskyfile ", $remote_id, $stack_id, $error_code, $fail_state);
     128    }
     129
     130    my $MDlist = $mdcParser->parse(join "", @$stdout_buf) or
     131        &my_die("Unable to determine stack component information.", $remote_id, $stack_id, $PS_EXIT_PROG_ERROR, $fail_state);
     132    my $warpData = parse_md_list($MDlist);
     133}
     134
     135# STEP 3: Iterate over the sub-components
     136{
    167137    my $warp_path_base_string = "";
    168     foreach my $warpEntry ( @{ $warpData2 } ) {
     138    foreach my $warpEntry ( @{ $warpData } ) {
    169139        my $warp_path_base = $warpEntry->{path_base};
    170140        my $remote_path_base = uri_local_to_remote($warp_path_base);
     
    191161    $ppstack_command    .= " -R PPSTACK.UNCONV.VARIANCE FITS.TYPE COMP_STACK";
    192162    $ppstack_command    .= " -tracedest ${remote_outroot}.trace -log ${remote_outroot}.log ";
    193     $ppstack_command    .= " -threads 4 ";
     163    $ppstack_command    .= " -threads $threads_req ";
    194164    $ppstack_command    .= " -dumpconfig ${remote_outroot}.mdc ";
    195165    $ppstack_command    .= " -stack_id $stack_id -skycell_id $skycell_id -tess_id $tess_id ";
     
    212182        print CONFIG " && mkdir -p ${remote_root}/tmp/${remote_outroot_dir} && ln -sf $remote_disk ${remote_root}/tmp/${ipp_disk} && touch $remote_disk ";
    213183    }
    214 
    215 #     my $cleanup_cmd   = " (rm -f /scratch3/watersc1/sys_temp/${tess_id}.${skycell_id}.stk.${stack_id}.*conv.*.fits || true) ";   
    216 #     print CONFIG " && ${cleanup_cmd} \n";
    217 
    218184    print CONFIG "\n";
    219185}
     
    224190close(GENERATE);
    225191
    226 #
    227 # Construct the moab command last, so we can use the job_index counter to estimate resources.  Somehow.
    228 my $proc_need = $job_index * $threads;       # how many total processors do we need?
    229 my $node_need = $proc_need / $proc_per_node; # this equals how many nodes?
    230 my $time_need = $job_index * $job_cost;      # How many seconds will this take?
    231 
    232 my $fill_factor = 0.8;  # This is the factor of how much of the time allocation we'd like to fill
    233 my ($time_req,$node_req);
    234 if ($node_need * $job_cost < $fill_factor * $min_nodes * $min_time) {
    235     $time_req = $min_time;
    236     $node_req = $min_nodes;
    237 }
    238 elsif ($node_need * $job_cost > $fill_factor * $max_nodes * $max_time) {
    239     $time_req = $max_time;
    240     $node_req = $max_nodes;
    241     print STDERR "You've requested the construction of a bundle that appears to need $node_need nodes and $job_cost time per job.  This exceeds the max limits ($max_nodes, $max_time).  Using those max values instead.  Good luck.\n";
    242 }
    243 else {
    244     $time_req = int(($node_need * $job_cost) / ($fill_factor * $max_nodes)) + 1;
    245     $node_req = int(($node_need * $job_cost) / ($fill_factor * $time_req)) + 1;
    246 }
    247 
    248 $time_req += 2;
    249 $node_req *= 3;
    250 open(COMMAND,  ">$disk_command") || &my_die("Couldn't open file? $disk_command",$remote_id,$PS_EXIT_SYS_ERROR);
    251 print COMMAND "#!/bin/tcsh\n";
    252 print COMMAND "##### Moab controll lines\n";
    253 print COMMAND "#MSUB -l nodes=${node_req}:ppn=${proc_per_node},walltime=${time_req}:00:00\n"; ## CHECK RESOURCES
    254 print COMMAND "#MSUB -j oe\n";
    255 print COMMAND "#MSUB -V\n";
    256 print COMMAND "#MSUB -o ${remote_root}stack.${remote_id}.out\n";
    257 print COMMAND "date\n";
    258 print COMMAND 'srun -n $SLURM_JOB_NUM_NODES -m cyclic -l /bin/hostname | sort -n | awk \'{printf "%s\n", $2}\' > hosts.${SLURM_JOB_ID}' . "\n";
    259 print COMMAND "${remote_root}/stask_chip.py $remote_config " . 'hosts.${SLURM_JOB_ID} 3' . "\n";
    260 print COMMAND "date\n";
    261 close(COMMAND);
    262 
    263192unless($no_update) {
    264     my $command = "remotetool -updaterun -remote_id $remote_id ";
    265     $command .= " -set_state pending ";
     193    my $command = "remotetool -updatecomponent -remote_id $remote_id -stage_id $stack_id ";
     194    $command .= " -set_jobs $job_index";
     195    $command .= " -set_path_base $path_base";
     196    $command .= " -set_state prep_done";
    266197    $command .= " -dbname $dbname " if defined $dbname;
    267198
    268199    system($command);
    269200}
    270 
    271201
    272202## Common SC routines
     
    278208   
    279209    unless(defined($ipp_disk)) {
    280         my_die();
     210        &my_die( "Unable to generate file for $neb_uri ", $remote_id, $stack_id, $PS_EXIT_SYS_ERROR, $fail_state);
    281211    }
    282212
     
    294224   
    295225    unless(defined($ipp_disk)) {
    296         my_die();
     226        &my_die( "Unable to generate file for $neb_uri ", $remote_id, $stack_id, $PS_EXIT_SYS_ERROR, $fail_state);
    297227    }
    298228
     
    350280sub my_die { # exit with status; my_die(message,stage_id,exit_code,exit_status);
    351281    my $msg = shift;
    352     my $id  = shift;
     282    my $remote_id  = shift;
     283    my $stage_id  = shift;
    353284    my $exit_code = shift;
    354285    my $exit_state = shift;
     
    358289    carp($msg);
    359290   
    360     if (defined $id and not $no_update) {
    361         my $command = "remotetool -updaterun -remote_id $id";
    362         $command .= " -fault $exit_code " if defined $exit_code;
     291    if (defined $remote_id and defined $stage_id and not $no_update) {
     292        my $command = "remotetool -updatecomponent -remote_id $remote_id -stage_id $stage_id";
    363293        $command .= " -set_state $exit_state " if defined $exit_state;
    364294        $command .= " -dbname $dbname " if defined $dbname;
  • tags/ipp-pv3-20140717/ippScripts/scripts/sc_prepare_warp.pl

    r37155 r37291  
    11#! /usr/bin/env perl
     2
     3# generate the input & output files lists and commands for a single warpRun
    24
    35use Carp;
     
    1618use Pod::Usage qw( pod2usage );
    1719
    18 
    1920# Hard coded values
    20 # my $remote_root   = '/scratch3/watersc1/'; 
    21 my $remote_root = '/lustre/scratch1/turquoise/watersc1/ps1/'; # Far side destination base location
    22 $remote_root = '/scratch3/watersc1/';
    23 my $threads       = 2;                      # How many threads are we going to use?
    24 my $job_cost      = 110 / 60 / 60;          # Estimate of how long a job runs, in hours.
    25 my $proc_per_node = 24;                     # processors per node
    26 my $min_nodes     = 1;                      # smallest allocation to ask for
    27 my $max_nodes     = 1000;                   # largest allocation to ask for
    28 my $min_time      = 1;                      # shortest allocation to ask for
    29 my $max_time      = 8;                      # longest allocation to ask for
    30 my $remote_hostname= "LANL/Mustang";         # Name of the remote node.
    31 my @return_component_list = ("DBINFO.EXP", "PSWARP.CONFIG", "PSWARP.OUTPUT", "PSWARP.OUTPUT.MASK", "PSWARP.OUTPUT.VARIANCE", "PSWARP.OUTPUT.SOURCES","PSPHOT.PSF.SKY.SAVE","LOG.EXP");
     21# my $remote_root = '/lustre/scratch1/turquoise/watersc1/ps1/'; # Far side destination base location
     22my $remote_root   = '/scratch3/watersc1/'; 
     23my $threads_req   = 4;                      # How many threads are we going to use?
     24
     25my $fail_state = "prep_fail";
     26
    3227# Look for programs we need
    3328my $missing_tools;
    34 
    3529my $remotetool = can_run('remotetool') or (warn "Can't find remotetool" and $missing_tools = 1);
    3630my $warptool    = can_run('warptool') or (warn "Can't find warptool" and $missing_tools = 1);
     
    4135}
    4236
    43 my ($remote_id,$warp_id,,$camera,$dbname,$verbose,$path_base,$no_update);
     37my ($remote_id,$warp_id,$camera,$dbname,$verbose,$path_base,$no_update);
    4438GetOptions(
    4539    'remote_id=s'    => \$remote_id,
     40    'warp_id=s'      => \$warp_id,
    4641    'camera|c=s'     => \$camera,
    4742    'dbname|d=s'     => \$dbname,
     
    5247
    5348pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV;
    54 pod2usage( -msg => "Required options: --remote_id --camera --dbname --path_base", -exitval => 3) unless
     49pod2usage( -msg => "Required options: --remote_id -warp_id --camera --dbname --path_base", -exitval => 3) unless
    5550    defined($remote_id) and
     51    defined($warp_id) and
    5652    defined($camera) and
    5753    defined($path_base) and
    5854    defined($dbname);
    59 my $ipprc = PS::IPP::Config->new( $camera ) or my_die( "Unable to set up", $warp_id);
     55
     56my $ipprc = PS::IPP::Config->new( $camera ) or my_die( "Unable to set up", $remote_id, $warp_id, $PS_EXIT_CONFIG_ERROR, $fail_state);
    6057
    6158my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files
    6259
    63 #
    64 # Step 1: Get a list of the components that make up this remoteRun
    65 
    66 # SHould this call listrun to ensure we're in state new?
    67 my $rt_cmd = "$remotetool -listcomponent -remote_id $remote_id";
    68 $rt_cmd   .= " -dbname $dbname " if defined($dbname);
    69 
    70 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    71     run(command => $rt_cmd, verbose => $verbose);
    72 unless ($success) {
    73     $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    74     &my_die("Unable to run remotetool to determine stage parameters.",
    75             $remote_id,$error_code);
    76 }
    77 my $compData = $mdcParser->parse(join "", @$stdout_buf) or
    78     &my_die("Unable to determine component information.",
    79             $remote_id,$PS_EXIT_PROG_ERROR);
    80 my $compData2= parse_md_list($compData);
    81 
    82 #
    83 # Step 1b: Open output files
    84 my $uri_command = $path_base . ".cmd";
     60my @return_component_list = ("DBINFO.EXP", "PSWARP.CONFIG", "PSWARP.OUTPUT", "PSWARP.OUTPUT.MASK", "PSWARP.OUTPUT.VARIANCE", "PSWARP.OUTPUT.SOURCES","PSPHOT.PSF.SKY.SAVE","LOG.EXP");
     61
     62# STEP 0: Open output files
    8563my $uri_transfer= $path_base . ".transfer";
    8664my $uri_check   = $path_base . ".check";
     
    8967my $uri_return  = $path_base . ".return";
    9068
    91 my $disk_command = $ipprc->file_resolve($uri_command,1);
    9269my $disk_transfer= $ipprc->file_resolve($uri_transfer,1);
    9370my $disk_check   = $ipprc->file_resolve($uri_check,1);
     
    9875my (undef, $remote_config) = uri_convert($uri_config); # Needs to be done after we've created it.
    9976
    100 open(TRANSFER, ">$disk_transfer")  || &my_die("Couldn't open file? $disk_transfer",$remote_id,$PS_EXIT_SYS_ERROR);
    101 open(CHECK,    ">$disk_check")  || &my_die("Couldn't open file? $disk_check",$remote_id,$PS_EXIT_SYS_ERROR);
    102 open(CONFIG,   ">$disk_config")  || &my_die("Couldn't open file? $disk_config",$remote_id,$PS_EXIT_SYS_ERROR);
    103 open(GENERATE, ">$disk_generate") || &my_die("Couldn't open file? $disk_generate",$remote_id,$PS_EXIT_SYS_ERROR);
    104 open(RETURN,   ">$disk_return") || &my_die("Couldn't open file? $disk_return", $remote_id, $PS_EXIT_SYS_ERROR);
    105 
    106 
    107 #
    108 # Step 2: Iterate over all componenets in this remote run.
     77open(TRANSFER, ">$disk_transfer")  || &my_die("Couldn't open file? $disk_transfer",$remote_id, $warp_id, $PS_EXIT_SYS_ERROR, $fail_state);
     78open(CHECK,    ">$disk_check")     || &my_die("Couldn't open file? $disk_check",   $remote_id, $warp_id, $PS_EXIT_SYS_ERROR, $fail_state);
     79open(CONFIG,   ">$disk_config")    || &my_die("Couldn't open file? $disk_config",  $remote_id, $warp_id, $PS_EXIT_SYS_ERROR, $fail_state);
     80open(GENERATE, ">$disk_generate")  || &my_die("Couldn't open file? $disk_generate",$remote_id, $warp_id, $PS_EXIT_SYS_ERROR, $fail_state);
     81open(RETURN,   ">$disk_return")    || &my_die("Couldn't open file? $disk_return",  $remote_id, $warp_id, $PS_EXIT_SYS_ERROR, $fail_state);
     82
    10983my $job_index = 0;
    110 my @pre_commands = ();
    111 my @main_commands = ();
    112 my @post_commands = ();
    113 
    114 my %file_filter = ();
    115 
    116 foreach my $compEntry (@$compData2) {
    117     my $warp_id = $compEntry->{stage_id};
    118 
    119 # Get exposure level information from the warpRun we're working from.
     84
     85# STEP 1: Get exposure level information from the warpRun we're working from.
     86my ($warpData);
     87{
    12088    # This actually returns all the individual warp/skyfiles that comprise this run.  Because consistency.
    12189    my $command = "$warptool -towarped -warp_id $warp_id ";
     
    12593    unless ($success) {
    12694        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    127         &my_die("Unable to run warptool -pendingimfile ",
    128                 $warp_id,$error_code);
    129     }
    130     my $warpData = $mdcParser->parse(join "", @$stdout_buf) or
    131         &my_die("Unable to determine warp component information.",
    132                 $warp_id,$PS_EXIT_PROG_ERROR);
    133     my $warpData2= parse_md_list($warpData);
    134 
    135 #
    136 # Step 3: Iterate over the sub-components
    137     foreach my $warpEntry ( @{ $warpData2 } ) {
     95        &my_die("Unable to run warptool -pendingimfile ", $remote_id, $warp_id, $error_code, $fail_state);
     96    }
     97    my $MDlist = $mdcParser->parse(join "", @$stdout_buf) or
     98        &my_die("Unable to determine warp component information.", $remote_id, $warp_id, $PS_EXIT_PROG_ERROR, $fail_state);
     99    $warpData = parse_md_list($MDlist);
     100}
     101
     102# STEP 2: Iterate over the sub-components
     103{
     104    foreach my $warpEntry ( @{ $warpData } ) {
    138105        my $workdir = $warpEntry->{workdir};
    139106        my $exp_tag = $warpEntry->{exp_tag};
     
    146113        my $remote_outroot = uri_local_to_remote($ipp_outroot);
    147114
    148         my $reg_command = "$warptool -scmap -warp_id $warp_id -skycell_id ${skycell_id}";
    149         $reg_command   .= " -dbname $dbname " if defined($dbname);
     115        my $command = "$warptool -scmap -warp_id $warp_id -skycell_id ${skycell_id}";
     116        $command   .= " -dbname $dbname " if defined($dbname);
    150117       
    151118        ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    152             run(command => $reg_command, verbose => 0);
     119            run(command => $command, verbose => 0);
    153120        unless ($success) {
    154121            $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    155             &my_die("Unable to run warptool -pendingimfile: $reg_command ",
    156                     $warp_id,$error_code);
     122            &my_die("Unable to run warptool -pendingimfile: $command ", $remote_id, $warp_id, $error_code, $fail_state);
    157123        }
    158124   
    159         my $inpData = $mdcParser->parse(join "", @$stdout_buf) or
    160             &my_die("Unable to determine warp component information.",
    161                     $warp_id, $PS_EXIT_PROG_ERROR);
    162         my $inpData2=parse_md_list($inpData);
     125        my $MDlist = $mdcParser->parse(join "", @$stdout_buf) or
     126            &my_die("Unable to determine warp component information.", $remote_id, $warp_id, $PS_EXIT_PROG_ERROR, $fail_state);
     127        my $inData = parse_md_list($MDlist);
    163128       
    164129        my $pre_cmd_ims = "ls -1 ";
     
    167132        my $pre_cmd_astrom = "";
    168133
    169         foreach my $imfile (@{ $inpData2 }) {
     134        foreach my $imfile (@{ $inData2 }) {
    170135            my $image = $ipprc->filename("PPIMAGE.CHIP", $imfile->{chip_path_base}, $imfile->{class_id});
    171136            my $mask  = $ipprc->filename("PSASTRO.OUTPUT.MASK", $imfile->{cam_path_base}, $imfile->{class_id});
     
    202167        $pswarp_command    .= " -recipe PSWARP $recipe_pswarp ";
    203168        $pswarp_command    .= " -tracedest ${remote_outroot}.trace -log ${remote_outroot}.log ";
    204         $pswarp_command    .= " -threads 4 "; # -image_id ${image_id} -source_id ${source_id} ";
     169        $pswarp_command    .= " -threads $threads_req "; # -image_id ${image_id} -source_id ${source_id} ";
    205170        $pswarp_command    .= " -recipe PPSTATS WARPSTATS ";
    206171        $pswarp_command    .= " -dumpconfig ${remote_outroot}.pswarp.mdc -stats ${remote_outroot}.stats ";
     
    225190            print CONFIG " && mkdir -p ${remote_root}/tmp/${remote_outroot_dir} && ln -sf $remote_disk ${remote_root}/tmp/${ipp_disk} && touch $remote_disk ";
    226191        }
    227 
    228192        print CONFIG "\n";
    229193#       die();
     
    236200close(GENERATE);
    237201
    238 #
    239 # Construct the moab command last, so we can use the job_index counter to estimate resources.  Somehow.
    240 my $proc_need = $job_index * $threads;       # how many total processors do we need?
    241 my $node_need = $proc_need / $proc_per_node; # this equals how many nodes?
    242 my $time_need = $job_index * $job_cost;      # How many seconds will this take?
    243 
    244 my $fill_factor = 0.8;  # This is the factor of how much of the time allocation we'd like to fill
    245 my ($time_req,$node_req);
    246 if ($node_need * $job_cost < $fill_factor * $min_nodes * $min_time) {
    247     $time_req = $min_time;
    248     $node_req = $min_nodes;
    249 }
    250 elsif ($node_need * $job_cost > $fill_factor * $max_nodes * $max_time) {
    251     $time_req = $max_time;
    252     $node_req = $max_nodes;
    253     print STDERR "You've requested the construction of a bundle that appears to need $node_need nodes and $job_cost time per job.  This exceeds the max limits ($max_nodes, $max_time).  Using those max values instead.  Good luck.\n";
    254 }
    255 else {
    256     $time_req = int(($node_need * $job_cost) / ($fill_factor * $max_nodes)) + 1;
    257     $node_req = int(($node_need * $job_cost) / ($fill_factor * $time_req)) + 1;
    258 }
    259 $time_req += 1; # Safety addition.
    260 
    261 open(COMMAND,  ">$disk_command") || &my_die("Couldn't open file? $disk_command",$remote_id,$PS_EXIT_SYS_ERROR);
    262 print COMMAND "#!/bin/tcsh\n";
    263 print COMMAND "##### Moab controll lines\n";
    264 print COMMAND "#MSUB -l nodes=${node_req}:ppn=${proc_per_node},walltime=${time_req}:00:00\n"; ## CHECK RESOURCES
    265 print COMMAND "#MSUB -j oe\n";
    266 print COMMAND "#MSUB -V\n";
    267 print COMMAND "#MSUB -o ${remote_root}warp.${remote_id}.out\n";
    268 print COMMAND "date\n";
    269 print COMMAND 'srun -n $SLURM_JOB_NUM_NODES -m cyclic -l /bin/hostname | sort -n | awk \'{printf "%s\n", $2}\' > hosts.${SLURM_JOB_ID}' . "\n";
    270 print COMMAND "${remote_root}/stask_chip.py $remote_config " . 'hosts.${SLURM_JOB_ID} 1' . "\n";
    271 print COMMAND "date\n";
    272 close(COMMAND);
    273 
    274202unless($no_update) {
    275     my $command = "remotetool -updaterun -remote_id $remote_id ";
    276     $command .= " -set_state pending ";
     203    my $command = "remotetool -updatecomponent -remote_id $remote_id -stage_id $warp_id ";
     204    $command .= " -set_jobs $job_index";
     205    $command .= " -set_path_base $path_base";
     206    $command .= " -set_state prep_done";
    277207    $command .= " -dbname $dbname " if defined $dbname;
    278208
    279209    system($command);
    280210}
    281 
     211exit (0);
    282212
    283213## Common SC routines
     
    289219   
    290220    unless(defined($ipp_disk)) {
    291         my_die();
     221        &my_die( "Unable to generate file for $neb_uri ", $remote_id, $warp_id, $PS_EXIT_SYS_ERROR, $fail_state);
    292222    }
    293223
     
    305235   
    306236    unless(defined($ipp_disk)) {
    307         my_die();
     237        &my_die( "Unable to generate file for $neb_uri ", $remote_id, $warp_id, $PS_EXIT_SYS_ERROR, $fail_state);
    308238    }
    309239
     
    361291sub my_die { # exit with status; my_die(message,stage_id,exit_code,exit_status);
    362292    my $msg = shift;
    363     my $id  = shift;
     293    my $remote_id  = shift;
     294    my $stage_id  = shift;
    364295    my $exit_code = shift;
    365296    my $exit_state = shift;
     
    369300    carp($msg);
    370301   
    371     if (defined $id and not $no_update) {
    372         my $command = "remotetool -updaterun -remote_id $id";
    373         $command .= " -fault $exit_code " if defined $exit_code;
     302    if (defined $remote_id and defined $stage_id and not $no_update) {
     303        my $command = "remotetool -updatecomponent -remote_id $remote_id -stage_id $stage_id";
    374304        $command .= " -set_state $exit_state " if defined $exit_state;
    375305        $command .= " -dbname $dbname " if defined $dbname;
Note: See TracChangeset for help on using the changeset viewer.