in reply to Re^2: Run a script in parallel mode
in thread Run a script in parallel mode
Then something simple like this might do:
#! perl -slw use strict; my $protienFile = shift; my $size = -S protienFile; my $chunk = int( $size / 20 ); open IN, '<', $protienFile or die; my %procs; for my $n ( 1 .. 20 ) { open O, '>', "temp$n.in" or die $!; print O, scalar <I> while tell( O ) < ( $n * $chunk ); close O; my $pid; if( $pid = fork() ) { ++$procs{ $pid }; } elsif( defined $pid ) { exec "java -Xmx300m java_code/ALPHAtest -a tables/A.TRAINED -e + tables/E.TRAINED -c tables/conf.tat -f temp$n.in > temp$n.out"; } else { die "Fork failed"; } } while( keys %procs ) { my $pid = wait; delete $procs{ $pid }; } open O, '>', $protienFile . '.out' or die $!; for my $n ( 1 .. 20 ) { open I, '<', "temp$n.out" or die $!; print O, <i>; close I; unlink "temp$n.in", "temp$n.out"; } close O;
Note:That's untested.
You might get a little more clever and use the piped-open to run the commands and read the output back directly into the parent for merging, but handling multiple concurrent input streams without mixing up the results gets messy.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Run a script in parallel mode
by RichardK (Parson) on May 26, 2015 at 14:21 UTC | |
|
Re^4: Run a script in parallel mode
by Anonymous Monk on May 26, 2015 at 13:38 UTC |