Friday, 30 August 2013

launching multiple applications using Parallel::ForkManager

launching multiple applications using Parallel::ForkManager

I am using perl's Parallel::ForkManager to launch multiple applications in
parallel. I have two subroutines, one for launching the application and
other for performing data processing on the output files generated as a
result of the application's complete run. In the first subroutine, I make
a system() call to cd to the desired directory and launch the application
there. I call the second subroutine inside the first subroutine after the
system() call. The problem is that after all the runs are launched, the
program exits and the data processing that is done by the 2nd subroutine
never gets completed, all I have are the output files of the application
that appear after the runs are completed in the background.
here is my code of what I am doing
#!/usr/bin/perl -w
use strict;
use Parallel::ForkManager;
use Getopt::Long;
# Get input from the command line. Also get max_no_processes for
Parallel::ForkManager
# Perform operations on the input file and seperate out data from them in
form of arrays.
# The arrays thus formed contain arguments for the application and
path_to_directory where operation is to be performed
my $pm = new Parallel::ForkManager($max_no_processes);
for (my $i = 0; $i < $#input; $i++){ #----> @input is the array
containing the input for the application. using its length as max value.
$pm->start and next;
&subroutine1( $input[$i], $path_to_directory[$i] );
$pm->finish;
}
$pm->wait_all_children;
sub subroutine1{
my($input, $dir) = @_;
system("cd dir && APPLICAION -$input");
&subroutine2($dir);
}
sub subroutin2{
my ($dir) = @_;
# data processing
# print to stdout and file
}

No comments:

Post a Comment