line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
############################################################################### |
2
|
|
|
|
|
|
|
## ---------------------------------------------------------------------------- |
3
|
|
|
|
|
|
|
## Core validation methods for Many-Core Engine. |
4
|
|
|
|
|
|
|
## |
5
|
|
|
|
|
|
|
## This package provides validation methods used internally by the manager |
6
|
|
|
|
|
|
|
## process. |
7
|
|
|
|
|
|
|
## |
8
|
|
|
|
|
|
|
## There is no public API. |
9
|
|
|
|
|
|
|
## |
10
|
|
|
|
|
|
|
############################################################################### |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
package MCE::Core::Validation; |
13
|
|
|
|
|
|
|
|
14
|
85
|
|
|
85
|
|
593
|
use strict; |
|
85
|
|
|
|
|
155
|
|
|
85
|
|
|
|
|
2489
|
|
15
|
85
|
|
|
85
|
|
417
|
use warnings; |
|
85
|
|
|
|
|
150
|
|
|
85
|
|
|
|
|
3844
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
our $VERSION = '1.889'; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
## Items below are folded into MCE. |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
package # hide from rpm |
22
|
|
|
|
|
|
|
MCE; |
23
|
|
|
|
|
|
|
|
24
|
85
|
|
|
85
|
|
440
|
no warnings qw( threads recursion uninitialized ); |
|
85
|
|
|
|
|
188
|
|
|
85
|
|
|
|
|
211257
|
|
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
############################################################################### |
27
|
|
|
|
|
|
|
## ---------------------------------------------------------------------------- |
28
|
|
|
|
|
|
|
## Validation method (attributes allowed for top-level). |
29
|
|
|
|
|
|
|
## |
30
|
|
|
|
|
|
|
############################################################################### |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub _validate_args { |
33
|
|
|
|
|
|
|
|
34
|
421
|
|
|
421
|
|
1126
|
my $_s = $_[0]; |
35
|
|
|
|
|
|
|
|
36
|
421
|
|
|
|
|
905
|
@_ = (); |
37
|
|
|
|
|
|
|
|
38
|
421
|
|
|
|
|
942
|
my $_tag = 'MCE::_validate_args'; |
39
|
|
|
|
|
|
|
|
40
|
421
|
100
|
100
|
|
|
1888
|
if (defined $_s->{input_data} && ref $_s->{input_data} eq '') { |
41
|
|
|
|
|
|
|
_croak("$_tag: ($_s->{input_data}) does not exist") |
42
|
18
|
50
|
|
|
|
274
|
unless (-e $_s->{input_data}); |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
421
|
|
|
|
|
1098
|
for my $_k (qw(job_delay spawn_delay submit_delay loop_timeout)) { |
46
|
|
|
|
|
|
|
_croak("$_tag: ($_k) is not valid") |
47
|
1684
|
0
|
0
|
|
|
3687
|
if ($_s->{$_k} && (!looks_like_number($_s->{$_k}) || $_s->{$_k} < 0)); |
|
|
|
33
|
|
|
|
|
48
|
|
|
|
|
|
|
} |
49
|
421
|
|
|
|
|
1030
|
for my $_k (qw(freeze thaw on_post_exit on_post_run user_error user_output)) { |
50
|
|
|
|
|
|
|
_croak("$_tag: ($_k) is not a CODE reference") |
51
|
2526
|
50
|
66
|
|
|
7356
|
if ($_s->{$_k} && ref $_s->{$_k} ne 'CODE'); |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
421
|
|
|
|
|
1361
|
_validate_args_s($_s); |
55
|
|
|
|
|
|
|
|
56
|
421
|
100
|
|
|
|
1025
|
if (defined $_s->{user_tasks}) { |
57
|
257
|
|
|
|
|
467
|
for my $_t (@{ $_s->{user_tasks} }) { |
|
257
|
|
|
|
|
780
|
|
58
|
406
|
|
|
|
|
788
|
_validate_args_s($_s, $_t); |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
421
|
|
|
|
|
1121
|
return; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
############################################################################### |
66
|
|
|
|
|
|
|
## ---------------------------------------------------------------------------- |
67
|
|
|
|
|
|
|
## Validation method (top-level and sub-tasks). |
68
|
|
|
|
|
|
|
## |
69
|
|
|
|
|
|
|
############################################################################### |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub _validate_args_s { |
72
|
|
|
|
|
|
|
|
73
|
827
|
|
66
|
827
|
|
1256
|
my $self = $_[0]; my $_s = $_[1] || $self; |
|
827
|
|
|
|
|
2390
|
|
74
|
|
|
|
|
|
|
|
75
|
827
|
|
|
|
|
1417
|
@_ = (); |
76
|
|
|
|
|
|
|
|
77
|
827
|
|
|
|
|
1273
|
my $_tag = 'MCE::_validate_args_s'; |
78
|
|
|
|
|
|
|
|
79
|
827
|
50
|
|
|
|
1834
|
if (defined $_s->{max_workers}) { |
80
|
827
|
|
|
|
|
1860
|
$_s->{max_workers} = _parse_max_workers($_s->{max_workers}); |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
_croak("$_tag: (max_workers) is not valid") |
83
|
827
|
50
|
|
|
|
4319
|
if ($_s->{max_workers} !~ /\A\d+\z/); |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
827
|
100
|
|
|
|
2015
|
if (defined $_s->{chunk_size}) { |
87
|
421
|
50
|
|
|
|
1920
|
if ($_s->{chunk_size} =~ /([0-9\.]+)K\z/i) { |
|
|
50
|
|
|
|
|
|
88
|
0
|
|
|
|
|
0
|
$_s->{chunk_size} = int($1 * 1024 + 0.5); |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
elsif ($_s->{chunk_size} =~ /([0-9\.]+)M\z/i) { |
91
|
0
|
|
|
|
|
0
|
$_s->{chunk_size} = int($1 * 1024 * 1024 + 0.5); |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
_croak("$_tag: (chunk_size) is not valid") |
95
|
421
|
50
|
33
|
|
|
3391
|
if ($_s->{chunk_size} !~ /\A[0-9e\+]+\z/ or $_s->{chunk_size} == 0); |
96
|
|
|
|
|
|
|
|
97
|
421
|
|
|
|
|
1137
|
$_s->{chunk_size} = int($_s->{chunk_size}); |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
_croak("$_tag: (RS) is not valid") |
101
|
827
|
50
|
33
|
|
|
1941
|
if ($_s->{RS} && ref $_s->{RS} ne ''); |
102
|
|
|
|
|
|
|
_croak("$_tag: (max_retries) is not valid") |
103
|
827
|
50
|
33
|
|
|
1799
|
if ($_s->{max_retries} && $_s->{max_retries} !~ /\A\d+\z/); |
104
|
|
|
|
|
|
|
|
105
|
827
|
|
|
|
|
1648
|
for my $_k (qw(progress user_begin user_end user_func task_end)) { |
106
|
|
|
|
|
|
|
_croak("$_tag: ($_k) is not a CODE reference") |
107
|
4135
|
50
|
66
|
|
|
10383
|
if ($_s->{$_k} && ref $_s->{$_k} ne 'CODE'); |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
827
|
100
|
|
|
|
1787
|
if (defined $_s->{gather}) { |
111
|
268
|
|
|
|
|
620
|
my $_ref = ref $_s->{gather}; |
112
|
|
|
|
|
|
|
|
113
|
268
|
50
|
66
|
|
|
2273
|
_croak("$_tag: (gather) is not a valid reference") |
|
|
|
100
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
|
66
|
|
|
|
|
114
|
|
|
|
|
|
|
if ( $_ref ne 'MCE::Queue' && $_ref ne 'Thread::Queue' && |
115
|
|
|
|
|
|
|
$_ref ne 'ARRAY' && $_ref ne 'HASH' && $_ref ne 'CODE' ); |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
|
118
|
827
|
100
|
|
|
|
1738
|
if (defined $_s->{sequence}) { |
119
|
18
|
|
|
|
|
42
|
my $_seq = $_s->{sequence}; |
120
|
|
|
|
|
|
|
|
121
|
18
|
50
|
|
|
|
72
|
if (ref $_seq eq 'ARRAY') { |
122
|
18
|
|
|
|
|
31
|
my ($_begin, $_end, $_step, $_fmt) = @{ $_seq }; |
|
18
|
|
|
|
|
53
|
|
123
|
18
|
|
|
|
|
173
|
$_seq = { |
124
|
|
|
|
|
|
|
begin => $_begin, end => $_end, step => $_step, format => $_fmt |
125
|
|
|
|
|
|
|
}; |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
else { |
128
|
0
|
0
|
|
|
|
0
|
_croak("$_tag: (sequence) is not a HASH or ARRAY reference") |
129
|
|
|
|
|
|
|
if (ref $_seq ne 'HASH'); |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
18
|
|
|
|
|
59
|
for my $_k (qw(begin end)) { |
133
|
|
|
|
|
|
|
_croak("$_tag: ($_k) is not defined for sequence") |
134
|
36
|
50
|
|
|
|
109
|
unless (defined $_seq->{$_k}); |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
|
137
|
18
|
|
|
|
|
46
|
for my $_p (qw(begin end step)) { |
138
|
|
|
|
|
|
|
_croak("$_tag: ($_p) is not valid for sequence") |
139
|
54
|
50
|
66
|
|
|
314
|
if (defined $_seq->{$_p} && !looks_like_number($_seq->{$_p})); |
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
|
142
|
18
|
50
|
|
|
|
61
|
unless (defined $_seq->{step}) { |
143
|
18
|
50
|
|
|
|
71
|
$_seq->{step} = ($_seq->{begin} <= $_seq->{end}) ? 1 : -1; |
144
|
18
|
50
|
|
|
|
82
|
if (ref $_s->{sequence} eq 'ARRAY') { |
145
|
18
|
|
|
|
|
55
|
$_s->{sequence}->[2] = $_seq->{step}; |
146
|
|
|
|
|
|
|
} |
147
|
|
|
|
|
|
|
} |
148
|
|
|
|
|
|
|
|
149
|
18
|
50
|
|
|
|
56
|
if (ref $_s->{sequence} eq 'HASH') { |
150
|
0
|
|
|
|
|
0
|
for my $_k ('begin', 'end', 'step') { |
151
|
|
|
|
|
|
|
$_s->{sequence}{$_k} = int($_s->{sequence}{$_k}) |
152
|
0
|
0
|
|
|
|
0
|
unless ($_s->{sequence}{$_k} =~ /\./); |
153
|
|
|
|
|
|
|
} |
154
|
|
|
|
|
|
|
} |
155
|
|
|
|
|
|
|
else { |
156
|
18
|
|
|
|
|
48
|
for my $_i (0, 1, 2) { |
157
|
|
|
|
|
|
|
$_s->{sequence}[$_i] = int($_s->{sequence}[$_i]) |
158
|
54
|
50
|
|
|
|
184
|
unless ($_s->{sequence}[$_i] =~ /\./); |
159
|
|
|
|
|
|
|
} |
160
|
|
|
|
|
|
|
} |
161
|
|
|
|
|
|
|
|
162
|
18
|
50
|
33
|
|
|
349
|
if ( ($_seq->{step} < 0 && $_seq->{begin} < $_seq->{end}) || |
|
|
|
33
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
33
|
|
|
|
|
163
|
|
|
|
|
|
|
($_seq->{step} > 0 && $_seq->{begin} > $_seq->{end}) || |
164
|
|
|
|
|
|
|
($_seq->{step} == 0) |
165
|
|
|
|
|
|
|
) { |
166
|
0
|
|
|
|
|
0
|
_croak("$_tag: impossible (step size) for sequence"); |
167
|
|
|
|
|
|
|
} |
168
|
|
|
|
|
|
|
} |
169
|
|
|
|
|
|
|
|
170
|
827
|
50
|
|
|
|
1641
|
if (defined $_s->{interval}) { |
171
|
0
|
0
|
|
|
|
0
|
if (ref $_s->{interval} eq '') { |
172
|
0
|
|
|
|
|
0
|
$_s->{interval} = { delay => $_s->{interval} }; |
173
|
|
|
|
|
|
|
} |
174
|
|
|
|
|
|
|
|
175
|
0
|
|
|
|
|
0
|
my $_i = $_s->{interval}; |
176
|
|
|
|
|
|
|
|
177
|
0
|
0
|
|
|
|
0
|
_croak("$_tag: (interval) is not a HASH reference") |
178
|
|
|
|
|
|
|
if (ref $_i ne 'HASH'); |
179
|
|
|
|
|
|
|
_croak("$_tag: (delay) is not defined for interval") |
180
|
0
|
0
|
|
|
|
0
|
unless (defined $_i->{delay}); |
181
|
|
|
|
|
|
|
_croak("$_tag: (delay) is not valid for interval") |
182
|
0
|
0
|
0
|
|
|
0
|
if (!looks_like_number($_i->{delay}) || $_i->{delay} < 0); |
183
|
|
|
|
|
|
|
|
184
|
0
|
|
|
|
|
0
|
for my $_p (qw(max_nodes node_id)) { |
185
|
|
|
|
|
|
|
_croak("$_tag: ($_p) is not valid for interval") |
186
|
|
|
|
|
|
|
if (defined $_i->{$_p} && ( |
187
|
|
|
|
|
|
|
!looks_like_number($_i->{$_p}) || |
188
|
|
|
|
|
|
|
int($_i->{$_p}) != $_i->{$_p} || |
189
|
0
|
0
|
0
|
|
|
0
|
$_i->{$_p} < 1 |
|
|
|
0
|
|
|
|
|
190
|
|
|
|
|
|
|
)); |
191
|
|
|
|
|
|
|
} |
192
|
|
|
|
|
|
|
|
193
|
0
|
0
|
|
|
|
0
|
$_i->{max_nodes} = 1 unless (exists $_i->{max_nodes}); |
194
|
0
|
0
|
|
|
|
0
|
$_i->{node_id} = 1 unless (exists $_i->{node_id}); |
195
|
0
|
|
|
|
|
0
|
$_i->{_time} = MCE::Util::_time(); |
196
|
|
|
|
|
|
|
} |
197
|
|
|
|
|
|
|
|
198
|
827
|
|
|
|
|
1590
|
return; |
199
|
|
|
|
|
|
|
} |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
############################################################################### |
202
|
|
|
|
|
|
|
## ---------------------------------------------------------------------------- |
203
|
|
|
|
|
|
|
## Validation method (run state). |
204
|
|
|
|
|
|
|
## |
205
|
|
|
|
|
|
|
############################################################################### |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
sub _validate_runstate { |
208
|
|
|
|
|
|
|
|
209
|
167
|
|
|
167
|
|
410
|
my $self = $_[0]; my $_tag = $_[1]; |
|
167
|
|
|
|
|
855
|
|
210
|
|
|
|
|
|
|
|
211
|
167
|
|
|
|
|
441
|
@_ = (); |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
_croak("$_tag: method is not allowed by the worker process") |
214
|
167
|
50
|
|
|
|
585
|
if ($self->{_wid}); |
215
|
|
|
|
|
|
|
_croak("$_tag: method is not allowed while processing") |
216
|
167
|
50
|
|
|
|
555
|
if ($self->{_send_cnt}); |
217
|
|
|
|
|
|
|
_croak("$_tag: method is not allowed while running") |
218
|
167
|
50
|
|
|
|
490
|
if ($self->{_total_running}); |
219
|
|
|
|
|
|
|
|
220
|
167
|
|
|
|
|
411
|
return; |
221
|
|
|
|
|
|
|
} |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
############################################################################### |
224
|
|
|
|
|
|
|
## ---------------------------------------------------------------------------- |
225
|
|
|
|
|
|
|
## Private functions for MCE Models { Flow, Grep, Loop, Map, Step, Stream }. |
226
|
|
|
|
|
|
|
## |
227
|
|
|
|
|
|
|
############################################################################### |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
sub _parse_chunk_size { |
230
|
|
|
|
|
|
|
|
231
|
182
|
|
|
182
|
|
792
|
my ($_chunk_size, $_max_workers, $_params, $_input_data, $_array_size) = @_; |
232
|
|
|
|
|
|
|
|
233
|
182
|
|
|
|
|
437
|
@_ = (); |
234
|
|
|
|
|
|
|
|
235
|
182
|
50
|
33
|
|
|
1068
|
return $_chunk_size if (!defined $_chunk_size || !defined $_max_workers); |
236
|
|
|
|
|
|
|
|
237
|
182
|
50
|
33
|
|
|
1288
|
if (defined $_params && exists $_params->{chunk_size}) { |
238
|
0
|
|
|
|
|
0
|
$_chunk_size = $_params->{chunk_size}; |
239
|
|
|
|
|
|
|
} |
240
|
|
|
|
|
|
|
|
241
|
182
|
50
|
|
|
|
1621
|
if ($_chunk_size =~ /([0-9\.]+)K\z/i) { |
|
|
50
|
|
|
|
|
|
242
|
0
|
|
|
|
|
0
|
$_chunk_size = int($1 * 1024 + 0.5); |
243
|
|
|
|
|
|
|
} |
244
|
|
|
|
|
|
|
elsif ($_chunk_size =~ /([0-9\.]+)M\z/i) { |
245
|
0
|
|
|
|
|
0
|
$_chunk_size = int($1 * 1024 * 1024 + 0.5); |
246
|
|
|
|
|
|
|
} |
247
|
|
|
|
|
|
|
|
248
|
182
|
50
|
|
|
|
667
|
if ($_chunk_size eq 'auto') { |
249
|
|
|
|
|
|
|
|
250
|
182
|
50
|
33
|
|
|
1719
|
if ( (defined $_params && ref $_params->{input_data} eq 'CODE') || |
|
|
|
66
|
|
|
|
|
|
|
|
33
|
|
|
|
|
251
|
|
|
|
|
|
|
(defined $_input_data && ref $_input_data eq 'CODE') |
252
|
|
|
|
|
|
|
) { |
253
|
|
|
|
|
|
|
# Iterators may optionally use chunk_size to determine how much |
254
|
|
|
|
|
|
|
# to return per iteration. The default is 1 for MCE Models, same |
255
|
|
|
|
|
|
|
# as for the Core API. The user_func receives an array_ref |
256
|
|
|
|
|
|
|
# regardless if 1 or greater. |
257
|
|
|
|
|
|
|
# |
258
|
|
|
|
|
|
|
# sub make_iter { |
259
|
|
|
|
|
|
|
# ... |
260
|
|
|
|
|
|
|
# return sub { |
261
|
|
|
|
|
|
|
# my ($chunk_size) = @_; |
262
|
|
|
|
|
|
|
# ... |
263
|
|
|
|
|
|
|
# }; |
264
|
|
|
|
|
|
|
# } |
265
|
0
|
|
|
|
|
0
|
return 1; |
266
|
|
|
|
|
|
|
} |
267
|
|
|
|
|
|
|
|
268
|
182
|
|
|
|
|
337
|
my $_is_file; |
269
|
182
|
|
|
|
|
366
|
my $_size = $_array_size; |
270
|
|
|
|
|
|
|
|
271
|
182
|
100
|
|
|
|
449
|
if (defined $_input_data) { |
272
|
24
|
100
|
|
|
|
111
|
if (ref $_input_data eq 'ARRAY') { |
|
|
50
|
|
|
|
|
|
273
|
18
|
|
|
|
|
39
|
$_size = scalar @{ $_input_data }; |
|
18
|
|
|
|
|
45
|
|
274
|
|
|
|
|
|
|
} elsif (ref $_input_data eq 'HASH') { |
275
|
6
|
|
|
|
|
14
|
$_size = scalar keys %{ $_input_data }; |
|
6
|
|
|
|
|
32
|
|
276
|
|
|
|
|
|
|
} |
277
|
|
|
|
|
|
|
} |
278
|
|
|
|
|
|
|
|
279
|
182
|
100
|
66
|
|
|
1938
|
if (defined $_params && exists $_params->{sequence}) { |
|
|
100
|
33
|
|
|
|
|
|
|
100
|
|
|
|
|
|
280
|
18
|
|
|
|
|
54
|
my ($_begin, $_end, $_step); |
281
|
|
|
|
|
|
|
|
282
|
18
|
50
|
|
|
|
71
|
if (ref $_params->{sequence} eq 'HASH') { |
283
|
0
|
|
|
|
|
0
|
$_begin = $_params->{sequence}->{begin}; |
284
|
0
|
|
|
|
|
0
|
$_end = $_params->{sequence}->{end}; |
285
|
0
|
|
0
|
|
|
0
|
$_step = $_params->{sequence}->{step} || 1; |
286
|
|
|
|
|
|
|
} |
287
|
|
|
|
|
|
|
else { |
288
|
18
|
|
|
|
|
42
|
$_begin = $_params->{sequence}[0]; |
289
|
18
|
|
|
|
|
31
|
$_end = $_params->{sequence}[1]; |
290
|
18
|
|
50
|
|
|
244
|
$_step = $_params->{sequence}[2] || 1; |
291
|
|
|
|
|
|
|
} |
292
|
|
|
|
|
|
|
|
293
|
18
|
50
|
33
|
|
|
233
|
if (!defined $_input_data && !$_array_size) { |
294
|
18
|
|
|
|
|
80
|
$_size = abs($_end - $_begin) / $_step + 1; |
295
|
|
|
|
|
|
|
} |
296
|
|
|
|
|
|
|
} |
297
|
|
|
|
|
|
|
elsif (defined $_params && exists $_params->{_file}) { |
298
|
36
|
|
|
|
|
104
|
my $_ref = ref $_params->{_file}; |
299
|
|
|
|
|
|
|
|
300
|
36
|
50
|
|
|
|
126
|
if ($_ref eq 'SCALAR') { |
|
|
100
|
|
|
|
|
|
301
|
0
|
|
|
|
|
0
|
$_size = length ${ $_params->{_file} }; |
|
0
|
|
|
|
|
0
|
|
302
|
|
|
|
|
|
|
} elsif ($_ref eq '') { |
303
|
18
|
|
|
|
|
260
|
$_size = -s $_params->{_file}; |
304
|
|
|
|
|
|
|
} else { |
305
|
18
|
|
|
|
|
103
|
$_size = 0; $_chunk_size = 393_216; # 384K |
|
18
|
|
|
|
|
55
|
|
306
|
|
|
|
|
|
|
} |
307
|
|
|
|
|
|
|
|
308
|
36
|
|
|
|
|
93
|
$_is_file = 1; |
309
|
|
|
|
|
|
|
} |
310
|
|
|
|
|
|
|
elsif (defined $_input_data) { |
311
|
24
|
50
|
|
|
|
354
|
if (ref($_input_data) =~ /^(?:GLOB|FileHandle|IO::)/) { |
|
|
50
|
|
|
|
|
|
312
|
0
|
|
|
|
|
0
|
$_is_file = 1; $_size = 0; $_chunk_size = 393_216; # 384K |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
313
|
|
|
|
|
|
|
} |
314
|
|
|
|
|
|
|
elsif (ref $_input_data eq 'SCALAR') { |
315
|
0
|
|
|
|
|
0
|
$_is_file = 1; $_size = length ${ $_input_data }; |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
316
|
|
|
|
|
|
|
} |
317
|
|
|
|
|
|
|
} |
318
|
|
|
|
|
|
|
|
319
|
182
|
100
|
|
|
|
554
|
if (defined $_is_file) { |
320
|
36
|
100
|
|
|
|
92
|
if ($_size) { |
321
|
18
|
|
|
|
|
80
|
$_chunk_size = int($_size / $_max_workers / 24 + 0.5); |
322
|
18
|
50
|
|
|
|
52
|
$_chunk_size = 5_242_880 if $_chunk_size > 5_242_880; # 5M |
323
|
18
|
50
|
|
|
|
52
|
if ($_chunk_size <= 8192) { |
324
|
18
|
100
|
|
|
|
345
|
$_chunk_size = (caller() =~ /^MCE::(?:Grep|Map|Stream)/) ? 1 : 2; |
325
|
|
|
|
|
|
|
} |
326
|
|
|
|
|
|
|
} |
327
|
|
|
|
|
|
|
} |
328
|
|
|
|
|
|
|
else { |
329
|
146
|
|
|
|
|
829
|
$_chunk_size = int($_size / $_max_workers / 24 + 0.5); |
330
|
146
|
50
|
|
|
|
547
|
$_chunk_size = 8000 if $_chunk_size > 8000; |
331
|
146
|
50
|
|
|
|
479
|
if ($_chunk_size < 2) { |
332
|
146
|
100
|
|
|
|
1349
|
$_chunk_size = (caller() =~ /^MCE::(?:Grep|Map|Stream)/) ? 1 : 2; |
333
|
|
|
|
|
|
|
} |
334
|
|
|
|
|
|
|
} |
335
|
|
|
|
|
|
|
} |
336
|
|
|
|
|
|
|
|
337
|
182
|
|
|
|
|
682
|
return $_chunk_size; |
338
|
|
|
|
|
|
|
} |
339
|
|
|
|
|
|
|
|
340
|
|
|
|
|
|
|
sub _parse_max_workers { |
341
|
|
|
|
|
|
|
|
342
|
1091
|
|
|
1091
|
|
2404
|
my ($_max_workers) = @_; |
343
|
|
|
|
|
|
|
|
344
|
1091
|
|
|
|
|
1693
|
@_ = (); |
345
|
|
|
|
|
|
|
|
346
|
1091
|
50
|
|
|
|
2248
|
return $_max_workers unless (defined $_max_workers); |
347
|
|
|
|
|
|
|
|
348
|
1091
|
100
|
|
|
|
3692
|
if ($_max_workers =~ /^auto(?:$|\s*([\-\+\/\*])\s*(.+)$)/i) { |
|
|
100
|
|
|
|
|
|
349
|
126
|
|
|
|
|
257
|
my ($_ncpu_ul, $_ncpu); |
350
|
|
|
|
|
|
|
|
351
|
126
|
|
|
|
|
514
|
$_ncpu_ul = $_ncpu = MCE::Util::get_ncpu(); |
352
|
126
|
50
|
|
|
|
482
|
$_ncpu_ul = 8 if ($_ncpu_ul > 8); |
353
|
|
|
|
|
|
|
|
354
|
126
|
100
|
66
|
|
|
622
|
if (defined($1) && defined($2)) { |
355
|
48
|
|
|
|
|
90
|
local $@; $_max_workers = eval "int($_ncpu_ul $1 $2 + 0.5)"; ## no critic |
|
48
|
|
|
|
|
2808
|
|
356
|
48
|
100
|
66
|
|
|
276
|
$_max_workers = 1 if (!$_max_workers || $_max_workers < 1); |
357
|
48
|
50
|
|
|
|
138
|
$_max_workers = $_ncpu if ($_max_workers > $_ncpu); |
358
|
|
|
|
|
|
|
} |
359
|
|
|
|
|
|
|
else { |
360
|
78
|
|
|
|
|
189
|
$_max_workers = $_ncpu_ul; |
361
|
|
|
|
|
|
|
} |
362
|
|
|
|
|
|
|
} |
363
|
|
|
|
|
|
|
elsif ($_max_workers =~ /^([0-9.]+)%$/) { |
364
|
54
|
|
|
|
|
210
|
my $_percent = $1 / 100; |
365
|
54
|
|
|
|
|
138
|
my $_ncpu = MCE::Util::get_ncpu(); |
366
|
|
|
|
|
|
|
|
367
|
54
|
|
|
|
|
228
|
$_max_workers = int($_ncpu * $_percent + 0.5); |
368
|
54
|
100
|
|
|
|
132
|
$_max_workers = 1 if ($_max_workers < 1); |
369
|
|
|
|
|
|
|
} |
370
|
|
|
|
|
|
|
|
371
|
1091
|
|
|
|
|
2935
|
return $_max_workers; |
372
|
|
|
|
|
|
|
} |
373
|
|
|
|
|
|
|
|
374
|
|
|
|
|
|
|
sub _validate_number { |
375
|
|
|
|
|
|
|
|
376
|
72
|
|
|
72
|
|
293
|
my ($_n, $_key, $_tag) = @_; |
377
|
|
|
|
|
|
|
|
378
|
72
|
50
|
|
|
|
237
|
_croak("$_tag: ($_key) is not valid") if (!defined $_n); |
379
|
|
|
|
|
|
|
|
380
|
72
|
|
|
|
|
306
|
$_n =~ s/K\z//i; $_n =~ s/M\z//i; |
|
72
|
|
|
|
|
213
|
|
381
|
|
|
|
|
|
|
|
382
|
72
|
50
|
33
|
|
|
956
|
if (!looks_like_number($_n) || int($_n) != $_n || $_n < 1) { |
|
|
|
33
|
|
|
|
|
383
|
0
|
|
|
|
|
0
|
_croak("$_tag: ($_key) is not valid"); |
384
|
|
|
|
|
|
|
} |
385
|
|
|
|
|
|
|
|
386
|
72
|
|
|
|
|
190
|
return; |
387
|
|
|
|
|
|
|
} |
388
|
|
|
|
|
|
|
|
389
|
|
|
|
|
|
|
1; |
390
|
|
|
|
|
|
|
|
391
|
|
|
|
|
|
|
__END__ |