diff options
author | Angel Abad <angel@debian.org> | 2018-03-17 09:54:54 +0100 |
---|---|---|
committer | Angel Abad <angel@debian.org> | 2018-03-17 09:54:54 +0100 |
commit | 3c267097308b1d6b3164bfc4968f4f54eec458f2 (patch) | |
tree | aa68d18aec8ad04ff9379160981f8cedbad65cb1 | |
parent | 7c44f26a443312c925a0353849b9a172b7bf8ceb (diff) |
New upstream version 1.835
-rw-r--r-- | Changes | 16 | ||||
-rw-r--r-- | META.json | 50 | ||||
-rw-r--r-- | META.yml | 50 | ||||
-rw-r--r-- | Makefile.PL | 50 | ||||
-rw-r--r-- | README.md | 4 | ||||
-rw-r--r-- | lib/MCE.pm | 47 | ||||
-rw-r--r-- | lib/MCE.pod | 4 | ||||
-rw-r--r-- | lib/MCE/Candy.pm | 4 | ||||
-rw-r--r-- | lib/MCE/Core.pod | 2 | ||||
-rw-r--r-- | lib/MCE/Core/Input/Generator.pm | 2 | ||||
-rw-r--r-- | lib/MCE/Core/Input/Handle.pm | 2 | ||||
-rw-r--r-- | lib/MCE/Core/Input/Iterator.pm | 2 | ||||
-rw-r--r-- | lib/MCE/Core/Input/Request.pm | 2 | ||||
-rw-r--r-- | lib/MCE/Core/Input/Sequence.pm | 2 | ||||
-rw-r--r-- | lib/MCE/Core/Manager.pm | 4 | ||||
-rw-r--r-- | lib/MCE/Core/Validation.pm | 2 | ||||
-rw-r--r-- | lib/MCE/Core/Worker.pm | 4 | ||||
-rw-r--r-- | lib/MCE/Examples.pod | 2 | ||||
-rw-r--r-- | lib/MCE/Flow.pm | 4 | ||||
-rw-r--r-- | lib/MCE/Grep.pm | 4 | ||||
-rw-r--r-- | lib/MCE/Loop.pm | 4 | ||||
-rw-r--r-- | lib/MCE/Map.pm | 4 | ||||
-rw-r--r-- | lib/MCE/Mutex.pm | 4 | ||||
-rw-r--r-- | lib/MCE/Mutex/Channel.pm | 4 | ||||
-rw-r--r-- | lib/MCE/Mutex/Flock.pm | 4 | ||||
-rw-r--r-- | lib/MCE/Queue.pm | 4 | ||||
-rw-r--r-- | lib/MCE/Relay.pm | 159 | ||||
-rw-r--r-- | lib/MCE/Signal.pm | 4 | ||||
-rw-r--r-- | lib/MCE/Step.pm | 4 | ||||
-rw-r--r-- | lib/MCE/Stream.pm | 4 | ||||
-rw-r--r-- | lib/MCE/Subs.pm | 4 | ||||
-rw-r--r-- | lib/MCE/Util.pm | 17 |
32 files changed, 327 insertions, 146 deletions
@@ -1,6 +1,22 @@ Revision history for Perl module MCE. +1.835 Tue Mar 13 15:00:00 EST 2018 + + * Added gather and relay demonstrations to MCE::Relay. + * Load IO::Handle for extra stability, preventing workers loading uniquely. + + * Load Net::HTTP and Net::HTTPS before spawning if present LWP::UserAgent. + See http://www.perlmonks.org/?node_id=1199760 + and http://www.perlmonks.org/?node_id=1199891. + +1.834 Tue Jan 23 08:00:00 EST 2018 + + * Improved Queue await and dequeue performance on the Windows platform. + + * Added chameneos-redux parallel demonstrations on Github: + https://github.com/marioroy/mce-examples/tree/master/chameneos + 1.833 Thu Dec 28 16:00:00 EST 2017 * Fixed bug with sequence (#10), broken in 1.832. Thank you, @djerius. @@ -64,99 +64,99 @@ "provides" : { "MCE" : { "file" : "lib/MCE.pm", - "version" : "1.833" + "version" : "1.835" }, "MCE::Candy" : { "file" : "lib/MCE/Candy.pm", - "version" : "1.833" + "version" : "1.835" }, "MCE::Core::Input::Generator" : { "file" : "lib/MCE/Core/Input/Generator.pm", - "version" : "1.833" + "version" : "1.835" }, "MCE::Core::Input::Handle" : { "file" : "lib/MCE/Core/Input/Handle.pm", - "version" : "1.833" + "version" : "1.835" }, "MCE::Core::Input::Iterator" : { "file" : "lib/MCE/Core/Input/Iterator.pm", - "version" : "1.833" + "version" : "1.835" }, "MCE::Core::Input::Request" : { "file" : "lib/MCE/Core/Input/Request.pm", - "version" : "1.833" + "version" : "1.835" }, "MCE::Core::Input::Sequence" : { "file" : "lib/MCE/Core/Input/Sequence.pm", - "version" : "1.833" + "version" : "1.835" }, "MCE::Core::Manager" : { "file" : "lib/MCE/Core/Manager.pm", - "version" : "1.833" + "version" : "1.835" }, "MCE::Core::Validation" : { "file" : "lib/MCE/Core/Validation.pm", - "version" : "1.833" + "version" : "1.835" }, "MCE::Core::Worker" : { "file" : "lib/MCE/Core/Worker.pm", - "version" : "1.833" + "version" : "1.835" }, "MCE::Flow" : { "file" : "lib/MCE/Flow.pm", - "version" : "1.833" + "version" : "1.835" }, "MCE::Grep" : { "file" : "lib/MCE/Grep.pm", - "version" : "1.833" + "version" : "1.835" }, "MCE::Loop" : { "file" : "lib/MCE/Loop.pm", - "version" : "1.833" + "version" : "1.835" }, "MCE::Map" : { "file" : "lib/MCE/Map.pm", - "version" : "1.833" + "version" : "1.835" }, "MCE::Mutex" : { "file" : "lib/MCE/Mutex.pm", - "version" : "1.833" + "version" : "1.835" }, "MCE::Mutex::Channel" : { "file" : "lib/MCE/Mutex/Channel.pm", - "version" : "1.833" + "version" : "1.835" }, "MCE::Mutex::Flock" : { "file" : "lib/MCE/Mutex/Flock.pm", - "version" : "1.833" + "version" : "1.835" }, "MCE::Queue" : { "file" : "lib/MCE/Queue.pm", - "version" : "1.833" + "version" : "1.835" }, "MCE::Relay" : { "file" : "lib/MCE/Relay.pm", - "version" : "1.833" + "version" : "1.835" }, "MCE::Signal" : { "file" : "lib/MCE/Signal.pm", - "version" : "1.833" + "version" : "1.835" }, "MCE::Step" : { "file" : "lib/MCE/Step.pm", - "version" : "1.833" + "version" : "1.835" }, "MCE::Stream" : { "file" : "lib/MCE/Stream.pm", - "version" : "1.833" + "version" : "1.835" }, "MCE::Subs" : { "file" : "lib/MCE/Subs.pm", - "version" : "1.833" + "version" : "1.835" }, "MCE::Util" : { "file" : "lib/MCE/Util.pm", - "version" : "1.833" + "version" : "1.835" } }, "release_status" : "stable", @@ -172,5 +172,5 @@ "url" : "https://github.com/marioroy/mce-perl.git" } }, - "version" : "1.833" + "version" : "1.835" } @@ -25,76 +25,76 @@ no_index: provides: MCE: file: lib/MCE.pm - version: '1.833' + version: '1.835' MCE::Candy: file: lib/MCE/Candy.pm - version: '1.833' + version: '1.835' MCE::Core::Input::Generator: file: lib/MCE/Core/Input/Generator.pm - version: '1.833' + version: '1.835' MCE::Core::Input::Handle: file: lib/MCE/Core/Input/Handle.pm - version: '1.833' + version: '1.835' MCE::Core::Input::Iterator: file: lib/MCE/Core/Input/Iterator.pm - version: '1.833' + version: '1.835' MCE::Core::Input::Request: file: lib/MCE/Core/Input/Request.pm - version: '1.833' + version: '1.835' MCE::Core::Input::Sequence: file: lib/MCE/Core/Input/Sequence.pm - version: '1.833' + version: '1.835' MCE::Core::Manager: file: lib/MCE/Core/Manager.pm - version: '1.833' + version: '1.835' MCE::Core::Validation: file: lib/MCE/Core/Validation.pm - version: '1.833' + version: '1.835' MCE::Core::Worker: file: lib/MCE/Core/Worker.pm - version: '1.833' + version: '1.835' MCE::Flow: file: lib/MCE/Flow.pm - version: '1.833' + version: '1.835' MCE::Grep: file: lib/MCE/Grep.pm - version: '1.833' + version: '1.835' MCE::Loop: file: lib/MCE/Loop.pm - version: '1.833' + version: '1.835' MCE::Map: file: lib/MCE/Map.pm - version: '1.833' + version: '1.835' MCE::Mutex: file: lib/MCE/Mutex.pm - version: '1.833' + version: '1.835' MCE::Mutex::Channel: file: lib/MCE/Mutex/Channel.pm - version: '1.833' + version: '1.835' MCE::Mutex::Flock: file: lib/MCE/Mutex/Flock.pm - version: '1.833' + version: '1.835' MCE::Queue: file: lib/MCE/Queue.pm - version: '1.833' + version: '1.835' MCE::Relay: file: lib/MCE/Relay.pm - version: '1.833' + version: '1.835' MCE::Signal: file: lib/MCE/Signal.pm - version: '1.833' + version: '1.835' MCE::Step: file: lib/MCE/Step.pm - version: '1.833' + version: '1.835' MCE::Stream: file: lib/MCE/Stream.pm - version: '1.833' + version: '1.835' MCE::Subs: file: lib/MCE/Subs.pm - version: '1.833' + version: '1.835' MCE::Util: file: lib/MCE/Util.pm - version: '1.833' + version: '1.835' recommends: Sereal::Decoder: '3.015' Sereal::Encoder: '3.015' @@ -120,4 +120,4 @@ resources: homepage: https://github.com/marioroy/mce-perl license: http://dev.perl.org/licenses/ repository: https://github.com/marioroy/mce-perl.git -version: '1.833' +version: '1.835' diff --git a/Makefile.PL b/Makefile.PL index dd6cc26..603f55f 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -17,7 +17,7 @@ WriteMakefile( ABSTRACT => 'Many-Core Engine for Perl providing parallel processing capabilities', AUTHOR => 'Mario E. Roy <marioeroy AT gmail DOT com>', NAME => 'MCE', - VERSION => '1.833', + VERSION => '1.835', EXE_FILES => [ @exe_files ], @@ -67,99 +67,99 @@ WriteMakefile( 'provides' => { 'MCE' => { 'file' => 'lib/MCE.pm', - 'version' => '1.833' + 'version' => '1.835' }, 'MCE::Candy' => { 'file' => 'lib/MCE/Candy.pm', - 'version' => '1.833' + 'version' => '1.835' }, 'MCE::Core::Input::Generator' => { 'file' => 'lib/MCE/Core/Input/Generator.pm', - 'version' => '1.833' + 'version' => '1.835' }, 'MCE::Core::Input::Handle' => { 'file' => 'lib/MCE/Core/Input/Handle.pm', - 'version' => '1.833' + 'version' => '1.835' }, 'MCE::Core::Input::Iterator' => { 'file' => 'lib/MCE/Core/Input/Iterator.pm', - 'version' => '1.833' + 'version' => '1.835' }, 'MCE::Core::Input::Request' => { 'file' => 'lib/MCE/Core/Input/Request.pm', - 'version' => '1.833' + 'version' => '1.835' }, 'MCE::Core::Input::Sequence' => { 'file' => 'lib/MCE/Core/Input/Sequence.pm', - 'version' => '1.833' + 'version' => '1.835' }, 'MCE::Core::Manager' => { 'file' => 'lib/MCE/Core/Manager.pm', - 'version' => '1.833' + 'version' => '1.835' }, 'MCE::Core::Validation' => { 'file' => 'lib/MCE/Core/Validation.pm', - 'version' => '1.833' + 'version' => '1.835' }, 'MCE::Core::Worker' => { 'file' => 'lib/MCE/Core/Worker.pm', - 'version' => '1.833' + 'version' => '1.835' }, 'MCE::Flow' => { 'file' => 'lib/MCE/Flow.pm', - 'version' => '1.833' + 'version' => '1.835' }, 'MCE::Grep' => { 'file' => 'lib/MCE/Grep.pm', - 'version' => '1.833' + 'version' => '1.835' }, 'MCE::Loop' => { 'file' => 'lib/MCE/Loop.pm', - 'version' => '1.833' + 'version' => '1.835' }, 'MCE::Map' => { 'file' => 'lib/MCE/Map.pm', - 'version' => '1.833' + 'version' => '1.835' }, 'MCE::Mutex' => { 'file' => 'lib/MCE/Mutex.pm', - 'version' => '1.833' + 'version' => '1.835' }, 'MCE::Mutex::Channel' => { 'file' => 'lib/MCE/Mutex/Channel.pm', - 'version' => '1.833' + 'version' => '1.835' }, 'MCE::Mutex::Flock' => { 'file' => 'lib/MCE/Mutex/Flock.pm', - 'version' => '1.833' + 'version' => '1.835' }, 'MCE::Queue' => { 'file' => 'lib/MCE/Queue.pm', - 'version' => '1.833' + 'version' => '1.835' }, 'MCE::Relay' => { 'file' => 'lib/MCE/Relay.pm', - 'version' => '1.833' + 'version' => '1.835' }, 'MCE::Signal' => { 'file' => 'lib/MCE/Signal.pm', - 'version' => '1.833' + 'version' => '1.835' }, 'MCE::Step' => { 'file' => 'lib/MCE/Step.pm', - 'version' => '1.833' + 'version' => '1.835' }, 'MCE::Stream' => { 'file' => 'lib/MCE/Stream.pm', - 'version' => '1.833' + 'version' => '1.835' }, 'MCE::Subs' => { 'file' => 'lib/MCE/Subs.pm', - 'version' => '1.833' + 'version' => '1.835' }, 'MCE::Util' => { 'file' => 'lib/MCE/Util.pm', - 'version' => '1.833' + 'version' => '1.835' } }, 'prereqs' => { @@ -1,6 +1,6 @@ ## Many-Core Engine for Perl -This document describes MCE version 1.833. +This document describes MCE version 1.835. Many-Core Engine (MCE) for Perl helps enable a new level of performance by maximizing all available cores. @@ -177,7 +177,7 @@ for more recipes. ### Copyright and Licensing -Copyright (C) 2012-2017 by Mario E. Roy <marioeroy AT gmail DOT com> +Copyright (C) 2012-2018 by Mario E. Roy <marioeroy AT gmail DOT com> This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself: @@ -11,7 +11,7 @@ use warnings; no warnings qw( threads recursion uninitialized ); -our $VERSION = '1.833'; +our $VERSION = '1.835'; ## no critic (BuiltinFunctions::ProhibitStringyEval) ## no critic (Subroutines::ProhibitSubroutinePrototypes) @@ -35,7 +35,7 @@ BEGIN { $_tid = $_has_threads ? threads->tid() : 0; $_oid = "$$.$_tid"; - if ($] ge '5.008008' && !exists $INC{'PDL.pm'}) { + if ($] ge '5.008008' && !$INC{'PDL.pm'}) { eval ' use Sereal::Encoder 3.015 qw( encode_sereal ); use Sereal::Decoder 3.015 qw( decode_sereal ); @@ -59,6 +59,7 @@ BEGIN { return; } +use IO::Handle (); use Scalar::Util qw( looks_like_number refaddr weaken ); use Socket qw( SOL_SOCKET SO_RCVBUF ); use Time::HiRes qw( sleep time ); @@ -359,6 +360,18 @@ sub _restore_state { ## ############################################################################### +sub _croak { + if (MCE->wid == 0 || ! $^S) { + $SIG{__DIE__} = \&MCE::Signal::_die_handler; + $SIG{__WARN__} = \&MCE::Signal::_warn_handler; + } + $\ = undef; goto &Carp::croak; +} + +use MCE::Core::Validation (); +use MCE::Core::Manager (); +use MCE::Core::Worker (); + sub new { my ($class, %self) = @_; my $_pkg = exists $self{pkg} ? delete $self{pkg} : caller; @@ -447,10 +460,6 @@ sub new { } } - require MCE::Core::Validation unless $INC{'MCE/Core/Validation.pm'}; - require MCE::Core::Manager unless $INC{'MCE/Core/Manager.pm'}; - require MCE::Core::Worker unless $INC{'MCE/Core/Worker.pm'}; - _validate_args(\%self); ## ------------------------------------------------------------------------- @@ -471,13 +480,13 @@ sub new { $self{_last_sref} = (ref $self{input_data} eq 'SCALAR') ? refaddr($self{input_data}) : 0; - my $_data_channels = ($_oid eq "$$.$_tid") ? DATA_CHANNELS : 2; + my $_data_channels = ("$$.$_tid" eq $_oid) ? DATA_CHANNELS : 2; my $_total_workers = 0; if (defined $self{user_tasks}) { $_total_workers += $_->{max_workers} for (@{ $self{user_tasks} }); } else { - $_total_workers = $self{max_workers}; + $_total_workers = $self{max_workers}; } $self{_init_total_workers} = $_total_workers; @@ -486,7 +495,7 @@ sub new { ? $_total_workers : $_data_channels; $self{_lock_chn} = ($_total_workers > $_data_channels) ? 1 : 0; - $self{_lock_chn} = 1 if ($INC{'MCE/Hobo.pm'}); + $self{_lock_chn} = 1 if $INC{'MCE/Hobo.pm'}; $MCE = \%self if ($MCE->{_wid} == 0); @@ -513,12 +522,13 @@ sub spawn { lock $_MCE_LOCK if $_has_threads; # Obtain locks lock $_WIN_LOCK if $_is_MSWin32; - sleep 0.015 if ($_tid && !$self->{use_threads}); - if ($INC{'PDL.pm'}) { local $@; eval 'use PDL::IO::Storable' unless $INC{'PDL/IO/Storable.pm'}; eval 'PDL::no_clone_skip_warning()'; } + if ( $INC{'LWP/UserAgent.pm'} && !$INC{'Net/HTTP.pm'} ) { + local $@; eval 'require Net::HTTP; require Net::HTTPS'; + } ## Start the shared-manager process if present. MCE::Shared->start() if $INC{'MCE/Shared.pm'}; @@ -544,6 +554,10 @@ sub spawn { } } + if ("$$.$_tid" ne $_oid && (!$self->{use_threads} || $_is_MSWin32)) { + sleep 0.015; + } + my $_die_handler = $SIG{__DIE__}; my $_warn_handler = $SIG{__WARN__}; @@ -1387,7 +1401,7 @@ sub sync { print {$_DAT_W_SOCK} OUTPUT_B_SYN.$LF . $_chn.$LF; ## Wait until all workers from (task_id 0) have synced. - MCE::Util::_sock_ready($_BSB_R_SOCK) if $_is_MSWin32; + MCE::Util::_sock_ready($_BSB_R_SOCK, -1) if $_is_MSWin32; 1 until sysread($_BSB_R_SOCK, $_buf, 1) || ($! && !$!{'EINTR'}); ## Notify the manager process (barrier end). @@ -1771,15 +1785,6 @@ sub say { ## ############################################################################### -sub _croak { - if (MCE->wid == 0 || ! $^S) { - $SIG{__DIE__} = \&MCE::Signal::_die_handler; - $SIG{__WARN__} = \&MCE::Signal::_warn_handler; - } - - $\ = undef; goto &Carp::croak; -} - sub _exit { my $self = shift; diff --git a/lib/MCE.pod b/lib/MCE.pod index 72dcaa8..980585b 100644 --- a/lib/MCE.pod +++ b/lib/MCE.pod @@ -5,7 +5,7 @@ MCE - Many-Core Engine for Perl providing parallel processing capabilities =head1 VERSION -This document describes MCE version 1.833 +This document describes MCE version 1.835 Many-Core Engine (MCE) for Perl helps enable a new level of performance by maximizing all available cores. @@ -282,7 +282,7 @@ Mario E. Roy, S<E<lt>marioeroy AT gmail DOT comE<gt>> =head1 COPYRIGHT AND LICENSE -Copyright (C) 2012-2017 by Mario E. Roy +Copyright (C) 2012-2018 by Mario E. Roy MCE is released under the same license as Perl. diff --git a/lib/MCE/Candy.pm b/lib/MCE/Candy.pm index 7d74911..07436e7 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.833'; +our $VERSION = '1.835'; 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.833 +This document describes MCE::Candy version 1.835 =head1 DESCRIPTION diff --git a/lib/MCE/Core.pod b/lib/MCE/Core.pod index 9d6fc75..4c16d8e 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.833 +This document describes MCE::Core version 1.835 =head1 SYNOPSIS diff --git a/lib/MCE/Core/Input/Generator.pm b/lib/MCE/Core/Input/Generator.pm index 93d86bd..d3c1b74 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.833'; +our $VERSION = '1.835'; ## Items below are folded into MCE. diff --git a/lib/MCE/Core/Input/Handle.pm b/lib/MCE/Core/Input/Handle.pm index c25211e..5a828dd 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.833'; +our $VERSION = '1.835'; ## Items below are folded into MCE. diff --git a/lib/MCE/Core/Input/Iterator.pm b/lib/MCE/Core/Input/Iterator.pm index f59b1b2..452a2d6 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.833'; +our $VERSION = '1.835'; ## Items below are folded into MCE. diff --git a/lib/MCE/Core/Input/Request.pm b/lib/MCE/Core/Input/Request.pm index 1919fe6..8878ef1 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.833'; +our $VERSION = '1.835'; ## Items below are folded into MCE. diff --git a/lib/MCE/Core/Input/Sequence.pm b/lib/MCE/Core/Input/Sequence.pm index 7af4985..644c87b 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.833'; +our $VERSION = '1.835'; ## Items below are folded into MCE. diff --git a/lib/MCE/Core/Manager.pm b/lib/MCE/Core/Manager.pm index eda8466..641e820 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.833'; +our $VERSION = '1.835'; ## no critic (BuiltinFunctions::ProhibitStringyEval) ## no critic (TestingAndDebugging::ProhibitNoStrict) @@ -570,8 +570,6 @@ sub _output_loop { read $_DAU_R_SOCK, $_buf, $_len; unless (exists $_sendto_fhs{$_fd}) { - require IO::Handle unless $INC{'IO/Handle.pm'}; - $_sendto_fhs{$_fd} = IO::Handle->new(); $_sendto_fhs{$_fd}->fdopen($_fd, 'w') or _croak "Cannot open file descriptor ($_fd): $!"; diff --git a/lib/MCE/Core/Validation.pm b/lib/MCE/Core/Validation.pm index 65fd9cf..d918d9a 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.833'; +our $VERSION = '1.835'; ## Items below are folded into MCE. diff --git a/lib/MCE/Core/Worker.pm b/lib/MCE/Core/Worker.pm index 4bb1bda..62fbc1f 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.833'; +our $VERSION = '1.835'; my $_has_threads = $INC{'threads.pm'} ? 1 : 0; my $_tid = $_has_threads ? threads->tid() : 0; @@ -528,7 +528,7 @@ sub _worker_loop { my $_job_delay = $self->{job_delay}; my $_wid = $self->{_wid}; - if ( $^O eq 'MSWin32' ) { + if ($^O eq 'MSWin32') { lock $MCE::_WIN_LOCK; } diff --git a/lib/MCE/Examples.pod b/lib/MCE/Examples.pod index 519324f..62122f0 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.833 +This document describes MCE::Examples version 1.835 =head1 INCLUDED WITH THE DISTRIBUTION diff --git a/lib/MCE/Flow.pm b/lib/MCE/Flow.pm index a719a4a..c0f1dcd 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.833'; +our $VERSION = '1.835'; ## no critic (BuiltinFunctions::ProhibitStringyEval) ## no critic (Subroutines::ProhibitSubroutinePrototypes) @@ -495,7 +495,7 @@ MCE::Flow - Parallel flow model for building creative applications =head1 VERSION -This document describes MCE::Flow version 1.833 +This document describes MCE::Flow version 1.835 =head1 DESCRIPTION diff --git a/lib/MCE/Grep.pm b/lib/MCE/Grep.pm index c4494e6..d9731aa 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.833'; +our $VERSION = '1.835'; ## no critic (BuiltinFunctions::ProhibitStringyEval) ## no critic (Subroutines::ProhibitSubroutinePrototypes) @@ -450,7 +450,7 @@ MCE::Grep - Parallel grep model similar to the native grep function =head1 VERSION -This document describes MCE::Grep version 1.833 +This document describes MCE::Grep version 1.835 =head1 SYNOPSIS diff --git a/lib/MCE/Loop.pm b/lib/MCE/Loop.pm index 5e2b78c..d904f27 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.833'; +our $VERSION = '1.835'; ## no critic (BuiltinFunctions::ProhibitStringyEval) ## no critic (Subroutines::ProhibitSubroutinePrototypes) @@ -365,7 +365,7 @@ MCE::Loop - MCE model for building parallel loops =head1 VERSION -This document describes MCE::Loop version 1.833 +This document describes MCE::Loop version 1.835 =head1 DESCRIPTION diff --git a/lib/MCE/Map.pm b/lib/MCE/Map.pm index b92f6c4..b23ada4 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.833'; +our $VERSION = '1.835'; ## no critic (BuiltinFunctions::ProhibitStringyEval) ## no critic (Subroutines::ProhibitSubroutinePrototypes) @@ -450,7 +450,7 @@ MCE::Map - Parallel map model similar to the native map function =head1 VERSION -This document describes MCE::Map version 1.833 +This document describes MCE::Map version 1.835 =head1 SYNOPSIS diff --git a/lib/MCE/Mutex.pm b/lib/MCE/Mutex.pm index 95edb49..f229bb6 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.833'; +our $VERSION = '1.835'; ## 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.833 +This document describes MCE::Mutex version 1.835 =head1 SYNOPSIS diff --git a/lib/MCE/Mutex/Channel.pm b/lib/MCE/Mutex/Channel.pm index 999d5cb..16100fc 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.833'; +our $VERSION = '1.835'; 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.833 +This document describes MCE::Mutex::Channel version 1.835 =head1 DESCRIPTION diff --git a/lib/MCE/Mutex/Flock.pm b/lib/MCE/Mutex/Flock.pm index 9dd9f47..22ed200 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.833'; +our $VERSION = '1.835'; 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.833 +This document describes MCE::Mutex::Flock version 1.835 =head1 DESCRIPTION diff --git a/lib/MCE/Queue.pm b/lib/MCE/Queue.pm index 36e2e7b..b897ff7 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.833'; +our $VERSION = '1.835'; ## no critic (Subroutines::ProhibitExplicitReturnUndef) ## no critic (TestingAndDebugging::ProhibitNoStrict) @@ -1621,7 +1621,7 @@ MCE::Queue - Hybrid (normal and priority) queues =head1 VERSION -This document describes MCE::Queue version 1.833 +This document describes MCE::Queue version 1.835 =head1 SYNOPSIS diff --git a/lib/MCE/Relay.pm b/lib/MCE/Relay.pm index c979d2d..a8de61a 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.833'; +our $VERSION = '1.835'; ## 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.833 +This document describes MCE::Relay version 1.835 =head1 SYNOPSIS @@ -922,6 +922,161 @@ Here, workers write exclusively and orderly to C<STDOUT>. =back +=head1 GATHER AND RELAY DEMONSTRATIONS + +I received a request from John Martel to process a large flat file and expand +each record to many records based on splitting out items in field 4 delimited +by semicolons. Each row in the output is given a unique ID starting with one +while preserving output order. + +=over 3 + +=item Input File, possibly larger than 500 GiB in size + + foo|field2|field3|item1;item2;item3;item4;itemN|field5|field6|field7 + bar|field2|field3|item1;item2;item3;item4;itemN|field5|field6|field7 + baz|field2|field3|item1;item2;item3;item4;itemN|field5|field6|field7 + ... + +=item Output File + + 000000000000001|item1|foo|field2|field3|field5|field6|field7 + 000000000000002|item2|foo|field2|field3|field5|field6|field7 + 000000000000003|item3|foo|field2|field3|field5|field6|field7 + 000000000000004|item4|foo|field2|field3|field5|field6|field7 + 000000000000005|itemN|foo|field2|field3|field5|field6|field7 + 000000000000006|item1|bar|field2|field3|field5|field6|field7 + 000000000000007|item2|bar|field2|field3|field5|field6|field7 + 000000000000008|item3|bar|field2|field3|field5|field6|field7 + 000000000000009|item4|bar|field2|field3|field5|field6|field7 + 000000000000010|itemN|bar|field2|field3|field5|field6|field7 + 000000000000011|item1|baz|field2|field3|field5|field6|field7 + 000000000000012|item2|baz|field2|field3|field5|field6|field7 + 000000000000013|item3|baz|field2|field3|field5|field6|field7 + 000000000000014|item4|baz|field2|field3|field5|field6|field7 + 000000000000015|itemN|baz|field2|field3|field5|field6|field7 + ... + +=item Example One + +This example configures a custom function for preserving output order. +Unfortunately, the sprintf function alone involves extra CPU time causing +the manager process to fall behind. Thus, workers may idle while waiting +for the manager process to respond to the gather request. + + use strict; + use warnings; + + use MCE::Loop; + + my $infile = shift or die "Usage: $0 infile\n"; + my $newfile = 'output.dat'; + + open my $fh_out, '>', $newfile or die "open error $newfile: $!\n"; + + sub preserve_order { + my ($fh) = @_; + my ($order_id, $start_idx, $idx, %tmp) = (1, 1); + + return sub { + my ($chunk_id, $aref) = @_; + $tmp{ $chunk_id } = $aref; + + while ( my $aref = delete $tmp{ $order_id } ) { + foreach my $line ( @{ $aref } ) { + $idx = sprintf "%015d", $start_idx++; + print $fh $idx, $line; + } + $order_id++; + } + } + } + + MCE::Loop::init { + chunk_size => 'auto', max_workers => 3, + gather => preserve_order($fh_out) + }; + + mce_loop_f { + my ($mce, $chunk_ref, $chunk_id) = @_; + my @buf; + + foreach my $line (@{ $chunk_ref }) { + $line =~ s/\r//g; chomp $line; + + my ($f1,$f2,$f3,$items,$f5,$f6,$f7) = split /\|/, $line; + my @items_array = split /;/, $items; + + foreach my $item (@items_array) { + push @buf, "|$item|$f1|$f2|$f3|$f5|$f6|$f7\n"; + } + } + + MCE->gather($chunk_id, \@buf); + + } $infile; + + MCE::Loop::finish(); + close $fh_out; + +=item Example Two + +In this example, workers obtain the current ID value and increment/relay for +the next worker, ordered by chunk ID behind the scene. Workers call sprintf +in parallel, allowing the manager process (out_iter_fh) to accommodate up to +32 workers and not fall behind. + +Relay accounts for the worker handling the next chunk_id value. Therefore, do +not call relay more than once per chunk. Doing so will cause IPC to stall. + + use strict; + use warnings; + + use MCE::Loop; + use MCE::Candy; + + my $infile = shift or die "Usage: $0 infile\n"; + my $newfile = 'output.dat'; + + open my $fh_out, '>', $newfile or die "open error $newfile: $!\n"; + + MCE::Loop::init { + chunk_size => 'auto', max_workers => 8, + gather => MCE::Candy::out_iter_fh($fh_out), + init_relay => 1 + }; + + mce_loop_f { + my ($mce, $chunk_ref, $chunk_id) = @_; + my @lines; + + foreach my $line (@{ $chunk_ref }) { + $line =~ s/\r//g; chomp $line; + + my ($f1,$f2,$f3,$items,$f5,$f6,$f7) = split /\|/, $line; + my @items_array = split /;/, $items; + + foreach my $item (@items_array) { + push @lines, "$item|$f1|$f2|$f3|$f5|$f6|$f7\n"; + } + } + + my $idx = MCE::relay { $_ += scalar @lines }; + my $buf = ''; + + foreach my $line ( @lines ) { + $buf .= sprintf "%015d|%s", $idx++, $line + } + + MCE->gather($chunk_id, $buf); + + } $infile; + + MCE::Loop::finish(); + close $fh_out; + +=back + =head1 INDEX L<MCE|MCE>, L<MCE::Core> diff --git a/lib/MCE/Signal.pm b/lib/MCE/Signal.pm index 5820553..c961214 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.833'; +our $VERSION = '1.835'; ## 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.833 +This document describes MCE::Signal version 1.835 =head1 SYNOPSIS diff --git a/lib/MCE/Step.pm b/lib/MCE/Step.pm index 9898b71..0dadb05 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.833'; +our $VERSION = '1.835'; ## no critic (BuiltinFunctions::ProhibitStringyEval) ## no critic (Subroutines::ProhibitSubroutinePrototypes) @@ -731,7 +731,7 @@ MCE::Step - Parallel step model for building creative steps =head1 VERSION -This document describes MCE::Step version 1.833 +This document describes MCE::Step version 1.835 =head1 DESCRIPTION diff --git a/lib/MCE/Stream.pm b/lib/MCE/Stream.pm index 5c13a2a..d0dfcc1 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.833'; +our $VERSION = '1.835'; ## no critic (BuiltinFunctions::ProhibitStringyEval) ## no critic (Subroutines::ProhibitSubroutinePrototypes) @@ -687,7 +687,7 @@ MCE::Stream - Parallel stream model for chaining multiple maps and greps =head1 VERSION -This document describes MCE::Stream version 1.833 +This document describes MCE::Stream version 1.835 =head1 SYNOPSIS diff --git a/lib/MCE/Subs.pm b/lib/MCE/Subs.pm index 5c14e69..a9f3a46 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.833'; +our $VERSION = '1.835'; ## 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.833 +This document describes MCE::Subs version 1.835 =head1 SYNOPSIS diff --git a/lib/MCE/Util.pm b/lib/MCE/Util.pm index d735fd7..b7250a5 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.833'; +our $VERSION = '1.835'; ## no critic (BuiltinFunctions::ProhibitStringyEval) @@ -20,7 +20,7 @@ use Time::HiRes qw( sleep time ); use base qw( Exporter ); use bytes; -my ($_is_winenv, $_zero_bytes); +my ($_is_winenv, $_zero_bytes, %_sock_ready); BEGIN { $_is_winenv = ( $^O =~ /mswin|mingw|msys|cygwin/i ) ? 1 : 0; @@ -278,11 +278,18 @@ sub _sock_ready { my ($_socket, $_timeout) = @_; + return '' if !defined $_timeout && exists $_sock_ready{"$_socket"}; + my $_val_bytes = "\x00\x00\x00\x00"; - my $_ptr_bytes = unpack( 'I', pack('P', $_val_bytes) ); + my $_ptr_bytes = unpack('I', pack('P', $_val_bytes)); my ($_count, $_start) = (1, time); - $_timeout += time if $_timeout; + if (!defined $_timeout) { + $_sock_ready{"$_socket"} = undef; + } else { + $_timeout = undef if $_timeout < 0; + $_timeout += $_start if $_timeout; + } while (1) { # MSWin32 FIONREAD @@ -457,7 +464,7 @@ MCE::Util - Utility functions =head1 VERSION -This document describes MCE::Util version 1.833 +This document describes MCE::Util version 1.835 =head1 SYNOPSIS |