4 ### Job distribution for discrete logs
6 ### (c) 2017 Mark Wooding
9 ###----- Licensing notice ---------------------------------------------------
11 ### This file is part of Rhodes, a distributed discrete-log finder.
13 ### Rhodes is free software; you can redistribute it and/or modify
14 ### it under the terms of the GNU General Public License as published by
15 ### the Free Software Foundation; either version 2 of the License, or
16 ### (at your option) any later version.
18 ### Rhodes is distributed in the hope that it will be useful,
19 ### but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ### GNU General Public License for more details.
23 ### You should have received a copy of the GNU General Public License
24 ### along with Rhodes; if not, write to the Free Software Foundation,
25 ### Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27 use POSIX qw(:sys_wait_h);
29 @ARGV == 2 or die "usage: $0 DIR WORKERS";
30 my ($DIR, $WORKERS) = @ARGV;
32 open my $fh, "<", $WORKERS or die "open($WORKERS): $!";
38 next unless /^\s*[^#]/;
39 my ($w, $n, @c) = split;
40 for (my $i = 0; $i < $n; $i++) {
45 for (my $i = 0; $i < @W; $i++) { push @F, $i; }
48 system "./rhodes", "done", $DIR;
49 if ($? == 0) { return 'DONE'; }
50 elsif ($? == 512) { return 'IDLE'; }
51 elsif ($? != 256) { die "job broken: done rc = $?"; }
52 else { $STATE = 'BUSY'; }
57 while ($RUN || $STATE ne 'DONE') {
58 if ($STATE ne 'DONE') { $STATE = state; }
59 while (@F && $STATE eq 'BUSY') {
61 print "## -> $W[$i]\n";
62 defined (my $kid = fork) or die "fork: $!";
64 exec "./rhodes", "step", $DIR, @{$C[$i]};
72 my $kid = waitpid -1, 0;
74 next unless exists $P{$kid};
76 print "## <- $W[$i] rc = $?\n";
78 $kid = waitpid -1, WNOHANG;