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
|
|
698
|
use strict; |
|
85
|
|
|
|
|
162
|
|
|
85
|
|
|
|
|
2409
|
|
15
|
85
|
|
|
85
|
|
334
|
use warnings; |
|
85
|
|
|
|
|
122
|
|
|
85
|
|
|
|
|
3462
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
our $VERSION = '1.887'; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
## Items below are folded into MCE. |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
package # hide from rpm |
22
|
|
|
|
|
|
|
MCE; |
23
|
|
|
|
|
|
|
|
24
|
85
|
|
|
85
|
|
348
|
no warnings qw( threads recursion uninitialized ); |
|
85
|
|
|
|
|
209
|
|
|
85
|
|
|
|
|
173849
|
|
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
############################################################################### |
27
|
|
|
|
|
|
|
## ---------------------------------------------------------------------------- |
28
|
|
|
|
|
|
|
## Validation method (attributes allowed for top-level). |
29
|
|
|
|
|
|
|
## |
30
|
|
|
|
|
|
|
############################################################################### |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub _validate_args { |
33
|
|
|
|
|
|
|
|
34
|
421
|
|
|
421
|
|
1013
|
my $_s = $_[0]; |
35
|
|
|
|
|
|
|
|
36
|
421
|
|
|
|
|
761
|
@_ = (); |
37
|
|
|
|
|
|
|
|
38
|
421
|
|
|
|
|
826
|
my $_tag = 'MCE::_validate_args'; |
39
|
|
|
|
|
|
|
|
40
|
421
|
100
|
100
|
|
|
1672
|
if (defined $_s->{input_data} && ref $_s->{input_data} eq '') { |
41
|
|
|
|
|
|
|
_croak("$_tag: ($_s->{input_data}) does not exist") |
42
|
18
|
50
|
|
|
|
273
|
unless (-e $_s->{input_data}); |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
421
|
|
|
|
|
1024
|
for my $_k (qw(job_delay spawn_delay submit_delay loop_timeout)) { |
46
|
|
|
|
|
|
|
_croak("$_tag: ($_k) is not valid") |
47
|
1684
|
0
|
0
|
|
|
3668
|
if ($_s->{$_k} && (!looks_like_number($_s->{$_k}) || $_s->{$_k} < 0)); |
|
|
|
33
|
|
|
|
|
48
|
|
|
|
|
|
|
} |
49
|
421
|
|
|
|
|
702
|
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
|
|
|
6215
|
if ($_s->{$_k} && ref $_s->{$_k} ne 'CODE'); |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
421
|
|
|
|
|
1296
|
_validate_args_s($_s); |
55
|
|
|
|
|
|
|
|
56
|
421
|
100
|
|
|
|
859
|
if (defined $_s->{user_tasks}) { |
57
|
257
|
|
|
|
|
378
|
for my $_t (@{ $_s->{user_tasks} }) { |
|
257
|
|
|
|
|
582
|
|
58
|
406
|
|
|
|
|
661
|
_validate_args_s($_s, $_t); |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
421
|
|
|
|
|
852
|
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
|
|
1244
|
my $self = $_[0]; my $_s = $_[1] || $self; |
|
827
|
|
|
|
|
2096
|
|
74
|
|
|
|
|
|
|
|
75
|
827
|
|
|
|
|
1279
|
@_ = (); |
76
|
|
|
|
|
|
|
|
77
|
827
|
|
|
|
|
1246
|
my $_tag = 'MCE::_validate_args_s'; |
78
|
|
|
|
|
|
|
|
79
|
827
|
50
|
|
|
|
1606
|
if (defined $_s->{max_workers}) { |
80
|
827
|
|
|
|
|
1722
|
$_s->{max_workers} = _parse_max_workers($_s->{max_workers}); |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
_croak("$_tag: (max_workers) is not valid") |
83
|
827
|
50
|
|
|
|
3990
|
if ($_s->{max_workers} !~ /\A\d+\z/); |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
827
|
100
|
|
|
|
1756
|
if (defined $_s->{chunk_size}) { |
87
|
421
|
50
|
|
|
|
1777
|
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
|
|
|
2804
|
if ($_s->{chunk_size} !~ /\A[0-9e\+]+\z/ or $_s->{chunk_size} == 0); |
96
|
|
|
|
|
|
|
|
97
|
421
|
|
|
|
|
997
|
$_s->{chunk_size} = int($_s->{chunk_size}); |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
_croak("$_tag: (RS) is not valid") |
101
|
827
|
50
|
33
|
|
|
1645
|
if ($_s->{RS} && ref $_s->{RS} ne ''); |
102
|
|
|
|
|
|
|
_croak("$_tag: (max_retries) is not valid") |
103
|
827
|
50
|
33
|
|
|
1661
|
if ($_s->{max_retries} && $_s->{max_retries} !~ /\A\d+\z/); |
104
|
|
|
|
|
|
|
|
105
|
827
|
|
|
|
|
1505
|
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
|
|
|
8536
|
if ($_s->{$_k} && ref $_s->{$_k} ne 'CODE'); |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
827
|
100
|
|
|
|
1829
|
if (defined $_s->{gather}) { |
111
|
268
|
|
|
|
|
552
|
my $_ref = ref $_s->{gather}; |
112
|
|
|
|
|
|
|
|
113
|
268
|
50
|
66
|
|
|
2126
|
_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
|
|
|
|
1591
|
if (defined $_s->{sequence}) { |
119
|
18
|
|
|
|
|
38
|
my $_seq = $_s->{sequence}; |
120
|
|
|
|
|
|
|
|
121
|
18
|
50
|
|
|
|
124
|
if (ref $_seq eq 'ARRAY') { |
122
|
18
|
|
|
|
|
35
|
my ($_begin, $_end, $_step, $_fmt) = @{ $_seq }; |
|
18
|
|
|
|
|
200
|
|
123
|
18
|
|
|
|
|
443
|
$_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
|
|
|
|
|
79
|
for my $_k (qw(begin end)) { |
133
|
|
|
|
|
|
|
_croak("$_tag: ($_k) is not defined for sequence") |
134
|
36
|
50
|
|
|
|
104
|
unless (defined $_seq->{$_k}); |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
|
137
|
18
|
|
|
|
|
44
|
for my $_p (qw(begin end step)) { |
138
|
|
|
|
|
|
|
_croak("$_tag: ($_p) is not valid for sequence") |
139
|
54
|
50
|
66
|
|
|
344
|
if (defined $_seq->{$_p} && !looks_like_number($_seq->{$_p})); |
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
|
142
|
18
|
50
|
|
|
|
62
|
unless (defined $_seq->{step}) { |
143
|
18
|
50
|
|
|
|
61
|
$_seq->{step} = ($_seq->{begin} <= $_seq->{end}) ? 1 : -1; |
144
|
18
|
50
|
|
|
|
67
|
if (ref $_s->{sequence} eq 'ARRAY') { |
145
|
18
|
|
|
|
|
37
|
$_s->{sequence}->[2] = $_seq->{step}; |
146
|
|
|
|
|
|
|
} |
147
|
|
|
|
|
|
|
} |
148
|
|
|
|
|
|
|
|
149
|
18
|
50
|
|
|
|
69
|
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
|
|
|
|
|
44
|
for my $_i (0, 1, 2) { |
157
|
|
|
|
|
|
|
$_s->{sequence}[$_i] = int($_s->{sequence}[$_i]) |
158
|
54
|
50
|
|
|
|
170
|
unless ($_s->{sequence}[$_i] =~ /\./); |
159
|
|
|
|
|
|
|
} |
160
|
|
|
|
|
|
|
} |
161
|
|
|
|
|
|
|
|
162
|
18
|
50
|
33
|
|
|
373
|
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
|
|
|
|
1390
|
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
|
|
|
|
|
1296
|
return; |
199
|
|
|
|
|
|
|
} |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
############################################################################### |
202
|
|
|
|
|
|
|
## ---------------------------------------------------------------------------- |
203
|
|
|
|
|
|
|
## Validation method (run state). |
204
|
|
|
|
|
|
|
## |
205
|
|
|
|
|
|
|
############################################################################### |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
sub _validate_runstate { |
208
|
|
|
|
|
|
|
|
209
|
167
|
|
|
167
|
|
383
|
my $self = $_[0]; my $_tag = $_[1]; |
|
167
|
|
|
|
|
525
|
|
210
|
|
|
|
|
|
|
|
211
|
167
|
|
|
|
|
386
|
@_ = (); |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
_croak("$_tag: method is not allowed by the worker process") |
214
|
167
|
50
|
|
|
|
499
|
if ($self->{_wid}); |
215
|
|
|
|
|
|
|
_croak("$_tag: method is not allowed while processing") |
216
|
167
|
50
|
|
|
|
453
|
if ($self->{_send_cnt}); |
217
|
|
|
|
|
|
|
_croak("$_tag: method is not allowed while running") |
218
|
167
|
50
|
|
|
|
397
|
if ($self->{_total_running}); |
219
|
|
|
|
|
|
|
|
220
|
167
|
|
|
|
|
339
|
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
|
|
734
|
my ($_chunk_size, $_max_workers, $_params, $_input_data, $_array_size) = @_; |
232
|
|
|
|
|
|
|
|
233
|
182
|
|
|
|
|
385
|
@_ = (); |
234
|
|
|
|
|
|
|
|
235
|
182
|
50
|
33
|
|
|
1103
|
return $_chunk_size if (!defined $_chunk_size || !defined $_max_workers); |
236
|
|
|
|
|
|
|
|
237
|
182
|
50
|
33
|
|
|
1159
|
if (defined $_params && exists $_params->{chunk_size}) { |
238
|
0
|
|
|
|
|
0
|
$_chunk_size = $_params->{chunk_size}; |
239
|
|
|
|
|
|
|
} |
240
|
|
|
|
|
|
|
|
241
|
182
|
50
|
|
|
|
1100
|
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
|
|
|
|
730
|
if ($_chunk_size eq 'auto') { |
249
|
|
|
|
|
|
|
|
250
|
182
|
50
|
33
|
|
|
1737
|
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
|
|
|
|
|
290
|
my $_is_file; |
269
|
182
|
|
|
|
|
294
|
my $_size = $_array_size; |
270
|
|
|
|
|
|
|
|
271
|
182
|
100
|
|
|
|
404
|
if (defined $_input_data) { |
272
|
24
|
100
|
|
|
|
100
|
if (ref $_input_data eq 'ARRAY') { |
|
|
50
|
|
|
|
|
|
273
|
18
|
|
|
|
|
52
|
$_size = scalar @{ $_input_data }; |
|
18
|
|
|
|
|
51
|
|
274
|
|
|
|
|
|
|
} elsif (ref $_input_data eq 'HASH') { |
275
|
6
|
|
|
|
|
16
|
$_size = scalar keys %{ $_input_data }; |
|
6
|
|
|
|
|
22
|
|
276
|
|
|
|
|
|
|
} |
277
|
|
|
|
|
|
|
} |
278
|
|
|
|
|
|
|
|
279
|
182
|
100
|
66
|
|
|
2099
|
if (defined $_params && exists $_params->{sequence}) { |
|
|
100
|
33
|
|
|
|
|
|
|
100
|
|
|
|
|
|
280
|
18
|
|
|
|
|
81
|
my ($_begin, $_end, $_step); |
281
|
|
|
|
|
|
|
|
282
|
18
|
50
|
|
|
|
114
|
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
|
|
|
|
|
75
|
$_begin = $_params->{sequence}[0]; |
289
|
18
|
|
|
|
|
39
|
$_end = $_params->{sequence}[1]; |
290
|
18
|
|
50
|
|
|
182
|
$_step = $_params->{sequence}[2] || 1; |
291
|
|
|
|
|
|
|
} |
292
|
|
|
|
|
|
|
|
293
|
18
|
50
|
33
|
|
|
185
|
if (!defined $_input_data && !$_array_size) { |
294
|
18
|
|
|
|
|
66
|
$_size = abs($_end - $_begin) / $_step + 1; |
295
|
|
|
|
|
|
|
} |
296
|
|
|
|
|
|
|
} |
297
|
|
|
|
|
|
|
elsif (defined $_params && exists $_params->{_file}) { |
298
|
36
|
|
|
|
|
89
|
my $_ref = ref $_params->{_file}; |
299
|
|
|
|
|
|
|
|
300
|
36
|
50
|
|
|
|
120
|
if ($_ref eq 'SCALAR') { |
|
|
100
|
|
|
|
|
|
301
|
0
|
|
|
|
|
0
|
$_size = length ${ $_params->{_file} }; |
|
0
|
|
|
|
|
0
|
|
302
|
|
|
|
|
|
|
} elsif ($_ref eq '') { |
303
|
18
|
|
|
|
|
361
|
$_size = -s $_params->{_file}; |
304
|
|
|
|
|
|
|
} else { |
305
|
18
|
|
|
|
|
32
|
$_size = 0; $_chunk_size = 393_216; # 384K |
|
18
|
|
|
|
|
36
|
|
306
|
|
|
|
|
|
|
} |
307
|
|
|
|
|
|
|
|
308
|
36
|
|
|
|
|
80
|
$_is_file = 1; |
309
|
|
|
|
|
|
|
} |
310
|
|
|
|
|
|
|
elsif (defined $_input_data) { |
311
|
24
|
50
|
|
|
|
226
|
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
|
|
|
|
526
|
if (defined $_is_file) { |
320
|
36
|
100
|
|
|
|
105
|
if ($_size) { |
321
|
18
|
|
|
|
|
104
|
$_chunk_size = int($_size / $_max_workers / 24 + 0.5); |
322
|
18
|
50
|
|
|
|
55
|
$_chunk_size = 5_242_880 if $_chunk_size > 5_242_880; # 5M |
323
|
18
|
50
|
|
|
|
47
|
if ($_chunk_size <= 8192) { |
324
|
18
|
100
|
|
|
|
181
|
$_chunk_size = (caller() =~ /^MCE::(?:Grep|Map|Stream)/) ? 1 : 2; |
325
|
|
|
|
|
|
|
} |
326
|
|
|
|
|
|
|
} |
327
|
|
|
|
|
|
|
} |
328
|
|
|
|
|
|
|
else { |
329
|
146
|
|
|
|
|
704
|
$_chunk_size = int($_size / $_max_workers / 24 + 0.5); |
330
|
146
|
50
|
|
|
|
489
|
$_chunk_size = 8000 if $_chunk_size > 8000; |
331
|
146
|
50
|
|
|
|
532
|
if ($_chunk_size < 2) { |
332
|
146
|
100
|
|
|
|
1214
|
$_chunk_size = (caller() =~ /^MCE::(?:Grep|Map|Stream)/) ? 1 : 2; |
333
|
|
|
|
|
|
|
} |
334
|
|
|
|
|
|
|
} |
335
|
|
|
|
|
|
|
} |
336
|
|
|
|
|
|
|
|
337
|
182
|
|
|
|
|
819
|
return $_chunk_size; |
338
|
|
|
|
|
|
|
} |
339
|
|
|
|
|
|
|
|
340
|
|
|
|
|
|
|
sub _parse_max_workers { |
341
|
|
|
|
|
|
|
|
342
|
1091
|
|
|
1091
|
|
2143
|
my ($_max_workers) = @_; |
343
|
|
|
|
|
|
|
|
344
|
1091
|
|
|
|
|
1653
|
@_ = (); |
345
|
|
|
|
|
|
|
|
346
|
1091
|
50
|
|
|
|
1986
|
return $_max_workers unless (defined $_max_workers); |
347
|
|
|
|
|
|
|
|
348
|
1091
|
100
|
|
|
|
3130
|
if ($_max_workers =~ /^auto(?:$|\s*([\-\+\/\*])\s*(.+)$)/i) { |
|
|
100
|
|
|
|
|
|
349
|
126
|
|
|
|
|
212
|
my ($_ncpu_ul, $_ncpu); |
350
|
|
|
|
|
|
|
|
351
|
126
|
|
|
|
|
703
|
$_ncpu_ul = $_ncpu = MCE::Util::get_ncpu(); |
352
|
126
|
50
|
|
|
|
420
|
$_ncpu_ul = 8 if ($_ncpu_ul > 8); |
353
|
|
|
|
|
|
|
|
354
|
126
|
100
|
66
|
|
|
658
|
if (defined($1) && defined($2)) { |
355
|
48
|
|
|
|
|
60
|
local $@; $_max_workers = eval "int($_ncpu_ul $1 $2 + 0.5)"; ## no critic |
|
48
|
|
|
|
|
2472
|
|
356
|
48
|
100
|
66
|
|
|
246
|
$_max_workers = 1 if (!$_max_workers || $_max_workers < 1); |
357
|
48
|
50
|
|
|
|
120
|
$_max_workers = $_ncpu if ($_max_workers > $_ncpu); |
358
|
|
|
|
|
|
|
} |
359
|
|
|
|
|
|
|
else { |
360
|
78
|
|
|
|
|
184
|
$_max_workers = $_ncpu_ul; |
361
|
|
|
|
|
|
|
} |
362
|
|
|
|
|
|
|
} |
363
|
|
|
|
|
|
|
elsif ($_max_workers =~ /^([0-9.]+)%$/) { |
364
|
54
|
|
|
|
|
156
|
my $_percent = $1 / 100; |
365
|
54
|
|
|
|
|
114
|
my $_ncpu = MCE::Util::get_ncpu(); |
366
|
|
|
|
|
|
|
|
367
|
54
|
|
|
|
|
186
|
$_max_workers = int($_ncpu * $_percent + 0.5); |
368
|
54
|
100
|
|
|
|
108
|
$_max_workers = 1 if ($_max_workers < 1); |
369
|
|
|
|
|
|
|
} |
370
|
|
|
|
|
|
|
|
371
|
1091
|
|
|
|
|
2575
|
return $_max_workers; |
372
|
|
|
|
|
|
|
} |
373
|
|
|
|
|
|
|
|
374
|
|
|
|
|
|
|
sub _validate_number { |
375
|
|
|
|
|
|
|
|
376
|
72
|
|
|
72
|
|
225
|
my ($_n, $_key, $_tag) = @_; |
377
|
|
|
|
|
|
|
|
378
|
72
|
50
|
|
|
|
260
|
_croak("$_tag: ($_key) is not valid") if (!defined $_n); |
379
|
|
|
|
|
|
|
|
380
|
72
|
|
|
|
|
285
|
$_n =~ s/K\z//i; $_n =~ s/M\z//i; |
|
72
|
|
|
|
|
357
|
|
381
|
|
|
|
|
|
|
|
382
|
72
|
50
|
33
|
|
|
929
|
if (!looks_like_number($_n) || int($_n) != $_n || $_n < 1) { |
|
|
|
33
|
|
|
|
|
383
|
0
|
|
|
|
|
0
|
_croak("$_tag: ($_key) is not valid"); |
384
|
|
|
|
|
|
|
} |
385
|
|
|
|
|
|
|
|
386
|
72
|
|
|
|
|
180
|
return; |
387
|
|
|
|
|
|
|
} |
388
|
|
|
|
|
|
|
|
389
|
|
|
|
|
|
|
1; |
390
|
|
|
|
|
|
|
|
391
|
|
|
|
|
|
|
__END__ |
392
|
|
|
|
|
|
|
|
393
|
|
|
|
|
|
|
############################################################################### |
394
|
|
|
|
|
|
|
## ---------------------------------------------------------------------------- |
395
|
|
|
|
|
|
|
## Module usage. |
396
|
|
|
|
|
|
|
## |
397
|
|
|
|
|
|
|
############################################################################### |
398
|
|
|
|
|
|
|
|
399
|
|
|
|
|
|
|
=head1 NAME |
400
|
|
|
|
|
|
|
|
401
|
|
|
|
|
|
|
MCE::Core::Validation - Core validation methods for Many-Core Engine |
402
|
|
|
|
|
|
|
|
403
|
|
|
|
|
|
|
=head1 VERSION |
404
|
|
|
|
|
|
|
|
405
|
|
|
|
|
|
|
This document describes MCE::Core::Validation version 1.887 |
406
|
|
|
|
|
|
|
|
407
|
|
|
|
|
|
|
=head1 DESCRIPTION |
408
|
|
|
|
|
|
|
|
409
|
|
|
|
|
|
|
This package provides validation methods used internally by the manager |
410
|
|
|
|
|
|
|
process. |
411
|
|
|
|
|
|
|
|
412
|
|
|
|
|
|
|
There is no public API. |
413
|
|
|
|
|
|
|
|
414
|
|
|
|
|
|
|
=head1 AUTHOR |
415
|
|
|
|
|
|
|
|
416
|
|
|
|
|
|
|
Mario E. Roy, S<E<lt>marioeroy AT gmail DOT comE<gt>> |
417
|
|
|
|
|
|
|
|
418
|
|
|
|
|
|
|
=cut |
419
|
|
|
|
|
|
|
|