[9] | 1 | #!/usr/bin/perl |
---|
| 2 | # |
---|
| 3 | # 2011/11/03 gabriel |
---|
| 4 | |
---|
| 5 | use strict; |
---|
| 6 | |
---|
| 7 | use Getopt::Long(); |
---|
| 8 | use Pod::Usage; |
---|
| 9 | use Coro; |
---|
| 10 | use Coro::Semaphore; |
---|
| 11 | |
---|
| 12 | my $task = 0; |
---|
| 13 | my $load = 1.5; |
---|
| 14 | my $file = ''; |
---|
| 15 | my $verbose; |
---|
| 16 | my $help; |
---|
| 17 | |
---|
| 18 | Getopt::Long::GetOptions( |
---|
| 19 | 'task=i' => \$task, |
---|
| 20 | 'load=f' => \$load, |
---|
| 21 | 'file=s' => \$file, |
---|
| 22 | 'verbose' => \$verbose, |
---|
| 23 | 'help' => \$help, |
---|
| 24 | ) || pod2usage(-verbose => 0); |
---|
| 25 | pod2usage(-verbose => 2) if $help; |
---|
| 26 | |
---|
| 27 | if ($task == 0) { |
---|
| 28 | open(NODE_FILE, '<', "$ENV{OAR_NODE_FILE}") or die "can't open ENV{OAR_NODE_FILE}: $!"; |
---|
| 29 | $task++ while <NODE_FILE>; |
---|
| 30 | close NODE_FILE; |
---|
| 31 | } |
---|
| 32 | |
---|
| 33 | my @job = (); |
---|
| 34 | open (JOB_LIST, '<', "$file") or die "can't open $file: $!"; |
---|
| 35 | while (<JOB_LIST>) { |
---|
| 36 | chomp; |
---|
| 37 | next if m/^#/; |
---|
| 38 | push @job, $_ if m/^\s*oarsub/; |
---|
| 39 | } |
---|
| 40 | close JOB_LIST; |
---|
| 41 | |
---|
| 42 | my $container_id=$ENV{OAR_JOB_ID}; |
---|
| 43 | my $insert_oar_option = "-t inner=$container_id"; |
---|
| 44 | |
---|
| 45 | # interactive job |
---|
| 46 | if (not $container_id > 1) { |
---|
| 47 | $insert_oar_option = ''; |
---|
| 48 | $load = 1; |
---|
| 49 | } |
---|
| 50 | |
---|
| 51 | |
---|
| 52 | my $finished = new Coro::Signal; |
---|
| 53 | my $job_active = new Coro::Semaphore 0; |
---|
| 54 | my $job_todo = new Coro::Semaphore 0; |
---|
| 55 | $job_todo->up for (@job); |
---|
| 56 | |
---|
| 57 | my %scheduled = (); |
---|
| 58 | |
---|
| 59 | async { |
---|
| 60 | for my $job (@job) { |
---|
| 61 | while ($job_active->count >= $task*$load) { |
---|
| 62 | cede; |
---|
| 63 | } |
---|
| 64 | $job =~ s/^\s*oarsub//; |
---|
| 65 | print "oarsub $insert_oar_option $job" if $verbose; |
---|
| 66 | my $job_id = `oarsub $insert_oar_option $job|grep ^OAR_JOB_ID|cut -f 2 -d '='`; |
---|
| 67 | chomp $job_id; |
---|
| 68 | if ($job_id > 1) { |
---|
| 69 | $scheduled{$job_id}++; |
---|
| 70 | $job_active->up; |
---|
| 71 | } |
---|
| 72 | cede; |
---|
| 73 | } |
---|
| 74 | } |
---|
| 75 | |
---|
| 76 | async { |
---|
| 77 | while () { |
---|
| 78 | for my $job_id (keys %scheduled) { |
---|
| 79 | my $is_finish = `oarstat -s -j $job_id`; |
---|
| 80 | chomp $is_finish; |
---|
| 81 | if ($is_finish =~ m/Terminated/) { |
---|
| 82 | delete $scheduled{$job_id}; |
---|
| 83 | $job_active->down; |
---|
| 84 | $job_todo->down; |
---|
| 85 | } |
---|
| 86 | cede; |
---|
| 87 | } |
---|
| 88 | |
---|
| 89 | $finished->send if $job_todo->count == 0; |
---|
| 90 | cede; |
---|
| 91 | } |
---|
| 92 | } |
---|
| 93 | |
---|
| 94 | cede; |
---|
| 95 | |
---|
| 96 | $finished->wait; |
---|
| 97 | |
---|
| 98 | |
---|
| 99 | __END__ |
---|
| 100 | |
---|
| 101 | =head1 NAME |
---|
| 102 | |
---|
| 103 | oar-dispatch - dispatch lot of small oar job |
---|
| 104 | |
---|
| 105 | =head1 SYNOPSIS |
---|
| 106 | |
---|
| 107 | oar-dispatch [--core integer] [--load real] --file filepath [--verbose] |
---|
| 108 | oar-dispatch --help |
---|
| 109 | |
---|
| 110 | =head1 OPTIONS |
---|
| 111 | |
---|
| 112 | --task number of task to do in parallel. |
---|
| 113 | default to line number of file OAR_NODE_FILE. |
---|
| 114 | |
---|
| 115 | --load number of OAR job to create / number of task. |
---|
| 116 | Some job are create in advance to start whenever it's possible. |
---|
| 117 | 1.5 by default. |
---|
| 118 | |
---|
| 119 | --file file name which content OAR job list |
---|
| 120 | |
---|
| 121 | --verbose |
---|
| 122 | |
---|
| 123 | --help |
---|
| 124 | |
---|
| 125 | File name content can have |
---|
| 126 | |
---|
| 127 | - empty line |
---|
| 128 | - comment line begin with # |
---|
| 129 | - oarsub command without -t option |
---|
| 130 | |
---|
| 131 | C<oar-dispatch> will add C<-t inner=container_id> in this command line, |
---|
| 132 | just after C<oarsub>. |
---|
| 133 | |
---|
| 134 | Example where F<$HOME/test/subjob1.oar> is an OAR script job (executable). |
---|
| 135 | |
---|
| 136 | oarsub -n test -l /core=1,walltime=00:05:00 $HOME/test/subjob1.oar |
---|
| 137 | oarsub -n test -l /core=1,walltime=00:05:00 $HOME/test/subjob2.oar |
---|
| 138 | oarsub -n test -l /core=1,walltime=00:05:00 $HOME/test/subjob3.oar |
---|
| 139 | oarsub -n test -l /core=1,walltime=00:05:00 $HOME/test/subjob4.oar |
---|
| 140 | ... |
---|
| 141 | oarsub -n test -l /core=1,walltime=00:05:00 $HOME/test/subjob38.oar |
---|
| 142 | oarsub -n test -l /core=1,walltime=00:05:00 $HOME/test/subjob39.oar |
---|
| 143 | oarsub -n test -l /core=1,walltime=00:05:00 $HOME/test/subjob40.oar |
---|
| 144 | |
---|
| 145 | These jobs could be launch by |
---|
| 146 | |
---|
| 147 | oarsub -t container -n test-container -l /core=6,walltime=00:35:00 "oar-dispatch -f ./subjob.list.txt" |
---|
| 148 | |
---|
| 149 | Total C<walltime> is define by the formula: |
---|
| 150 | |
---|
| 151 | total_walltime = subjob_walltime * total_subjob / core + global_delay |
---|
| 152 | |
---|
| 153 | In practise, C<oar-dispatch> take few second and each subjob run less than it's walltime so |
---|
| 154 | |
---|
| 155 | total_walltime < subjob_walltime * total_subjob / core |
---|
| 156 | |
---|
| 157 | If launch in interactif, C<load> parameter is equal to 1, |
---|
| 158 | C<task> must be define |
---|
| 159 | and no inner container is add to the C<oarsub> command line. |
---|
| 160 | |
---|
| 161 | |
---|
| 162 | =head1 AUTHORS |
---|
| 163 | |
---|
| 164 | Gabriel Moreau (C) 2011 |
---|