in reply to Re^11: Parallel::ForkManager is time consuming...takes too long
in thread Parallel::ForkManager is time consuming...takes too long
I have tonnes of such subroutines and the entire code takes 1 minute and 35 seconds.
Hm. 95 / 0.609 implies that "tonnes" == 156 subroutines?
If that is really the case, then recoding them all similar to this:
use List::Util qw[ sum ]; ... sub subroutine { our( @a, @b, @c, @d, @e ); ( *a, *b, *c, *d, *e ) = @_; foreach my $i ( 10 .. $#a ) { $c[$i] = $d[$i] = $e[$i] = 0; my $b = $b[$i]; if( ( $b >= 5 ) && ( $b < 7 ) ) { $c[$i] += sum @a[ $i-$b+1 .. $i ]; $c[$i] /= $b; } elsif( ( $b >= 7 ) && ( $b < 9 ) ) { $d[$i] += sum @a[ $i-$b+1 .. $i ]; $d[$i] /= $b; } elsif( ( $b >= 9 ) && ( $b < 15 ) ) { $e[$i] += sum @a[ $i-$b+1 .. $i ]; $e[$i] /= $b; } } return; } ## called like this my @a = ...; my @b = ...; my( @c, @d, @e ); subroutine( \@a, \@b, \@c, \@d, \@e );
which runs in 1/3rd the time of your original, should get you close to your target. If not, then you'd have to sort out the inefficiencies in the rest of your code as well.
If it is really going to be necessary to multi-process this to achieve your target, then you should not be trying to inject the forks or threads into the loops within these subroutines -- as in your OP code-- but rather call the subroutines themselves concurrently. To advise you further on doing that, I'd need to see the calling code in its entirety.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^13: Parallel::ForkManager is time consuming...takes too long
by ikegami (Patriarch) on Aug 17, 2011 at 03:15 UTC | |
|
Re^13: Parallel::ForkManager is time consuming...takes too long
by esolkc (Acolyte) on Aug 17, 2011 at 17:38 UTC | |
by BrowserUk (Patriarch) on Aug 17, 2011 at 23:23 UTC | |
by ikegami (Patriarch) on Aug 17, 2011 at 23:35 UTC |