line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
############################################################################### |
2
|
|
|
|
|
|
|
## ---------------------------------------------------------------------------- |
3
|
|
|
|
|
|
|
## Sequence of numbers (for task_id == 0). |
4
|
|
|
|
|
|
|
## |
5
|
|
|
|
|
|
|
## This package provides a sequence of numbers used internally by the worker |
6
|
|
|
|
|
|
|
## process. Distribution follows a bank-queuing model. |
7
|
|
|
|
|
|
|
## |
8
|
|
|
|
|
|
|
## There is no public API. |
9
|
|
|
|
|
|
|
## |
10
|
|
|
|
|
|
|
############################################################################### |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
package MCE::Core::Input::Sequence; |
13
|
|
|
|
|
|
|
|
14
|
13
|
|
|
13
|
|
1030
|
use strict; |
|
13
|
|
|
|
|
32
|
|
|
13
|
|
|
|
|
394
|
|
15
|
13
|
|
|
13
|
|
66
|
use warnings; |
|
13
|
|
|
|
|
28
|
|
|
13
|
|
|
|
|
1374
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
our $VERSION = '1.887'; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
## Items below are folded into MCE. |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
package # hide from rpm |
22
|
|
|
|
|
|
|
MCE; |
23
|
|
|
|
|
|
|
|
24
|
13
|
|
|
13
|
|
197
|
no warnings qw( threads recursion uninitialized ); |
|
13
|
|
|
|
|
33
|
|
|
13
|
|
|
|
|
15698
|
|
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
my $_que_read_size = $MCE::_que_read_size; |
27
|
|
|
|
|
|
|
my $_que_template = $MCE::_que_template; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
############################################################################### |
30
|
|
|
|
|
|
|
## ---------------------------------------------------------------------------- |
31
|
|
|
|
|
|
|
## Worker process -- Sequence Queue (distribution via bank queuing model). |
32
|
|
|
|
|
|
|
## |
33
|
|
|
|
|
|
|
############################################################################### |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub _worker_sequence_queue { |
36
|
|
|
|
|
|
|
|
37
|
14
|
|
|
14
|
|
37
|
my ($self) = @_; |
38
|
|
|
|
|
|
|
|
39
|
14
|
|
|
|
|
26
|
@_ = (); |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
_croak('MCE::_worker_sequence_queue: (user_func) is not specified') |
42
|
14
|
50
|
|
|
|
124
|
unless (defined $self->{user_func}); |
43
|
|
|
|
|
|
|
|
44
|
14
|
50
|
|
|
|
64
|
my $_is_MSWin32 = ($^O eq 'MSWin32') ? 1 : 0; |
45
|
14
|
|
|
|
|
30
|
my $_QUE_R_SOCK = $self->{_que_r_sock}; |
46
|
14
|
|
|
|
|
39
|
my $_QUE_W_SOCK = $self->{_que_w_sock}; |
47
|
14
|
|
50
|
|
|
76
|
my $_bounds_only = $self->{bounds_only} || 0; |
48
|
14
|
|
|
|
|
33
|
my $_chunk_size = $self->{chunk_size}; |
49
|
14
|
|
|
|
|
26
|
my $_wuf = $self->{_wuf}; |
50
|
|
|
|
|
|
|
|
51
|
14
|
|
|
|
|
52
|
my ($_next, $_chunk_id, $_seq_n, $_begin, $_end, $_step, $_fmt); |
52
|
14
|
|
|
|
|
0
|
my ($_DAT_LOCK, $_dat_ex, $_dat_un, $_pid, $_abort, $_offset); |
53
|
|
|
|
|
|
|
|
54
|
14
|
50
|
|
|
|
60
|
$_pid = $INC{'threads.pm'} ? $$ .'.'. threads->tid() : $$; |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
# inlined for performance |
57
|
14
|
|
|
|
|
65
|
$_DAT_LOCK = $self->{'_mutex_'.( $self->{_wid} % 2 + 10 )}; |
58
|
|
|
|
|
|
|
$_dat_ex = sub { |
59
|
|
|
|
|
|
|
CORE::lock($_DAT_LOCK->{_t_lock}), MCE::Util::_sock_ready($_DAT_LOCK->{_r_sock}) |
60
|
65
|
50
|
|
65
|
|
127
|
if $_is_MSWin32; |
61
|
|
|
|
|
|
|
MCE::Util::_sysread($_DAT_LOCK->{_r_sock}, my($b), 1), $_DAT_LOCK->{ $_pid } = 1 |
62
|
65
|
50
|
|
|
|
263
|
unless $_DAT_LOCK->{ $_pid }; |
63
|
14
|
|
|
|
|
75
|
}; |
64
|
|
|
|
|
|
|
$_dat_un = sub { |
65
|
|
|
|
|
|
|
syswrite($_DAT_LOCK->{_w_sock}, '0'), $_DAT_LOCK->{ $_pid } = 0 |
66
|
65
|
50
|
|
65
|
|
691
|
if $_DAT_LOCK->{ $_pid }; |
67
|
14
|
|
|
|
|
43
|
}; |
68
|
|
|
|
|
|
|
|
69
|
14
|
50
|
|
|
|
57
|
if (ref $self->{sequence} eq 'ARRAY') { |
70
|
14
|
|
|
|
|
25
|
($_begin, $_end, $_step, $_fmt) = @{ $self->{sequence} }; |
|
14
|
|
|
|
|
49
|
|
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
else { |
73
|
0
|
|
|
|
|
0
|
$_begin = $self->{sequence}->{begin}; |
74
|
0
|
|
|
|
|
0
|
$_end = $self->{sequence}->{end}; |
75
|
0
|
|
|
|
|
0
|
$_step = $self->{sequence}->{step}; |
76
|
0
|
|
|
|
|
0
|
$_fmt = $self->{sequence}->{format}; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
14
|
|
|
|
|
26
|
$_abort = $self->{_abort_msg}; |
80
|
14
|
|
|
|
|
23
|
$_chunk_id = $_offset = 0; |
81
|
|
|
|
|
|
|
|
82
|
14
|
50
|
|
|
|
43
|
$_fmt =~ s/%// if (defined $_fmt); |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
## ------------------------------------------------------------------------- |
85
|
|
|
|
|
|
|
|
86
|
14
|
|
|
0
|
|
46
|
$self->{_next_jmp} = sub { goto _WORKER_SEQUENCE__NEXT; }; |
|
0
|
|
|
|
|
0
|
|
87
|
14
|
|
|
0
|
|
38
|
$self->{_last_jmp} = sub { goto _WORKER_SEQUENCE__LAST; }; |
|
0
|
|
|
|
|
0
|
|
88
|
|
|
|
|
|
|
|
89
|
14
|
|
|
|
|
26
|
local $_; |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
_WORKER_SEQUENCE__NEXT: |
92
|
|
|
|
|
|
|
|
93
|
14
|
|
|
|
|
30
|
while (1) { |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
## Obtain the next chunk_id and sequence number. |
96
|
65
|
|
|
|
|
147
|
$_dat_ex->(); |
97
|
65
|
50
|
|
|
|
462
|
MCE::Util::_sock_ready($_QUE_R_SOCK) if $_is_MSWin32; |
98
|
65
|
|
|
|
|
153
|
MCE::Util::_sysread($_QUE_R_SOCK, $_next, $_que_read_size); |
99
|
|
|
|
|
|
|
|
100
|
65
|
|
|
|
|
240
|
($_chunk_id, $_offset) = unpack($_que_template, $_next); |
101
|
|
|
|
|
|
|
|
102
|
65
|
100
|
|
|
|
356
|
if ($_offset >= $_abort) { |
103
|
14
|
|
|
|
|
166
|
syswrite($_QUE_W_SOCK, pack($_que_template, 0, $_offset)); |
104
|
14
|
|
|
|
|
60
|
$_dat_un->(); |
105
|
14
|
|
|
|
|
130
|
return; |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
syswrite( |
109
|
51
|
|
|
|
|
722
|
$_QUE_W_SOCK, pack($_que_template, $_chunk_id + 1, $_offset + 1) |
110
|
|
|
|
|
|
|
); |
111
|
|
|
|
|
|
|
|
112
|
51
|
|
|
|
|
160
|
$_dat_un->(); |
113
|
51
|
|
|
|
|
97
|
$_chunk_id++; |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
## Call user function. |
116
|
51
|
100
|
66
|
|
|
207
|
if ($_chunk_size == 1 || $_begin == $_end) { |
117
|
36
|
|
|
|
|
55
|
$_ = $_offset * $_step + $_begin; |
118
|
36
|
50
|
|
|
|
64
|
$_ = _sprintf("%$_fmt", $_) if (defined $_fmt); |
119
|
36
|
50
|
33
|
|
|
116
|
if ($_chunk_size > 1 || $_bounds_only) { |
120
|
0
|
0
|
|
|
|
0
|
$_ = ($_bounds_only) ? [ $_, $_ ] : [ $_ ]; |
121
|
|
|
|
|
|
|
} |
122
|
36
|
|
|
|
|
97
|
$_wuf->($self, $_, $_chunk_id); |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
else { |
125
|
15
|
|
|
|
|
30
|
my $_n_begin = ($_offset * $_chunk_size) * $_step + $_begin; |
126
|
15
|
|
|
|
|
27
|
my @_n = (); $_seq_n = $_n_begin; |
|
15
|
|
|
|
|
48
|
|
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
## ------------------------------------------------------------------- |
129
|
|
|
|
|
|
|
|
130
|
15
|
50
|
|
|
|
37
|
if ($_bounds_only) { |
131
|
0
|
|
|
|
|
0
|
my ($_tmp_b, $_tmp_e) = ($_seq_n); |
132
|
|
|
|
|
|
|
|
133
|
0
|
0
|
|
|
|
0
|
if ($_begin <= $_end) { |
134
|
0
|
0
|
|
|
|
0
|
if ($_step * ($_chunk_size - 1) + $_n_begin <= $_end) { |
|
|
0
|
|
|
|
|
|
135
|
0
|
|
|
|
|
0
|
$_tmp_e = $_step * ($_chunk_size - 1) + $_n_begin; |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
elsif ($_step == 1) { |
138
|
0
|
|
|
|
|
0
|
$_tmp_e = $_end; |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
else { |
141
|
0
|
|
|
|
|
0
|
for my $_i (1 .. $_chunk_size) { |
142
|
0
|
0
|
|
|
|
0
|
last if ($_seq_n > $_end); |
143
|
0
|
|
|
|
|
0
|
$_tmp_e = $_seq_n; |
144
|
0
|
|
|
|
|
0
|
$_seq_n = $_step * $_i + $_n_begin; |
145
|
|
|
|
|
|
|
} |
146
|
|
|
|
|
|
|
} |
147
|
|
|
|
|
|
|
} |
148
|
|
|
|
|
|
|
else { |
149
|
0
|
0
|
|
|
|
0
|
if ($_step * ($_chunk_size - 1) + $_n_begin >= $_end) { |
|
|
0
|
|
|
|
|
|
150
|
0
|
|
|
|
|
0
|
$_tmp_e = $_step * ($_chunk_size - 1) + $_n_begin; |
151
|
|
|
|
|
|
|
} |
152
|
|
|
|
|
|
|
elsif ($_step == -1) { |
153
|
0
|
|
|
|
|
0
|
$_tmp_e = $_end; |
154
|
|
|
|
|
|
|
} |
155
|
|
|
|
|
|
|
else { |
156
|
0
|
|
|
|
|
0
|
for my $_i (1 .. $_chunk_size) { |
157
|
0
|
0
|
|
|
|
0
|
last if ($_seq_n < $_end); |
158
|
0
|
|
|
|
|
0
|
$_tmp_e = $_seq_n; |
159
|
0
|
|
|
|
|
0
|
$_seq_n = $_step * $_i + $_n_begin; |
160
|
|
|
|
|
|
|
} |
161
|
|
|
|
|
|
|
} |
162
|
|
|
|
|
|
|
} |
163
|
|
|
|
|
|
|
|
164
|
0
|
0
|
|
|
|
0
|
@_n = (defined $_fmt) |
165
|
|
|
|
|
|
|
? ( _sprintf("%$_fmt",$_tmp_b), _sprintf("%$_fmt",$_tmp_e) ) |
166
|
|
|
|
|
|
|
: ( $_tmp_b, $_tmp_e ); |
167
|
|
|
|
|
|
|
} |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
## ------------------------------------------------------------------- |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
else { |
172
|
15
|
50
|
|
|
|
34
|
if ($_begin <= $_end) { |
173
|
15
|
50
|
33
|
|
|
124
|
if (!defined $_fmt && $_step == 1 && abs($_end) < ~1 && abs($_begin) < ~1) { |
|
|
|
33
|
|
|
|
|
|
|
|
33
|
|
|
|
|
174
|
15
|
100
|
|
|
|
62
|
$_ = ($_seq_n + $_chunk_size <= $_end) |
175
|
|
|
|
|
|
|
? [ $_seq_n .. $_seq_n + $_chunk_size - 1 ] |
176
|
|
|
|
|
|
|
: [ $_seq_n .. $_end ]; |
177
|
|
|
|
|
|
|
|
178
|
15
|
|
|
|
|
67
|
$_wuf->($self, $_, $_chunk_id); |
179
|
15
|
|
|
|
|
33
|
next; |
180
|
|
|
|
|
|
|
} |
181
|
|
|
|
|
|
|
else { |
182
|
0
|
|
|
|
|
|
for my $_i (1 .. $_chunk_size) { |
183
|
0
|
0
|
|
|
|
|
last if ($_seq_n > $_end); |
184
|
|
|
|
|
|
|
|
185
|
0
|
0
|
|
|
|
|
push @_n, (defined $_fmt) |
186
|
|
|
|
|
|
|
? _sprintf("%$_fmt", $_seq_n) : $_seq_n; |
187
|
|
|
|
|
|
|
|
188
|
0
|
|
|
|
|
|
$_seq_n = $_step * $_i + $_n_begin; |
189
|
|
|
|
|
|
|
} |
190
|
|
|
|
|
|
|
} |
191
|
|
|
|
|
|
|
} |
192
|
|
|
|
|
|
|
else { |
193
|
0
|
|
|
|
|
|
for my $_i (1 .. $_chunk_size) { |
194
|
0
|
0
|
|
|
|
|
last if ($_seq_n < $_end); |
195
|
|
|
|
|
|
|
|
196
|
0
|
0
|
|
|
|
|
push @_n, (defined $_fmt) |
197
|
|
|
|
|
|
|
? _sprintf("%$_fmt", $_seq_n) : $_seq_n; |
198
|
|
|
|
|
|
|
|
199
|
0
|
|
|
|
|
|
$_seq_n = $_step * $_i + $_n_begin; |
200
|
|
|
|
|
|
|
} |
201
|
|
|
|
|
|
|
} |
202
|
|
|
|
|
|
|
} |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
## ------------------------------------------------------------------- |
205
|
|
|
|
|
|
|
|
206
|
0
|
|
|
|
|
|
$_ = \@_n; |
207
|
0
|
|
|
|
|
|
$_wuf->($self, \@_n, $_chunk_id); |
208
|
|
|
|
|
|
|
} |
209
|
|
|
|
|
|
|
} |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
_WORKER_SEQUENCE__LAST: |
212
|
|
|
|
|
|
|
|
213
|
0
|
|
|
|
|
|
return; |
214
|
|
|
|
|
|
|
} |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
1; |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
__END__ |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
############################################################################### |
221
|
|
|
|
|
|
|
## ---------------------------------------------------------------------------- |
222
|
|
|
|
|
|
|
## Module usage. |
223
|
|
|
|
|
|
|
## |
224
|
|
|
|
|
|
|
############################################################################### |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
=head1 NAME |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
MCE::Core::Input::Sequence - Sequence of numbers (for task_id == 0) |
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
=head1 VERSION |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
This document describes MCE::Core::Input::Sequence version 1.887 |
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
=head1 DESCRIPTION |
235
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
This package provides a sequence of numbers used internally by the worker |
237
|
|
|
|
|
|
|
process. Distribution follows a bank-queuing model. |
238
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
There is no public API. |
240
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
=head1 SEE ALSO |
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
The syntax for the C<sequence> option is described in L<MCE::Core>. |
244
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
=head1 AUTHOR |
246
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
Mario E. Roy, S<E<lt>marioeroy AT gmail DOT comE<gt>> |
248
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
=cut |
250
|
|
|
|
|
|
|
|