line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
############################################################################### |
2
|
|
|
|
|
|
|
## ---------------------------------------------------------------------------- |
3
|
|
|
|
|
|
|
## MCE model for building parallel loops. |
4
|
|
|
|
|
|
|
## |
5
|
|
|
|
|
|
|
############################################################################### |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
package MCE::Loop; |
8
|
|
|
|
|
|
|
|
9
|
5
|
|
|
5
|
|
283690
|
use strict; |
|
5
|
|
|
|
|
50
|
|
|
5
|
|
|
|
|
154
|
|
10
|
5
|
|
|
5
|
|
29
|
use warnings; |
|
5
|
|
|
|
|
6
|
|
|
5
|
|
|
|
|
208
|
|
11
|
|
|
|
|
|
|
|
12
|
5
|
|
|
5
|
|
29
|
no warnings qw( threads recursion uninitialized ); |
|
5
|
|
|
|
|
10
|
|
|
5
|
|
|
|
|
317
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
our $VERSION = '1.889'; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
## no critic (BuiltinFunctions::ProhibitStringyEval) |
17
|
|
|
|
|
|
|
## no critic (Subroutines::ProhibitSubroutinePrototypes) |
18
|
|
|
|
|
|
|
## no critic (TestingAndDebugging::ProhibitNoStrict) |
19
|
|
|
|
|
|
|
|
20
|
5
|
|
|
5
|
|
35
|
use Scalar::Util qw( looks_like_number ); |
|
5
|
|
|
|
|
6
|
|
|
5
|
|
|
|
|
314
|
|
21
|
5
|
|
|
5
|
|
2568
|
use MCE; |
|
5
|
|
|
|
|
17
|
|
|
5
|
|
|
|
|
22
|
|
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
our @CARP_NOT = qw( MCE ); |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
my $_tid = $INC{'threads.pm'} ? threads->tid() : 0; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub CLONE { |
28
|
0
|
0
|
|
0
|
|
0
|
$_tid = threads->tid() if $INC{'threads.pm'}; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
############################################################################### |
32
|
|
|
|
|
|
|
## ---------------------------------------------------------------------------- |
33
|
|
|
|
|
|
|
## Import routine. |
34
|
|
|
|
|
|
|
## |
35
|
|
|
|
|
|
|
############################################################################### |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
my ($_MCE, $_def, $_params, $_prev_c, $_tag) = ({}, {}, {}, {}, 'MCE::Loop'); |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub import { |
40
|
5
|
|
|
5
|
|
81
|
my ($_class, $_pkg) = (shift, caller); |
41
|
|
|
|
|
|
|
|
42
|
5
|
|
|
|
|
26
|
my $_p = $_def->{$_pkg} = { |
43
|
|
|
|
|
|
|
MAX_WORKERS => 'auto', |
44
|
|
|
|
|
|
|
CHUNK_SIZE => 'auto', |
45
|
|
|
|
|
|
|
}; |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
## Import functions. |
48
|
5
|
50
|
|
|
|
16
|
if ($_pkg !~ /^MCE::/) { |
49
|
5
|
|
|
5
|
|
60
|
no strict 'refs'; no warnings 'redefine'; |
|
5
|
|
|
5
|
|
9
|
|
|
5
|
|
|
|
|
240
|
|
|
5
|
|
|
|
|
29
|
|
|
5
|
|
|
|
|
9
|
|
|
5
|
|
|
|
|
11356
|
|
50
|
5
|
|
|
|
|
14
|
*{ $_pkg.'::mce_loop_f' } = \&run_file; |
|
5
|
|
|
|
|
46
|
|
51
|
5
|
|
|
|
|
15
|
*{ $_pkg.'::mce_loop_s' } = \&run_seq; |
|
5
|
|
|
|
|
19
|
|
52
|
5
|
|
|
|
|
10
|
*{ $_pkg.'::mce_loop' } = \&run; |
|
5
|
|
|
|
|
15
|
|
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
## Process module arguments. |
56
|
5
|
|
|
|
|
20
|
while ( my $_argument = shift ) { |
57
|
0
|
|
|
|
|
0
|
my $_arg = lc $_argument; |
58
|
|
|
|
|
|
|
|
59
|
0
|
0
|
|
|
|
0
|
$_p->{MAX_WORKERS} = shift, next if ( $_arg eq 'max_workers' ); |
60
|
0
|
0
|
|
|
|
0
|
$_p->{CHUNK_SIZE} = shift, next if ( $_arg eq 'chunk_size' ); |
61
|
0
|
0
|
|
|
|
0
|
$_p->{TMP_DIR} = shift, next if ( $_arg eq 'tmp_dir' ); |
62
|
0
|
0
|
|
|
|
0
|
$_p->{FREEZE} = shift, next if ( $_arg eq 'freeze' ); |
63
|
0
|
0
|
|
|
|
0
|
$_p->{THAW} = shift, next if ( $_arg eq 'thaw' ); |
64
|
0
|
0
|
|
|
|
0
|
$_p->{INIT_RELAY} = shift, next if ( $_arg eq 'init_relay' ); |
65
|
0
|
0
|
|
|
|
0
|
$_p->{USE_THREADS} = shift, next if ( $_arg eq 'use_threads' ); |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
## Sereal 3.015+, if available, is used automatically by MCE 1.8+. |
68
|
0
|
0
|
|
|
|
0
|
if ( $_arg eq 'sereal' ) { |
69
|
0
|
0
|
|
|
|
0
|
if ( shift eq '0' ) { |
70
|
0
|
|
|
|
|
0
|
require Storable; |
71
|
0
|
|
|
|
|
0
|
$_p->{FREEZE} = \&Storable::freeze; |
72
|
0
|
|
|
|
|
0
|
$_p->{THAW} = \&Storable::thaw; |
73
|
|
|
|
|
|
|
} |
74
|
0
|
|
|
|
|
0
|
next; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
0
|
|
|
|
|
0
|
_croak("Error: ($_argument) invalid module option"); |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
5
|
|
|
|
|
24
|
$_p->{MAX_WORKERS} = MCE::_parse_max_workers($_p->{MAX_WORKERS}); |
81
|
|
|
|
|
|
|
|
82
|
5
|
|
|
|
|
16
|
MCE::_validate_number($_p->{MAX_WORKERS}, 'MAX_WORKERS', $_tag); |
83
|
|
|
|
|
|
|
MCE::_validate_number($_p->{CHUNK_SIZE}, 'CHUNK_SIZE', $_tag) |
84
|
5
|
50
|
|
|
|
16
|
unless ($_p->{CHUNK_SIZE} eq 'auto'); |
85
|
|
|
|
|
|
|
|
86
|
5
|
|
|
|
|
75
|
return; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
############################################################################### |
90
|
|
|
|
|
|
|
## ---------------------------------------------------------------------------- |
91
|
|
|
|
|
|
|
## Init and finish routines. |
92
|
|
|
|
|
|
|
## |
93
|
|
|
|
|
|
|
############################################################################### |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub init (@) { |
96
|
|
|
|
|
|
|
|
97
|
6
|
50
|
33
|
6
|
1
|
754
|
shift if (defined $_[0] && $_[0] eq 'MCE::Loop'); |
98
|
6
|
|
|
|
|
48
|
my $_pkg = "$$.$_tid.".caller(); |
99
|
|
|
|
|
|
|
|
100
|
6
|
50
|
|
|
|
102
|
$_params->{$_pkg} = (ref $_[0] eq 'HASH') ? shift : { @_ }; |
101
|
|
|
|
|
|
|
|
102
|
6
|
|
|
|
|
22
|
@_ = (); |
103
|
|
|
|
|
|
|
|
104
|
6
|
|
|
|
|
14
|
return; |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
sub finish (@) { |
108
|
|
|
|
|
|
|
|
109
|
11
|
50
|
33
|
11
|
1
|
3993
|
shift if (defined $_[0] && $_[0] eq 'MCE::Loop'); |
110
|
11
|
100
|
|
|
|
115
|
my $_pkg = (defined $_[0]) ? shift : "$$.$_tid.".caller(); |
111
|
|
|
|
|
|
|
|
112
|
11
|
100
|
66
|
|
|
168
|
if ( $_pkg eq 'MCE' ) { |
|
|
100
|
|
|
|
|
|
113
|
5
|
|
|
|
|
10
|
for my $_k ( keys %{ $_MCE } ) { MCE::Loop->finish($_k, 1); } |
|
5
|
|
|
|
|
44
|
|
|
3
|
|
|
|
|
79
|
|
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
elsif ( $_MCE->{$_pkg} && $_MCE->{$_pkg}{_init_pid} eq "$$.$_tid" ) { |
116
|
3
|
50
|
|
|
|
67
|
$_MCE->{$_pkg}->shutdown(@_) if $_MCE->{$_pkg}{_spawned}; |
117
|
|
|
|
|
|
|
|
118
|
3
|
|
|
|
|
19
|
delete $_prev_c->{$_pkg}; |
119
|
3
|
|
|
|
|
29
|
delete $_MCE->{$_pkg}; |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
11
|
|
|
|
|
38
|
@_ = (); |
123
|
|
|
|
|
|
|
|
124
|
11
|
|
|
|
|
40
|
return; |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
############################################################################### |
128
|
|
|
|
|
|
|
## ---------------------------------------------------------------------------- |
129
|
|
|
|
|
|
|
## Parallel loop with MCE -- file. |
130
|
|
|
|
|
|
|
## |
131
|
|
|
|
|
|
|
############################################################################### |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
sub run_file (&@) { |
134
|
|
|
|
|
|
|
|
135
|
4
|
50
|
33
|
4
|
1
|
3062
|
shift if (defined $_[0] && $_[0] eq 'MCE::Loop'); |
136
|
|
|
|
|
|
|
|
137
|
4
|
|
|
|
|
34
|
my $_code = shift; my $_file = shift; |
|
4
|
|
|
|
|
10
|
|
138
|
4
|
|
|
|
|
22
|
my $_pid = "$$.$_tid.".caller(); |
139
|
|
|
|
|
|
|
|
140
|
4
|
50
|
|
|
|
16
|
if (defined (my $_p = $_params->{$_pid})) { |
141
|
4
|
50
|
|
|
|
8
|
delete $_p->{input_data} if (exists $_p->{input_data}); |
142
|
4
|
50
|
|
|
|
12
|
delete $_p->{sequence} if (exists $_p->{sequence}); |
143
|
|
|
|
|
|
|
} |
144
|
|
|
|
|
|
|
else { |
145
|
0
|
|
|
|
|
0
|
$_params->{$_pid} = {}; |
146
|
|
|
|
|
|
|
} |
147
|
|
|
|
|
|
|
|
148
|
4
|
100
|
66
|
|
|
116
|
if (defined $_file && ref $_file eq '' && $_file ne '') { |
|
|
50
|
66
|
|
|
|
|
|
|
|
33
|
|
|
|
|
149
|
2
|
50
|
|
|
|
80
|
_croak("$_tag: ($_file) does not exist") unless (-e $_file); |
150
|
2
|
50
|
|
|
|
36
|
_croak("$_tag: ($_file) is not readable") unless (-r $_file); |
151
|
2
|
50
|
|
|
|
28
|
_croak("$_tag: ($_file) is not a plain file") unless (-f $_file); |
152
|
2
|
|
|
|
|
22
|
$_params->{$_pid}{_file} = $_file; |
153
|
|
|
|
|
|
|
} |
154
|
|
|
|
|
|
|
elsif (ref $_file eq 'SCALAR' || ref($_file) =~ /^(?:GLOB|FileHandle|IO::)/) { |
155
|
2
|
|
|
|
|
8
|
$_params->{$_pid}{_file} = $_file; |
156
|
|
|
|
|
|
|
} |
157
|
|
|
|
|
|
|
else { |
158
|
0
|
|
|
|
|
0
|
_croak("$_tag: (file) is not specified or valid"); |
159
|
|
|
|
|
|
|
} |
160
|
|
|
|
|
|
|
|
161
|
4
|
|
|
|
|
12
|
@_ = (); |
162
|
|
|
|
|
|
|
|
163
|
4
|
|
|
|
|
12
|
return run($_code); |
164
|
|
|
|
|
|
|
} |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
############################################################################### |
167
|
|
|
|
|
|
|
## ---------------------------------------------------------------------------- |
168
|
|
|
|
|
|
|
## Parallel loop with MCE -- sequence. |
169
|
|
|
|
|
|
|
## |
170
|
|
|
|
|
|
|
############################################################################### |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
sub run_seq (&@) { |
173
|
|
|
|
|
|
|
|
174
|
2
|
50
|
33
|
2
|
1
|
1524
|
shift if (defined $_[0] && $_[0] eq 'MCE::Loop'); |
175
|
|
|
|
|
|
|
|
176
|
2
|
|
|
|
|
8
|
my $_code = shift; |
177
|
2
|
|
|
|
|
12
|
my $_pid = "$$.$_tid.".caller(); |
178
|
|
|
|
|
|
|
|
179
|
2
|
50
|
|
|
|
10
|
if (defined (my $_p = $_params->{$_pid})) { |
180
|
2
|
50
|
|
|
|
6
|
delete $_p->{input_data} if (exists $_p->{input_data}); |
181
|
2
|
50
|
|
|
|
6
|
delete $_p->{_file} if (exists $_p->{_file}); |
182
|
|
|
|
|
|
|
} |
183
|
|
|
|
|
|
|
else { |
184
|
0
|
|
|
|
|
0
|
$_params->{$_pid} = {}; |
185
|
|
|
|
|
|
|
} |
186
|
|
|
|
|
|
|
|
187
|
2
|
|
|
|
|
8
|
my ($_begin, $_end); |
188
|
|
|
|
|
|
|
|
189
|
2
|
50
|
33
|
|
|
14
|
if (ref $_[0] eq 'HASH') { |
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
190
|
0
|
|
|
|
|
0
|
$_begin = $_[0]->{begin}, $_end = $_[0]->{end}; |
191
|
0
|
|
|
|
|
0
|
$_params->{$_pid}{sequence} = $_[0]; |
192
|
|
|
|
|
|
|
} |
193
|
|
|
|
|
|
|
elsif (ref $_[0] eq 'ARRAY') { |
194
|
0
|
0
|
0
|
|
|
0
|
if (@{ $_[0] } > 3 && $_[0]->[3] =~ /\d$/) { |
|
0
|
|
|
|
|
0
|
|
195
|
0
|
|
|
|
|
0
|
$_begin = $_[0]->[0], $_end = $_[0]->[-1]; |
196
|
0
|
|
|
|
|
0
|
$_params->{$_pid}{sequence} = [ $_[0]->[0], $_[0]->[-1] ]; |
197
|
|
|
|
|
|
|
} |
198
|
|
|
|
|
|
|
else { |
199
|
0
|
|
|
|
|
0
|
$_begin = $_[0]->[0], $_end = $_[0]->[1]; |
200
|
0
|
|
|
|
|
0
|
$_params->{$_pid}{sequence} = $_[0]; |
201
|
|
|
|
|
|
|
} |
202
|
|
|
|
|
|
|
} |
203
|
|
|
|
|
|
|
elsif (ref $_[0] eq '' || ref($_[0]) =~ /^Math::/) { |
204
|
2
|
50
|
33
|
|
|
10
|
if (@_ > 3 && $_[3] =~ /\d$/) { |
205
|
0
|
|
|
|
|
0
|
$_begin = $_[0], $_end = $_[-1]; |
206
|
0
|
|
|
|
|
0
|
$_params->{$_pid}{sequence} = [ $_[0], $_[-1] ]; |
207
|
|
|
|
|
|
|
} |
208
|
|
|
|
|
|
|
else { |
209
|
2
|
|
|
|
|
6
|
$_begin = $_[0], $_end = $_[1]; |
210
|
2
|
|
|
|
|
6
|
$_params->{$_pid}{sequence} = [ @_ ]; |
211
|
|
|
|
|
|
|
} |
212
|
|
|
|
|
|
|
} |
213
|
|
|
|
|
|
|
else { |
214
|
0
|
|
|
|
|
0
|
_croak("$_tag: (sequence) is not specified or valid"); |
215
|
|
|
|
|
|
|
} |
216
|
|
|
|
|
|
|
|
217
|
2
|
50
|
|
|
|
6
|
_croak("$_tag: (begin) is not specified for sequence") |
218
|
|
|
|
|
|
|
unless (defined $_begin); |
219
|
2
|
50
|
|
|
|
6
|
_croak("$_tag: (end) is not specified for sequence") |
220
|
|
|
|
|
|
|
unless (defined $_end); |
221
|
|
|
|
|
|
|
|
222
|
2
|
|
|
|
|
4
|
$_params->{$_pid}{sequence_run} = undef; |
223
|
|
|
|
|
|
|
|
224
|
2
|
|
|
|
|
6
|
@_ = (); |
225
|
|
|
|
|
|
|
|
226
|
2
|
|
|
|
|
8
|
return run($_code); |
227
|
|
|
|
|
|
|
} |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
############################################################################### |
230
|
|
|
|
|
|
|
## ---------------------------------------------------------------------------- |
231
|
|
|
|
|
|
|
## Parallel loop with MCE. |
232
|
|
|
|
|
|
|
## |
233
|
|
|
|
|
|
|
############################################################################### |
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
sub run (&@) { |
236
|
|
|
|
|
|
|
|
237
|
14
|
50
|
33
|
14
|
1
|
5156
|
shift if (defined $_[0] && $_[0] eq 'MCE::Loop'); |
238
|
|
|
|
|
|
|
|
239
|
14
|
|
|
|
|
40
|
my $_code = shift; |
240
|
14
|
100
|
|
|
|
80
|
my $_pkg = caller() eq 'MCE::Loop' ? caller(1) : caller(); |
241
|
14
|
|
|
|
|
56
|
my $_pid = "$$.$_tid.$_pkg"; |
242
|
|
|
|
|
|
|
|
243
|
14
|
|
|
|
|
24
|
my $_input_data; my $_max_workers = $_def->{$_pkg}{MAX_WORKERS}; |
|
14
|
|
|
|
|
36
|
|
244
|
14
|
|
|
|
|
30
|
my $_r = ref $_[0]; |
245
|
|
|
|
|
|
|
|
246
|
14
|
100
|
66
|
|
|
100
|
if (@_ == 1 && $_r =~ /^(?:ARRAY|HASH|SCALAR|CODE|GLOB|FileHandle|IO::)/) { |
247
|
4
|
|
|
|
|
14
|
$_input_data = shift; |
248
|
|
|
|
|
|
|
} |
249
|
|
|
|
|
|
|
|
250
|
14
|
50
|
|
|
|
38
|
if (defined (my $_p = $_params->{$_pid})) { |
251
|
|
|
|
|
|
|
$_max_workers = MCE::_parse_max_workers($_p->{max_workers}) |
252
|
14
|
50
|
|
|
|
106
|
if (exists $_p->{max_workers}); |
253
|
|
|
|
|
|
|
|
254
|
14
|
100
|
100
|
|
|
86
|
delete $_p->{sequence} if (defined $_input_data || scalar @_); |
255
|
14
|
50
|
|
|
|
40
|
delete $_p->{user_func} if (exists $_p->{user_func}); |
256
|
14
|
50
|
|
|
|
54
|
delete $_p->{user_tasks} if (exists $_p->{user_tasks}); |
257
|
|
|
|
|
|
|
} |
258
|
|
|
|
|
|
|
|
259
|
|
|
|
|
|
|
my $_chunk_size = MCE::_parse_chunk_size( |
260
|
14
|
|
|
|
|
120
|
$_def->{$_pkg}{CHUNK_SIZE}, $_max_workers, $_params->{$_pid}, |
261
|
|
|
|
|
|
|
$_input_data, scalar @_ |
262
|
|
|
|
|
|
|
); |
263
|
|
|
|
|
|
|
|
264
|
14
|
50
|
|
|
|
98
|
if (defined (my $_p = $_params->{$_pid})) { |
265
|
14
|
100
|
|
|
|
42
|
if (exists $_p->{_file}) { |
266
|
4
|
|
|
|
|
8
|
$_input_data = delete $_p->{_file}; |
267
|
|
|
|
|
|
|
} else { |
268
|
10
|
50
|
|
|
|
28
|
$_input_data = $_p->{input_data} if exists $_p->{input_data}; |
269
|
|
|
|
|
|
|
} |
270
|
|
|
|
|
|
|
} |
271
|
|
|
|
|
|
|
|
272
|
|
|
|
|
|
|
## ------------------------------------------------------------------------- |
273
|
|
|
|
|
|
|
|
274
|
14
|
|
|
|
|
92
|
MCE::_save_state($_MCE->{$_pid}); |
275
|
|
|
|
|
|
|
|
276
|
14
|
100
|
66
|
|
|
106
|
if (!defined $_prev_c->{$_pid} || $_prev_c->{$_pid} != $_code) { |
277
|
6
|
50
|
|
|
|
26
|
$_MCE->{$_pid}->shutdown() if (defined $_MCE->{$_pid}); |
278
|
6
|
|
|
|
|
18
|
$_prev_c->{$_pid} = $_code; |
279
|
|
|
|
|
|
|
|
280
|
6
|
|
|
|
|
48
|
my %_opts = ( |
281
|
|
|
|
|
|
|
max_workers => $_max_workers, task_name => $_tag, |
282
|
|
|
|
|
|
|
user_func => $_code, |
283
|
|
|
|
|
|
|
); |
284
|
|
|
|
|
|
|
|
285
|
6
|
50
|
|
|
|
32
|
if (defined (my $_p = $_params->{$_pid})) { |
286
|
6
|
|
|
|
|
10
|
for my $_k (keys %{ $_p }) { |
|
6
|
|
|
|
|
36
|
|
287
|
10
|
50
|
|
|
|
20
|
next if ($_k eq 'sequence_run'); |
288
|
10
|
50
|
|
|
|
30
|
next if ($_k eq 'input_data'); |
289
|
10
|
50
|
|
|
|
32
|
next if ($_k eq 'chunk_size'); |
290
|
|
|
|
|
|
|
|
291
|
|
|
|
|
|
|
_croak("$_tag: ($_k) is not a valid constructor argument") |
292
|
10
|
50
|
|
|
|
36
|
unless (exists $MCE::_valid_fields_new{$_k}); |
293
|
|
|
|
|
|
|
|
294
|
10
|
|
|
|
|
22
|
$_opts{$_k} = $_p->{$_k}; |
295
|
|
|
|
|
|
|
} |
296
|
|
|
|
|
|
|
} |
297
|
|
|
|
|
|
|
|
298
|
6
|
|
|
|
|
20
|
for my $_k (qw/ tmp_dir freeze thaw init_relay use_threads /) { |
299
|
|
|
|
|
|
|
$_opts{$_k} = $_def->{$_pkg}{uc($_k)} |
300
|
30
|
50
|
33
|
|
|
124
|
if (exists $_def->{$_pkg}{uc($_k)} && !exists $_opts{$_k}); |
301
|
|
|
|
|
|
|
} |
302
|
|
|
|
|
|
|
|
303
|
6
|
|
|
|
|
102
|
$_MCE->{$_pid} = MCE->new(pkg => $_pkg, %_opts); |
304
|
|
|
|
|
|
|
} |
305
|
|
|
|
|
|
|
|
306
|
|
|
|
|
|
|
## ------------------------------------------------------------------------- |
307
|
|
|
|
|
|
|
|
308
|
14
|
100
|
|
|
|
34
|
my @_a; my $_wa = wantarray; $_MCE->{$_pid}{gather} = \@_a if (defined $_wa); |
|
14
|
|
|
|
|
22
|
|
|
14
|
|
|
|
|
36
|
|
309
|
|
|
|
|
|
|
|
310
|
14
|
100
|
|
|
|
42
|
if (defined $_input_data) { |
|
|
100
|
|
|
|
|
|
311
|
8
|
|
|
|
|
20
|
@_ = (); |
312
|
8
|
|
|
|
|
66
|
$_MCE->{$_pid}->process({ chunk_size => $_chunk_size }, $_input_data); |
313
|
7
|
|
|
|
|
41
|
delete $_MCE->{$_pid}{input_data}; |
314
|
|
|
|
|
|
|
} |
315
|
|
|
|
|
|
|
elsif (scalar @_) { |
316
|
4
|
|
|
|
|
40
|
$_MCE->{$_pid}->process({ chunk_size => $_chunk_size }, \@_); |
317
|
2
|
|
|
|
|
32
|
delete $_MCE->{$_pid}{input_data}; |
318
|
|
|
|
|
|
|
} |
319
|
|
|
|
|
|
|
else { |
320
|
2
|
50
|
33
|
|
|
32
|
if (defined $_params->{$_pid} && exists $_params->{$_pid}{sequence}) { |
321
|
|
|
|
|
|
|
$_MCE->{$_pid}->run({ |
322
|
|
|
|
|
|
|
chunk_size => $_chunk_size, |
323
|
|
|
|
|
|
|
sequence => $_params->{$_pid}{sequence} |
324
|
2
|
|
|
|
|
14
|
}, 0); |
325
|
2
|
50
|
|
|
|
14
|
if (exists $_params->{$_pid}{sequence_run}) { |
326
|
2
|
|
|
|
|
4
|
delete $_params->{$_pid}{sequence_run}; |
327
|
2
|
|
|
|
|
6
|
delete $_params->{$_pid}{sequence}; |
328
|
|
|
|
|
|
|
} |
329
|
2
|
|
|
|
|
8
|
delete $_MCE->{$_pid}{sequence}; |
330
|
|
|
|
|
|
|
} |
331
|
|
|
|
|
|
|
} |
332
|
|
|
|
|
|
|
|
333
|
11
|
|
|
|
|
90
|
MCE::_restore_state(); |
334
|
|
|
|
|
|
|
|
335
|
11
|
100
|
|
|
|
30
|
delete $_MCE->{$_pid}{gather} if (defined $_wa); |
336
|
|
|
|
|
|
|
|
337
|
11
|
100
|
|
|
|
196
|
return ((defined $_wa) ? @_a : ()); |
338
|
|
|
|
|
|
|
} |
339
|
|
|
|
|
|
|
|
340
|
|
|
|
|
|
|
############################################################################### |
341
|
|
|
|
|
|
|
## ---------------------------------------------------------------------------- |
342
|
|
|
|
|
|
|
## Private methods. |
343
|
|
|
|
|
|
|
## |
344
|
|
|
|
|
|
|
############################################################################### |
345
|
|
|
|
|
|
|
|
346
|
|
|
|
|
|
|
sub _croak { |
347
|
|
|
|
|
|
|
|
348
|
0
|
|
|
0
|
|
|
goto &MCE::_croak; |
349
|
|
|
|
|
|
|
} |
350
|
|
|
|
|
|
|
|
351
|
|
|
|
|
|
|
1; |
352
|
|
|
|
|
|
|
|
353
|
|
|
|
|
|
|
__END__ |