| 1 | package Parallel::Simple::Dynamic; | ||||||||||
| 2 | |||||||||||
| 3 | 1 | ▶ | use Class::Std; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 1 | ▶ | use Class::Std::Utils; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 1 | ▶ | use POSIX qw(ceil); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 1 | ▶ | use Parallel::Simple qw( prun ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 1 | ▶ | use version; our $VERSION = qv('0.0.4'); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | |||||||||||
| 13 | { | ||||||||||
| 14 | 1 | my %list_of :ATTR( :get<list> :set<list> :default<[]> :init_arg<list> ); | |||||||||
| 15 | 1 | my %call_back :ATTR( :get<call_back> :set<call_back> :default<''> :init_arg<call_back> ); | |||||||||
| 16 | 1 | my %num_of_cores :ATTR( :get<num_of_cores> :set<num_of_cores> :default<''> :init_arg<num_of_cores> ); | |||||||||
| 17 | |||||||||||
| 18 | 0 | ▶ | sub START { | ||||||||
|
Subroutine
START: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 19 | 0 | my ($self, $ident, $arg_ref) = @_; | |||||||||
| 20 | 0 | return; | |||||||||
| 21 | } | ||||||||||
| 22 | |||||||||||
| 23 | 0 | ▶ | sub drun { | ||||||||
|
Subroutine
drun: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||
| 24 | 0 | my ( $self, $arg_ref ) = @_; | |||||||||
| 25 | |||||||||||
| 26 | 0 | ▶ | my $parts = defined $arg_ref->{parts} ? $arg_ref->{parts} : 2; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 27 | 0 | ▶ | my $list = defined $arg_ref->{list} ? $arg_ref->{list} :[]; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 28 | 0 | ▶ | my $call_back = defined $arg_ref->{call_back} ? $arg_ref->{call_back} :''; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 29 | |||||||||||
| 30 | 0 | my @partitions = $self->partition( {parts => $parts, list => $list } ); | |||||||||
| 31 | |||||||||||
| 32 | 0 | my ( $pindex, @prun ); | |||||||||
| 33 | 0 | foreach my $partition ( @partitions ) { | |||||||||
| 34 | 0 | my $prun = [ $call_back, ++$pindex, @$partition ]; | |||||||||
| 35 | 0 | push @prun, $prun; | |||||||||
| 36 | } | ||||||||||
| 37 | 0 | ▶ | prun( @prun ) or die( Parallel::Simple::errplus() ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 38 | } | ||||||||||
| 39 | |||||||||||
| 40 | 0 | ▶ | sub partition { | ||||||||
|
Subroutine
partition: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||
| 41 | 0 | my ( $self, $arg_ref ) = @_; | |||||||||
| 42 | |||||||||||
| 43 | 0 | ▶ | my $parts = defined $arg_ref->{parts} ? $arg_ref->{parts} : 2; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 44 | 0 | ▶ | my $list = defined $arg_ref->{list} ? $arg_ref->{list} : []; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 45 | 0 | my @results; | |||||||||
| 46 | 0 | my @segments = $self->calc_segments( {parts => $parts, list_length => scalar( @$list )} ); | |||||||||
| 47 | 0 | ▶ | for ( my $i = 1; $i <= $parts; $i++ ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 48 | 0 | my $start = $segments[$i-1]; | |||||||||
| 49 | 0 | my $end = $segments[$i] - 1; | |||||||||
| 50 | 0 | my @segment = @$list[$start..$end]; | |||||||||
| 51 | 0 | push @results, \@segment; | |||||||||
| 52 | } | ||||||||||
| 53 | 0 | return @results; | |||||||||
| 54 | } | ||||||||||
| 55 | |||||||||||
| 56 | 0 | ▶ | sub calc_segments { | ||||||||
|
Subroutine
calc_segments: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||
| 57 | 0 | my ( $self, $arg_ref ) = @_; | |||||||||
| 58 | |||||||||||
| 59 | 0 | ▶ | my $parts = defined $arg_ref->{parts} ? $arg_ref->{parts} : 2; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 60 | 0 | ▶ | my $list_length = defined $arg_ref->{list_length} ? $arg_ref->{list_length} :''; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 61 | 0 | my @segments = (0); | |||||||||
| 62 | 0 | my $width = $list_length / $parts; | |||||||||
| 63 | 0 | ▶ | for ( my $i = 1; $i <= $parts; $i++ ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 64 | 0 | $segments[$i] = ceil( ($i) * $width ); | |||||||||
| 65 | } | ||||||||||
| 66 | 0 | return @segments; | |||||||||
| 67 | } | ||||||||||
| 68 | } | ||||||||||
| 69 | 1 | 1; # End of Parallel::Simple::Dynamic | |||||||||
| 70 | __END__ | ||||||||||