well i have done exactly that, though i m unable to use Parallel::Forkmanager as it is not available(in my env)

Using threads

use strict; use warnings; use Benchmark;# use threads; #open(PROD,"/ms/user/j/juyva/dev/files_xls_tmpl_cfg_nonscripts/prod. +txt") || die " $! "; #my @allProd = <PROD>; #close PROD; #open(TEST,"/ms/user/j/juyva/dev/files_xls_tmpl_cfg_nonscripts/test. +txt") || die " $! "; #my @allTest = <TEST>; #close TEST; my @allPort = qw(22600 22610); my %hashOp; sub boss { for(my $i = 0;$i < @allPort; $i++) { my $thr = threads->new(\&worker,$allPort[$i]); } foreach my $thr (threads->list) { # Don't join the main thread or ourselves if ($thr->tid && !threads::equal($thr, threads->self)) { $thr->join; } } } sub worker { my $port = shift; my $timeTakenDm = timeit(1,sub { system(" /ms/dist/pcs/bin/cli +ent hqsas501 $port 200 \-f /ms/user/j/juyva/dev/files_xls_tmpl_cfg_no +nscripts/sql1.clmod.NEW.txt > $port.txt " )}); print "Dm took:",timestr($timeTakenDm),"\n"; if ($? == -1) { print "failed to execute: $!\n"; } elsif ($? & 127) { printf "child died with signal %d, %s coredump\n", ($? & 127), ($? & 128) ? 'with' : 'without'; } else { printf "child exited with value %d\n", $? >> 8; } } my $obj = timeit(1, sub { my $thrboss = threads->new(\&boss); $thrboss->join; my (@allProd,@allTest); foreach my $port (@allPort) { open(HAN,"$port.txt") || die " $!"; my @temp = <HAN>; $hashOp{$port} = \@temp; #print $hashOp{$port}; close HAN; } my $timeSort = timeit(1, sub { @allProd = sort +@{$hashOp{"22600"}}; @allTest = sort +@{$hashOp{"22610"}}; }); print "sort took:",timestr($timeSort),"\n"; #my @allProd = sort @{$hashOp{"22600"}}; #my @allTest = sort @{$hashOp{"22610"}}; #print @allProd; #print @allTest; unless(@allProd == @allTest) { print " inside unequal rows retunred\n +"; my $whichhasmoreelements = @allProd > +@allTest ? 'allProd' : 'allTest'; if($whichhasmoreelements =~ /Prod/) { print " the no of lines do not ma +tch prod has more rows are they are \n"; my @tempallProd = @allProd; my @diffProdTest = splice(@tempa +llProd,(@allTest -1),(@allProd - @allTest)); print @diffProdTest; print " do u want to continue : e +nter y/n "; my $choice = <STDIN>; exit if($choice =~ /^n$/i); } else { print " the no of lines do not ma +tch test has more rows are they are \n"; my @tempallTest = @allTest; my @diffProdTest = splice(@tempal +lTest,(@allProd - 1),(@allTest - @allProd)); print @diffProdTest; print " do u want to continue : e +nter y/n "; my $choice = <STDIN>; print " $choice "; exit if($choice =~ /^n$/i); } } for( my $i = 0;$i < (@allProd > @allTest ? @ +allProd : @allTest); $i++) { unless($allProd[$i] eq $allTest[$i]) { my @defaultProd = split/\|/,$allP +rod[$i]; my @defaultTest = split/\|/,$allT +est[$i]; unless(@defaultProd == @defaultTe +st) { my $whichhasmoreelements = +@defaultProd > @defaultTest ? 'defaultProd' : 'defaultTest'; if($whichhasmoreelements =~ + /Prod/) { print " the no of l +ines do not match prod has more rows are they are \n"; my @tempallProd = @ +defaultProd; my @diffProdTest = + splice(@tempallProd,(@defaultTest -1),(@defaultProd - @defaultTest)) +; print @diffProdTest +; print " do u want t +o continue : enter y/n "; my $choice = <STDIN +>; exit if($choice =~ +/^n$/i); } else { print " the no of l +ines do not match test has more rows are they are \n"; my @tempallTest = @ +defaultTest; my @diffProdTest = +splice(@tempallTest,(@defaultProd - 1),(@defaultTest - @defaultProd)) +; print @diffProdTest +; print " do u want t +o continue : enter y/n "; my $choice = <STDIN +>; print " $choice "; exit if($choice =~ +/^n$/i); } } for( my $a = 0;$a < (@defaultProd + > @defaultTest ? @defaultProd : @defaultTest); $a++) { unless($defaultProd[$a] eq $ +defaultTest[$a]) { print " Column $a differ +s::"; print " PROD value $defa +ultProd[$a] : TEST value $defaultTest[$a] \n"; } } } } } ); print "code took:",timestr($obj),"\n";

