MCE/Step.pm

filter: Statementstmt 72.4% 266 / 367 Branchbran 49.6% 125 / 252 Conditioncond 46.6% 48 / 103 MC/DCmcdc 23.4% 15 / 64 Subroutinesub 72.4% 21 / 29 Podpod 55.5% 5 / 9 totaltotal 58.2% 480 / 824 CC 179 SCAR 43.5
CC
179
Cov
61%
run
139.2
enqp
110.0
await
110.0
CRAP 77.7
« MCE/Core/Worker.pm ↑ Summary MCE/Flow.pm »
1 ###############################################################################
2 ## ----------------------------------------------------------------------------
3 ## Parallel step model for building creative steps.
4 ##
5 ###############################################################################
6  
7 package MCE::Step;
8  
9 12 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 12 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 12 ▶no warnings qw( threads recursion uninitialized );
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 12 our $VERSION = '1.904';
15  
16 ## no critic (BuiltinFunctions::ProhibitStringyEval)
17 ## no critic (Subroutines::ProhibitSubroutinePrototypes)
18 ## no critic (TestingAndDebugging::ProhibitNoStrict)
19  
20 12 ▶use Scalar::Util qw( looks_like_number );
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 12 ▶use MCE;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 12 ▶use MCE::Queue;
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 12 our @CARP_NOT = qw( MCE );
26  
27 12 ▶my $_tid = $INC{'threads.pm'} ? threads->tid() : 0;
Branch: 1 branch
BranchTrueFalseTotal
$INC{'threads.pm'} ? : 0 12 12
28  
29 0 ▶sub CLONE {
Subroutine CLONE: not called CC=2 SCAR=17.9
30 0 ▶ $_tid = threads->tid() if $INC{'threads.pm'};
Branch: 1 branch
BranchTrueFalseTotal
if $INC{"threads.pm"} 0 0 0
31 }
32  
33 ###############################################################################
34 ## ----------------------------------------------------------------------------
35 ## Import routine.
36 ##
37 ###############################################################################
38  
39 12 my ($_MCE, $_def, $_params, $_tag) = ({}, {}, {}, 'MCE::Step');
40 12 my ($_prev_c, $_prev_n, $_prev_t, $_prev_w) = ({}, {}, {}, {});
41 12 my ($_user_tasks, $_queue, $_last_task_id, $_lkup) = ({}, {}, {}, {});
42  
43 12 ▶sub import {
Subroutine import: called CC=14 SCAR=41.4
44 12 my ($_class, $_pkg) = (shift, caller);
45  
46 12 my $_p = $_def->{$_pkg} = {
47 MAX_WORKERS => 'auto',
48 CHUNK_SIZE => 'auto',
49 };
50  
51 ## Import functions.
52 12 ▶ if ($_pkg !~ /^MCE::/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($_pkg =~ /^MCE::/) 12 0 12
53 12 ▶ no strict 'refs'; no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
54 12 *{ $_pkg.'::mce_step_f' } = \&run_file;
55 12 *{ $_pkg.'::mce_step_s' } = \&run_seq;
56 12 *{ $_pkg.'::mce_step' } = \&run;
57 }
58  
59 ## Process module arguments.
60 12 ▶ while ( my $_argument = shift ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $_argument = shift()) 0 12 12
61 0 my $_arg = lc $_argument;
62  
63 0 ▶ $_p->{MAX_WORKERS} = shift, next if ( $_arg eq 'max_workers' );
Branch: 1 branch
BranchTrueFalseTotal
if $_arg eq "max_workers" 0 0 0
64 0 ▶ $_p->{CHUNK_SIZE} = shift, next if ( $_arg eq 'chunk_size' );
Branch: 1 branch
BranchTrueFalseTotal
if $_arg eq "chunk_size" 0 0 0
65 0 ▶ $_p->{TMP_DIR} = shift, next if ( $_arg eq 'tmp_dir' );
Branch: 1 branch
BranchTrueFalseTotal
if $_arg eq "tmp_dir" 0 0 0
66 0 ▶ $_p->{FREEZE} = shift, next if ( $_arg eq 'freeze' );
Branch: 1 branch
BranchTrueFalseTotal
if $_arg eq "freeze" 0 0 0
67 0 ▶ $_p->{THAW} = shift, next if ( $_arg eq 'thaw' );
Branch: 1 branch
BranchTrueFalseTotal
if $_arg eq "thaw" 0 0 0
68 0 ▶ $_p->{INIT_RELAY} = shift, next if ( $_arg eq 'init_relay' );
Branch: 1 branch
BranchTrueFalseTotal
if $_arg eq "init_relay" 0 0 0
69 0 ▶ $_p->{USE_THREADS} = shift, next if ( $_arg eq 'use_threads' );
Branch: 1 branch
BranchTrueFalseTotal
if $_arg eq "use_threads" 0 0 0
70  
71 0 ▶ shift, next if ( $_arg eq 'fast' ); # ignored
Branch: 1 branch
BranchTrueFalseTotal
if $_arg eq "fast" 0 0 0
72  
73 ## Sereal 3.015+, if available, is used automatically by MCE 1.8+.
74 0 ▶ if ( $_arg eq 'sereal' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_arg eq "sereal") 0 0 0
75 0 ▶ if ( shift eq '0' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (shift() eq 0) 0 0 0
76 0 require Storable;
77 0 $_p->{FREEZE} = \&Storable::freeze;
78 0 $_p->{THAW} = \&Storable::thaw;
79 }
80 0 next;
81 }
82  
83 0 _croak("Error: ($_argument) invalid module option");
84 }
85  
86 12 $_p->{MAX_WORKERS} = MCE::_parse_max_workers($_p->{MAX_WORKERS});
87  
88 12 MCE::_validate_number($_p->{MAX_WORKERS}, 'MAX_WORKERS', $_tag);
89 MCE::_validate_number($_p->{CHUNK_SIZE}, 'CHUNK_SIZE', $_tag)
90 12 ▶ unless ($_p->{CHUNK_SIZE} eq 'auto');
Branch: 1 branch
BranchTrueFalseTotal
unless $_p->{"CHUNK_SIZE"} eq "auto" 0 12 12
91  
92 12 return;
93 }
94  
95 ###############################################################################
96 ## ----------------------------------------------------------------------------
97 ## The task end callback for when a task completes.
98 ##
99 ###############################################################################
100  
101 22 ▶sub _task_end {
Subroutine _task_end: called CC=4 SCAR=14.2
102  
103 22 my ($_mce, $_task_id, $_task_name) = @_;
104 22 my $_pid = $_mce->{_init_pid}.'.'.$_mce->{_caller};
105  
106 22 ▶ if (defined $_mce->{user_tasks}->[$_task_id + 1]) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_mce->{"user_tasks"}[$_task_id + 1]) 10 12 22
107 10 my $n_workers = $_mce->{user_tasks}->[$_task_id + 1]->{max_workers};
108 10 $_queue->{$_pid}[$_task_id]->enqueue((undef) x $n_workers);
109 }
110  
111 $_params->{task_end}->($_mce, $_task_id, $_task_name)
112 22 ▶ if (exists $_params->{task_end} && ref $_params->{task_end} eq 'CODE');
Branch: 1 branch
BranchTrueFalseTotal
if exists $_params->{"task_end"} and ref $_params->{"task_end"} eq "CODE" 0 22 22
Condition33%1/3
exists $_params->{"task_end"} and ref $_params->{"task_end"} eq "CODE"
!ll&&!rl&&r
2200
MC/DC0%0/2
exists $_params->{"task_end"} and ref $_params->{"task_end"} eq "CODE"
exists $_params->{"task_end"} ref $_params->{"task_end"} eq "CODE"
Truth table33%1/3
A and B
A= exists $_params->{"task_end"}B= ref $_params->{"task_end"} eq "CODE"
ABresult
0X0
100
111
113  
114 22 return;
115 }
116  
117 ###############################################################################
118 ## ----------------------------------------------------------------------------
119 ## Methods for MCE; step, enq, enqp, await.
120 ##
121 ###############################################################################
122  
123 {
124 12 ▶ no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
125  
126 21 ▶ sub MCE::step {
Subroutine step: called CC=4 SCAR=14.6
Pod undocumented
127  
128 21 ▶ my $x = shift; my $self = ref($x) ? $x : $MCE::MCE;
Branch: 1 branch
BranchTrueFalseTotal
ref $x ? : 0 21 21
129 21 my $_pid = $self->{_init_pid}.'.'.$self->{_caller};
130  
131 _croak('MCE::step: method is not allowed by the manager process')
132 21 ▶ unless ($self->{_wid});
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"_wid"} 0 21 21
133  
134 21 my $_task_id = $self->{_task_id};
135  
136 21 ▶ if ($_task_id < $_last_task_id->{$_pid}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_task_id < $_last_task_id->{$_pid}) { } 21 0 21
137 21 $_queue->{$_pid}[$_task_id]->enqueue($self->freeze([ @_ ]));
138 }
139 else {
140 0 _croak('MCE::step: method is not allowed by the last task');
141 }
142  
143 21 return;
144 }
145  
146 ############################################################################
147  
148 0 ▶ sub MCE::enq {
Subroutine enq: not called CC=8 SCAR=42.8
Pod undocumented
149  
150 0 ▶ my $x = shift; my $self = ref($x) ? $x : $MCE::MCE;
Branch: 1 branch
BranchTrueFalseTotal
ref $x ? : 0 0 0
151 0 my $_pid = $self->{_init_pid}.'.'.$self->{_caller};
152 0 my $_name = shift;
153  
154 _croak('MCE::enq: method is not allowed by the manager process')
155 0 ▶ unless ($self->{_wid});
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"_wid"} 0 0 0
156 _croak('MCE::enq: (task_name) is not specified or valid')
157 0 ▶ if (!defined $_name || !exists $_lkup->{$_pid}{$_name});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_name and exists $_lkup->{$_pid}{$_name} 0 0 0
Condition0%0/3
defined $_name and exists $_lkup->{$_pid}{$_name}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_name and exists $_lkup->{$_pid}{$_name}
defined $_name exists $_lkup->{$_pid}{$_name}
Truth table0%0/3
A and B
A= defined $_nameB= exists $_lkup->{$_pid}{$_name}
ABresult
0X0
100
111
158 _croak('MCE::enq: stepping to same task or backwards is not allowed')
159 0 ▶ if ($_lkup->{$_pid}{$_name} <= $self->{_task_id});
Branch: 1 branch
BranchTrueFalseTotal
if $_lkup->{$_pid}{$_name} <= $self->{"_task_id"} 0 0 0
160  
161 0 my $_task_id = $_lkup->{$_pid}{$_name} - 1;
162  
163 0 ▶ if ($_task_id < $_last_task_id->{$_pid}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_task_id < $_last_task_id->{$_pid}) { } 0 0 0
164 0 ▶ if (scalar @_ > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @_ > 1) { } 0 0 0
165 0 my @_items = map { $self->freeze([ $_ ]) } @_;
166 0 $_queue->{$_pid}[$_task_id]->enqueue(@_items);
167 }
168 else {
169 0 $_queue->{$_pid}[$_task_id]->enqueue($self->freeze([ @_ ]));
170 }
171 }
172 else {
173 0 _croak('MCE::enq: method is not allowed by the last task');
174 }
175  
176 0 return;
177 }
178  
179 ############################################################################
180  
181 0 ▶ sub MCE::enqp {
Subroutine enqp: not called CC=10 SCAR=47.0
Pod undocumented
182  
183 0 ▶ my $x = shift; my $self = ref($x) ? $x : $MCE::MCE;
Branch: 1 branch
BranchTrueFalseTotal
ref $x ? : 0 0 0
184 0 my $_pid = $self->{_init_pid}.'.'.$self->{_caller};
185 0 my ($_name, $_p) = (shift, shift);
186  
187 _croak('MCE::enqp: method is not allowed by the manager process')
188 0 ▶ unless ($self->{_wid});
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"_wid"} 0 0 0
189 _croak('MCE::enqp: (task_name) is not specified or valid')
190 0 ▶ if (!defined $_name || !exists $_lkup->{$_pid}{$_name});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_name and exists $_lkup->{$_pid}{$_name} 0 0 0
Condition0%0/3
defined $_name and exists $_lkup->{$_pid}{$_name}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_name and exists $_lkup->{$_pid}{$_name}
defined $_name exists $_lkup->{$_pid}{$_name}
Truth table0%0/3
A and B
A= defined $_nameB= exists $_lkup->{$_pid}{$_name}
ABresult
0X0
100
111
191 _croak('MCE::enqp: stepping to same task or backwards is not allowed')
192 0 ▶ if ($_lkup->{$_pid}{$_name} <= $self->{_task_id});
Branch: 1 branch
BranchTrueFalseTotal
if $_lkup->{$_pid}{$_name} <= $self->{"_task_id"} 0 0 0
193 0 ▶ _croak('MCE::enqp: (priority) is not an integer')
Branch: 1 branch
BranchTrueFalseTotal
if not &looks_like_number($_p) or int $_p != $_p 0 0 0
Condition0%0/3
not &looks_like_number($_p) or int $_p != $_p
l!l&&r!l&&!r
000
MC/DC0%0/2
not &looks_like_number($_p) or int $_p != $_p
not &looks_like_number($_p) int $_p != $_p
Truth table0%0/3
not(A) or B
A= not &looks_like_number($_p)B= int $_p != $_p
ABresult
1X1
011
000
194 if (!looks_like_number($_p) || int($_p) != $_p);
195  
196 0 my $_task_id = $_lkup->{$_pid}{$_name} - 1;
197  
198 0 ▶ if ($_task_id < $_last_task_id->{$_pid}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_task_id < $_last_task_id->{$_pid}) { } 0 0 0
199 0 ▶ if (scalar @_ > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @_ > 1) { } 0 0 0
200 0 my @_items = map { $self->freeze([ $_ ]) } @_;
201 0 $_queue->{$_pid}[$_task_id]->enqueuep($_p, @_items);
202 }
203 else {
204 0 $_queue->{$_pid}[$_task_id]->enqueuep($_p, $self->freeze([ @_ ]));
205 }
206 }
207 else {
208 0 _croak('MCE::enqp: method is not allowed by the last task');
209 }
210  
211 0 return;
212 }
213  
214 ############################################################################
215  
216 0 ▶ sub MCE::await {
Subroutine await: not called CC=10 SCAR=47.0
Pod undocumented
217  
218 0 ▶ my $x = shift; my $self = ref($x) ? $x : $MCE::MCE;
Branch: 1 branch
BranchTrueFalseTotal
ref $x ? : 0 0 0
219 0 my $_pid = $self->{_init_pid}.'.'.$self->{_caller};
220 0 my $_name = shift;
221  
222 _croak('MCE::await: method is not allowed by the manager process')
223 0 ▶ unless ($self->{_wid});
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"_wid"} 0 0 0
224 _croak('MCE::await: (task_name) is not specified or valid')
225 0 ▶ if (!defined $_name || !exists $_lkup->{$_pid}{$_name});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_name and exists $_lkup->{$_pid}{$_name} 0 0 0
Condition0%0/3
defined $_name and exists $_lkup->{$_pid}{$_name}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_name and exists $_lkup->{$_pid}{$_name}
defined $_name exists $_lkup->{$_pid}{$_name}
Truth table0%0/3
A and B
A= defined $_nameB= exists $_lkup->{$_pid}{$_name}
ABresult
0X0
100
111
226 _croak('MCE::await: awaiting from same task or backwards is not allowed')
227 0 ▶ if ($_lkup->{$_pid}{$_name} <= $self->{_task_id});
Branch: 1 branch
BranchTrueFalseTotal
if $_lkup->{$_pid}{$_name} <= $self->{"_task_id"} 0 0 0
228  
229 0 ▶ my $_task_id = $_lkup->{$_pid}{$_name} - 1; my $_t = shift || 0;
Condition0%0/2
shift() || 0
l!l
00
MC/DC0%0/1
shift() || 0
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
230  
231 0 ▶ _croak('MCE::await: (threshold) is not an integer')
Branch: 1 branch
BranchTrueFalseTotal
if not &looks_like_number($_t) or int $_t != $_t 0 0 0
Condition0%0/3
not &looks_like_number($_t) or int $_t != $_t
l!l&&r!l&&!r
000
MC/DC0%0/2
not &looks_like_number($_t) or int $_t != $_t
not &looks_like_number($_t) int $_t != $_t
Truth table0%0/3
not(A) or B
A= not &looks_like_number($_t)B= int $_t != $_t
ABresult
1X1
011
000
232 if (!looks_like_number($_t) || int($_t) != $_t);
233  
234 0 ▶ if ($_task_id < $_last_task_id->{$_pid}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_task_id < $_last_task_id->{$_pid}) { } 0 0 0
235 0 $_queue->{$_pid}[$_task_id]->await($_t);
236 } else {
237 0 _croak('MCE::await: method is not allowed by the last task');
238 }
239  
240 0 return;
241 }
242  
243 }
244  
245 ###############################################################################
246 ## ----------------------------------------------------------------------------
247 ## Init and finish routines.
248 ##
249 ###############################################################################
250  
251 12 ▶sub MCE::Step::_guard::DESTROY {
Subroutine DESTROY: not called CC=3 SCAR=23.1
252 0 my ($_pkg, $_id) = @{ $_[0] };
253  
254 0 ▶ if (defined $_pkg && $_id eq "$$.$_tid") {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_pkg and $_id eq "${$}.$_tid") 0 0 0
Condition0%0/3
defined $_pkg and $_id eq "${$}.$_tid"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_pkg and $_id eq "${$}.$_tid"
defined $_pkg $_id eq "${$}.$_tid"
Truth table0%0/3
A and B
A= defined $_pkgB= $_id eq "${$}.$_tid"
ABresult
0X0
100
111
255 0 @{ $_[0] } = ();
256 0 MCE::Step->finish($_pkg);
257 }
258  
259 0 return;
260 }
261  
262 13 ▶sub init (@) {
Subroutine init: called CC=5 SCAR=18.1
Pod documented
263  
264 13 ▶ shift if (defined $_[0] && $_[0] eq 'MCE::Step');
Branch: 1 branch
BranchTrueFalseTotal
if defined $_[0] and $_[0] eq "MCE::Step" 13 0 13
Condition33%1/3
defined $_[0] and $_[0] eq "MCE::Step"
!ll&&!rl&&r
0013
MC/DC0%0/2
defined $_[0] and $_[0] eq "MCE::Step"
defined $_[0] $_[0] eq "MCE::Step"
Truth table33%1/3
A and B
A= defined $_[0]B= $_[0] eq "MCE::Step"
ABresult
0X0
100
111
265 13 my $_pkg = "$$.$_tid.".caller();
266  
267 13 ▶ $_params->{$_pkg} = (ref $_[0] eq 'HASH') ? shift : { @_ };
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'HASH' ? : 0 13 13
268  
269 13 @_ = ();
270  
271 defined wantarray
272 13 ▶ ? bless([$_pkg, "$$.$_tid"], MCE::Step::_guard::)
Branch: 1 branch
BranchTrueFalseTotal
defined wantarray ? : 0 13 13
273 : ();
274 }
275  
276 25 ▶sub finish (@) {
Subroutine finish: called CC=11 SCAR=24.3
Pod documented
277  
278 25 ▶ shift if (defined $_[0] && $_[0] eq 'MCE::Step');
Branch: 1 branch
BranchTrueFalseTotal
if defined $_[0] and $_[0] eq "MCE::Step" 25 0 25
Condition33%1/3
defined $_[0] and $_[0] eq "MCE::Step"
!ll&&!rl&&r
0025
MC/DC0%0/2
defined $_[0] and $_[0] eq "MCE::Step"
defined $_[0] $_[0] eq "MCE::Step"
Truth table33%1/3
A and B
A= defined $_[0]B= $_[0] eq "MCE::Step"
ABresult
0X0
100
111
279 25 ▶ my $_pkg = (defined $_[0]) ? shift : "$$.$_tid.".caller();
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0] ? : 21 4 25
280  
281 25 ▶ if ( $_pkg eq 'MCE' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($_pkg eq 'MCE') { } 12 13 25
elsif ($_MCE->{$_pkg} and $_MCE->{$_pkg}{'_init_pid'} eq "${$}.$_tid") { } 4 9 13
282 12 for my $_k ( keys %{ $_MCE } ) { MCE::Step->finish($_k, 1); }
283 }
284 ▶ elsif ( $_MCE->{$_pkg} && $_MCE->{$_pkg}{_init_pid} eq "$$.$_tid" ) {
Condition66%2/3
$_MCE->{$_pkg} and $_MCE->{$_pkg}{"_init_pid"} eq "${$}.$_tid"
!ll&&!rl&&r
094
MC/DC50%1/2
$_MCE->{$_pkg} and $_MCE->{$_pkg}{"_init_pid"} eq "${$}.$_tid"
$_MCE->{$_pkg} $_MCE->{$_pkg}{"_init_pid"} eq "${$}.$_tid"
Truth table66%2/3
A and B
A= $_MCE->{$_pkg}B= $_MCE->{$_pkg}{"_init_pid"} eq "${$}.$_tid"
ABresult
0X0
100
111
285 4 ▶ $_MCE->{$_pkg}->shutdown(@_) if $_MCE->{$_pkg}{_spawned};
Branch: 1 branch
BranchTrueFalseTotal
if $_MCE->{$_pkg}{"_spawned"} 4 0 4
286  
287 4 delete $_lkup->{$_pkg};
288 4 delete $_last_task_id->{$_pkg};
289  
290 4 delete $_user_tasks->{$_pkg};
291 4 delete $_prev_c->{$_pkg};
292 4 delete $_prev_n->{$_pkg};
293 4 delete $_prev_t->{$_pkg};
294 4 delete $_prev_w->{$_pkg};
295 4 delete $_MCE->{$_pkg};
296  
297 4 ▶ if (defined $_queue->{$_pkg}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_queue->{$_pkg}) 4 0 4
298 4 local $_;
299 4 $_->DESTROY() for (@{ $_queue->{$_pkg} });
300 4 delete $_queue->{$_pkg};
301 }
302 }
303  
304 25 @_ = ();
305  
306 25 return;
307 }
308  
309 ###############################################################################
310 ## ----------------------------------------------------------------------------
311 ## Parallel step with MCE -- file.
312 ##
313 ###############################################################################
314  
315 4 ▶sub run_file (@) {
Subroutine run_file: called CC=21 SCAR=34.5
Pod documented
316  
317 4 ▶ shift if (defined $_[0] && $_[0] eq 'MCE::Step');
Branch: 1 branch
BranchTrueFalseTotal
if defined $_[0] and $_[0] eq "MCE::Step" 0 4 4
Condition33%1/3
defined $_[0] and $_[0] eq "MCE::Step"
!ll&&!rl&&r
040
MC/DC0%0/2
defined $_[0] and $_[0] eq "MCE::Step"
defined $_[0] $_[0] eq "MCE::Step"
Truth table33%1/3
A and B
A= defined $_[0]B= $_[0] eq "MCE::Step"
ABresult
0X0
100
111
318  
319 4 ▶ my ($_file, $_pos); my $_start_pos = (ref $_[0] eq 'HASH') ? 2 : 1;
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'HASH' ? : 4 0 4
320 4 my $_pid = "$$.$_tid.".caller();
321  
322 4 ▶ if (defined (my $_p = $_params->{$_pid})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $_p = $_params->{$_pid})) { } 4 0 4
323 4 ▶ delete $_p->{input_data} if (exists $_p->{input_data});
Branch: 1 branch
BranchTrueFalseTotal
if exists $_p->{"input_data"} 0 4 4
324 4 ▶ delete $_p->{sequence} if (exists $_p->{sequence});
Branch: 1 branch
BranchTrueFalseTotal
if exists $_p->{"sequence"} 0 4 4
325 }
326 else {
327 0 $_params->{$_pid} = {};
328 }
329  
330 4 for my $_i ($_start_pos .. @_ - 1) {
331 8 my $_r = ref $_[$_i];
332 8 ▶ if ($_r eq '' || $_r eq 'SCALAR' || $_r =~ /^(?:GLOB|FileHandle|IO::)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_r eq "" or $_r eq "SCALAR" or $_r =~ /^(?:GLOB|FileHandle|IO::)/) 4 4 8
Condition83%5/6
$_r eq "" or $_r eq "SCALAR" or $_r =~ /^(?:GLOB|FileHandle|IO::)/
l!l&&r!l&&!r
224
$_r eq "" or $_r eq "SCALAR"
l!l&&r!l&&!r
206
MC/DC66%2/3
$_r eq "" or $_r eq "SCALAR" or $_r =~ /^(?:GLOB|FileHandle|IO::)/
$_r eq "" $_r eq "SCALAR" $_r =~ /^(?:GLOB|FileHandle|IO::)/
Truth table75%3/4
A or B or C
A= $_r eq ""B= $_r eq "SCALAR"C= $_r =~ /^(?:GLOB|FileHandle|IO::)/
ABCresult
1XX1
01X1
0011
0000
333 4 $_file = $_[$_i]; $_pos = $_i;
334 4 last;
335 }
336 }
337  
338 4 ▶ if (defined $_file && ref $_file eq '' && $_file ne '') {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $_file and ref $_file eq '' and $_file ne '') { } 2 2 4
elsif (ref $_file eq 'SCALAR' or ref($_file) =~ /^(?:GLOB|FileHandle|IO::)/) { } 2 0 2
Condition66%4/6
defined $_file and ref $_file eq "" and $_file ne ""
!ll&&!rl&&r
202
defined $_file and ref $_file eq ""
!ll&&!rl&&r
022
MC/DC33%1/3
defined $_file and ref $_file eq "" and $_file ne ""
defined $_file ref $_file eq "" $_file ne ""
Truth table50%2/4
A and B and C
A= defined $_fileB= ref $_file eq ""C= $_file ne ""
ABCresult
0XX0
10X0
1100
1111
339 2 ▶ _croak("$_tag: ($_file) does not exist") unless (-e $_file);
Branch: 1 branch
BranchTrueFalseTotal
unless -e $_file 0 2 2
340 2 ▶ _croak("$_tag: ($_file) is not readable") unless (-r $_file);
Branch: 1 branch
BranchTrueFalseTotal
unless -r $_file 0 2 2
341 2 ▶ _croak("$_tag: ($_file) is not a plain file") unless (-f $_file);
Branch: 1 branch
BranchTrueFalseTotal
unless -f $_file 0 2 2
342 2 $_params->{$_pid}{_file} = $_file;
343 }
344 ▶ elsif (ref $_file eq 'SCALAR' || ref($_file) =~ /^(?:GLOB|FileHandle|IO::)/) {
Condition33%1/3
ref $_file eq "SCALAR" or ref($_file) =~ /^(?:GLOB|FileHandle|IO::)/
l!l&&r!l&&!r
020
MC/DC0%0/2
ref $_file eq "SCALAR" or ref($_file) =~ /^(?:GLOB|FileHandle|IO::)/
ref $_file eq "SCALAR" ref($_file) =~ /^(?:GLOB|FileHandle|IO::)/
Truth table33%1/3
A or B
A= ref $_file eq "SCALAR"B= ref($_file) =~ /^(?:GLOB|FileHandle|IO::)/
ABresult
1X1
011
000
345 2 $_params->{$_pid}{_file} = $_file;
346 }
347 else {
348 0 _croak("$_tag: (file) is not specified or valid");
349 }
350  
351 4 ▶ if (defined $_pos) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_pos) 4 0 4
352 4 pop @_ for ($_pos .. @_ - 1);
353 }
354  
355 4 return run(@_);
356 }
357  
358 ###############################################################################
359 ## ----------------------------------------------------------------------------
360 ## Parallel step with MCE -- sequence.
361 ##
362 ###############################################################################
363  
364 2 ▶sub run_seq (@) {
Subroutine run_seq: called CC=22 SCAR=38.8
Pod documented
365  
366 2 ▶ shift if (defined $_[0] && $_[0] eq 'MCE::Step');
Branch: 1 branch
BranchTrueFalseTotal
if defined $_[0] and $_[0] eq "MCE::Step" 0 2 2
Condition33%1/3
defined $_[0] and $_[0] eq "MCE::Step"
!ll&&!rl&&r
020
MC/DC0%0/2
defined $_[0] and $_[0] eq "MCE::Step"
defined $_[0] $_[0] eq "MCE::Step"
Truth table33%1/3
A and B
A= defined $_[0]B= $_[0] eq "MCE::Step"
ABresult
0X0
100
111
367  
368 2 ▶ my ($_begin, $_end, $_pos); my $_start_pos = (ref $_[0] eq 'HASH') ? 2 : 1;
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'HASH' ? : 2 0 2
369 2 my $_pid = "$$.$_tid.".caller();
370  
371 2 ▶ if (defined (my $_p = $_params->{$_pid})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $_p = $_params->{$_pid})) { } 2 0 2
372 2 ▶ delete $_p->{sequence} if (exists $_p->{sequence});
Branch: 1 branch
BranchTrueFalseTotal
if exists $_p->{"sequence"} 0 2 2
373 2 ▶ delete $_p->{input_data} if (exists $_p->{input_data});
Branch: 1 branch
BranchTrueFalseTotal
if exists $_p->{"input_data"} 0 2 2
374 2 ▶ delete $_p->{_file} if (exists $_p->{_file});
Branch: 1 branch
BranchTrueFalseTotal
if exists $_p->{"_file"} 0 2 2
375 }
376 else {
377 0 $_params->{$_pid} = {};
378 }
379  
380 2 for my $_i ($_start_pos .. @_ - 1) {
381 4 my $_r = ref $_[$_i];
382  
383 4 ▶ if ($_r eq '' || $_r =~ /^Math::/ || $_r eq 'HASH' || $_r eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if ($_r eq "" or $_r =~ /^Math::/ or $_r eq "HASH" or $_r eq "ARRAY") 2 2 4
Condition66%6/9
$_r eq "" or $_r =~ /^Math::/ or $_r eq "HASH" or $_r eq "ARRAY"
l!l&&r!l&&!r
202
$_r eq "" or $_r =~ /^Math::/ or $_r eq "HASH"
l!l&&r!l&&!r
202
$_r eq "" or $_r =~ /^Math::/
l!l&&r!l&&!r
202
MC/DC25%1/4
$_r eq "" or $_r =~ /^Math::/ or $_r eq "HASH" or $_r eq "ARRAY"
$_r eq "" $_r =~ /^Math::/ $_r eq "HASH" $_r eq "ARRAY"
Truth table40%2/5
A or B or C or D
A= $_r eq ""B= $_r =~ /^Math::/C= $_r eq "HASH"D= $_r eq "ARRAY"
ABCDresult
1XXX1
01XX1
001X1
00011
00000
384 2 $_pos = $_i;
385  
386 2 ▶ if ($_r eq '' || $_r =~ /^Math::/) {
Branch: 3 branches
BranchTrueFalseTotal
if ($_r eq '' or $_r =~ /^Math::/) { } 2 0 2
elsif ($_r eq 'HASH') { } 0 0 0
elsif ($_r eq 'ARRAY') { } 0 0 0
Condition33%1/3
$_r eq "" or $_r =~ /^Math::/
l!l&&r!l&&!r
200
MC/DC0%0/2
$_r eq "" or $_r =~ /^Math::/
$_r eq "" $_r =~ /^Math::/
Truth table33%1/3
A or B
A= $_r eq ""B= $_r =~ /^Math::/
ABresult
1X1
011
000
387 2 $_begin = $_[$_pos], $_end = $_[$_pos + 1];
388 $_params->{$_pid}{sequence} = [
389 2 $_[$_pos], $_[$_pos + 1], $_[$_pos + 2], $_[$_pos + 3]
390 ];
391 }
392 elsif ($_r eq 'HASH') {
393 0 $_begin = $_[$_pos]->{begin}, $_end = $_[$_pos]->{end};
394 0 $_params->{$_pid}{sequence} = $_[$_pos];
395 }
396 elsif ($_r eq 'ARRAY') {
397 0 $_begin = $_[$_pos]->[0], $_end = $_[$_pos]->[1];
398 0 $_params->{$_pid}{sequence} = $_[$_pos];
399 }
400  
401 2 last;
402 }
403 }
404  
405 _croak("$_tag: (sequence) is not specified or valid")
406 2 ▶ unless (exists $_params->{$_pid}{sequence});
Branch: 1 branch
BranchTrueFalseTotal
unless exists $_params->{$_pid}{"sequence"} 0 2 2
407 2 ▶ _croak("$_tag: (begin) is not specified for sequence")
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_begin 0 2 2
408 unless (defined $_begin);
409 2 ▶ _croak("$_tag: (end) is not specified for sequence")
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_end 0 2 2
410 unless (defined $_end);
411  
412 2 $_params->{$_pid}{sequence_run} = undef;
413  
414 2 ▶ if (defined $_pos) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_pos) 2 0 2
415 2 pop @_ for ($_pos .. @_ - 1);
416 }
417  
418 2 return run(@_);
419 }
420  
421 ###############################################################################
422 ## ----------------------------------------------------------------------------
423 ## Parallel step with MCE.
424 ##
425 ###############################################################################
426  
427 21 ▶sub run (@) {
Subroutine run: called CC=75 SCAR=49.4
Pod documented
428  
429 21 my $_caller = caller();
430 21 ▶ if ($_caller ne 'MCE::Step' && !exists $_def->{$_caller}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_caller ne "MCE::Step" and not exists $_def->{$_caller}) 0 21 21
Condition66%2/3
$_caller ne "MCE::Step" and not exists $_def->{$_caller}
!ll&&!rl&&r
6150
MC/DC0%0/2
$_caller ne "MCE::Step" and not exists $_def->{$_caller}
$_caller ne "MCE::Step" not exists $_def->{$_caller}
Truth table66%2/3
A and not(B)
A= $_caller ne "MCE::Step"B= not exists $_def->{$_caller}
ABresult
0X0
100
111
431 0 warn "MCE::Step is not imported into the \"$_caller\" namespace. Aborting...\n";
432 0 return;
433 }
434  
435 21 ▶ shift if (defined $_[0] && $_[0] eq 'MCE::Step');
Branch: 1 branch
BranchTrueFalseTotal
if defined $_[0] and $_[0] eq "MCE::Step" 0 21 21
Condition33%1/3
defined $_[0] and $_[0] eq "MCE::Step"
!ll&&!rl&&r
0210
MC/DC0%0/2
defined $_[0] and $_[0] eq "MCE::Step"
defined $_[0] $_[0] eq "MCE::Step"
Truth table33%1/3
A and B
A= defined $_[0]B= $_[0] eq "MCE::Step"
ABresult
0X0
100
111
436  
437 21 ▶ my $_pkg = $_caller eq 'MCE::Step' ? caller(1) : $_caller;
Branch: 1 branch
BranchTrueFalseTotal
$_caller eq 'MCE::Step' ? : 6 15 21
438 21 my $_pid = "$$.$_tid.$_pkg";
439  
440 21 ▶ if (ref $_[0] eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[0] eq "HASH") 14 7 21
441 14 ▶ $_params->{$_pid} = {} unless defined $_params->{$_pid};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_params->{$_pid} 0 14 14
442 14 for my $_p (keys %{ $_[0] }) {
443 14 $_params->{$_pid}{$_p} = $_[0]->{$_p};
444 }
445  
446 14 shift;
447 }
448  
449 ## -------------------------------------------------------------------------
450  
451 21 my (@_code, @_name, @_thrs, @_wrks); my $_init_mce = 0; my $_pos = 0;
452  
453 21 %{ $_lkup->{$_pid} } = ();
454  
455 21 ▶ while (ref $_[0] eq 'CODE') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[0] eq "CODE") 35 21 56
456 35 push @_code, $_[0];
457  
458 35 ▶ if (defined (my $_p = $_params->{$_pid})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $_p = $_params->{$_pid})) 35 0 35
459 push @_name, (ref $_p->{task_name} eq 'ARRAY')
460 35 ▶ ? $_p->{task_name}->[$_pos] : undef;
Branch: 1 branch
BranchTrueFalseTotal
ref $_p->{'task_name'} eq 'ARRAY' ? : 28 7 35
461 push @_thrs, (ref $_p->{use_threads} eq 'ARRAY')
462 35 ▶ ? $_p->{use_threads}->[$_pos] : undef;
Branch: 1 branch
BranchTrueFalseTotal
ref $_p->{'use_threads'} eq 'ARRAY' ? : 0 35 35
463 push @_wrks, (ref $_p->{max_workers} eq 'ARRAY')
464 35 ▶ ? $_p->{max_workers}->[$_pos] : undef;
Branch: 1 branch
BranchTrueFalseTotal
ref $_p->{'max_workers'} eq 'ARRAY' ? : 28 7 35
465 }
466  
467 35 ▶ $_lkup->{$_pid}{ $_name[ $_pos ] } = $_pos if (defined $_name[ $_pos ]);
Branch: 1 branch
BranchTrueFalseTotal
if defined $_name[$_pos] 28 7 35
468  
469 $_init_mce = 1 if (
470 !defined $_prev_c->{$_pid}[$_pos] ||
471 35 ▶ $_prev_c->{$_pid}[$_pos] != $_code[$_pos]
Branch: 1 branch
BranchTrueFalseTotal
if not defined $_prev_c->{$_pid}[$_pos] or $_prev_c->{$_pid}[$_pos] != $_code[$_pos] 19 16 35
Condition66%2/3
not defined $_prev_c->{$_pid}[$_pos] or $_prev_c->{$_pid}[$_pos] != $_code[$_pos]
l!l&&r!l&&!r
19016
MC/DC50%1/2
not defined $_prev_c->{$_pid}[$_pos] or $_prev_c->{$_pid}[$_pos] != $_code[$_pos]
not defined $_prev_c->{$_pid}[$_pos] $_prev_c->{$_pid}[$_pos] != $_code[$_pos]
Truth table66%2/3
not(A) or B
A= not defined $_prev_c->{$_pid}[$_pos]B= $_prev_c->{$_pid}[$_pos] != $_code[$_pos]
ABresult
1X1
011
000
472 );
473  
474 35 ▶ $_init_mce = 1 if ($_prev_n->{$_pid}[$_pos] ne $_name[$_pos]);
Branch: 1 branch
BranchTrueFalseTotal
if $_prev_n->{$_pid}[$_pos] ne $_name[$_pos] 12 23 35
475 35 ▶ $_init_mce = 1 if ($_prev_t->{$_pid}[$_pos] ne $_thrs[$_pos]);
Branch: 1 branch
BranchTrueFalseTotal
if $_prev_t->{$_pid}[$_pos] ne $_thrs[$_pos] 0 35 35
476 35 ▶ $_init_mce = 1 if ($_prev_w->{$_pid}[$_pos] ne $_wrks[$_pos]);
Branch: 1 branch
BranchTrueFalseTotal
if $_prev_w->{$_pid}[$_pos] ne $_wrks[$_pos] 12 23 35
477  
478 35 $_prev_c->{$_pid}[$_pos] = $_code[$_pos];
479 35 $_prev_n->{$_pid}[$_pos] = $_name[$_pos];
480 35 $_prev_t->{$_pid}[$_pos] = $_thrs[$_pos];
481 35 $_prev_w->{$_pid}[$_pos] = $_wrks[$_pos];
482  
483 35 shift; $_pos++;
484 }
485  
486 21 ▶ if (defined $_prev_c->{$_pid}[$_pos]) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_prev_c->{$_pid}[$_pos]) 0 21 21
487 0 pop @{ $_prev_c->{$_pid} } for ($_pos .. $#{ $_prev_c->{$_pid } });
488 0 pop @{ $_prev_n->{$_pid} } for ($_pos .. $#{ $_prev_n->{$_pid } });
489 0 pop @{ $_prev_t->{$_pid} } for ($_pos .. $#{ $_prev_t->{$_pid } });
490 0 pop @{ $_prev_w->{$_pid} } for ($_pos .. $#{ $_prev_w->{$_pid } });
491  
492 0 $_init_mce = 1;
493 }
494  
495 21 ▶ return unless (scalar @_code);
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @_code 0 21 21
496  
497 ## -------------------------------------------------------------------------
498  
499 21 my $_input_data; my $_max_workers = $_def->{$_pkg}{MAX_WORKERS};
500 21 my $_r = ref $_[0];
501  
502 21 ▶ if (@_ == 1 && $_r =~ /^(?:ARRAY|HASH|SCALAR|GLOB|FileHandle|IO::|Iterator::)/) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 1 and $_r =~ /^(?:ARRAY|HASH|SCALAR|GLOB|FileHandle|IO::|Iterator::)/) 4 17 21
Condition66%2/3
@_ == 1 and $_r =~ /^(?:ARRAY|HASH|SCALAR|GLOB|FileHandle|IO::|Iterator::)/
!ll&&!rl&&r
1704
MC/DC50%1/2
@_ == 1 and $_r =~ /^(?:ARRAY|HASH|SCALAR|GLOB|FileHandle|IO::|Iterator::)/
@_ == 1 $_r =~ /^(?:ARRAY|HASH|SCALAR|GLOB|FileHandle|IO::|Iterator::)/
Truth table66%2/3
A and B
A= @_ == 1B= $_r =~ /^(?:ARRAY|HASH|SCALAR|GLOB|FileHandle|IO::|Iterator::)/
ABresult
0X0
100
111
503 4 $_input_data = shift;
504 }
505  
506 21 ▶ if (defined (my $_p = $_params->{$_pid})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $_p = $_params->{$_pid})) 21 0 21
507 $_max_workers = MCE::_parse_max_workers($_p->{max_workers})
508 21 ▶ if (exists $_p->{max_workers} && ref $_p->{max_workers} ne 'ARRAY');
Branch: 1 branch
BranchTrueFalseTotal
if exists $_p->{"max_workers"} and ref $_p->{"max_workers"} ne "ARRAY" 7 14 21
Condition66%2/3
exists $_p->{"max_workers"} and ref $_p->{"max_workers"} ne "ARRAY"
!ll&&!rl&&r
0147
MC/DC50%1/2
exists $_p->{"max_workers"} and ref $_p->{"max_workers"} ne "ARRAY"
exists $_p->{"max_workers"} ref $_p->{"max_workers"} ne "ARRAY"
Truth table66%2/3
A and B
A= exists $_p->{"max_workers"}B= ref $_p->{"max_workers"} ne "ARRAY"
ABresult
0X0
100
111
509  
510 21 ▶ delete $_p->{sequence} if (defined $_input_data || scalar @_);
Branch: 1 branch
BranchTrueFalseTotal
if defined $_input_data or scalar @_ 10 11 21
Condition100%2/2
defined $_input_data or scalar @_
l!l
417
MC/DC100%1/1
defined $_input_data or scalar @_
defined $_input_data
Truth table100%2/2
A
A= defined $_input_data
Aresult
11
00
511 21 ▶ delete $_p->{user_func} if (exists $_p->{user_func});
Branch: 1 branch
BranchTrueFalseTotal
if exists $_p->{"user_func"} 0 21 21
512 21 ▶ delete $_p->{user_tasks} if (exists $_p->{user_tasks});
Branch: 1 branch
BranchTrueFalseTotal
if exists $_p->{"user_tasks"} 0 21 21
513 }
514  
515 21 ▶ if (@_code > 1 && $_max_workers > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_code > 1 and $_max_workers > 1) 14 7 21
Condition66%2/3
@_code > 1 and $_max_workers > 1
!ll&&!rl&&r
7014
MC/DC50%1/2
@_code > 1 and $_max_workers > 1
@_code > 1 $_max_workers > 1
Truth table66%2/3
A and B
A= @_code > 1B= $_max_workers > 1
ABresult
0X0
100
111
516 14 $_max_workers = int($_max_workers / @_code + 0.5) + 1;
517 }
518  
519 my $_chunk_size = MCE::_parse_chunk_size(
520 21 $_def->{$_pkg}{CHUNK_SIZE}, $_max_workers, $_params->{$_pid},
521 $_input_data, scalar @_
522 );
523  
524 21 ▶ if (defined (my $_p = $_params->{$_pid})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $_p = $_params->{$_pid})) 21 0 21
525 21 ▶ if (exists $_p->{_file}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $_p->{'_file'}) { } 4 17 21
526 4 $_input_data = delete $_p->{_file};
527 } else {
528 17 ▶ $_input_data = $_p->{input_data} if exists $_p->{input_data};
Branch: 1 branch
BranchTrueFalseTotal
if exists $_p->{"input_data"} 0 17 17
529 }
530 }
531  
532 ## -------------------------------------------------------------------------
533  
534 21 MCE::_save_state($_MCE->{$_pid});
535  
536 21 ▶ if ($_init_mce || !exists $_queue->{$_pid}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_init_mce or not exists $_queue->{$_pid}) { } 13 8 21
Condition66%2/3
$_init_mce or not exists $_queue->{$_pid}
l!l&&r!l&&!r
1308
MC/DC50%1/2
$_init_mce or not exists $_queue->{$_pid}
$_init_mce not exists $_queue->{$_pid}
Truth table66%2/3
A or not(B)
A= $_init_mceB= not exists $_queue->{$_pid}
ABresult
1X1
011
000
537 13 ▶ $_MCE->{$_pid}->shutdown() if (defined $_MCE->{$_pid});
Branch: 1 branch
BranchTrueFalseTotal
if defined $_MCE->{$_pid} 0 13 13
538 13 ▶ $_queue->{$_pid} = [] if (!defined $_queue->{$_pid});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_queue->{$_pid} 13 0 13
539  
540 13 my $_Q = $_queue->{$_pid};
541 0 pop(@{ $_Q })->DESTROY for (@_code .. @{ $_Q });
542  
543 6 push @{ $_Q }, MCE::Queue->new(await => 1)
544 13 for (@{ $_Q } .. @_code - 2);
545  
546 13 $_last_task_id->{$_pid} = @_code - 1;
547  
548 ## must clear arrays for nested session to work with Perl < v5.14
549 13 _gen_user_tasks($_pid,$_Q, [@_code],[@_name],[@_thrs],[@_wrks], $_chunk_size);
550  
551 13 @_code = @_name = @_thrs = @_wrks = ();
552  
553 my %_opts = (
554 max_workers => $_max_workers, task_name => $_tag,
555 13 user_tasks => $_user_tasks->{$_pid}, task_end => \&_task_end,
556 );
557  
558 13 ▶ if (defined (my $_p = $_params->{$_pid})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $_p = $_params->{$_pid})) 13 0 13
559 13 local $_;
560  
561 13 for (keys %{ $_p }) {
562 25 ▶ next if ($_ eq 'max_workers' && ref $_p->{max_workers} eq 'ARRAY');
Branch: 1 branch
BranchTrueFalseTotal
if $_ eq "max_workers" and ref $_p->{"max_workers"} eq "ARRAY" 6 19 25
Condition100%3/3
$_ eq "max_workers" and ref $_p->{"max_workers"} eq "ARRAY"
!ll&&!rl&&r
1276
MC/DC100%2/2
$_ eq "max_workers" and ref $_p->{"max_workers"} eq "ARRAY"
$_ eq "max_workers" ref $_p->{"max_workers"} eq "ARRAY"
Truth table100%3/3
A and B
A= $_ eq "max_workers"B= ref $_p->{"max_workers"} eq "ARRAY"
ABresult
0X0
100
111
563 19 ▶ next if ($_ eq 'task_name' && ref $_p->{task_name} eq 'ARRAY');
Branch: 1 branch
BranchTrueFalseTotal
if $_ eq "task_name" and ref $_p->{"task_name"} eq "ARRAY" 6 13 19
Condition66%2/3
$_ eq "task_name" and ref $_p->{"task_name"} eq "ARRAY"
!ll&&!rl&&r
1306
MC/DC50%1/2
$_ eq "task_name" and ref $_p->{"task_name"} eq "ARRAY"
$_ eq "task_name" ref $_p->{"task_name"} eq "ARRAY"
Truth table66%2/3
A and B
A= $_ eq "task_name"B= ref $_p->{"task_name"} eq "ARRAY"
ABresult
0X0
100
111
564 13 ▶ next if ($_ eq 'use_threads' && ref $_p->{use_threads} eq 'ARRAY');
Branch: 1 branch
BranchTrueFalseTotal
if $_ eq "use_threads" and ref $_p->{"use_threads"} eq "ARRAY" 0 13 13
Condition33%1/3
$_ eq "use_threads" and ref $_p->{"use_threads"} eq "ARRAY"
!ll&&!rl&&r
1300
MC/DC0%0/2
$_ eq "use_threads" and ref $_p->{"use_threads"} eq "ARRAY"
$_ eq "use_threads" ref $_p->{"use_threads"} eq "ARRAY"
Truth table33%1/3
A and B
A= $_ eq "use_threads"B= ref $_p->{"use_threads"} eq "ARRAY"
ABresult
0X0
100
111
565  
566 13 ▶ next if ($_ eq 'chunk_size');
Branch: 1 branch
BranchTrueFalseTotal
if $_ eq "chunk_size" 0 13 13
567 13 ▶ next if ($_ eq 'input_data');
Branch: 1 branch
BranchTrueFalseTotal
if $_ eq "input_data" 0 13 13
568 13 ▶ next if ($_ eq 'sequence_run');
Branch: 1 branch
BranchTrueFalseTotal
if $_ eq "sequence_run" 0 13 13
569 13 ▶ next if ($_ eq 'task_end');
Branch: 1 branch
BranchTrueFalseTotal
if $_ eq "task_end" 0 13 13
570  
571 _croak("$_tag: ($_) is not a valid constructor argument")
572 13 ▶ unless (exists $MCE::_valid_fields_new{$_});
Branch: 1 branch
BranchTrueFalseTotal
unless exists $MCE::_valid_fields_new{$_} 0 13 13
573  
574 13 $_opts{$_} = $_p->{$_};
575 }
576 }
577  
578 13 for my $_k (qw/ tmp_dir freeze thaw init_relay use_threads /) {
579 $_opts{$_k} = $_def->{$_pkg}{uc($_k)}
580 65 ▶ if (exists $_def->{$_pkg}{uc($_k)} && !exists $_opts{$_k});
Branch: 1 branch
BranchTrueFalseTotal
if exists $_def->{$_pkg}{uc $_k} and not exists $_opts{$_k} 0 65 65
Condition33%1/3
exists $_def->{$_pkg}{uc $_k} and not exists $_opts{$_k}
!ll&&!rl&&r
6500
MC/DC0%0/2
exists $_def->{$_pkg}{uc $_k} and not exists $_opts{$_k}
exists $_def->{$_pkg}{uc $_k} not exists $_opts{$_k}
Truth table33%1/3
A and not(B)
A= exists $_def->{$_pkg}{uc $_k}B= not exists $_opts{$_k}
ABresult
0X0
100
111
581 }
582  
583 13 $_MCE->{$_pid} = MCE->new(pkg => $_pkg, %_opts);
584 }
585 else {
586 ## Workers may persist after running. Thus, updating the MCE instance.
587 ## These options do not require respawning.
588 8 ▶ if (defined (my $_p = $_params->{$_pid})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $_p = $_params->{$_pid})) 8 0 8
589 8 for my $_k (qw(
590 RS interval stderr_file stdout_file user_error user_output
591 job_delay submit_delay on_post_exit on_post_run user_args
592 flush_file flush_stderr flush_stdout gather max_retries
593 )) {
594 128 ▶ $_MCE->{$_pid}{$_k} = $_p->{$_k} if (exists $_p->{$_k});
Branch: 1 branch
BranchTrueFalseTotal
if exists $_p->{$_k} 8 120 128
595 }
596 }
597 }
598  
599 ## -------------------------------------------------------------------------
600  
601 21 ▶ my @_a; my $_wa = wantarray; $_MCE->{$_pid}{gather} = \@_a if (defined $_wa);
Branch: 1 branch
BranchTrueFalseTotal
if defined $_wa 7 14 21
602  
603 21 ▶ if (defined $_input_data) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $_input_data) { } 8 13 21
elsif (scalar @_) { } 6 7 13
604 8 @_ = ();
605 8 $_MCE->{$_pid}->process({ chunk_size => $_chunk_size }, $_input_data);
606 7 delete $_MCE->{$_pid}{input_data};
607 }
608 elsif (scalar @_) {
609 6 $_MCE->{$_pid}->process({ chunk_size => $_chunk_size }, \@_);
610 2 delete $_MCE->{$_pid}{input_data};
611 }
612 else {
613 7 ▶ if (defined $_params->{$_pid} && exists $_params->{$_pid}{sequence}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_params->{$_pid} and exists $_params->{$_pid}{'sequence'}) { } 2 5 7
Condition66%2/3
defined $_params->{$_pid} and exists $_params->{$_pid}{"sequence"}
!ll&&!rl&&r
052
MC/DC50%1/2
defined $_params->{$_pid} and exists $_params->{$_pid}{"sequence"}
defined $_params->{$_pid} exists $_params->{$_pid}{"sequence"}
Truth table66%2/3
A and B
A= defined $_params->{$_pid}B= exists $_params->{$_pid}{"sequence"}
ABresult
0X0
100
111
614 $_MCE->{$_pid}->run({
615 chunk_size => $_chunk_size,
616 sequence => $_params->{$_pid}{sequence}
617 2 }, 0);
618 2 ▶ if (exists $_params->{$_pid}{sequence_run}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $_params->{$_pid}{"sequence_run"}) 2 0 2
619 2 delete $_params->{$_pid}{sequence_run};
620 2 delete $_params->{$_pid}{sequence};
621 }
622 2 delete $_MCE->{$_pid}{sequence};
623 }
624 else {
625 5 $_MCE->{$_pid}->run({ chunk_size => $_chunk_size }, 0);
626 }
627 }
628  
629 12 MCE::_restore_state();
630  
631 # destroy queue(s) if MCE::run requested workers to shutdown
632 12 ▶ if (!$_MCE->{$_pid}{_spawned}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($_MCE->{$_pid}{"_spawned"}) 0 12 12
633 0 $_->DESTROY() for @{ $_queue->{$_pid} };
634 0 delete $_queue->{$_pid};
635 }
636  
637 12 ▶ delete $_MCE->{$_pid}{gather} if (defined $_wa);
Branch: 1 branch
BranchTrueFalseTotal
if defined $_wa 2 10 12
638  
639 12 ▶ return ((defined $_wa) ? @_a : ());
Branch: 1 branch
BranchTrueFalseTotal
defined $_wa ? : 2 10 12
640 }
641  
642 ###############################################################################
643 ## ----------------------------------------------------------------------------
644 ## Private methods.
645 ##
646 ###############################################################################
647  
648 0 ▶sub _croak {
Subroutine _croak: not called CC=1 SCAR=6.9
649  
650 0 goto &MCE::_croak;
651 }
652  
653 6 ▶sub _gen_user_func {
Subroutine _gen_user_func: called CC=1 SCAR=0.0
654  
655 6 my ($_qref, $_cref, $_chunk_size, $_pos) = @_;
656  
657 6 my $_q_in = $_qref->[$_pos - 1];
658 6 my $_code = $_cref->[$_pos];
659  
660 10 ▶ return sub {
Subroutine __ANON__: called CC=2 SCAR=7.0
661 10 my ($_mce) = @_;
662  
663 0 ▶ $_mce->{_next_jmp} = sub { goto _MCE_STEP__NEXT; };
Subroutine __ANON__: not called CC=1 SCAR=1.2
664 0 ▶ $_mce->{_last_jmp} = sub { goto _MCE_STEP__LAST; };
Subroutine __ANON__: not called CC=1 SCAR=1.2
665  
666 _MCE_STEP__NEXT:
667  
668 10 ▶ while (defined (local $_ = $_q_in->dequeue())) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(local $_ = $_q_in->dequeue)) 21 10 31
669 21 my $_args = $_mce->thaw($_); $_ = $_args->[0];
670 21 $_code->($_mce, @{ $_args });
671 }
672  
673 _MCE_STEP__LAST:
674  
675 10 return;
676 6 };
677 }
678  
679 13 ▶sub _gen_user_tasks {
Subroutine _gen_user_tasks: called CC=2 SCAR=6.9
680  
681 13 my ($_pid, $_qref, $_cref, $_nref, $_tref, $_wref, $_chunk_size) = @_;
682  
683 13 @{ $_user_tasks->{$_pid} } = ();
684  
685 13 push @{ $_user_tasks->{$_pid} }, {
686 task_name => $_nref->[0],
687 use_threads => $_tref->[0],
688 max_workers => $_wref->[0],
689 30 ▶ user_func => sub { $_cref->[0]->(@_); return; }
Subroutine __ANON__: called CC=1 SCAR=0.0
690 13 };
691  
692 13 for my $_pos (1 .. @{ $_cref } - 1) {
693 6 push @{ $_user_tasks->{$_pid} }, {
694 task_name => $_nref->[$_pos],
695 use_threads => $_tref->[$_pos],
696 max_workers => $_wref->[$_pos],
697 user_func => _gen_user_func(
698 $_qref, $_cref, $_chunk_size, $_pos
699 )
700 };
701 }
702  
703 13 return;
704 }
705  
706 12 1;
707  
708 __END__
« MCE/Core/Worker.pm ↑ Summary MCE/Flow.pm »