MCE/Core/Input/Generator.pm

filter: Statementstmt 11.8% 11 / 93 Branchbran 0.0% 0 / 66 Conditioncond 0.0% 0 / 23 MC/DCmcdc 0.0% 0 / 13 Subroutinesub 37.5% 3 / 8 Podpod n/a totaltotal 6.9% 14 / 203 CC 46 SCAR 75.4
CC
46
Cov
6%
_worker_sequence_generator
2162.0
__ANON__
2.0
__ANON__
2.0
CRAP 1876.7
↑ Summary MCE/Core/Manager.pm »
1 ###############################################################################
2 ## ----------------------------------------------------------------------------
3 ## Sequence of numbers (for task_id > 0).
4 ##
5 ## This package provides a sequence of numbers used internally by the worker
6 ## process. Distribution is divided equally among workers. This allows sequence
7 ## to be configured independently among multiple user tasks.
8 ##
9 ## There is no public API.
10 ##
11 ###############################################################################
12  
13 package MCE::Core::Input::Generator;
14  
15 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 1 our $VERSION = '1.904';
19  
20 ## Items below are folded into MCE.
21  
22 package # hide from rpm
23 MCE;
24  
25 1 ▶no warnings qw( threads recursion uninitialized );
Subroutine BEGIN: called CC=1 SCAR=0.0
26  
27 ###############################################################################
28 ## ----------------------------------------------------------------------------
29 ## Worker process -- Sequence Generator (equal distribution among workers).
30 ##
31 ###############################################################################
32  
33 0 ▶sub _worker_sequence_generator {
Subroutine _worker_sequence_generator: not called CC=46 SCAR=76.8
34  
35 0 my ($self) = @_;
36  
37 0 @_ = ();
38  
39 _croak('MCE::_worker_sequence_generator: (user_func) is not specified')
40 0 ▶ unless (defined $self->{user_func});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"user_func"} 0 0 0
41  
42 0 ▶ my $_bounds_only = $self->{bounds_only} || 0;
Condition0%0/2
$self->{'bounds_only'} || 0
l!l
00
MC/DC0%0/1
$self->{'bounds_only'} || 0
$self->{'bounds_only'}
Truth table0%0/2
A
A= $self->{'bounds_only'}
Aresult
11
00
43 0 my $_max_workers = $self->{max_workers};
44 0 my $_chunk_size = $self->{chunk_size};
45 0 my $_wuf = $self->{_wuf};
46  
47 0 my ($_begin, $_end, $_step, $_fmt);
48  
49 0 ▶ if (ref $self->{sequence} eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self->{'sequence'} eq 'ARRAY') { } 0 0 0
50 0 ($_begin, $_end, $_step, $_fmt) = @{ $self->{sequence} };
51 }
52 else {
53 0 $_begin = $self->{sequence}->{begin};
54 0 $_end = $self->{sequence}->{end};
55 0 $_step = $self->{sequence}->{step};
56 0 $_fmt = $self->{sequence}->{format};
57 }
58  
59 0 ▶ my $_wid = $self->{_task_wid} || $self->{_wid};
Condition0%0/3
$self->{'_task_wid'} || $self->{'_wid'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{'_task_wid'} || $self->{'_wid'}
$self->{'_task_wid'} $self->{'_wid'}
Truth table0%0/3
A || B
A= $self->{'_task_wid'}B= $self->{'_wid'}
ABresult
1X1
011
000
60 0 my $_next = ($_wid - 1) * $_chunk_size * $_step + $_begin;
61 0 my $_chunk_id = $_wid;
62  
63 0 ▶ $_fmt =~ s/%// if (defined $_fmt);
Branch: 1 branch
BranchTrueFalseTotal
if defined $_fmt 0 0 0
64  
65 ## -------------------------------------------------------------------------
66  
67 0 local $_;
68  
69 0 ▶ $self->{_last_jmp} = sub { goto _WORKER_SEQ_GEN__LAST; };
Subroutine __ANON__: not called CC=1 SCAR=6.9
70  
71 0 ▶ if ($_begin == $_end) { ## Identical, yes.
Branch: 2 branches
BranchTrueFalseTotal
if ($_begin == $_end) { } 0 0 0
elsif ($_chunk_size == 1) { } 0 0 0
72  
73 0 ▶ if ($_wid == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_wid == 1) 0 0 0
74 0 ▶ $self->{_next_jmp} = sub { goto _WORKER_SEQ_GEN__LAST; };
Subroutine __ANON__: not called CC=1 SCAR=6.9
75  
76 0 ▶ $_ = (defined $_fmt) ? _sprintf("%$_fmt", $_next) : $_next;
Branch: 1 branch
BranchTrueFalseTotal
defined $_fmt ? : 0 0 0
77  
78 0 ▶ if ($_chunk_size > 1 || $_bounds_only) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_chunk_size > 1 or $_bounds_only) 0 0 0
Condition0%0/3
$_chunk_size > 1 or $_bounds_only
l!l&&r!l&&!r
000
MC/DC0%0/2
$_chunk_size > 1 or $_bounds_only
$_chunk_size > 1 $_bounds_only
Truth table0%0/3
A or B
A= $_chunk_size > 1B= $_bounds_only
ABresult
1X1
011
000
79 0 ▶ $_ = ($_bounds_only) ? [ $_, $_ ] : [ $_ ];
Branch: 1 branch
BranchTrueFalseTotal
$_bounds_only ? : 0 0 0
80 }
81  
82 0 $_wuf->($self, $_, $_chunk_id);
83 }
84 }
85 elsif ($_chunk_size == 1) { ## Chunking, no.
86  
87 0 ▶ $self->{_next_jmp} = sub { goto _WORKER_SEQ_GEN__NEXT_A; };
Subroutine __ANON__: not called CC=1 SCAR=6.9
88  
89 0 my $_flag = ($_begin < $_end);
90  
91 0 while (1) {
92 0 ▶ return if ( $_flag && $_next > $_end);
Branch: 1 branch
BranchTrueFalseTotal
if $_flag and $_next > $_end 0 0 0
Condition0%0/3
$_flag and $_next > $_end
!ll&&!rl&&r
000
MC/DC0%0/2
$_flag and $_next > $_end
$_flag $_next > $_end
Truth table0%0/3
A and B
A= $_flagB= $_next > $_end
ABresult
0X0
100
111
93 0 ▶ return if (!$_flag && $_next < $_end);
Branch: 1 branch
BranchTrueFalseTotal
if not $_flag and $_next < $_end 0 0 0
Condition0%0/3
not $_flag and $_next < $_end
!ll&&!rl&&r
000
MC/DC0%0/2
not $_flag and $_next < $_end
not $_flag $_next < $_end
Truth table0%0/3
not(A) and B
A= not $_flagB= $_next < $_end
ABresult
0X0
100
111
94  
95 0 ▶ $_ = (defined $_fmt) ? _sprintf("%$_fmt", $_next) : $_next;
Branch: 1 branch
BranchTrueFalseTotal
defined $_fmt ? : 0 0 0
96 0 ▶ $_ = [ $_, $_ ] if ($_bounds_only);
Branch: 1 branch
BranchTrueFalseTotal
if $_bounds_only 0 0 0
97  
98 0 $_wuf->($self, $_, $_chunk_id);
99  
100 0 _WORKER_SEQ_GEN__NEXT_A:
101  
102 $_chunk_id += $_max_workers;
103 0 $_next = ($_chunk_id - 1) * $_step + $_begin;
104 }
105 }
106 else { ## Chunking, yes.
107  
108 0 ▶ $self->{_next_jmp} = sub { goto _WORKER_SEQ_GEN__NEXT_B; };
Subroutine __ANON__: not called CC=1 SCAR=6.9
109  
110 0 while (1) {
111 0 my @_n = (); my $_n_begin = $_next;
112  
113 ## -------------------------------------------------------------------
114  
115 0 ▶ if ($_bounds_only) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_bounds_only) { } 0 0 0
116 0 my ($_tmp_b, $_tmp_e) = ($_next);
117  
118 0 ▶ if ($_begin <= $_end) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_begin <= $_end) { } 0 0 0
119 0 ▶ if ($_step * ($_chunk_size - 1) + $_n_begin <= $_end) {
Branch: 2 branches
BranchTrueFalseTotal
if ($_step * ($_chunk_size - 1) + $_n_begin <= $_end) { } 0 0 0
elsif ($_step == 1) { } 0 0 0
120 0 $_tmp_e = $_step * ($_chunk_size - 1) + $_n_begin;
121 }
122 elsif ($_step == 1) {
123 0 ▶ $_tmp_e = $_end if ($_next <= $_end);
Branch: 1 branch
BranchTrueFalseTotal
if $_next <= $_end 0 0 0
124 }
125 else {
126 0 for my $_i (1 .. $_chunk_size) {
127 0 ▶ last if ($_next > $_end);
Branch: 1 branch
BranchTrueFalseTotal
if $_next > $_end 0 0 0
128 0 $_tmp_e = $_next;
129 0 $_next = $_step * $_i + $_n_begin;
130 }
131 }
132 }
133 else {
134 0 ▶ if ($_step * ($_chunk_size - 1) + $_n_begin >= $_end) {
Branch: 2 branches
BranchTrueFalseTotal
if ($_step * ($_chunk_size - 1) + $_n_begin >= $_end) { } 0 0 0
elsif ($_step == -1) { } 0 0 0
135 0 $_tmp_e = $_step * ($_chunk_size - 1) + $_n_begin;
136 }
137 elsif ($_step == -1) {
138 0 ▶ $_tmp_e = $_end if ($_next >= $_end);
Branch: 1 branch
BranchTrueFalseTotal
if $_next >= $_end 0 0 0
139 }
140 else {
141 0 for my $_i (1 .. $_chunk_size) {
142 0 ▶ last if ($_next < $_end);
Branch: 1 branch
BranchTrueFalseTotal
if $_next < $_end 0 0 0
143 0 $_tmp_e = $_next;
144 0 $_next = $_step * $_i + $_n_begin;
145 }
146 }
147 }
148  
149 0 ▶ return unless (defined $_tmp_e);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_tmp_e 0 0 0
150  
151 0 ▶ @_n = (defined $_fmt)
Branch: 1 branch
BranchTrueFalseTotal
defined $_fmt ? : 0 0 0
152 ? ( _sprintf("%$_fmt",$_tmp_b), _sprintf("%$_fmt",$_tmp_e) )
153 : ( $_tmp_b, $_tmp_e );
154 }
155  
156 ## -------------------------------------------------------------------
157  
158 else {
159 0 ▶ if ($_begin <= $_end) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_begin <= $_end) { } 0 0 0
160 0 ▶ if (!defined $_fmt && $_step == 1 && abs($_end) < ~1 && abs($_begin) < ~1) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $_fmt and $_step == 1 and abs $_end < 18446744073709551614 and abs $_begin < 18446744073709551614) { } 0 0 0
Condition0%0/9
not defined $_fmt and $_step == 1 and abs $_end < '18446744073709551614' and abs $_begin < '18446744073709551614'
!ll&&!rl&&r
000
not defined $_fmt and $_step == 1 and abs $_end < '18446744073709551614'
!ll&&!rl&&r
000
not defined $_fmt and $_step == 1
!ll&&!rl&&r
000
MC/DC0%0/4
not defined $_fmt and $_step == 1 and abs $_end < '18446744073709551614' and abs $_begin < '18446744073709551614'
not defined $_fmt $_step == 1 abs $_end < '18446744073709551614' abs $_begin < '18446744073709551614'
Truth table0%0/5
not(A) and B and C and D
A= not defined $_fmtB= $_step == 1C= abs $_end < '18446744073709551614'D= abs $_begin < '18446744073709551614'
ABCDresult
0XXX0
10XX0
110X0
11100
11111
161 0 ▶ @_n = ($_next + $_chunk_size <= $_end)
Branch: 1 branch
BranchTrueFalseTotal
$_next + $_chunk_size <= $_end ? : 0 0 0
162 ? ($_next .. $_next + $_chunk_size - 1)
163 : ($_next .. $_end);
164 }
165 else {
166 0 for my $_i (1 .. $_chunk_size) {
167 0 ▶ last if ($_next > $_end);
Branch: 1 branch
BranchTrueFalseTotal
if $_next > $_end 0 0 0
168  
169 0 ▶ push @_n, (defined $_fmt)
Branch: 1 branch
BranchTrueFalseTotal
defined $_fmt ? : 0 0 0
170 ? _sprintf("%$_fmt", $_next) : $_next;
171  
172 0 $_next = $_step * $_i + $_n_begin;
173 }
174 }
175 }
176 else {
177 0 for my $_i (1 .. $_chunk_size) {
178 0 ▶ last if ($_next < $_end);
Branch: 1 branch
BranchTrueFalseTotal
if $_next < $_end 0 0 0
179  
180 0 ▶ push @_n, (defined $_fmt)
Branch: 1 branch
BranchTrueFalseTotal
defined $_fmt ? : 0 0 0
181 ? _sprintf("%$_fmt", $_next) : $_next;
182  
183 0 $_next = $_step * $_i + $_n_begin;
184 }
185 }
186  
187 0 ▶ return unless (scalar @_n);
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @_n 0 0 0
188 }
189  
190 ## -------------------------------------------------------------------
191  
192 0 $_ = \@_n;
193 0 $_wuf->($self, \@_n, $_chunk_id);
194  
195 0 _WORKER_SEQ_GEN__NEXT_B:
196  
197 $_chunk_id += $_max_workers;
198 0 $_next = ($_chunk_id - 1) * $_chunk_size * $_step + $_begin;
199 }
200 }
201  
202 0 _WORKER_SEQ_GEN__LAST:
203  
204 return;
205 }
206  
207 1 1;
208  
209 __END__
↑ Summary MCE/Core/Manager.pm »