Using multiple processes

use strict; use Benchmark ; use warnings; my @allPort = qw(22600 22610); my %hashOp; sub spawnChild { for (0..$#allPort) { my $cpid = fork(); die unless defined $cpid; if (! $cpid) { # This is the child #my $wait = int rand 4; #sleep $wait; #print "Child $$ exiting after $wait seconds\n"; print "$_\n"; my $port = $allPort[$_]; my $timeTakenDm = timeit(1,sub { system(" /ms/dist +/pcs/bin/client hqsas501 $port 200 \-f /ms/user/j/juyva/dev/files_xls +_tmpl_cfg_nonscripts/sql1.clmod.NEW.txt > $port.txt " )}); if ($? == -1) { print "failed to execute: $!\n"; } elsif ($? & 127) { printf "child died with signal %d, %s +coredump\n", ($? & 127), ($? & 128) ? 'with' : 'wi +thout'; } else { printf "child exited with value %d\n", + $? >> 8; } print "Dm took $cpid:",timestr($timeTakenDm),"\n"; exit; } } } # Just parent code, after this my $obj = timeit(1, sub { &spawnChild; my (@allProd,@allTest); foreach my $port (@allPort) { open(HAN,"$port.txt") || die " $!"; my @temp = <HAN>; $hashOp{$port} = \@temp; #print $hashOp{$port}; close HAN; } my $timeSort = timeit(1, sub { @allProd = sort +@{$hashOp{"22600"}}; @allTest = sort +@{$hashOp{"22610"}}; }); print "sort took:",timestr($timeSort),"\n"; #my @allProd = sort @{$hashOp{"22600"}}; #my @allTest = sort @{$hashOp{"22610"}}; #print @allProd; #print @allTest; unless(@allProd == @allTest) { print " inside unequal rows retunred\n +"; my $whichhasmoreelements = @allProd > +@allTest ? 'allProd' : 'allTest'; if($whichhasmoreelements =~ /Prod/) { print " the no of lines do not ma +tch prod has more rows are they are \n"; my @tempallProd = @allProd; my @diffProdTest = splice(@tempa +llProd,(@allTest -1),(@allProd - @allTest)); print @diffProdTest; print " do u want to continue : e +nter y/n "; my $choice = <STDIN>; exit if($choice =~ /^n$/i); } else { print " the no of lines do not ma +tch test has more rows are they are \n"; my @tempallTest = @allTest; my @diffProdTest = splice(@tempal +lTest,(@allProd - 1),(@allTest - @allProd)); print @diffProdTest; print " do u want to continue : e +nter y/n "; my $choice = <STDIN>; print " $choice "; exit if($choice =~ /^n$/i); } } for( my $i = 0;$i < (@allProd > @allTest ? @ +allProd : @allTest); $i++) { unless($allProd[$i] eq $allTest[$i]) { my @defaultProd = split/\|/,$allP +rod[$i]; my @defaultTest = split/\|/,$allT +est[$i]; unless(@defaultProd == @defaultTe +st) { my $whichhasmoreelements = +@defaultProd > @defaultTest ? 'defaultProd' : 'defaultTest'; if($whichhasmoreelements =~ + /Prod/) { print " the no of l +ines do not match prod has more rows are they are \n"; my @tempallProd = @ +defaultProd; my @diffProdTest = + splice(@tempallProd,(@defaultTest -1),(@defaultProd - @defaultTest)) +; print @diffProdTest +; print " do u want t +o continue : enter y/n "; my $choice = <STDIN +>; exit if($choice =~ +/^n$/i); } else { print " the no of l +ines do not match test has more rows are they are \n"; my @tempallTest = @ +defaultTest; my @diffProdTest = +splice(@tempallTest,(@defaultProd - 1),(@defaultTest - @defaultProd)) +; print @diffProdTest +; print " do u want t +o continue : enter y/n "; my $choice = <STDIN +>; print " $choice "; exit if($choice =~ +/^n$/i); } } for( my $a = 0;$a < (@defaultProd + > @defaultTest ? @defaultProd : @defaultTest); $a++) { unless($defaultProd[$a] eq $ +defaultTest[$a]) { print " Column $a differ +s::"; print " PROD value $defa +ultProd[$a] : TEST value $defaultTest[$a] \n"; } } } } } ); print "code took:",timestr($obj),"\n"; # Just parent code, after this while ((my $cpid = wait()) != -1) { print "Waited for child $cpid\n"; } print "Parent Exiting\n";

In reply to Re^2: best strategy by libvenus
in thread best strategy by libvenus

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.