parallel: added --shuf.

This commit is contained in:
Ole Tange 2015-04-22 00:08:50 +02:00
parent d134e2df4d
commit 1b54fefc10
2 changed files with 36 additions and 6 deletions

View file

@ -110,8 +110,9 @@ if($opt::nonall or $opt::onall) {
$Global::JobQueue = JobQueue->new( $Global::JobQueue = JobQueue->new(
\@command,\@input_source_fh,$Global::ContextReplace,$number_of_args,\@Global::ret_files); \@command,\@input_source_fh,$Global::ContextReplace,$number_of_args,\@Global::ret_files);
if($opt::eta or $opt::bar) { if($opt::eta or $opt::bar or $opt::shuf) {
# Count the number of jobs before starting any # Count the number of jobs or shuffle all jobs
# before starting any
$Global::JobQueue->total_jobs(); $Global::JobQueue->total_jobs();
} }
if($opt::pipepart) { if($opt::pipepart) {
@ -757,6 +758,7 @@ sub options_hash {
"progress" => \$opt::progress, "progress" => \$opt::progress,
"eta" => \$opt::eta, "eta" => \$opt::eta,
"bar" => \$opt::bar, "bar" => \$opt::bar,
"shuf" => \$opt::shuf,
"arg-sep|argsep=s" => \$opt::arg_sep, "arg-sep|argsep=s" => \$opt::arg_sep,
"arg-file-sep|argfilesep=s" => \$opt::arg_file_sep, "arg-file-sep|argfilesep=s" => \$opt::arg_file_sep,
"trim=s" => \$opt::trim, "trim=s" => \$opt::trim,
@ -5555,6 +5557,7 @@ sub total_jobs {
::warning("Reading all arguments takes longer than 10 seconds.\n"); ::warning("Reading all arguments takes longer than 10 seconds.\n");
$opt::eta && ::warning("Consider removing --eta.\n"); $opt::eta && ::warning("Consider removing --eta.\n");
$opt::bar && ::warning("Consider removing --bar.\n"); $opt::bar && ::warning("Consider removing --bar.\n");
$opt::shuf && ::warning("Consider removing --shuf.\n");
last; last;
} }
push @queue, $job; push @queue, $job;
@ -5562,8 +5565,18 @@ sub total_jobs {
while($job = $self->get()) { while($job = $self->get()) {
push @queue, $job; push @queue, $job;
} }
if($opt::shuf) {
$self->unget(@queue); my $i = @queue;
while (--$i) {
my $j = int rand($i+1);
@queue[$i,$j] = @queue[$j,$i];
}
my $seq = 1;
for my $job (@queue) {
$job->{'commandline'}->set_seq($seq++);
}
}
$self->unget(@queue);
$self->{'total_jobs'} = $#queue+1; $self->{'total_jobs'} = $#queue+1;
} }
return $self->{'total_jobs'}; return $self->{'total_jobs'};
@ -5620,6 +5633,11 @@ sub seq {
return $self->{'commandline'}->seq(); return $self->{'commandline'}->seq();
} }
sub set_seq {
my $self = shift;
return $self->{'commandline'}->set_seq(shift);
}
sub slot { sub slot {
my $self = shift; my $self = shift;
return $self->{'commandline'}->slot(); return $self->{'commandline'}->slot();
@ -7459,9 +7477,8 @@ sub set_exitsignal {
("$Global::progname: This job failed:\n", ("$Global::progname: This job failed:\n",
$job->replaced(),"\n"); $job->replaced(),"\n");
} }
my $status = $job->exitstatus();
::killall(); ::killall();
::wait_and_exit($status); ::wait_and_exit($job->exitstatus());
} }
} }
} else { } else {
@ -7527,6 +7544,11 @@ sub seq {
return $self->{'seq'}; return $self->{'seq'};
} }
sub set_seq {
my $self = shift;
$self->{'seq'} = shift;
}
{ {
my $max_slot_number; my $max_slot_number;

View file

@ -1616,6 +1616,14 @@ Does not run the command but quotes it. Useful for making quoted
composed commands for GNU B<parallel>. composed commands for GNU B<parallel>.
=item B<--shuf> (alpha testing)
Shuffle jobs. When having multiple input sources it is hard to
randomize jobs. --shuf will generate all jobs, and shuffle them before
running them. This is useful to get a quick preview of the results
before running the full batch.
=item B<--skip-first-line> =item B<--skip-first-line>
Do not use the first line of input (used by GNU B<parallel> itself Do not use the first line of input (used by GNU B<parallel> itself