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