Changeset 41


Ignore:
Timestamp:
Dec 5, 2011, 11:56:31 AM (12 years ago)
Author:
g7moreau
Message:
  • Reformat oar-parexec with perltidy
Location:
trunk/oarutils
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/oarutils/Makefile

    r30 r41  
    2929
    3030# astyle --style=banner -s3 mpilauncher.cpp
     31# perltidy -i=3 -ci=3 -icp -icb -pt=2 -bt=2 -bbt=2 -b oar-parexec
  • trunk/oarutils/oar-parexec

    r40 r41  
    1616use Cwd qw( getcwd );
    1717
    18 my $file = '';
     18my $file    = '';
    1919my $logfile = '';
    2020my $verbose;
     
    3636   'masterio=s' => \$masterio,
    3737   'switchio'   => \$switchio,
    38    ) || pod2usage( -verbose => 0 );
    39 pod2usage( -verbose => 2 ) if $help;
    40 pod2usage( -verbose => 2 ) if not -e $file;
     38   ) || pod2usage(-verbose => 0);
     39pod2usage(-verbose => 2) if $help;
     40pod2usage(-verbose => 2) if not -e $file;
    4141
    4242my %state;
     
    4646      or die "can't read log file: $!";
    4747   while (<$log_h>) {
    48                 $state{$1} = 'start' if m/^start\s+job\s+(\d+)\s/;
    49                 $state{$1} = 'end'   if m/^end\s+job\s+(\d+)\s/;
    50            }
     48      $state{$1} = 'start' if m/^start\s+job\s+(\d+)\s/;
     49      $state{$1} = 'end'   if m/^end\s+job\s+(\d+)\s/;
     50      }
    5151   $log_h->close();
    5252   }
    5353if ($logfile) {
    5454   $log_h->open(">> $logfile")
    55          or die "can't append log file $logfile: $!";
     55      or die "can't append log file $logfile: $!";
    5656   $log_h->autoflush;
    5757   $log_h = unblock $log_h;
     
    5959
    6060my @job = ();
    61 open( JOB_LIST, '<', "$file" ) or die "can't open job file $file: $!";
     61open(JOB_LIST, '<', "$file") or die "can't open job file $file: $!";
    6262while (<JOB_LIST>) {
    6363   chomp;
    6464   next if m/^#/;
    6565   next if m/^\s*$/;
    66    push @job, $_ ;
     66   push @job, $_;
    6767   }
    6868close JOB_LIST;
    6969
    7070my @ressources = ();
    71 open( NODE_FILE, '<', "$nodefile" )
     71open(NODE_FILE, '<', "$nodefile")
    7272   or die "can't open $nodefile: $!";
    7373while (<NODE_FILE>) {
     
    7575   next if m/^#/;
    7676   next if m/^\s*$/;
    77    push @ressources, $_ ;
     77   push @ressources, $_;
    7878   }
    7979close NODE_FILE;
    8080
    8181my $ressource_size = scalar(@ressources);
    82 die "not enought ressources jobnp $job_np > ressources $ressource_size" if $job_np > $ressource_size;
     82die "not enought ressources jobnp $job_np > ressources $ressource_size"
     83   if $job_np > $ressource_size;
    8384
    8485my $current_dir = getcwd();
     
    9192$stdout = $masterio if $masterio;
    9293
    93 
    9494my $finished = new Coro::Signal;
    9595my $job_todo = new Coro::Semaphore 0;
     
    9898my $ressources = new Coro::Channel;
    9999for my $slot (1 .. int($ressource_size / $job_np)) {
    100    $ressources->put( join(',', @ressources[(($slot - 1) * $job_np) .. (($slot * $job_np) - 1)] ) );
    101    }
    102 
     100   $ressources->put(
     101      join(',',
     102         @ressources[ (($slot - 1) * $job_np) .. (($slot * $job_np) - 1) ])
     103         );
     104   }
    103105
    104106my $job_num   = 0;
     
    106108
    107109my $oar_checkpoint = new Coro::Semaphore 0;
    108 $SIG{USR2} = sub { $oar_checkpoint->up };
     110$SIG{USR2} = sub {$oar_checkpoint->up};
    109111
    110112async {
     
    113115
    114116      if (exists $state{$job_num}) {
    115          if ($state{$job_num} eq 'start') {
    116             print "warning: job $job_num was not finished, relaunching...\n" if $verbose;
    117             }
     117         if ($state{$job_num} eq 'start') {
     118            print "warning: job $job_num was not finished, relaunching...\n"
     119               if $verbose;
     120            }
    118121         elsif ($state{$job_num} eq 'end') {
    119             delete $state{$job_num};
    120             $job_todo->down;
    121             print "warning: job $job_num already done\n" if $verbose;
    122             cede;
    123             next;
    124             }
    125          }             
     122            delete $state{$job_num};
     123            $job_todo->down;
     124            print "warning: job $job_num already done\n" if $verbose;
     125            cede;
     126            next;
     127            }
     128         }
    126129
    127130      my $job_ressource = $ressources->get;
     
    130133
    131134      my ($node_connect) = split ',', $job_ressource;
    132       my $fh      = IO::File->new();
     135      my $fh = IO::File->new();
    133136      my $job_pid = $fh->open("| $oarsh $node_connect >/dev/null 2>&1")
    134137         or die "don't start subjob: $!";
     
    137140      $fh = unblock $fh;
    138141
    139       $scheduled{$job_pid} = { fh => $fh, node_connect => $node_connect, ressource => $job_ressource, num => $job_num };
     142      $scheduled{$job_pid} = {
     143         fh           => $fh,
     144         node_connect => $node_connect,
     145         ressource    => $job_ressource,
     146         num          => $job_num
     147         };
    140148
    141149      $log_h->printf("start job %5i at %s\n", $job_num, time) if $logfile;
     
    144152         if $verbose;
    145153
    146       my ( $job_stdout, $job_stderr );
     154      my ($job_stdout, $job_stderr);
    147155      $job_stdout = ">  $stdout-$job_num.stdout" if $stdout ne '' and $switchio;
    148156      $job_stderr = "2> $stderr-$job_num.stderr" if $stderr ne '' and $switchio;
     
    152160      if ($job_np > 1) {
    153161         $fh->print("printf \""
    154             . join('\n',split(',',$job_ressource,))
    155             . "\" > $job_nodefile\n");
     162               . join('\n', split(',', $job_ressource,))
     163               . "\" > $job_nodefile\n");
    156164         $fh->print("OAR_NODE_FILE=$job_nodefile\n");
    157165         $fh->print("OAR_NP=$job_np\n");
     
    170178async {
    171179   while () {
    172       for my $job_pid ( keys %scheduled ) {
    173          if ( waitpid( $job_pid, WNOHANG ) ) {
     180      for my $job_pid (keys %scheduled) {
     181         if (waitpid($job_pid, WNOHANG)) {
    174182            $log_h->printf("end   job %5i at %s\n",
    175                $scheduled{$job_pid}->{num},
    176                time) if $logfile;
     183               $scheduled{$job_pid}->{num}, time)
     184              if $logfile;
    177185            printf "end   job %5i / %5i at %s on node %s\n",
    178186               $scheduled{$job_pid}->{num},
    179                $job_pid, time,
    180                $scheduled{$job_pid}->{ressource}
     187               $job_pid, time, $scheduled{$job_pid}->{ressource}
    181188               if $verbose;
    182189            close $scheduled{$job_pid}->{fh};
    183             $ressources->put( $scheduled{$job_pid}->{ressource} );
     190            $ressources->put($scheduled{$job_pid}->{ressource});
    184191            $job_todo->down;
    185192            delete $scheduled{$job_pid};
     
    200207
    201208$log_h->close() if $logfile;
    202 
    203209
    204210__END__
Note: See TracChangeset for help on using the changeset viewer.