| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
############################################################################### |
|
2
|
|
|
|
|
|
|
## ---------------------------------------------------------------------------- |
|
3
|
|
|
|
|
|
|
## Core methods for the worker process. |
|
4
|
|
|
|
|
|
|
## |
|
5
|
|
|
|
|
|
|
## This package provides main, loop, and relevant methods used internally by |
|
6
|
|
|
|
|
|
|
## the worker process. |
|
7
|
|
|
|
|
|
|
## |
|
8
|
|
|
|
|
|
|
## There is no public API. |
|
9
|
|
|
|
|
|
|
## |
|
10
|
|
|
|
|
|
|
############################################################################### |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
package MCE::Core::Worker; |
|
13
|
|
|
|
|
|
|
|
|
14
|
85
|
|
|
85
|
|
521
|
use strict; |
|
|
85
|
|
|
|
|
144
|
|
|
|
85
|
|
|
|
|
2278
|
|
|
15
|
85
|
|
|
85
|
|
395
|
use warnings; |
|
|
85
|
|
|
|
|
168
|
|
|
|
85
|
|
|
|
|
7285
|
|
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
our $VERSION = '1.887'; |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
my $_tid = $INC{'threads.pm'} ? threads->tid() : 0; |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub CLONE { |
|
22
|
0
|
0
|
|
0
|
|
0
|
$_tid = threads->tid() if $INC{'threads.pm'}; |
|
23
|
|
|
|
|
|
|
} |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
## Items below are folded into MCE. |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
package # hide from rpm |
|
28
|
|
|
|
|
|
|
MCE; |
|
29
|
|
|
|
|
|
|
|
|
30
|
85
|
|
|
85
|
|
463
|
no warnings qw( bareword threads recursion uninitialized ); |
|
|
85
|
|
|
|
|
129
|
|
|
|
85
|
|
|
|
|
92368
|
|
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
############################################################################### |
|
33
|
|
|
|
|
|
|
## ---------------------------------------------------------------------------- |
|
34
|
|
|
|
|
|
|
## Internal do, gather and send related functions for serializing data to |
|
35
|
|
|
|
|
|
|
## destination. User functions for handling gather, queue or void. |
|
36
|
|
|
|
|
|
|
## |
|
37
|
|
|
|
|
|
|
############################################################################### |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
{ |
|
40
|
|
|
|
|
|
|
my ( |
|
41
|
|
|
|
|
|
|
$_dest, $_len, $_tag, $_task_id, $_user_func, $_val, $_wa, |
|
42
|
|
|
|
|
|
|
$_DAT_LOCK, $_DAT_W_SOCK, $_DAU_W_SOCK, $_chn, $_lock_chn, |
|
43
|
|
|
|
|
|
|
$_dat_ex, $_dat_un |
|
44
|
|
|
|
|
|
|
); |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
my $_is_MSWin32 = ($^O eq 'MSWin32') ? 1 : 0; |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
## Create array structure containing various send functions. |
|
49
|
|
|
|
|
|
|
my @_dest_function = (); |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
$_dest_function[SENDTO_FILEV2] = sub { ## Content >> File |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
return unless (defined $_val); |
|
54
|
|
|
|
|
|
|
local $\ = undef if (defined $\); |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
if (length ${ $_[1] }) { |
|
57
|
|
|
|
|
|
|
my $_buf = $_[0]->{freeze}([ $_val, ${ $_[1] } ]); |
|
58
|
|
|
|
|
|
|
$_dat_ex->() if $_lock_chn; |
|
59
|
|
|
|
|
|
|
print({$_DAT_W_SOCK} OUTPUT_F_SND.$LF . $_chn.$LF), |
|
60
|
|
|
|
|
|
|
print({$_DAU_W_SOCK} length($_buf).$LF, $_buf); |
|
61
|
|
|
|
|
|
|
$_dat_un->() if $_lock_chn; |
|
62
|
|
|
|
|
|
|
} |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
return; |
|
65
|
|
|
|
|
|
|
}; |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
$_dest_function[SENDTO_FD] = sub { ## Content >> File descriptor |
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
return unless (defined $_val); |
|
70
|
|
|
|
|
|
|
local $\ = undef if (defined $\); |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
if (length ${ $_[1] }) { |
|
73
|
|
|
|
|
|
|
my $_buf = $_[0]->{freeze}([ $_val, ${ $_[1] } ]); |
|
74
|
|
|
|
|
|
|
$_dat_ex->() if $_lock_chn; |
|
75
|
|
|
|
|
|
|
print({$_DAT_W_SOCK} OUTPUT_D_SND.$LF . $_chn.$LF), |
|
76
|
|
|
|
|
|
|
print({$_DAU_W_SOCK} length($_buf).$LF, $_buf); |
|
77
|
|
|
|
|
|
|
$_dat_un->() if $_lock_chn; |
|
78
|
|
|
|
|
|
|
} |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
return; |
|
81
|
|
|
|
|
|
|
}; |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
$_dest_function[SENDTO_STDOUT] = sub { ## Content >> STDOUT |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
local $\ = undef if (defined $\); |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
if (length ${ $_[1] }) { |
|
88
|
|
|
|
|
|
|
my $_buf = $_[0]->{freeze}($_[1]); |
|
89
|
|
|
|
|
|
|
$_dat_ex->() if $_lock_chn; |
|
90
|
|
|
|
|
|
|
print({$_DAT_W_SOCK} OUTPUT_O_SND.$LF . $_chn.$LF), |
|
91
|
|
|
|
|
|
|
print({$_DAU_W_SOCK} length($_buf).$LF, $_buf); |
|
92
|
|
|
|
|
|
|
$_dat_un->() if $_lock_chn; |
|
93
|
|
|
|
|
|
|
} |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
return; |
|
96
|
|
|
|
|
|
|
}; |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
$_dest_function[SENDTO_STDERR] = sub { ## Content >> STDERR |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
local $\ = undef if (defined $\); |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
if (length ${ $_[1] }) { |
|
103
|
|
|
|
|
|
|
my $_buf = $_[0]->{freeze}($_[1]); |
|
104
|
|
|
|
|
|
|
$_dat_ex->() if $_lock_chn; |
|
105
|
|
|
|
|
|
|
print({$_DAT_W_SOCK} OUTPUT_E_SND.$LF . $_chn.$LF), |
|
106
|
|
|
|
|
|
|
print({$_DAU_W_SOCK} length($_buf).$LF, $_buf); |
|
107
|
|
|
|
|
|
|
$_dat_un->() if $_lock_chn; |
|
108
|
|
|
|
|
|
|
} |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
return; |
|
111
|
|
|
|
|
|
|
}; |
|
112
|
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
## ------------------------------------------------------------------------- |
|
114
|
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
sub _do_callback { |
|
116
|
|
|
|
|
|
|
|
|
117
|
133
|
|
|
133
|
|
241
|
my ($self, $_buf, $_aref); |
|
118
|
|
|
|
|
|
|
|
|
119
|
133
|
|
|
|
|
273
|
($self, $_val, $_aref) = @_; |
|
120
|
|
|
|
|
|
|
|
|
121
|
133
|
100
|
|
|
|
280
|
unless (defined wantarray) { |
|
|
|
100
|
|
|
|
|
|
|
122
|
126
|
|
|
|
|
174
|
$_wa = WANTS_UNDEF; |
|
123
|
0
|
|
|
|
|
0
|
} elsif (wantarray) { |
|
124
|
2
|
|
|
|
|
4
|
$_wa = WANTS_ARRAY; |
|
125
|
|
|
|
|
|
|
} else { |
|
126
|
5
|
|
|
|
|
12
|
$_wa = WANTS_SCALAR; |
|
127
|
|
|
|
|
|
|
} |
|
128
|
|
|
|
|
|
|
|
|
129
|
133
|
50
|
|
|
|
354
|
local $\ = undef if (defined $\); |
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
## Crossover: Send arguments |
|
132
|
|
|
|
|
|
|
|
|
133
|
133
|
100
|
|
|
|
170
|
if ( ! @{ $_aref } ) { |
|
|
133
|
|
|
|
|
243
|
|
|
134
|
2
|
50
|
|
|
|
5
|
$_dat_ex->() if $_lock_chn; |
|
135
|
2
|
|
|
|
|
67
|
print({$_DAT_W_SOCK} OUTPUT_N_CBK.$LF . $_chn.$LF), |
|
136
|
2
|
|
|
|
|
2
|
print({$_DAU_W_SOCK} $_wa.$LF . $_val.$LF); |
|
|
2
|
|
|
|
|
31
|
|
|
137
|
|
|
|
|
|
|
} |
|
138
|
|
|
|
|
|
|
else { |
|
139
|
131
|
|
|
|
|
9600
|
$_buf = $self->{freeze}($_aref); |
|
140
|
131
|
|
|
|
|
392
|
$_len = length $_buf; |
|
141
|
|
|
|
|
|
|
|
|
142
|
131
|
50
|
|
|
|
268
|
$_dat_ex->() if $_lock_chn; |
|
143
|
131
|
|
|
|
|
3725
|
print({$_DAT_W_SOCK} OUTPUT_A_CBK.$LF . $_chn.$LF), |
|
144
|
131
|
|
|
|
|
170
|
print({$_DAU_W_SOCK} $_wa.$LF . $_val.$LF . $_len.$LF, $_buf); |
|
|
131
|
|
|
|
|
1634
|
|
|
145
|
|
|
|
|
|
|
} |
|
146
|
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
## Crossover: Receive value |
|
148
|
|
|
|
|
|
|
|
|
149
|
133
|
100
|
|
|
|
8682
|
if ( $_wa ) { |
|
150
|
7
|
50
|
|
|
|
33
|
local $/ = $LF if ($/ ne $LF); |
|
151
|
7
|
|
|
|
|
3412
|
chomp(my $_len = <$_DAU_W_SOCK>); |
|
152
|
|
|
|
|
|
|
|
|
153
|
7
|
|
|
|
|
39
|
read $_DAU_W_SOCK, my($_buf), $_len; |
|
154
|
7
|
50
|
|
|
|
21
|
$_dat_un->() if $_lock_chn; |
|
155
|
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
return ( $_wa != WANTS_ARRAY ) |
|
157
|
|
|
|
|
|
|
? ($self->{thaw}($_buf))->[0] |
|
158
|
7
|
100
|
|
|
|
111
|
: @{ $self->{thaw}($_buf) }; |
|
|
2
|
|
|
|
|
65
|
|
|
159
|
|
|
|
|
|
|
} |
|
160
|
|
|
|
|
|
|
|
|
161
|
126
|
50
|
|
|
|
536
|
$_dat_un->() if $_lock_chn; |
|
162
|
|
|
|
|
|
|
} |
|
163
|
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
## ------------------------------------------------------------------------- |
|
165
|
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
sub _do_gather { |
|
167
|
|
|
|
|
|
|
|
|
168
|
357
|
|
|
357
|
|
486
|
my $_buf; my ($self, $_aref) = @_; |
|
|
357
|
|
|
|
|
1264
|
|
|
169
|
|
|
|
|
|
|
|
|
170
|
357
|
50
|
|
|
|
446
|
return unless (scalar @{ $_aref }); |
|
|
357
|
|
|
|
|
778
|
|
|
171
|
|
|
|
|
|
|
|
|
172
|
357
|
|
|
|
|
1302
|
$_tag = OUTPUT_A_GTR; |
|
173
|
357
|
|
|
|
|
2832
|
$_buf = $self->{freeze}($_aref); |
|
174
|
357
|
|
|
|
|
599
|
$_len = length $_buf; |
|
175
|
|
|
|
|
|
|
|
|
176
|
357
|
50
|
|
|
|
957
|
local $\ = undef if (defined $\); |
|
177
|
|
|
|
|
|
|
|
|
178
|
357
|
50
|
|
|
|
661
|
$_dat_ex->() if $_lock_chn; |
|
179
|
357
|
|
|
|
|
7858
|
print({$_DAT_W_SOCK} $_tag.$LF . $_chn.$LF), |
|
180
|
357
|
|
|
|
|
432
|
print({$_DAU_W_SOCK} $_task_id.$LF . $_len.$LF, $_buf); |
|
|
357
|
|
|
|
|
4168
|
|
|
181
|
357
|
50
|
|
|
|
1124
|
$_dat_un->() if $_lock_chn; |
|
182
|
|
|
|
|
|
|
|
|
183
|
357
|
|
|
|
|
2134
|
return; |
|
184
|
|
|
|
|
|
|
} |
|
185
|
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
## ------------------------------------------------------------------------- |
|
187
|
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
sub _do_send { |
|
189
|
|
|
|
|
|
|
|
|
190
|
0
|
|
|
0
|
|
0
|
my $_data_ref; my $self = shift; |
|
|
0
|
|
|
|
|
0
|
|
|
191
|
|
|
|
|
|
|
|
|
192
|
0
|
|
|
|
|
0
|
$_dest = shift; $_val = shift; |
|
|
0
|
|
|
|
|
0
|
|
|
193
|
|
|
|
|
|
|
|
|
194
|
0
|
0
|
|
|
|
0
|
if (scalar @_ > 1) { |
|
|
|
0
|
|
|
|
|
|
|
195
|
0
|
|
|
|
|
0
|
$_data_ref = \join('', @_); |
|
196
|
|
|
|
|
|
|
} |
|
197
|
|
|
|
|
|
|
elsif (my $_ref = ref $_[0]) { |
|
198
|
0
|
0
|
|
|
|
0
|
if ($_ref eq 'SCALAR') { |
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
199
|
0
|
|
|
|
|
0
|
$_data_ref = $_[0]; |
|
200
|
|
|
|
|
|
|
} |
|
201
|
|
|
|
|
|
|
elsif ($_ref eq 'ARRAY') { |
|
202
|
0
|
|
|
|
|
0
|
$_data_ref = \join('', @{ $_[0] }); |
|
|
0
|
|
|
|
|
0
|
|
|
203
|
|
|
|
|
|
|
} |
|
204
|
|
|
|
|
|
|
elsif ($_ref eq 'HASH') { |
|
205
|
0
|
|
|
|
|
0
|
$_data_ref = \join('', %{ $_[0] }); |
|
|
0
|
|
|
|
|
0
|
|
|
206
|
|
|
|
|
|
|
} |
|
207
|
|
|
|
|
|
|
else { |
|
208
|
0
|
|
|
|
|
0
|
$_data_ref = \join('', @_); |
|
209
|
|
|
|
|
|
|
} |
|
210
|
|
|
|
|
|
|
} |
|
211
|
|
|
|
|
|
|
else { |
|
212
|
0
|
|
|
|
|
0
|
$_data_ref = \(''.$_[0]); |
|
213
|
|
|
|
|
|
|
} |
|
214
|
|
|
|
|
|
|
|
|
215
|
0
|
|
|
|
|
0
|
$_dest_function[$_dest]($self, $_data_ref); |
|
216
|
|
|
|
|
|
|
|
|
217
|
0
|
|
|
|
|
0
|
return 1; |
|
218
|
|
|
|
|
|
|
} |
|
219
|
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
sub _do_send_glob { |
|
221
|
|
|
|
|
|
|
|
|
222
|
0
|
|
|
0
|
|
0
|
my ($self, $_glob, $_fd, $_data_ref) = @_; |
|
223
|
|
|
|
|
|
|
|
|
224
|
0
|
0
|
|
|
|
0
|
if ($self->{_wid} > 0) { |
|
225
|
0
|
0
|
|
|
|
0
|
if ($_fd == 1) { |
|
|
|
0
|
|
|
|
|
|
|
226
|
0
|
|
|
|
|
0
|
_do_send($self, SENDTO_STDOUT, undef, $_data_ref); |
|
227
|
|
|
|
|
|
|
} |
|
228
|
|
|
|
|
|
|
elsif ($_fd == 2) { |
|
229
|
0
|
|
|
|
|
0
|
_do_send($self, SENDTO_STDERR, undef, $_data_ref); |
|
230
|
|
|
|
|
|
|
} |
|
231
|
|
|
|
|
|
|
else { |
|
232
|
0
|
|
|
|
|
0
|
_do_send($self, SENDTO_FD, $_fd, $_data_ref); |
|
233
|
|
|
|
|
|
|
} |
|
234
|
|
|
|
|
|
|
} |
|
235
|
|
|
|
|
|
|
else { |
|
236
|
85
|
|
|
85
|
|
560
|
use bytes; |
|
|
85
|
|
|
|
|
165
|
|
|
|
85
|
|
|
|
|
526
|
|
|
237
|
0
|
|
|
|
|
0
|
my $_fh = _sendto_fhs_get($self, $_fd); |
|
238
|
0
|
0
|
|
|
|
0
|
local $\ = undef if (defined $\); |
|
239
|
|
|
|
|
|
|
|
|
240
|
0
|
|
|
|
|
0
|
print {$_fh} ${ $_data_ref }; |
|
|
0
|
|
|
|
|
0
|
|
|
|
0
|
|
|
|
|
0
|
|
|
241
|
|
|
|
|
|
|
} |
|
242
|
|
|
|
|
|
|
|
|
243
|
0
|
|
|
|
|
0
|
return 1; |
|
244
|
|
|
|
|
|
|
} |
|
245
|
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
## ------------------------------------------------------------------------- |
|
247
|
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
sub _do_send_init { |
|
249
|
|
|
|
|
|
|
|
|
250
|
65
|
|
|
65
|
|
315
|
my ($self) = @_; |
|
251
|
|
|
|
|
|
|
|
|
252
|
65
|
|
|
|
|
356
|
$_chn = $self->{_chn}; |
|
253
|
65
|
|
|
|
|
235
|
$_DAT_LOCK = $self->{_dat_lock}; |
|
254
|
65
|
|
|
|
|
351
|
$_DAT_W_SOCK = $self->{_dat_w_sock}->[0]; |
|
255
|
65
|
|
|
|
|
246
|
$_DAU_W_SOCK = $self->{_dat_w_sock}->[$_chn]; |
|
256
|
65
|
|
|
|
|
188
|
$_lock_chn = $self->{_lock_chn}; |
|
257
|
65
|
|
|
|
|
189
|
$_task_id = $self->{_task_id}; |
|
258
|
|
|
|
|
|
|
|
|
259
|
65
|
50
|
|
|
|
342
|
if ($_lock_chn) { |
|
260
|
|
|
|
|
|
|
# inlined for performance |
|
261
|
|
|
|
|
|
|
$_dat_ex = sub { |
|
262
|
0
|
0
|
|
0
|
|
0
|
my $_pid = $_tid ? $$ .'.'. $_tid : $$; |
|
263
|
|
|
|
|
|
|
CORE::lock($_DAT_LOCK->{_t_lock}), MCE::Util::_sock_ready($_DAT_LOCK->{_r_sock}) |
|
264
|
0
|
0
|
|
|
|
0
|
if $_is_MSWin32; |
|
265
|
|
|
|
|
|
|
MCE::Util::_sysread($_DAT_LOCK->{_r_sock}, my($b), 1), $_DAT_LOCK->{ $_pid } = 1 |
|
266
|
0
|
0
|
|
|
|
0
|
unless $_DAT_LOCK->{ $_pid }; |
|
267
|
0
|
|
|
|
|
0
|
}; |
|
268
|
|
|
|
|
|
|
$_dat_un = sub { |
|
269
|
0
|
0
|
|
0
|
|
0
|
my $_pid = $_tid ? $$ .'.'. $_tid : $$; |
|
270
|
|
|
|
|
|
|
syswrite($_DAT_LOCK->{_w_sock}, '0'), $_DAT_LOCK->{ $_pid } = 0 |
|
271
|
0
|
0
|
|
|
|
0
|
if $_DAT_LOCK->{ $_pid }; |
|
272
|
0
|
|
|
|
|
0
|
}; |
|
273
|
|
|
|
|
|
|
} |
|
274
|
|
|
|
|
|
|
|
|
275
|
|
|
|
|
|
|
{ |
|
276
|
65
|
|
|
|
|
239
|
local $!; |
|
|
65
|
|
|
|
|
5274
|
|
|
277
|
65
|
50
|
|
|
|
3351
|
(*STDERR)->autoflush(1) if defined( fileno *STDERR ); |
|
278
|
65
|
50
|
|
|
|
14147
|
(*STDOUT)->autoflush(1) if defined( fileno *STDOUT ); |
|
279
|
|
|
|
|
|
|
} |
|
280
|
|
|
|
|
|
|
|
|
281
|
65
|
|
|
|
|
2074
|
return; |
|
282
|
|
|
|
|
|
|
} |
|
283
|
|
|
|
|
|
|
|
|
284
|
|
|
|
|
|
|
sub _do_send_clear { |
|
285
|
|
|
|
|
|
|
|
|
286
|
65
|
|
|
65
|
|
266
|
my ($self) = @_; |
|
287
|
|
|
|
|
|
|
|
|
288
|
65
|
|
|
|
|
316
|
$_dest = $_len = $_task_id = $_user_func = $_val = $_wa = undef; |
|
289
|
65
|
|
|
|
|
232
|
$_DAT_LOCK = $_DAT_W_SOCK = $_DAU_W_SOCK = $_chn = $_lock_chn = undef; |
|
290
|
65
|
|
|
|
|
393
|
$_dat_ex = $_dat_un = $_tag = undef; |
|
291
|
|
|
|
|
|
|
|
|
292
|
65
|
|
|
|
|
142
|
return; |
|
293
|
|
|
|
|
|
|
} |
|
294
|
|
|
|
|
|
|
|
|
295
|
|
|
|
|
|
|
## ------------------------------------------------------------------------- |
|
296
|
|
|
|
|
|
|
|
|
297
|
|
|
|
|
|
|
sub _do_user_func { |
|
298
|
|
|
|
|
|
|
|
|
299
|
246
|
|
|
246
|
|
728
|
my ($self, $_chunk, $_chunk_id) = @_; |
|
300
|
246
|
|
|
|
|
348
|
my $_size = 0; |
|
301
|
|
|
|
|
|
|
|
|
302
|
246
|
|
|
|
|
477
|
delete $self->{_relayed}; |
|
303
|
246
|
|
|
|
|
594
|
$self->{_chunk_id} = $_chunk_id; |
|
304
|
|
|
|
|
|
|
|
|
305
|
246
|
50
|
33
|
|
|
658
|
if ($self->{progress} && $self->{_task_id} == 0) { |
|
306
|
|
|
|
|
|
|
# use_slurpio |
|
307
|
0
|
0
|
0
|
|
|
0
|
if (ref $_chunk eq 'SCALAR') { |
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
308
|
0
|
|
|
|
|
0
|
$_size += length ${ $_chunk }; |
|
|
0
|
|
|
|
|
0
|
|
|
309
|
|
|
|
|
|
|
} |
|
310
|
|
|
|
|
|
|
# sequence and bounds_only |
|
311
|
|
|
|
|
|
|
elsif ($self->{sequence} && $self->{bounds_only}) { |
|
312
|
0
|
|
|
|
|
0
|
my $_seq = $self->{sequence}; |
|
313
|
0
|
0
|
|
|
|
0
|
my $_step = (ref $_seq eq 'ARRAY') ? $_seq->[2] : $_seq->{step}; |
|
314
|
0
|
|
|
|
|
0
|
$_size += int(abs($_chunk->[0] - $_chunk->[1]) / abs($_step)) + 1; |
|
315
|
|
|
|
|
|
|
} |
|
316
|
|
|
|
|
|
|
# workers clear {input_data} to conserve memory when array ref |
|
317
|
|
|
|
|
|
|
# otherwise, /path/to/infile or scalar reference |
|
318
|
|
|
|
|
|
|
elsif ($self->{input_data}) { |
|
319
|
0
|
|
|
|
|
0
|
map { $_size += length } @{ $_chunk }; |
|
|
0
|
|
|
|
|
0
|
|
|
|
0
|
|
|
|
|
0
|
|
|
320
|
|
|
|
|
|
|
} |
|
321
|
|
|
|
|
|
|
# array or sequence |
|
322
|
|
|
|
|
|
|
else { |
|
323
|
0
|
0
|
|
|
|
0
|
$_size += (ref $_chunk eq 'ARRAY') ? @{ $_chunk } : 1; |
|
|
0
|
|
|
|
|
0
|
|
|
324
|
|
|
|
|
|
|
} |
|
325
|
|
|
|
|
|
|
} |
|
326
|
|
|
|
|
|
|
|
|
327
|
246
|
50
|
|
|
|
459
|
if ($self->{max_retries}) { |
|
328
|
0
|
|
|
|
|
0
|
$self->{_retry} = [ $_chunk, $_chunk_id, $self->{max_retries} ]; |
|
329
|
|
|
|
|
|
|
} |
|
330
|
|
|
|
|
|
|
|
|
331
|
246
|
0
|
33
|
|
|
558
|
if ($self->{loop_timeout} && $self->{_task_id} == 0 && |
|
|
|
|
33
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
332
|
|
|
|
|
|
|
defined $self->{init_relay} && !$self->{_is_thread} && !$_is_MSWin32) { |
|
333
|
|
|
|
|
|
|
|
|
334
|
0
|
0
|
|
|
|
0
|
local $\ = undef if (defined $\); |
|
335
|
|
|
|
|
|
|
|
|
336
|
0
|
0
|
|
|
|
0
|
$_dat_ex->() if $_lock_chn; |
|
337
|
0
|
|
|
|
|
0
|
print({$_DAT_W_SOCK} OUTPUT_C_NFY.$LF . $_chn.$LF), |
|
338
|
0
|
|
|
|
|
0
|
print({$_DAU_W_SOCK} "$$:$_chunk_id".$LF); |
|
|
0
|
|
|
|
|
0
|
|
|
339
|
0
|
0
|
|
|
|
0
|
$_dat_un->() if $_lock_chn; |
|
340
|
|
|
|
|
|
|
} |
|
341
|
|
|
|
|
|
|
|
|
342
|
246
|
|
|
|
|
949
|
$_user_func->($self, $_chunk, $_chunk_id); |
|
343
|
|
|
|
|
|
|
|
|
344
|
246
|
50
|
33
|
|
|
1373
|
if ($self->{progress} && $self->{_task_id} == 0) { |
|
345
|
0
|
0
|
|
|
|
0
|
local $\ = undef if (defined $\); |
|
346
|
|
|
|
|
|
|
|
|
347
|
0
|
0
|
|
|
|
0
|
$_dat_ex->() if $_lock_chn; |
|
348
|
0
|
|
|
|
|
0
|
print({$_DAT_W_SOCK} OUTPUT_P_NFY.$LF . $_chn.$LF), |
|
349
|
0
|
|
|
|
|
0
|
print({$_DAU_W_SOCK} $_size.$LF); |
|
|
0
|
|
|
|
|
0
|
|
|
350
|
0
|
0
|
|
|
|
0
|
$_dat_un->() if $_lock_chn; |
|
351
|
|
|
|
|
|
|
} |
|
352
|
|
|
|
|
|
|
|
|
353
|
246
|
|
|
|
|
876
|
return; |
|
354
|
|
|
|
|
|
|
} |
|
355
|
|
|
|
|
|
|
|
|
356
|
|
|
|
|
|
|
sub _do_user_func_init { |
|
357
|
|
|
|
|
|
|
|
|
358
|
163
|
|
|
163
|
|
1049
|
my ($self) = @_; |
|
359
|
|
|
|
|
|
|
|
|
360
|
163
|
|
|
|
|
457
|
$_user_func = $self->{user_func}; |
|
361
|
|
|
|
|
|
|
|
|
362
|
163
|
|
|
|
|
379
|
return; |
|
363
|
|
|
|
|
|
|
} |
|
364
|
|
|
|
|
|
|
} |
|
365
|
|
|
|
|
|
|
|
|
366
|
|
|
|
|
|
|
############################################################################### |
|
367
|
|
|
|
|
|
|
## ---------------------------------------------------------------------------- |
|
368
|
|
|
|
|
|
|
## Worker process -- Do. |
|
369
|
|
|
|
|
|
|
## |
|
370
|
|
|
|
|
|
|
############################################################################### |
|
371
|
|
|
|
|
|
|
|
|
372
|
|
|
|
|
|
|
sub MCE::Core::Worker::_guard::DESTROY { |
|
373
|
|
|
|
|
|
|
|
|
374
|
163
|
|
|
163
|
|
412
|
my ($mce, $id) = @{ $_[0] }; |
|
|
163
|
|
|
|
|
454
|
|
|
375
|
|
|
|
|
|
|
|
|
376
|
163
|
50
|
33
|
|
|
745
|
if (defined $mce && $id eq "$$.$_tid") { |
|
377
|
0
|
|
|
|
|
0
|
@{ $_[0] } = (); |
|
|
0
|
|
|
|
|
0
|
|
|
378
|
0
|
|
|
|
|
0
|
warn "MCE worker $id exited prematurely.\n"; |
|
379
|
0
|
|
|
|
|
0
|
$mce->exit(2); |
|
380
|
|
|
|
|
|
|
} |
|
381
|
|
|
|
|
|
|
|
|
382
|
163
|
|
|
|
|
459
|
return; |
|
383
|
|
|
|
|
|
|
}; |
|
384
|
|
|
|
|
|
|
|
|
385
|
|
|
|
|
|
|
sub _worker_do { |
|
386
|
|
|
|
|
|
|
|
|
387
|
163
|
|
|
163
|
|
742
|
my ($self, $_params_ref) = @_; |
|
388
|
|
|
|
|
|
|
|
|
389
|
163
|
|
|
|
|
382
|
@_ = (); |
|
390
|
|
|
|
|
|
|
|
|
391
|
|
|
|
|
|
|
## Set options. |
|
392
|
163
|
|
|
|
|
598
|
$self->{_abort_msg} = $_params_ref->{_abort_msg}; |
|
393
|
163
|
|
|
|
|
436
|
$self->{_run_mode} = $_params_ref->{_run_mode}; |
|
394
|
163
|
|
|
|
|
548
|
$self->{use_slurpio} = $_params_ref->{_use_slurpio}; |
|
395
|
163
|
|
|
|
|
555
|
$self->{parallel_io} = $_params_ref->{_parallel_io}; |
|
396
|
163
|
|
|
|
|
620
|
$self->{progress} = $_params_ref->{_progress}; |
|
397
|
163
|
|
|
|
|
1015
|
$self->{max_retries} = $_params_ref->{_max_retries}; |
|
398
|
163
|
|
|
|
|
447
|
$self->{RS} = $_params_ref->{_RS}; |
|
399
|
|
|
|
|
|
|
|
|
400
|
163
|
|
|
|
|
1228
|
_do_user_func_init($self); |
|
401
|
|
|
|
|
|
|
|
|
402
|
|
|
|
|
|
|
## Init local vars. |
|
403
|
163
|
|
|
|
|
314
|
my $_chn = $self->{_chn}; |
|
404
|
163
|
|
|
|
|
554
|
my $_DAT_LOCK = $self->{_dat_lock}; |
|
405
|
163
|
|
|
|
|
455
|
my $_DAT_W_SOCK = $self->{_dat_w_sock}->[0]; |
|
406
|
163
|
|
|
|
|
677
|
my $_DAU_W_SOCK = $self->{_dat_w_sock}->[$_chn]; |
|
407
|
163
|
|
|
|
|
427
|
my $_lock_chn = $self->{_lock_chn}; |
|
408
|
163
|
|
|
|
|
367
|
my $_run_mode = $self->{_run_mode}; |
|
409
|
163
|
|
|
|
|
490
|
my $_task_id = $self->{_task_id}; |
|
410
|
163
|
|
|
|
|
611
|
my $_task_name = $self->{task_name}; |
|
411
|
|
|
|
|
|
|
|
|
412
|
|
|
|
|
|
|
## Do not override params if defined in user_tasks during instantiation. |
|
413
|
163
|
|
|
|
|
513
|
for my $_p (qw(bounds_only chunk_size sequence user_args)) { |
|
414
|
652
|
100
|
|
|
|
2028
|
if (defined $_params_ref->{"_${_p}"}) { |
|
415
|
|
|
|
|
|
|
$self->{$_p} = $_params_ref->{"_${_p}"} |
|
416
|
208
|
50
|
|
|
|
1159
|
unless (defined $self->{_task}->{$_p}); |
|
417
|
|
|
|
|
|
|
} |
|
418
|
|
|
|
|
|
|
} |
|
419
|
|
|
|
|
|
|
|
|
420
|
|
|
|
|
|
|
{ |
|
421
|
163
|
|
|
|
|
316
|
my $_guard = bless([ $self, "$$.$_tid" ], MCE::Core::Worker::_guard::); |
|
|
163
|
|
|
|
|
9286
|
|
|
422
|
163
|
|
|
|
|
1838
|
weaken( $self->{_guard} = $_guard ); |
|
423
|
|
|
|
|
|
|
|
|
424
|
|
|
|
|
|
|
## Assign user function. |
|
425
|
163
|
|
|
|
|
727
|
$self->{_wuf} = \&_do_user_func; |
|
426
|
|
|
|
|
|
|
|
|
427
|
|
|
|
|
|
|
## Call user_begin if defined. |
|
428
|
163
|
50
|
|
|
|
1941
|
if (defined $self->{user_begin}) { |
|
429
|
0
|
|
|
|
|
0
|
$self->{_chunk_id} = 0; |
|
430
|
0
|
|
|
|
|
0
|
$self->{user_begin}($self, $_task_id, $_task_name); |
|
431
|
0
|
0
|
0
|
|
|
0
|
if ($_task_id == 0 && defined $self->{init_relay} && !$self->{_retry}) { |
|
|
|
|
0
|
|
|
|
|
|
432
|
0
|
|
|
|
|
0
|
$self->sync(); |
|
433
|
|
|
|
|
|
|
} |
|
434
|
|
|
|
|
|
|
} |
|
435
|
|
|
|
|
|
|
|
|
436
|
|
|
|
|
|
|
## Retry chunk if previous attempt died. |
|
437
|
163
|
50
|
|
|
|
548
|
if ($self->{_retry}) { |
|
438
|
0
|
|
|
|
|
0
|
$self->{_chunk_id} = $self->{_retry}->[1]; |
|
439
|
0
|
|
|
|
|
0
|
$self->{user_func}->($self, $self->{_retry}->[0], $self->{_retry}->[1]); |
|
440
|
0
|
|
|
|
|
0
|
delete $self->{_retry}; |
|
441
|
|
|
|
|
|
|
} |
|
442
|
|
|
|
|
|
|
|
|
443
|
|
|
|
|
|
|
## Call worker function. |
|
444
|
163
|
100
|
|
|
|
1979
|
if ($_run_mode eq 'sequence') { |
|
|
|
50
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
445
|
|
|
|
|
|
|
require MCE::Core::Input::Sequence |
|
446
|
14
|
100
|
|
|
|
13320
|
unless $INC{'MCE/Core/Input/Sequence.pm'}; |
|
447
|
14
|
|
|
|
|
113
|
_worker_sequence_queue($self); |
|
448
|
|
|
|
|
|
|
} |
|
449
|
|
|
|
|
|
|
elsif (defined $self->{_task}->{sequence}) { |
|
450
|
|
|
|
|
|
|
require MCE::Core::Input::Generator |
|
451
|
0
|
0
|
|
|
|
0
|
unless $INC{'MCE/Core/Input/Generator.pm'}; |
|
452
|
0
|
|
|
|
|
0
|
_worker_sequence_generator($self); |
|
453
|
|
|
|
|
|
|
} |
|
454
|
|
|
|
|
|
|
elsif ($_run_mode eq 'array') { |
|
455
|
|
|
|
|
|
|
require MCE::Core::Input::Request |
|
456
|
36
|
50
|
|
|
|
151
|
unless $INC{'MCE/Core/Input/Request.pm'}; |
|
457
|
36
|
|
|
|
|
512
|
_worker_request_chunk($self, REQUEST_ARRAY); |
|
458
|
|
|
|
|
|
|
} |
|
459
|
|
|
|
|
|
|
elsif ($_run_mode eq 'glob') { |
|
460
|
|
|
|
|
|
|
require MCE::Core::Input::Request |
|
461
|
14
|
50
|
|
|
|
66
|
unless $INC{'MCE/Core/Input/Request.pm'}; |
|
462
|
14
|
|
|
|
|
559
|
_worker_request_chunk($self, REQUEST_GLOB); |
|
463
|
|
|
|
|
|
|
} |
|
464
|
|
|
|
|
|
|
elsif ($_run_mode eq 'hash') { |
|
465
|
|
|
|
|
|
|
require MCE::Core::Input::Request |
|
466
|
3
|
50
|
|
|
|
154
|
unless $INC{'MCE/Core/Input/Request.pm'}; |
|
467
|
3
|
|
|
|
|
67
|
_worker_request_chunk($self, REQUEST_HASH); |
|
468
|
|
|
|
|
|
|
} |
|
469
|
|
|
|
|
|
|
elsif ($_run_mode eq 'iterator') { |
|
470
|
|
|
|
|
|
|
require MCE::Core::Input::Iterator |
|
471
|
0
|
0
|
|
|
|
0
|
unless $INC{'MCE/Core/Input/Iterator.pm'}; |
|
472
|
0
|
|
|
|
|
0
|
_worker_user_iterator($self); |
|
473
|
|
|
|
|
|
|
} |
|
474
|
|
|
|
|
|
|
elsif ($_run_mode eq 'file') { |
|
475
|
|
|
|
|
|
|
require MCE::Core::Input::Handle |
|
476
|
14
|
100
|
|
|
|
15140
|
unless $INC{'MCE/Core/Input/Handle.pm'}; |
|
477
|
14
|
|
|
|
|
79
|
_worker_read_handle($self, READ_FILE, $_params_ref->{_input_file}); |
|
478
|
|
|
|
|
|
|
} |
|
479
|
|
|
|
|
|
|
elsif ($_run_mode eq 'memory') { |
|
480
|
|
|
|
|
|
|
require MCE::Core::Input::Handle |
|
481
|
0
|
0
|
|
|
|
0
|
unless $INC{'MCE/Core/Input/Handle.pm'}; |
|
482
|
0
|
|
|
|
|
0
|
_worker_read_handle($self, READ_MEMORY, $self->{input_data}); |
|
483
|
|
|
|
|
|
|
} |
|
484
|
|
|
|
|
|
|
elsif (defined $self->{user_func}) { |
|
485
|
82
|
50
|
|
|
|
286
|
if ($self->{max_retries}) { |
|
486
|
0
|
|
|
|
|
0
|
$self->{_retry} = [ undef, 0, $self->{max_retries} ]; |
|
487
|
|
|
|
|
|
|
} |
|
488
|
82
|
|
|
|
|
214
|
$self->{_chunk_id} = 0; |
|
489
|
82
|
|
|
|
|
651
|
$self->{user_func}->($self); |
|
490
|
|
|
|
|
|
|
} |
|
491
|
|
|
|
|
|
|
|
|
492
|
163
|
100
|
|
|
|
1270
|
undef $self->{_next_jmp} if (defined $self->{_next_jmp}); |
|
493
|
163
|
100
|
|
|
|
726
|
undef $self->{_last_jmp} if (defined $self->{_last_jmp}); |
|
494
|
163
|
50
|
|
|
|
586
|
undef $self->{user_data} if (defined $self->{user_data}); |
|
495
|
|
|
|
|
|
|
|
|
496
|
|
|
|
|
|
|
## Call user_end if defined. |
|
497
|
163
|
50
|
|
|
|
868
|
if (defined $self->{user_end}) { |
|
498
|
0
|
|
|
|
|
0
|
$self->{_chunk_id} = 0; |
|
499
|
0
|
0
|
0
|
|
|
0
|
$self->sync() if ($_task_id == 0 && defined $self->{init_relay}); |
|
500
|
0
|
|
|
|
|
0
|
$self->{user_end}($self, $_task_id, $_task_name); |
|
501
|
|
|
|
|
|
|
} |
|
502
|
|
|
|
|
|
|
|
|
503
|
163
|
|
|
|
|
317
|
@{ $_guard } = (); |
|
|
163
|
|
|
|
|
1863
|
|
|
504
|
163
|
|
|
|
|
420
|
delete $self->{_guard}; |
|
505
|
163
|
|
|
|
|
1207
|
delete $self->{_wuf}; |
|
506
|
|
|
|
|
|
|
} |
|
507
|
|
|
|
|
|
|
|
|
508
|
|
|
|
|
|
|
## Check for nested workers not yet joined. |
|
509
|
163
|
50
|
|
|
|
485
|
MCE::Child->finish('MCE') if $INC{'MCE/Child.pm'}; |
|
510
|
163
|
50
|
|
|
|
533
|
MCE::Hobo->finish('MCE') if $INC{'MCE/Hobo.pm'}; |
|
511
|
|
|
|
|
|
|
|
|
512
|
|
|
|
|
|
|
## Notify the main process a worker has completed. |
|
513
|
163
|
50
|
|
|
|
511
|
local $\ = undef if (defined $\); |
|
514
|
|
|
|
|
|
|
|
|
515
|
163
|
50
|
|
|
|
468
|
$_DAT_LOCK->lock() if $_lock_chn; |
|
516
|
|
|
|
|
|
|
|
|
517
|
163
|
|
|
|
|
3988
|
print({$_DAT_W_SOCK} OUTPUT_W_DNE.$LF . $_chn.$LF), |
|
518
|
163
|
|
|
|
|
299
|
print({$_DAU_W_SOCK} $_task_id.$LF); |
|
|
163
|
|
|
|
|
1679
|
|
|
519
|
|
|
|
|
|
|
|
|
520
|
163
|
50
|
|
|
|
814
|
$_DAT_LOCK->unlock() if $_lock_chn; |
|
521
|
|
|
|
|
|
|
|
|
522
|
163
|
50
|
|
|
|
785
|
if ($^O eq 'MSWin32') { |
|
523
|
0
|
|
|
|
|
0
|
lock $self->{_run_lock}; |
|
524
|
|
|
|
|
|
|
} |
|
525
|
|
|
|
|
|
|
|
|
526
|
163
|
|
|
|
|
552
|
return; |
|
527
|
|
|
|
|
|
|
} |
|
528
|
|
|
|
|
|
|
|
|
529
|
|
|
|
|
|
|
############################################################################### |
|
530
|
|
|
|
|
|
|
## ---------------------------------------------------------------------------- |
|
531
|
|
|
|
|
|
|
## Worker process -- Loop. |
|
532
|
|
|
|
|
|
|
## |
|
533
|
|
|
|
|
|
|
############################################################################### |
|
534
|
|
|
|
|
|
|
|
|
535
|
|
|
|
|
|
|
sub _worker_loop { |
|
536
|
|
|
|
|
|
|
|
|
537
|
65
|
|
|
65
|
|
243
|
my ($self) = @_; |
|
538
|
|
|
|
|
|
|
|
|
539
|
65
|
|
|
|
|
220
|
@_ = (); |
|
540
|
|
|
|
|
|
|
|
|
541
|
65
|
|
|
|
|
428
|
my ($_response, $_len, $_buf, $_params_ref); |
|
542
|
|
|
|
|
|
|
|
|
543
|
65
|
|
|
|
|
242
|
my $_COM_LOCK = $self->{_com_lock}; |
|
544
|
65
|
|
|
|
|
297
|
my $_COM_W_SOCK = $self->{_com_w_sock}; |
|
545
|
65
|
|
|
|
|
278
|
my $_job_delay = $self->{job_delay}; |
|
546
|
|
|
|
|
|
|
|
|
547
|
65
|
50
|
|
|
|
1512
|
if ($^O eq 'MSWin32') { lock $MCE::_WIN_LOCK; } |
|
|
0
|
|
|
|
|
0
|
|
|
548
|
|
|
|
|
|
|
|
|
549
|
65
|
|
|
|
|
198
|
while (1) { |
|
550
|
|
|
|
|
|
|
{ |
|
551
|
228
|
|
|
|
|
405
|
local $\ = undef; local $/ = $LF; |
|
|
228
|
|
|
|
|
1312
|
|
|
|
228
|
|
|
|
|
2360
|
|
|
552
|
228
|
|
|
|
|
2109
|
$_COM_LOCK->lock(); |
|
553
|
|
|
|
|
|
|
|
|
554
|
|
|
|
|
|
|
## Wait for the next job request. |
|
555
|
228
|
|
|
|
|
307588
|
$_response = <$_COM_W_SOCK>, print {$_COM_W_SOCK} $self->{_wid}.$LF; |
|
|
228
|
|
|
|
|
14382
|
|
|
556
|
|
|
|
|
|
|
|
|
557
|
|
|
|
|
|
|
## Return if instructed to exit. |
|
558
|
228
|
100
|
|
|
|
2010
|
$_COM_LOCK->unlock(), return if ($_response eq "_exit\n"); |
|
559
|
|
|
|
|
|
|
|
|
560
|
|
|
|
|
|
|
## Process send request. |
|
561
|
163
|
50
|
|
|
|
3461
|
if ($_response eq "_data\n") { |
|
|
|
50
|
|
|
|
|
|
|
562
|
0
|
|
|
|
|
0
|
chomp($_len = <$_COM_W_SOCK>), read($_COM_W_SOCK, $_buf, $_len); |
|
563
|
0
|
|
|
|
|
0
|
print({$_COM_W_SOCK} $LF), $_COM_LOCK->unlock(); |
|
|
0
|
|
|
|
|
0
|
|
|
564
|
0
|
|
|
|
|
0
|
$self->{user_data} = $self->{thaw}($_buf), undef $_buf; |
|
565
|
|
|
|
|
|
|
|
|
566
|
|
|
|
|
|
|
sleep $_job_delay * $self->{_wid} |
|
567
|
0
|
0
|
0
|
|
|
0
|
if defined($_job_delay) && $_job_delay > 0.0; |
|
568
|
|
|
|
|
|
|
} |
|
569
|
|
|
|
|
|
|
|
|
570
|
|
|
|
|
|
|
## Process normal request. |
|
571
|
|
|
|
|
|
|
elsif ($_response =~ /\d+/) { |
|
572
|
163
|
|
|
|
|
44341
|
chomp($_len = <$_COM_W_SOCK>), read($_COM_W_SOCK, $_buf, $_len); |
|
573
|
163
|
|
|
|
|
642
|
print({$_COM_W_SOCK} $LF), $_COM_LOCK->unlock(); |
|
|
163
|
|
|
|
|
12917
|
|
|
574
|
163
|
|
|
|
|
6786
|
$_params_ref = $self->{thaw}($_buf), undef $_buf; |
|
575
|
|
|
|
|
|
|
} |
|
576
|
|
|
|
|
|
|
|
|
577
|
|
|
|
|
|
|
## Leave loop if invalid response. |
|
578
|
|
|
|
|
|
|
else { |
|
579
|
0
|
|
|
|
|
0
|
last; |
|
580
|
|
|
|
|
|
|
} |
|
581
|
|
|
|
|
|
|
} |
|
582
|
|
|
|
|
|
|
|
|
583
|
|
|
|
|
|
|
## Send request. |
|
584
|
163
|
50
|
|
|
|
695
|
_worker_do($self, {}), next if ($_response eq "_data\n"); |
|
585
|
|
|
|
|
|
|
|
|
586
|
|
|
|
|
|
|
## Wait here until MCE completes job submission to all workers. |
|
587
|
163
|
|
|
|
|
1167
|
MCE::Util::_sysread($self->{_bsb_w_sock}, my($_b), 1); |
|
588
|
|
|
|
|
|
|
|
|
589
|
|
|
|
|
|
|
## Normal request. |
|
590
|
|
|
|
|
|
|
sleep $_job_delay * $self->{_wid} |
|
591
|
163
|
50
|
33
|
|
|
2901
|
if defined($_job_delay) && $_job_delay > 0.0; |
|
592
|
|
|
|
|
|
|
|
|
593
|
163
|
|
|
|
|
2042
|
_worker_do($self, $_params_ref); undef $_params_ref; |
|
|
163
|
|
|
|
|
1045
|
|
|
594
|
|
|
|
|
|
|
} |
|
595
|
|
|
|
|
|
|
|
|
596
|
|
|
|
|
|
|
## Notify the main process a worker has ended. The following is executed |
|
597
|
|
|
|
|
|
|
## when an invalid reply was received above (not likely to occur). |
|
598
|
|
|
|
|
|
|
|
|
599
|
0
|
|
|
|
|
0
|
$_COM_LOCK->unlock(); |
|
600
|
|
|
|
|
|
|
|
|
601
|
0
|
|
|
|
|
0
|
die "Error: worker $self->{_wid} has ended prematurely"; |
|
602
|
|
|
|
|
|
|
} |
|
603
|
|
|
|
|
|
|
|
|
604
|
|
|
|
|
|
|
############################################################################### |
|
605
|
|
|
|
|
|
|
## ---------------------------------------------------------------------------- |
|
606
|
|
|
|
|
|
|
## Worker process -- Main. |
|
607
|
|
|
|
|
|
|
## |
|
608
|
|
|
|
|
|
|
############################################################################### |
|
609
|
|
|
|
|
|
|
|
|
610
|
|
|
|
|
|
|
sub _worker_main { |
|
611
|
|
|
|
|
|
|
|
|
612
|
65
|
|
|
65
|
|
646
|
my ( $self, $_wid, $_task, $_task_id, $_task_wid, $_params, |
|
613
|
|
|
|
|
|
|
$_plugin_worker_init ) = @_; |
|
614
|
|
|
|
|
|
|
|
|
615
|
65
|
|
|
|
|
498
|
@_ = (); |
|
616
|
|
|
|
|
|
|
|
|
617
|
65
|
100
|
|
|
|
991
|
if (exists $self->{input_data}) { |
|
618
|
27
|
|
|
|
|
906
|
my $_ref = ref $self->{input_data}; |
|
619
|
27
|
50
|
33
|
|
|
1371
|
delete $self->{input_data} if ($_ref && $_ref ne 'SCALAR'); |
|
620
|
|
|
|
|
|
|
} |
|
621
|
|
|
|
|
|
|
|
|
622
|
65
|
100
|
|
|
|
1164
|
$self->{_task_id} = (defined $_task_id ) ? $_task_id : 0; |
|
623
|
65
|
100
|
|
|
|
804
|
$self->{_task_wid} = (defined $_task_wid) ? $_task_wid : $_wid; |
|
624
|
65
|
|
|
|
|
602
|
$self->{_task} = $_task; |
|
625
|
65
|
|
|
|
|
3703
|
$self->{_wid} = $_wid; |
|
626
|
|
|
|
|
|
|
|
|
627
|
|
|
|
|
|
|
## Define exit pid and DIE handler. |
|
628
|
|
|
|
|
|
|
my $_use_threads = (defined $_task->{use_threads}) |
|
629
|
65
|
100
|
|
|
|
1810
|
? $_task->{use_threads} : $self->{use_threads}; |
|
630
|
|
|
|
|
|
|
|
|
631
|
65
|
50
|
33
|
|
|
1254
|
if ($INC{'threads.pm'} && $_use_threads) { |
|
632
|
0
|
|
|
|
|
0
|
$self->{_exit_pid} = 'TID_' . $_tid; |
|
633
|
|
|
|
|
|
|
} else { |
|
634
|
65
|
|
|
|
|
6264
|
$self->{_exit_pid} = 'PID_' . $$; |
|
635
|
|
|
|
|
|
|
} |
|
636
|
|
|
|
|
|
|
|
|
637
|
65
|
|
|
|
|
1561
|
my $_running_inside_eval = $^S; |
|
638
|
|
|
|
|
|
|
|
|
639
|
65
|
|
|
0
|
|
6993
|
local $SIG{SEGV} = sub { $self->exit(11) }; |
|
|
0
|
|
|
|
|
0
|
|
|
640
|
|
|
|
|
|
|
|
|
641
|
|
|
|
|
|
|
local $SIG{__DIE__} = sub { |
|
642
|
0
|
0
|
0
|
0
|
|
0
|
if (!defined $^S || $^S) { |
|
643
|
0
|
0
|
0
|
|
|
0
|
if ( ($INC{'threads.pm'} && $_tid != 0) || |
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
644
|
|
|
|
|
|
|
$ENV{'PERL_IPERL_RUNNING'} || |
|
645
|
|
|
|
|
|
|
$_running_inside_eval |
|
646
|
|
|
|
|
|
|
) { |
|
647
|
|
|
|
|
|
|
# thread env or running inside IPerl, check stack trace |
|
648
|
0
|
|
|
|
|
0
|
my $_t = Carp::longmess(); $_t =~ s/\teval [^\n]+\n$//; |
|
|
0
|
|
|
|
|
0
|
|
|
649
|
0
|
0
|
0
|
|
|
0
|
if ( $_t =~ /^(?:[^\n]+\n){1,7}\teval / || |
|
650
|
|
|
|
|
|
|
$_t =~ /\n\teval [^\n]+\n\t(?:eval|Try)/ ) |
|
651
|
|
|
|
|
|
|
{ |
|
652
|
0
|
|
|
|
|
0
|
CORE::die(@_); |
|
653
|
|
|
|
|
|
|
} |
|
654
|
|
|
|
|
|
|
} |
|
655
|
|
|
|
|
|
|
else { |
|
656
|
|
|
|
|
|
|
# normal env, trust $^S |
|
657
|
0
|
|
|
|
|
0
|
CORE::die(@_); |
|
658
|
|
|
|
|
|
|
} |
|
659
|
|
|
|
|
|
|
} |
|
660
|
|
|
|
|
|
|
|
|
661
|
0
|
|
|
|
|
0
|
$SIG{__DIE__} = $SIG{__WARN__} = sub {}; |
|
662
|
0
|
0
|
|
|
|
0
|
my $_die_msg = (defined $_[0]) ? $_[0] : ''; |
|
663
|
0
|
|
|
|
|
0
|
$_die_msg =~ s/, <__ANONIO__> line \d+//; |
|
664
|
0
|
|
|
|
|
0
|
local $\ = undef; print {*STDERR} $_die_msg; |
|
|
0
|
|
|
|
|
0
|
|
|
|
0
|
|
|
|
|
0
|
|
|
665
|
|
|
|
|
|
|
|
|
666
|
0
|
|
|
|
|
0
|
$self->exit(255, $_die_msg, $self->{_chunk_id}); |
|
667
|
65
|
|
|
|
|
2934
|
}; |
|
668
|
|
|
|
|
|
|
|
|
669
|
|
|
|
|
|
|
## Use options from user_tasks if defined. |
|
670
|
65
|
100
|
|
|
|
2066
|
$self->{max_workers} = $_task->{max_workers} if ($_task->{max_workers}); |
|
671
|
65
|
50
|
|
|
|
741
|
$self->{chunk_size} = $_task->{chunk_size} if ($_task->{chunk_size}); |
|
672
|
65
|
100
|
|
|
|
575
|
$self->{gather} = $_task->{gather} if ($_task->{gather}); |
|
673
|
65
|
50
|
|
|
|
884
|
$self->{sequence} = $_task->{sequence} if ($_task->{sequence}); |
|
674
|
65
|
50
|
|
|
|
411
|
$self->{bounds_only} = $_task->{bounds_only} if ($_task->{bounds_only}); |
|
675
|
65
|
100
|
|
|
|
711
|
$self->{task_name} = $_task->{task_name} if ($_task->{task_name}); |
|
676
|
65
|
50
|
|
|
|
624
|
$self->{user_args} = $_task->{user_args} if ($_task->{user_args}); |
|
677
|
65
|
50
|
|
|
|
430
|
$self->{user_begin} = $_task->{user_begin} if ($_task->{user_begin}); |
|
678
|
65
|
100
|
|
|
|
1012
|
$self->{user_func} = $_task->{user_func} if ($_task->{user_func}); |
|
679
|
65
|
50
|
|
|
|
482
|
$self->{user_end} = $_task->{user_end} if ($_task->{user_end}); |
|
680
|
|
|
|
|
|
|
|
|
681
|
|
|
|
|
|
|
## Init runtime vars. Obtain handle to lock files. |
|
682
|
65
|
|
|
|
|
367
|
my $_chn; |
|
683
|
|
|
|
|
|
|
|
|
684
|
65
|
50
|
33
|
|
|
613
|
if (defined $_params && exists $_params->{_chn}) { |
|
685
|
0
|
|
|
|
|
0
|
$_chn = $self->{_chn} = delete $_params->{_chn}; # worker restarted |
|
686
|
|
|
|
|
|
|
} else { |
|
687
|
65
|
|
|
|
|
682
|
$_chn = $self->{_chn} = $_wid % $self->{_data_channels} + 1; # default |
|
688
|
|
|
|
|
|
|
} |
|
689
|
|
|
|
|
|
|
|
|
690
|
|
|
|
|
|
|
## Choose locks for DATA channels. |
|
691
|
65
|
|
|
|
|
932
|
$self->{_com_lock} = $self->{'_mutex_0'}; |
|
692
|
65
|
50
|
|
|
|
683
|
$self->{_dat_lock} = $self->{'_mutex_'.$_chn} if ($self->{_lock_chn}); |
|
693
|
|
|
|
|
|
|
|
|
694
|
|
|
|
|
|
|
## Delete attributes no longer required after being spawned. |
|
695
|
65
|
|
|
|
|
240
|
delete @{ $self }{ qw( |
|
|
65
|
|
|
|
|
2911
|
|
|
696
|
|
|
|
|
|
|
flush_file flush_stderr flush_stdout stderr_file stdout_file |
|
697
|
|
|
|
|
|
|
on_post_exit on_post_run user_data user_error user_output |
|
698
|
|
|
|
|
|
|
_pids _state _status _thrs _tids |
|
699
|
|
|
|
|
|
|
) }; |
|
700
|
|
|
|
|
|
|
|
|
701
|
|
|
|
|
|
|
## Call MCE::Shared's init routine if present; enables parallel IPC. |
|
702
|
|
|
|
|
|
|
## For threads, init is called automatically via the CLONE feature. |
|
703
|
65
|
50
|
33
|
|
|
1280
|
MCE::Shared::init() if (!$_use_threads && $INC{'MCE/Shared.pm'}); |
|
704
|
|
|
|
|
|
|
|
|
705
|
65
|
|
|
|
|
1217
|
_do_send_init($self); |
|
706
|
|
|
|
|
|
|
|
|
707
|
|
|
|
|
|
|
## Call module's worker_init routine for modules plugged into MCE. |
|
708
|
65
|
|
|
|
|
164
|
for my $_p (@{ $_plugin_worker_init }) { $_p->($self); } |
|
|
65
|
|
|
|
|
894
|
|
|
|
28
|
|
|
|
|
1110
|
|
|
709
|
|
|
|
|
|
|
|
|
710
|
|
|
|
|
|
|
## Begin processing if worker was added during processing. |
|
711
|
65
|
50
|
|
|
|
670
|
_worker_do($self, $_params), undef $_params if defined($_params); |
|
712
|
|
|
|
|
|
|
|
|
713
|
|
|
|
|
|
|
## Enter worker loop. |
|
714
|
65
|
|
|
|
|
1031
|
_worker_loop($self); |
|
715
|
|
|
|
|
|
|
|
|
716
|
|
|
|
|
|
|
## Clear worker session. |
|
717
|
65
|
|
|
|
|
417
|
_do_send_clear($self); |
|
718
|
|
|
|
|
|
|
|
|
719
|
65
|
|
|
|
|
216
|
$self->{_com_lock} = undef; |
|
720
|
65
|
|
|
|
|
295
|
$self->{_dat_lock} = undef; |
|
721
|
|
|
|
|
|
|
|
|
722
|
65
|
|
|
|
|
2699
|
return; |
|
723
|
|
|
|
|
|
|
} |
|
724
|
|
|
|
|
|
|
|
|
725
|
|
|
|
|
|
|
1; |
|
726
|
|
|
|
|
|
|
|
|
727
|
|
|
|
|
|
|
__END__ |
|
728
|
|
|
|
|
|
|
|
|
729
|
|
|
|
|
|
|
############################################################################### |
|
730
|
|
|
|
|
|
|
## ---------------------------------------------------------------------------- |
|
731
|
|
|
|
|
|
|
## Module usage. |
|
732
|
|
|
|
|
|
|
## |
|
733
|
|
|
|
|
|
|
############################################################################### |
|
734
|
|
|
|
|
|
|
|
|
735
|
|
|
|
|
|
|
=head1 NAME |
|
736
|
|
|
|
|
|
|
|
|
737
|
|
|
|
|
|
|
MCE::Core::Worker - Core methods for the worker process |
|
738
|
|
|
|
|
|
|
|
|
739
|
|
|
|
|
|
|
=head1 VERSION |
|
740
|
|
|
|
|
|
|
|
|
741
|
|
|
|
|
|
|
This document describes MCE::Core::Worker version 1.887 |
|
742
|
|
|
|
|
|
|
|
|
743
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
744
|
|
|
|
|
|
|
|
|
745
|
|
|
|
|
|
|
This package provides main, loop, and relevant methods used internally by |
|
746
|
|
|
|
|
|
|
the worker process. |
|
747
|
|
|
|
|
|
|
|
|
748
|
|
|
|
|
|
|
There is no public API. |
|
749
|
|
|
|
|
|
|
|
|
750
|
|
|
|
|
|
|
=head1 AUTHOR |
|
751
|
|
|
|
|
|
|
|
|
752
|
|
|
|
|
|
|
Mario E. Roy, S<E<lt>marioeroy AT gmail DOT comE<gt>> |
|
753
|
|
|
|
|
|
|
|
|
754
|
|
|
|
|
|
|
=cut |
|
755
|
|
|
|
|
|
|
|