summaryrefslogtreecommitdiff
path: root/lib/MCE
diff options
context:
space:
mode:
authorgregor herrmann <gregoa@debian.org>2018-07-20 20:40:05 +0200
committergregor herrmann <gregoa@debian.org>2018-07-20 20:40:05 +0200
commit0dbe66f3950af0de939f19e59d9459aba8fe2347 (patch)
tree58a3d4db1ce7e7c3372da6683fadc25131fa2be0 /lib/MCE
parent3c267097308b1d6b3164bfc4968f4f54eec458f2 (diff)
New upstream version 1.836
Diffstat (limited to 'lib/MCE')
-rw-r--r--lib/MCE/Candy.pm4
-rw-r--r--lib/MCE/Core.pod2
-rw-r--r--lib/MCE/Core/Input/Generator.pm2
-rw-r--r--lib/MCE/Core/Input/Handle.pm2
-rw-r--r--lib/MCE/Core/Input/Iterator.pm2
-rw-r--r--lib/MCE/Core/Input/Request.pm2
-rw-r--r--lib/MCE/Core/Input/Sequence.pm2
-rw-r--r--lib/MCE/Core/Manager.pm4
-rw-r--r--lib/MCE/Core/Validation.pm157
-rw-r--r--lib/MCE/Core/Worker.pm10
-rw-r--r--lib/MCE/Examples.pod2
-rw-r--r--lib/MCE/Flow.pm29
-rw-r--r--lib/MCE/Grep.pm29
-rw-r--r--lib/MCE/Loop.pm29
-rw-r--r--lib/MCE/Map.pm29
-rw-r--r--lib/MCE/Mutex.pm4
-rw-r--r--lib/MCE/Mutex/Channel.pm4
-rw-r--r--lib/MCE/Mutex/Flock.pm4
-rw-r--r--lib/MCE/Queue.pm20
-rw-r--r--lib/MCE/Relay.pm4
-rw-r--r--lib/MCE/Signal.pm4
-rw-r--r--lib/MCE/Step.pm29
-rw-r--r--lib/MCE/Stream.pm29
-rw-r--r--lib/MCE/Subs.pm4
-rw-r--r--lib/MCE/Util.pm144
25 files changed, 238 insertions, 313 deletions
diff --git a/lib/MCE/Candy.pm b/lib/MCE/Candy.pm
index 07436e7..f411ff7 100644
--- a/lib/MCE/Candy.pm
+++ b/lib/MCE/Candy.pm
@@ -11,7 +11,7 @@ use warnings;
no warnings qw( threads recursion uninitialized );
-our $VERSION = '1.835';
+our $VERSION = '1.836';
our @CARP_NOT = qw( MCE );
@@ -219,7 +219,7 @@ MCE::Candy - Sugar methods and output iterators
=head1 VERSION
-This document describes MCE::Candy version 1.835
+This document describes MCE::Candy version 1.836
=head1 DESCRIPTION
diff --git a/lib/MCE/Core.pod b/lib/MCE/Core.pod
index 4c16d8e..191e518 100644
--- a/lib/MCE/Core.pod
+++ b/lib/MCE/Core.pod
@@ -5,7 +5,7 @@ MCE::Core - Documentation describing the core MCE API
=head1 VERSION
-This document describes MCE::Core version 1.835
+This document describes MCE::Core version 1.836
=head1 SYNOPSIS
diff --git a/lib/MCE/Core/Input/Generator.pm b/lib/MCE/Core/Input/Generator.pm
index d3c1b74..eee63c4 100644
--- a/lib/MCE/Core/Input/Generator.pm
+++ b/lib/MCE/Core/Input/Generator.pm
@@ -15,7 +15,7 @@ package MCE::Core::Input::Generator;
use strict;
use warnings;
-our $VERSION = '1.835';
+our $VERSION = '1.836';
## Items below are folded into MCE.
diff --git a/lib/MCE/Core/Input/Handle.pm b/lib/MCE/Core/Input/Handle.pm
index 5a828dd..dfa7c65 100644
--- a/lib/MCE/Core/Input/Handle.pm
+++ b/lib/MCE/Core/Input/Handle.pm
@@ -14,7 +14,7 @@ package MCE::Core::Input::Handle;
use strict;
use warnings;
-our $VERSION = '1.835';
+our $VERSION = '1.836';
## Items below are folded into MCE.
diff --git a/lib/MCE/Core/Input/Iterator.pm b/lib/MCE/Core/Input/Iterator.pm
index 452a2d6..1cf98fe 100644
--- a/lib/MCE/Core/Input/Iterator.pm
+++ b/lib/MCE/Core/Input/Iterator.pm
@@ -14,7 +14,7 @@ package MCE::Core::Input::Iterator;
use strict;
use warnings;
-our $VERSION = '1.835';
+our $VERSION = '1.836';
## Items below are folded into MCE.
diff --git a/lib/MCE/Core/Input/Request.pm b/lib/MCE/Core/Input/Request.pm
index 8878ef1..9387424 100644
--- a/lib/MCE/Core/Input/Request.pm
+++ b/lib/MCE/Core/Input/Request.pm
@@ -14,7 +14,7 @@ package MCE::Core::Input::Request;
use strict;
use warnings;
-our $VERSION = '1.835';
+our $VERSION = '1.836';
## Items below are folded into MCE.
diff --git a/lib/MCE/Core/Input/Sequence.pm b/lib/MCE/Core/Input/Sequence.pm
index 644c87b..e950ccb 100644
--- a/lib/MCE/Core/Input/Sequence.pm
+++ b/lib/MCE/Core/Input/Sequence.pm
@@ -14,7 +14,7 @@ package MCE::Core::Input::Sequence;
use strict;
use warnings;
-our $VERSION = '1.835';
+our $VERSION = '1.836';
## Items below are folded into MCE.
diff --git a/lib/MCE/Core/Manager.pm b/lib/MCE/Core/Manager.pm
index 641e820..6fc3762 100644
--- a/lib/MCE/Core/Manager.pm
+++ b/lib/MCE/Core/Manager.pm
@@ -14,7 +14,7 @@ package MCE::Core::Manager;
use strict;
use warnings;
-our $VERSION = '1.835';
+our $VERSION = '1.836';
## no critic (BuiltinFunctions::ProhibitStringyEval)
## no critic (TestingAndDebugging::ProhibitNoStrict)
@@ -116,7 +116,7 @@ sub _output_loop {
my $_ret = $_cb->(@_);
return print {$_DAU_R_SOCK} length($_ret).'0'.$LF, $_ret
- if ( !ref $_ret && defined $_ret && !looks_like_number $_ret );
+ if ( !looks_like_number $_ret && !ref $_ret && defined $_ret );
my $_buf = $self->{freeze}([ $_ret ]);
diff --git a/lib/MCE/Core/Validation.pm b/lib/MCE/Core/Validation.pm
index d918d9a..c35eb1b 100644
--- a/lib/MCE/Core/Validation.pm
+++ b/lib/MCE/Core/Validation.pm
@@ -14,7 +14,7 @@ package MCE::Core::Validation;
use strict;
use warnings;
-our $VERSION = '1.835';
+our $VERSION = '1.836';
## Items below are folded into MCE.
@@ -223,5 +223,160 @@ sub _validate_runstate {
return;
}
+###############################################################################
+## ----------------------------------------------------------------------------
+## Private functions for MCE Models { Flow, Grep, Loop, Map, Step, Stream }.
+##
+###############################################################################
+
+sub _parse_chunk_size {
+
+ my ($_chunk_size, $_max_workers, $_params, $_input_data, $_array_size) = @_;
+
+ @_ = ();
+
+ return $_chunk_size if (!defined $_chunk_size || !defined $_max_workers);
+
+ if (defined $_params && exists $_params->{chunk_size}) {
+ $_chunk_size = $_params->{chunk_size};
+ }
+
+ if ($_chunk_size =~ /([0-9\.]+)K\z/i) {
+ $_chunk_size = int($1 * 1024 + 0.5);
+ }
+ elsif ($_chunk_size =~ /([0-9\.]+)M\z/i) {
+ $_chunk_size = int($1 * 1024 * 1024 + 0.5);
+ }
+
+ if ($_chunk_size eq 'auto') {
+
+ if ( (defined $_params && ref $_params->{input_data} eq 'CODE') ||
+ (defined $_input_data && ref $_input_data eq 'CODE')
+ ) {
+ # Iterators may optionally use chunk_size to determine how much
+ # to return per iteration. The default is 1 for MCE Models, same
+ # as for the Core API. The user_func receives an array_ref
+ # regardless if 1 or higher.
+ #
+ # sub make_iter {
+ # ...
+ # return sub {
+ # my ($chunk_size) = @_;
+ # ...
+ # };
+ # }
+ return 1;
+ }
+
+ my $_is_file;
+ my $_size = $_array_size;
+
+ if (defined $_input_data) {
+ if (ref $_input_data eq 'ARRAY') {
+ $_size = scalar @{ $_input_data };
+ } elsif (ref $_input_data eq 'HASH') {
+ $_size = scalar keys %{ $_input_data };
+ }
+ }
+
+ if (defined $_params && exists $_params->{sequence}) {
+ my ($_begin, $_end, $_step);
+
+ if (ref $_params->{sequence} eq 'HASH') {
+ $_begin = $_params->{sequence}->{begin};
+ $_end = $_params->{sequence}->{end};
+ $_step = $_params->{sequence}->{step} || 1;
+ }
+ else {
+ $_begin = $_params->{sequence}[0];
+ $_end = $_params->{sequence}[1];
+ $_step = $_params->{sequence}[2] || 1;
+ }
+
+ if (!defined $_input_data && !$_array_size) {
+ $_size = abs($_end - $_begin) / $_step + 1;
+ }
+ }
+ elsif (defined $_params && exists $_params->{_file}) {
+ my $_ref = ref $_params->{_file};
+
+ if ($_ref eq 'SCALAR') {
+ $_size = length ${ $_params->{_file} };
+ } elsif ($_ref eq '') {
+ $_size = -s $_params->{_file};
+ } else {
+ $_size = 0; $_chunk_size = 393_216; # 384K
+ }
+
+ $_is_file = 1;
+ }
+ elsif (defined $_input_data) {
+ if (ref($_input_data) =~ /^(?:GLOB|FileHandle|IO::)/) {
+ $_is_file = 1; $_size = 0; $_chunk_size = 393_216; # 384K
+ }
+ elsif (ref $_input_data eq 'SCALAR') {
+ $_is_file = 1; $_size = length ${ $_input_data };
+ }
+ }
+
+ if (defined $_is_file) {
+ if ($_size) {
+ $_chunk_size = int($_size / $_max_workers / 24 + 0.5);
+ $_chunk_size = 5_242_880 if $_chunk_size > 5_242_880; # 5M
+ $_chunk_size = 2 if $_chunk_size <= 8192;
+ }
+ }
+ else {
+ $_chunk_size = int($_size / $_max_workers / 24 + 0.5);
+ $_chunk_size = 8000 if $_chunk_size > 8000;
+ $_chunk_size = 2 if $_chunk_size < 2;
+ }
+ }
+
+ return $_chunk_size;
+}
+
+sub _parse_max_workers {
+
+ my ($_max_workers) = @_;
+
+ @_ = ();
+
+ return $_max_workers unless (defined $_max_workers);
+
+ if ($_max_workers =~ /^auto(?:$|\s*([\-\+\/\*])\s*(.+)$)/i) {
+ my ($_ncpu_ul, $_ncpu);
+
+ $_ncpu_ul = $_ncpu = MCE::Util::get_ncpu();
+ $_ncpu_ul = 8 if ($_ncpu_ul > 8);
+
+ if ($1 && $2) {
+ local $@; $_max_workers = eval "int($_ncpu_ul $1 $2 + 0.5)";
+ $_max_workers = 1 if (!$_max_workers || $_max_workers < 1);
+ $_max_workers = $_ncpu if ($_max_workers > $_ncpu);
+ }
+ else {
+ $_max_workers = $_ncpu_ul;
+ }
+ }
+
+ return $_max_workers;
+}
+
+sub _validate_number {
+
+ my ($_n, $_key, $_tag) = @_;
+
+ _croak("$_tag: ($_key) is not valid") if (!defined $_n);
+
+ $_n =~ s/K\z//i; $_n =~ s/M\z//i;
+
+ if (!looks_like_number($_n) || int($_n) != $_n || $_n < 1) {
+ _croak("$_tag: ($_key) is not valid");
+ }
+
+ return;
+}
+
1;
diff --git a/lib/MCE/Core/Worker.pm b/lib/MCE/Core/Worker.pm
index 62fbc1f..6dc19b9 100644
--- a/lib/MCE/Core/Worker.pm
+++ b/lib/MCE/Core/Worker.pm
@@ -14,7 +14,7 @@ package MCE::Core::Worker;
use strict;
use warnings;
-our $VERSION = '1.835';
+our $VERSION = '1.836';
my $_has_threads = $INC{'threads.pm'} ? 1 : 0;
my $_tid = $_has_threads ? threads->tid() : 0;
@@ -130,8 +130,8 @@ use bytes;
print({$_DAT_W_SOCK} OUTPUT_N_CBK.$LF . $_chn.$LF),
print({$_DAU_W_SOCK} $_wa.$LF . $_val.$LF);
}
- elsif ( @{ $_aref } == 1 && !ref $_aref->[0] &&
- defined $_aref->[0] && !looks_like_number($_aref->[0]) ) {
+ elsif ( @{ $_aref } == 1 && !looks_like_number $_aref->[0] &&
+ !ref $_aref->[0] && defined $_aref->[0] ) {
$_len = length $_aref->[0];
$_dat_ex->() if $_lock_chn;
@@ -173,8 +173,8 @@ use bytes;
return unless (scalar @{ $_aref });
- if (scalar @{ $_aref } > 1 || ref $_aref->[0] ||
- !defined $_aref->[0] || looks_like_number $_aref->[0]) {
+ if ( scalar @{ $_aref } > 1 || looks_like_number $_aref->[0] ||
+ ref $_aref->[0] || !defined $_aref->[0] ) {
$_tag = OUTPUT_A_GTR;
$_buf = $self->{freeze}($_aref);
$_len = length $_buf;
diff --git a/lib/MCE/Examples.pod b/lib/MCE/Examples.pod
index 62122f0..96bed6e 100644
--- a/lib/MCE/Examples.pod
+++ b/lib/MCE/Examples.pod
@@ -5,7 +5,7 @@ MCE::Examples - Various examples and demonstrations
=head1 VERSION
-This document describes MCE::Examples version 1.835
+This document describes MCE::Examples version 1.836
=head1 INCLUDED WITH THE DISTRIBUTION
diff --git a/lib/MCE/Flow.pm b/lib/MCE/Flow.pm
index c0f1dcd..e6a5ea1 100644
--- a/lib/MCE/Flow.pm
+++ b/lib/MCE/Flow.pm
@@ -11,7 +11,7 @@ use warnings;
no warnings qw( threads recursion uninitialized );
-our $VERSION = '1.835';
+our $VERSION = '1.836';
## no critic (BuiltinFunctions::ProhibitStringyEval)
## no critic (Subroutines::ProhibitSubroutinePrototypes)
@@ -77,10 +77,10 @@ sub import {
_croak("Error: ($_argument) invalid module option");
}
- $_p->{MAX_WORKERS} = MCE::Util::_parse_max_workers($_p->{MAX_WORKERS});
+ $_p->{MAX_WORKERS} = MCE::_parse_max_workers($_p->{MAX_WORKERS});
- _validate_number($_p->{MAX_WORKERS}, 'MAX_WORKERS');
- _validate_number($_p->{CHUNK_SIZE}, 'CHUNK_SIZE')
+ MCE::_validate_number($_p->{MAX_WORKERS}, 'MAX_WORKERS', $_tag);
+ MCE::_validate_number($_p->{CHUNK_SIZE}, 'CHUNK_SIZE', $_tag)
unless ($_p->{CHUNK_SIZE} eq 'auto');
return;
@@ -316,7 +316,7 @@ sub run (@) {
}
if (defined (my $_p = $_params->{$_pid})) {
- $_max_workers = MCE::Util::_parse_max_workers($_p->{max_workers})
+ $_max_workers = MCE::_parse_max_workers($_p->{max_workers})
if (exists $_p->{max_workers} && ref $_p->{max_workers} ne 'ARRAY');
delete $_p->{sequence} if (defined $_input_data || scalar @_);
@@ -328,7 +328,7 @@ sub run (@) {
$_max_workers = int($_max_workers / @_code + 0.5) + 1;
}
- my $_chunk_size = MCE::Util::_parse_chunk_size(
+ my $_chunk_size = MCE::_parse_chunk_size(
$_def->{$_pkg}{CHUNK_SIZE}, $_max_workers, $_params->{$_pid},
$_input_data, scalar @_
);
@@ -464,21 +464,6 @@ sub _gen_user_tasks {
return;
}
-sub _validate_number {
-
- my ($_n, $_key) = @_;
-
- _croak("$_tag: ($_key) is not valid") if (!defined $_n);
-
- $_n =~ s/K\z//i; $_n =~ s/M\z//i;
-
- if (!looks_like_number($_n) || int($_n) != $_n || $_n < 1) {
- _croak("$_tag: ($_key) is not valid");
- }
-
- return;
-}
-
1;
__END__
@@ -495,7 +480,7 @@ MCE::Flow - Parallel flow model for building creative applications
=head1 VERSION
-This document describes MCE::Flow version 1.835
+This document describes MCE::Flow version 1.836
=head1 DESCRIPTION
diff --git a/lib/MCE/Grep.pm b/lib/MCE/Grep.pm
index d9731aa..ad74197 100644
--- a/lib/MCE/Grep.pm
+++ b/lib/MCE/Grep.pm
@@ -11,7 +11,7 @@ use warnings;
no warnings qw( threads recursion uninitialized );
-our $VERSION = '1.835';
+our $VERSION = '1.836';
## no critic (BuiltinFunctions::ProhibitStringyEval)
## no critic (Subroutines::ProhibitSubroutinePrototypes)
@@ -75,10 +75,10 @@ sub import {
_croak("Error: ($_argument) invalid module option");
}
- $_p->{MAX_WORKERS} = MCE::Util::_parse_max_workers($_p->{MAX_WORKERS});
+ $_p->{MAX_WORKERS} = MCE::_parse_max_workers($_p->{MAX_WORKERS});
- _validate_number($_p->{MAX_WORKERS}, 'MAX_WORKERS');
- _validate_number($_p->{CHUNK_SIZE}, 'CHUNK_SIZE')
+ MCE::_validate_number($_p->{MAX_WORKERS}, 'MAX_WORKERS', $_tag);
+ MCE::_validate_number($_p->{CHUNK_SIZE}, 'CHUNK_SIZE', $_tag)
unless ($_p->{CHUNK_SIZE} eq 'auto');
return;
@@ -258,7 +258,7 @@ sub run (&@) {
}
if (defined (my $_p = $_params->{$_pid})) {
- $_max_workers = MCE::Util::_parse_max_workers($_p->{max_workers})
+ $_max_workers = MCE::_parse_max_workers($_p->{max_workers})
if (exists $_p->{max_workers});
delete $_p->{sequence} if (defined $_input_data || scalar @_);
@@ -269,7 +269,7 @@ sub run (&@) {
delete $_p->{gather} if (exists $_p->{gather});
}
- my $_chunk_size = MCE::Util::_parse_chunk_size(
+ my $_chunk_size = MCE::_parse_chunk_size(
$_def->{$_pkg}{CHUNK_SIZE}, $_max_workers, $_params->{$_pid},
$_input_data, scalar @_
);
@@ -419,21 +419,6 @@ sub _croak {
goto &MCE::_croak;
}
-sub _validate_number {
-
- my ($_n, $_key) = @_;
-
- _croak("$_tag: ($_key) is not valid") if (!defined $_n);
-
- $_n =~ s/K\z//i; $_n =~ s/M\z//i;
-
- if (!looks_like_number($_n) || int($_n) != $_n || $_n < 1) {
- _croak("$_tag: ($_key) is not valid");
- }
-
- return;
-}
-
1;
__END__
@@ -450,7 +435,7 @@ MCE::Grep - Parallel grep model similar to the native grep function
=head1 VERSION
-This document describes MCE::Grep version 1.835
+This document describes MCE::Grep version 1.836
=head1 SYNOPSIS
diff --git a/lib/MCE/Loop.pm b/lib/MCE/Loop.pm
index d904f27..c096436 100644
--- a/lib/MCE/Loop.pm
+++ b/lib/MCE/Loop.pm
@@ -11,7 +11,7 @@ use warnings;
no warnings qw( threads recursion uninitialized );
-our $VERSION = '1.835';
+our $VERSION = '1.836';
## no critic (BuiltinFunctions::ProhibitStringyEval)
## no critic (Subroutines::ProhibitSubroutinePrototypes)
@@ -75,10 +75,10 @@ sub import {
_croak("Error: ($_argument) invalid module option");
}
- $_p->{MAX_WORKERS} = MCE::Util::_parse_max_workers($_p->{MAX_WORKERS});
+ $_p->{MAX_WORKERS} = MCE::_parse_max_workers($_p->{MAX_WORKERS});
- _validate_number($_p->{MAX_WORKERS}, 'MAX_WORKERS');
- _validate_number($_p->{CHUNK_SIZE}, 'CHUNK_SIZE')
+ MCE::_validate_number($_p->{MAX_WORKERS}, 'MAX_WORKERS', $_tag);
+ MCE::_validate_number($_p->{CHUNK_SIZE}, 'CHUNK_SIZE', $_tag)
unless ($_p->{CHUNK_SIZE} eq 'auto');
return;
@@ -234,7 +234,7 @@ sub run (&@) {
}
if (defined (my $_p = $_params->{$_pid})) {
- $_max_workers = MCE::Util::_parse_max_workers($_p->{max_workers})
+ $_max_workers = MCE::_parse_max_workers($_p->{max_workers})
if (exists $_p->{max_workers});
delete $_p->{sequence} if (defined $_input_data || scalar @_);
@@ -242,7 +242,7 @@ sub run (&@) {
delete $_p->{user_tasks} if (exists $_p->{user_tasks});
}
- my $_chunk_size = MCE::Util::_parse_chunk_size(
+ my $_chunk_size = MCE::_parse_chunk_size(
$_def->{$_pkg}{CHUNK_SIZE}, $_max_workers, $_params->{$_pid},
$_input_data, scalar @_
);
@@ -334,21 +334,6 @@ sub _croak {
goto &MCE::_croak;
}
-sub _validate_number {
-
- my ($_n, $_key) = @_;
-
- _croak("$_tag: ($_key) is not valid") if (!defined $_n);
-
- $_n =~ s/K\z//i; $_n =~ s/M\z//i;
-
- if (!looks_like_number($_n) || int($_n) != $_n || $_n < 1) {
- _croak("$_tag: ($_key) is not valid");
- }
-
- return;
-}
-
1;
__END__
@@ -365,7 +350,7 @@ MCE::Loop - MCE model for building parallel loops
=head1 VERSION
-This document describes MCE::Loop version 1.835
+This document describes MCE::Loop version 1.836
=head1 DESCRIPTION
diff --git a/lib/MCE/Map.pm b/lib/MCE/Map.pm
index b23ada4..20bf96e 100644
--- a/lib/MCE/Map.pm
+++ b/lib/MCE/Map.pm
@@ -11,7 +11,7 @@ use warnings;
no warnings qw( threads recursion uninitialized );
-our $VERSION = '1.835';
+our $VERSION = '1.836';
## no critic (BuiltinFunctions::ProhibitStringyEval)
## no critic (Subroutines::ProhibitSubroutinePrototypes)
@@ -75,10 +75,10 @@ sub import {
_croak("Error: ($_argument) invalid module option");
}
- $_p->{MAX_WORKERS} = MCE::Util::_parse_max_workers($_p->{MAX_WORKERS});
+ $_p->{MAX_WORKERS} = MCE::_parse_max_workers($_p->{MAX_WORKERS});
- _validate_number($_p->{MAX_WORKERS}, 'MAX_WORKERS');
- _validate_number($_p->{CHUNK_SIZE}, 'CHUNK_SIZE')
+ MCE::_validate_number($_p->{MAX_WORKERS}, 'MAX_WORKERS', $_tag);
+ MCE::_validate_number($_p->{CHUNK_SIZE}, 'CHUNK_SIZE', $_tag)
unless ($_p->{CHUNK_SIZE} eq 'auto');
return;
@@ -258,7 +258,7 @@ sub run (&@) {
}
if (defined (my $_p = $_params->{$_pid})) {
- $_max_workers = MCE::Util::_parse_max_workers($_p->{max_workers})
+ $_max_workers = MCE::_parse_max_workers($_p->{max_workers})
if (exists $_p->{max_workers});
delete $_p->{sequence} if (defined $_input_data || scalar @_);
@@ -269,7 +269,7 @@ sub run (&@) {
delete $_p->{gather} if (exists $_p->{gather});
}
- my $_chunk_size = MCE::Util::_parse_chunk_size(
+ my $_chunk_size = MCE::_parse_chunk_size(
$_def->{$_pkg}{CHUNK_SIZE}, $_max_workers, $_params->{$_pid},
$_input_data, scalar @_
);
@@ -419,21 +419,6 @@ sub _croak {
goto &MCE::_croak;
}
-sub _validate_number {
-
- my ($_n, $_key) = @_;
-
- _croak("$_tag: ($_key) is not valid") if (!defined $_n);
-
- $_n =~ s/K\z//i; $_n =~ s/M\z//i;
-
- if (!looks_like_number($_n) || int($_n) != $_n || $_n < 1) {
- _croak("$_tag: ($_key) is not valid");
- }
-
- return;
-}
-
1;
__END__
@@ -450,7 +435,7 @@ MCE::Map - Parallel map model similar to the native map function
=head1 VERSION
-This document describes MCE::Map version 1.835
+This document describes MCE::Map version 1.836
=head1 SYNOPSIS
diff --git a/lib/MCE/Mutex.pm b/lib/MCE/Mutex.pm
index f229bb6..c0f6bfe 100644
--- a/lib/MCE/Mutex.pm
+++ b/lib/MCE/Mutex.pm
@@ -11,7 +11,7 @@ use warnings;
no warnings qw( threads recursion uninitialized );
-our $VERSION = '1.835';
+our $VERSION = '1.836';
## no critic (BuiltinFunctions::ProhibitStringyEval)
## no critic (TestingAndDebugging::ProhibitNoStrict)
@@ -71,7 +71,7 @@ MCE::Mutex - Locking for Many-Core Engine
=head1 VERSION
-This document describes MCE::Mutex version 1.835
+This document describes MCE::Mutex version 1.836
=head1 SYNOPSIS
diff --git a/lib/MCE/Mutex/Channel.pm b/lib/MCE/Mutex/Channel.pm
index 16100fc..c2a6f49 100644
--- a/lib/MCE/Mutex/Channel.pm
+++ b/lib/MCE/Mutex/Channel.pm
@@ -11,7 +11,7 @@ use warnings;
no warnings qw( threads recursion uninitialized once );
-our $VERSION = '1.835';
+our $VERSION = '1.836';
use base 'MCE::Mutex';
use Scalar::Util qw(refaddr weaken);
@@ -130,7 +130,7 @@ MCE::Mutex::Channel - Mutex locking via a pipe or socket
=head1 VERSION
-This document describes MCE::Mutex::Channel version 1.835
+This document describes MCE::Mutex::Channel version 1.836
=head1 DESCRIPTION
diff --git a/lib/MCE/Mutex/Flock.pm b/lib/MCE/Mutex/Flock.pm
index 22ed200..c7b39a3 100644
--- a/lib/MCE/Mutex/Flock.pm
+++ b/lib/MCE/Mutex/Flock.pm
@@ -11,7 +11,7 @@ use warnings;
no warnings qw( threads recursion uninitialized once );
-our $VERSION = '1.835';
+our $VERSION = '1.836';
use base 'MCE::Mutex';
use Fcntl ':flock';
@@ -186,7 +186,7 @@ MCE::Mutex::Flock - Mutex locking via Fcntl
=head1 VERSION
-This document describes MCE::Mutex::Flock version 1.835
+This document describes MCE::Mutex::Flock version 1.836
=head1 DESCRIPTION
diff --git a/lib/MCE/Queue.pm b/lib/MCE/Queue.pm
index b897ff7..c4700d9 100644
--- a/lib/MCE/Queue.pm
+++ b/lib/MCE/Queue.pm
@@ -11,7 +11,7 @@ use warnings;
no warnings qw( threads recursion uninitialized );
-our $VERSION = '1.835';
+our $VERSION = '1.836';
## no critic (Subroutines::ProhibitExplicitReturnUndef)
## no critic (TestingAndDebugging::ProhibitNoStrict)
@@ -587,7 +587,7 @@ sub _heap_insert_high {
print {$_DAU_R_SOCK} length($_buf).'1'.$LF, $_buf;
}
elsif (defined $_buf) {
- if (!ref $_buf && !looks_like_number $_buf) {
+ if (!looks_like_number $_buf && !ref $_buf) {
print {$_DAU_R_SOCK} length($_buf).'0'.$LF, $_buf;
} else {
$_buf = $_MCE->{freeze}([ $_buf ]);
@@ -626,7 +626,7 @@ sub _heap_insert_high {
my $_buf = $_Q->_dequeue();
if (defined $_buf) {
- if (!ref $_buf && !looks_like_number($_buf)) {
+ if (!looks_like_number $_buf && !ref $_buf) {
print {$_DAU_R_SOCK} length($_buf).'0'.$LF, $_buf;
} else {
$_buf = $_MCE->{freeze}([ $_buf ]);
@@ -732,7 +732,7 @@ sub _heap_insert_high {
print {$_DAU_R_SOCK} '-1'.$LF;
}
else {
- if (!ref $_buf && !looks_like_number($_buf)) {
+ if (!looks_like_number $_buf && !ref $_buf) {
print {$_DAU_R_SOCK} length($_buf).'0'.$LF, $_buf;
} else {
$_buf = $_MCE->{freeze}([ $_buf ]);
@@ -757,7 +757,7 @@ sub _heap_insert_high {
print {$_DAU_R_SOCK} '-1'.$LF;
}
else {
- if (!ref $_buf && !looks_like_number($_buf)) {
+ if (!looks_like_number $_buf && !ref $_buf) {
print {$_DAU_R_SOCK} length($_buf).'0'.$LF, $_buf;
} else {
$_buf = $_MCE->{freeze}([ $_buf ]);
@@ -1370,7 +1370,7 @@ sub _mce_m_heap {
my $_buf = $_Q->{_id}.$LF . length($_tmp).$LF;
$_req1->(OUTPUT_A_QUE, $_buf, $_tmp);
}
- elsif (defined $_[0] && !looks_like_number $_[0]) {
+ elsif (!looks_like_number $_[0] && defined $_[0]) {
my $_buf = $_Q->{_id}.$LF . length($_[0]).$LF;
$_req1->(OUTPUT_S_QUE, $_buf, $_[0]);
}
@@ -1396,7 +1396,7 @@ sub _mce_m_heap {
my $_buf = $_Q->{_id}.$LF . $_p.$LF . length($_tmp).$LF;
$_req1->(OUTPUT_A_QUP, $_buf, $_tmp);
}
- elsif (defined $_[0] && !looks_like_number $_[0]) {
+ elsif (!looks_like_number $_[0] && defined $_[0]) {
my $_buf = $_Q->{_id}.$LF . $_p.$LF . length($_[0]).$LF;
$_req1->(OUTPUT_S_QUP, $_buf, $_[0]);
}
@@ -1516,7 +1516,7 @@ sub _mce_m_heap {
my ($_buf, $_tmp);
- if (scalar @_ > 1 || ref $_[0] || !defined $_[0] || looks_like_number $_[0]) {
+ if (scalar @_ > 1 || looks_like_number $_[0] || ref $_[0] || !defined $_[0]) {
$_tmp = $_MCE->{freeze}([ @_ ]);
$_buf = $_Q->{_id}.$LF . $_i.$LF . (length($_tmp) + 1).$LF . $_tmp.'1';
} else {
@@ -1542,7 +1542,7 @@ sub _mce_m_heap {
my ($_buf, $_tmp);
- if (scalar @_ > 1 || ref $_[0] || !defined $_[0] || looks_like_number $_[0]) {
+ if (scalar @_ > 1 || looks_like_number $_[0] || ref $_[0] || !defined $_[0]) {
$_tmp = $_MCE->{freeze}([ @_ ]);
$_buf = $_Q->{_id}.$LF . $_p.$LF . $_i.$LF .
(length($_tmp) + 1).$LF . $_tmp.'1';
@@ -1621,7 +1621,7 @@ MCE::Queue - Hybrid (normal and priority) queues
=head1 VERSION
-This document describes MCE::Queue version 1.835
+This document describes MCE::Queue version 1.836
=head1 SYNOPSIS
diff --git a/lib/MCE/Relay.pm b/lib/MCE/Relay.pm
index a8de61a..1f83cf7 100644
--- a/lib/MCE/Relay.pm
+++ b/lib/MCE/Relay.pm
@@ -11,7 +11,7 @@ use warnings;
no warnings qw( threads recursion uninitialized );
-our $VERSION = '1.835';
+our $VERSION = '1.836';
## no critic (Subroutines::ProhibitSubroutinePrototypes)
@@ -343,7 +343,7 @@ MCE::Relay - Extends Many-Core Engine with relay capabilities
=head1 VERSION
-This document describes MCE::Relay version 1.835
+This document describes MCE::Relay version 1.836
=head1 SYNOPSIS
diff --git a/lib/MCE/Signal.pm b/lib/MCE/Signal.pm
index c961214..97b5f36 100644
--- a/lib/MCE/Signal.pm
+++ b/lib/MCE/Signal.pm
@@ -11,7 +11,7 @@ use warnings;
no warnings qw( threads recursion uninitialized );
-our $VERSION = '1.835';
+our $VERSION = '1.836';
## no critic (BuiltinFunctions::ProhibitStringyEval)
@@ -427,7 +427,7 @@ MCE::Signal - Temporary directory creation/cleanup and signal handling
=head1 VERSION
-This document describes MCE::Signal version 1.835
+This document describes MCE::Signal version 1.836
=head1 SYNOPSIS
diff --git a/lib/MCE/Step.pm b/lib/MCE/Step.pm
index 0dadb05..f819ed2 100644
--- a/lib/MCE/Step.pm
+++ b/lib/MCE/Step.pm
@@ -11,7 +11,7 @@ use warnings;
no warnings qw( threads recursion uninitialized );
-our $VERSION = '1.835';
+our $VERSION = '1.836';
## no critic (BuiltinFunctions::ProhibitStringyEval)
## no critic (Subroutines::ProhibitSubroutinePrototypes)
@@ -81,10 +81,10 @@ sub import {
_croak("Error: ($_argument) invalid module option");
}
- $_p->{MAX_WORKERS} = MCE::Util::_parse_max_workers($_p->{MAX_WORKERS});
+ $_p->{MAX_WORKERS} = MCE::_parse_max_workers($_p->{MAX_WORKERS});
- _validate_number($_p->{MAX_WORKERS}, 'MAX_WORKERS');
- _validate_number($_p->{CHUNK_SIZE}, 'CHUNK_SIZE')
+ MCE::_validate_number($_p->{MAX_WORKERS}, 'MAX_WORKERS', $_tag);
+ MCE::_validate_number($_p->{CHUNK_SIZE}, 'CHUNK_SIZE', $_tag)
unless ($_p->{CHUNK_SIZE} eq 'auto');
return;
@@ -497,7 +497,7 @@ sub run (@) {
}
if (defined (my $_p = $_params->{$_pid})) {
- $_max_workers = MCE::Util::_parse_max_workers($_p->{max_workers})
+ $_max_workers = MCE::_parse_max_workers($_p->{max_workers})
if (exists $_p->{max_workers} && ref $_p->{max_workers} ne 'ARRAY');
delete $_p->{sequence} if (defined $_input_data || scalar @_);
@@ -509,7 +509,7 @@ sub run (@) {
$_max_workers = int($_max_workers / @_code + 0.5) + 1;
}
- my $_chunk_size = MCE::Util::_parse_chunk_size(
+ my $_chunk_size = MCE::_parse_chunk_size(
$_def->{$_pkg}{CHUNK_SIZE}, $_max_workers, $_params->{$_pid},
$_input_data, scalar @_
);
@@ -700,21 +700,6 @@ sub _gen_user_tasks {
return;
}
-sub _validate_number {
-
- my ($_n, $_key) = @_;
-
- _croak("$_tag: ($_key) is not valid") if (!defined $_n);
-
- $_n =~ s/K\z//i; $_n =~ s/M\z//i;
-
- if (!looks_like_number($_n) || int($_n) != $_n || $_n < 1) {
- _croak("$_tag: ($_key) is not valid");
- }
-
- return;
-}
-
1;
__END__
@@ -731,7 +716,7 @@ MCE::Step - Parallel step model for building creative steps
=head1 VERSION
-This document describes MCE::Step version 1.835
+This document describes MCE::Step version 1.836
=head1 DESCRIPTION
diff --git a/lib/MCE/Stream.pm b/lib/MCE/Stream.pm
index d0dfcc1..f1c8d94 100644
--- a/lib/MCE/Stream.pm
+++ b/lib/MCE/Stream.pm
@@ -11,7 +11,7 @@ use warnings;
no warnings qw( threads recursion uninitialized );
-our $VERSION = '1.835';
+our $VERSION = '1.836';
## no critic (BuiltinFunctions::ProhibitStringyEval)
## no critic (Subroutines::ProhibitSubroutinePrototypes)
@@ -86,10 +86,10 @@ sub import {
_croak("Error: (DEFAULT_MODE) is not valid")
if ($_p->{DEFAULT_MODE} ne 'grep' && $_p->{DEFAULT_MODE} ne 'map');
- $_p->{MAX_WORKERS} = MCE::Util::_parse_max_workers($_p->{MAX_WORKERS});
+ $_p->{MAX_WORKERS} = MCE::_parse_max_workers($_p->{MAX_WORKERS});
- _validate_number($_p->{MAX_WORKERS}, 'MAX_WORKERS');
- _validate_number($_p->{CHUNK_SIZE}, 'CHUNK_SIZE')
+ MCE::_validate_number($_p->{MAX_WORKERS}, 'MAX_WORKERS', $_tag);
+ MCE::_validate_number($_p->{CHUNK_SIZE}, 'CHUNK_SIZE', $_tag)
unless ($_p->{CHUNK_SIZE} eq 'auto');
return;
@@ -409,7 +409,7 @@ sub run (@) {
}
if (defined (my $_p = $_params->{$_pid})) {
- $_max_workers = MCE::Util::_parse_max_workers($_p->{max_workers})
+ $_max_workers = MCE::_parse_max_workers($_p->{max_workers})
if (exists $_p->{max_workers} && ref $_p->{max_workers} ne 'ARRAY');
delete $_p->{sequence} if (defined $_input_data || scalar @_);
@@ -424,7 +424,7 @@ sub run (@) {
$_max_workers = int($_max_workers / @_code + 0.5) + 1;
}
- my $_chunk_size = MCE::Util::_parse_chunk_size(
+ my $_chunk_size = MCE::_parse_chunk_size(
$_def->{$_pkg}{CHUNK_SIZE}, $_max_workers, $_params->{$_pid},
$_input_data, scalar @_
);
@@ -656,21 +656,6 @@ sub _gen_user_tasks {
return;
}
-sub _validate_number {
-
- my ($_n, $_key) = @_;
-
- _croak("$_tag: ($_key) is not valid") if (!defined $_n);
-
- $_n =~ s/K\z//i; $_n =~ s/M\z//i;
-
- if (!looks_like_number($_n) || int($_n) != $_n || $_n < 1) {
- _croak("$_tag: ($_key) is not valid");
- }
-
- return;
-}
-
1;
__END__
@@ -687,7 +672,7 @@ MCE::Stream - Parallel stream model for chaining multiple maps and greps
=head1 VERSION
-This document describes MCE::Stream version 1.835
+This document describes MCE::Stream version 1.836
=head1 SYNOPSIS
diff --git a/lib/MCE/Subs.pm b/lib/MCE/Subs.pm
index a9f3a46..efd6c00 100644
--- a/lib/MCE/Subs.pm
+++ b/lib/MCE/Subs.pm
@@ -11,7 +11,7 @@ use warnings;
no warnings qw( threads recursion uninitialized );
-our $VERSION = '1.835';
+our $VERSION = '1.836';
## no critic (Subroutines::ProhibitSubroutinePrototypes)
## no critic (TestingAndDebugging::ProhibitNoStrict)
@@ -204,7 +204,7 @@ MCE::Subs - Exports functions mapped directly to MCE methods
=head1 VERSION
-This document describes MCE::Subs version 1.835
+This document describes MCE::Subs version 1.836
=head1 SYNOPSIS
diff --git a/lib/MCE/Util.pm b/lib/MCE/Util.pm
index b7250a5..45c108d 100644
--- a/lib/MCE/Util.pm
+++ b/lib/MCE/Util.pm
@@ -11,7 +11,7 @@ use warnings;
no warnings qw( threads recursion uninitialized numeric );
-our $VERSION = '1.835';
+our $VERSION = '1.836';
## no critic (BuiltinFunctions::ProhibitStringyEval)
@@ -308,146 +308,6 @@ sub _sock_ready {
}
}
-###############################################################################
-## ----------------------------------------------------------------------------
-## Private routines for MCE Models: Flow, Grep, Loop, Map, Step, and Stream.
-##
-###############################################################################
-
-sub _parse_max_workers {
-
- my ($_max_workers) = @_;
-
- @_ = ();
-
- return $_max_workers unless (defined $_max_workers);
-
- if ($_max_workers =~ /^auto(?:$|\s*([\-\+\/\*])\s*(.+)$)/i) {
- my ($_ncpu_ul, $_ncpu);
-
- $_ncpu_ul = $_ncpu = get_ncpu();
- $_ncpu_ul = 8 if ($_ncpu_ul > 8);
-
- if ($1 && $2) {
- local $@; $_max_workers = eval "int($_ncpu_ul $1 $2 + 0.5)";
- $_max_workers = 1 if (!$_max_workers || $_max_workers < 1);
- $_max_workers = $_ncpu if ($_max_workers > $_ncpu);
- }
- else {
- $_max_workers = $_ncpu_ul;
- }
- }
-
- return $_max_workers;
-}
-
-sub _parse_chunk_size {
-
- my ($_chunk_size, $_max_workers, $_params, $_input_data, $_array_size) = @_;
-
- @_ = ();
-
- return $_chunk_size if (!defined $_chunk_size || !defined $_max_workers);
-
- if (defined $_params && exists $_params->{chunk_size}) {
- $_chunk_size = $_params->{chunk_size};
- }
-
- if ($_chunk_size =~ /([0-9\.]+)K\z/i) {
- $_chunk_size = int($1 * 1024 + 0.5);
- }
- elsif ($_chunk_size =~ /([0-9\.]+)M\z/i) {
- $_chunk_size = int($1 * 1024 * 1024 + 0.5);
- }
-
- if ($_chunk_size eq 'auto') {
-
- if ( (defined $_params && ref $_params->{input_data} eq 'CODE') ||
- (defined $_input_data && ref $_input_data eq 'CODE')
- ) {
- # Iterators may optionally use chunk_size to determine how much
- # to return per iteration. The default is 1 for MCE Models, same
- # as for the Core API. The user_func receives an array_ref
- # regardless if 1 or higher.
- #
- # sub make_iter {
- # ...
- # return sub {
- # my ($chunk_size) = @_;
- # ...
- # };
- # }
- return 1;
- }
-
- my $_is_file;
- my $_size = $_array_size;
-
- if (defined $_input_data) {
- if (ref $_input_data eq 'ARRAY') {
- $_size = scalar @{ $_input_data };
- } elsif (ref $_input_data eq 'HASH') {
- $_size = scalar keys %{ $_input_data };
- }
- }
-
- if (defined $_params && exists $_params->{sequence}) {
- my ($_begin, $_end, $_step);
-
- if (ref $_params->{sequence} eq 'HASH') {
- $_begin = $_params->{sequence}->{begin};
- $_end = $_params->{sequence}->{end};
- $_step = $_params->{sequence}->{step} || 1;
- }
- else {
- $_begin = $_params->{sequence}[0];
- $_end = $_params->{sequence}[1];
- $_step = $_params->{sequence}[2] || 1;
- }
-
- if (!defined $_input_data && !$_array_size) {
- $_size = abs($_end - $_begin) / $_step + 1;
- }
- }
- elsif (defined $_params && exists $_params->{_file}) {
- my $_ref = ref $_params->{_file};
-
- if ($_ref eq 'SCALAR') {
- $_size = length ${ $_params->{_file} };
- } elsif ($_ref eq '') {
- $_size = -s $_params->{_file};
- } else {
- $_size = 0; $_chunk_size = 393_216; # 384K
- }
-
- $_is_file = 1;
- }
- elsif (defined $_input_data) {
- if (ref($_input_data) =~ /^(?:GLOB|FileHandle|IO::)/) {
- $_is_file = 1; $_size = 0; $_chunk_size = 393_216; # 384K
- }
- elsif (ref $_input_data eq 'SCALAR') {
- $_is_file = 1; $_size = length ${ $_input_data };
- }
- }
-
- if (defined $_is_file) {
- if ($_size) {
- $_chunk_size = int($_size / $_max_workers / 24 + 0.5);
- $_chunk_size = 5_242_880 if $_chunk_size > 5_242_880; # 5M
- $_chunk_size = 2 if $_chunk_size <= 8192;
- }
- }
- else {
- $_chunk_size = int($_size / $_max_workers / 24 + 0.5);
- $_chunk_size = 8000 if $_chunk_size > 8000;
- $_chunk_size = 2 if $_chunk_size < 2;
- }
- }
-
- return $_chunk_size;
-}
-
1;
__END__
@@ -464,7 +324,7 @@ MCE::Util - Utility functions
=head1 VERSION
-This document describes MCE::Util version 1.835
+This document describes MCE::Util version 1.836
=head1 SYNOPSIS