.\" Automatically generated by Pod::Man 4.07 (Pod::Simple 3.32) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .if !\nF .nr F 0 .if \nF>0 \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} .\} .\" ======================================================================== .\" .IX Title "MCE 3pm" .TH MCE 3pm "2016-12-11" "perl v5.24.1" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" MCE \- Many\-Core Engine for Perl providing parallel processing capabilities .SH "VERSION" .IX Header "VERSION" This document describes \s-1MCE\s0 version 1.810 .PP Many-Core Engine (\s-1MCE\s0) for Perl helps enable a new level of performance by maximizing all available cores. .SH "DESCRIPTION" .IX Header "DESCRIPTION" \&\s-1MCE\s0 spawns a pool of workers and therefore does not fork a new process per each element of data. Instead, \s-1MCE\s0 follows a bank queuing model. Imagine the line being the data and bank-tellers the parallel workers. \s-1MCE\s0 enhances that model by adding the ability to chunk the next n elements from the input stream to the next available worker. .SH "SYNOPSIS" .IX Header "SYNOPSIS" This is a simplistic use case of \s-1MCE\s0 running with 5 workers. .PP .Vb 1 \& # Construction using the Core API \& \& use MCE; \& \& my $mce = MCE\->new( \& max_workers => 5, \& user_func => sub { \& my ($mce) = @_; \& $mce\->say("Hello from " . $mce\->wid); \& } \& ); \& \& $mce\->run; \& \& # Construction using a MCE model \& \& use MCE::Flow max_workers => 5; \& \& mce_flow sub { \& my ($mce) = @_; \& MCE\->say("Hello from " . MCE\->wid); \& }; .Ve .PP The following is a demonstration for parsing a huge log file in parallel. .PP .Vb 1 \& use MCE::Loop; \& \& MCE::Loop::init { max_workers => 8, use_slurpio => 1 }; \& \& my $pattern = \*(Aqsomething\*(Aq; \& my $hugefile = \*(Aqvery_huge.file\*(Aq; \& \& my @result = mce_loop_f { \& my ($mce, $slurp_ref, $chunk_id) = @_; \& \& # Quickly determine if a match is found. \& # Process the slurped chunk only if true. \& \& if ($$slurp_ref =~ /$pattern/m) { \& my @matches; \& \& # The following is fast on Unix, but performance degrades \& # drastically on Windows beyond 4 workers. \& \& open my $MEM_FH, \*(Aq<\*(Aq, $slurp_ref; \& binmode $MEM_FH, \*(Aq:raw\*(Aq; \& while (<$MEM_FH>) { push @matches, $_ if (/$pattern/); } \& close $MEM_FH; \& \& # Therefore, use the following construction on Windows. \& \& while ( $$slurp_ref =~ /([^\en]+\en)/mg ) { \& my $line = $1; # save $1 to not lose the value \& push @matches, $line if ($line =~ /$pattern/); \& } \& \& # Gather matched lines. \& \& MCE\->gather(@matches); \& } \& \& } $hugefile; \& \& print join(\*(Aq\*(Aq, @result); .Ve .PP The next demonstration loops through a sequence of numbers with MCE::Flow. .PP .Vb 1 \& use MCE::Flow; \& \& my $N = shift || 4_000_000; \& \& sub compute_pi { \& my ( $beg_seq, $end_seq ) = @_; \& my ( $pi, $t ) = ( 0.0 ); \& \& foreach my $i ( $beg_seq .. $end_seq ) { \& $t = ( $i + 0.5 ) / $N; \& $pi += 4.0 / ( 1.0 + $t * $t ); \& } \& \& MCE\->gather( $pi ); \& } \& \& # Compute bounds only, workers receive [ begin, end ] values \& \& MCE::Flow::init( \& chunk_size => 200_000, \& max_workers => 8, \& bounds_only => 1 \& ); \& \& my @ret = mce_flow_s sub { \& compute_pi( $_\->[0], $_\->[1] ); \& }, 0, $N \- 1; \& \& my $pi = 0.0; $pi += $_ for @ret; \& \& printf "pi = %0.13f\en", $pi / $N; # 3.1415926535898 .Ve .SH "CORE MODULES" .IX Header "CORE MODULES" Three modules make up the core engine for \s-1MCE.\s0 .IP "MCE::Core" 3 .IX Item "MCE::Core" Provides the Core \s-1API\s0 for Many-Core Engine. The various \s-1MCE\s0 options are described here. .IP "MCE::Signal" 3 .IX Item "MCE::Signal" Temporary directory creation, cleanup, and signal handling. .IP "MCE::Util" 3 .IX Item "MCE::Util" Utility functions for Many-Core Engine. .SH "MCE EXTRAS" .IX Header "MCE EXTRAS" There are 4 add-on modules for use with \s-1MCE.\s0 .IP "MCE::Candy" 3 .IX Item "MCE::Candy" Provides a collection of sugar methods and output iterators for preserving output order. .IP "MCE::Mutex" 3 .IX Item "MCE::Mutex" Provides a simple semaphore implementation supporting threads and processes. .IP "MCE::Queue" 3 .IX Item "MCE::Queue" Provides a hybrid queuing implementation for \s-1MCE\s0 supporting normal queues and priority queues from a single module. MCE::Queue exchanges data via the core engine to enable queuing to work for both children (spawned from fork) and threads. .IP "MCE::Relay" 3 .IX Item "MCE::Relay" Enables workers to receive and pass on information orderly with zero involvement by the manager process while running. .SH "MCE MODELS" .IX Header "MCE MODELS" The models take Many-Core Engine to a new level for ease of use. Two options (chunk_size and max_workers) are configured automatically as well as spawning and shutdown. .IP "MCE::Loop" 3 .IX Item "MCE::Loop" Provides a parallel loop utilizing \s-1MCE\s0 for building creative loops. .IP "MCE::Flow" 3 .IX Item "MCE::Flow" A parallel flow model for building creative applications. This makes use of user_tasks in \s-1MCE.\s0 The author has full control when utilizing this model. MCE::Flow is similar to MCE::Loop, but allows for multiple code blocks to run in parallel with a slight change to syntax. .IP "MCE::Grep" 3 .IX Item "MCE::Grep" Provides a parallel grep implementation similar to the native grep function. .IP "MCE::Map" 3 .IX Item "MCE::Map" Provides a parallel map model similar to the native map function. .IP "MCE::Step" 3 .IX Item "MCE::Step" Provides a parallel step implementation utilizing MCE::Queue between user tasks. MCE::Step is a spin off from MCE::Flow with a touch of MCE::Stream. This model, introduced in 1.506, allows one to pass data from one sub-task into the next transparently. .IP "MCE::Stream" 3 .IX Item "MCE::Stream" Provides an efficient parallel implementation for chaining multiple maps and greps together through user_tasks and MCE::Queue. Like with MCE::Flow, MCE::Stream can run multiple code blocks in parallel with a slight change to syntax from MCE::Map and MCE::Grep. .SH "MISCELLANEOUS" .IX Header "MISCELLANEOUS" Miscellaneous additions included with the distribution. .IP "MCE::Examples" 3 .IX Item "MCE::Examples" Describes various demonstrations for \s-1MCE\s0 including a Monte Carlo simulation. .IP "MCE::Subs" 3 .IX Item "MCE::Subs" Exports functions mapped directly to \s-1MCE\s0 methods; e.g. mce_wid. The module allows 3 options; :manager, :worker, and :getter. .SH "REQUIREMENTS" .IX Header "REQUIREMENTS" Perl 5.8.0 or later. PDL::IO::Storable is required in scripts running \s-1PDL.\s0 .SH "SOURCE AND FURTHER READING" .IX Header "SOURCE AND FURTHER READING" The source, cookbook, and examples are hosted at GitHub. .IP "\(bu" 3 .IP "\(bu" 3 .IP "\(bu" 3 .SH "SEE ALSO" .IX Header "SEE ALSO" \&\f(CW\*(C`MCE::Shared\*(C'\fR provides data sharing capabilities for \f(CW\*(C`MCE\*(C'\fR. It includes \&\f(CW\*(C`MCE::Hobo\*(C'\fR for running code asynchronously. .IP "\(bu" 3 MCE::Shared .IP "\(bu" 3 MCE::Hobo .SH "AUTHOR" .IX Header "AUTHOR" Mario E. Roy, .SH "COPYRIGHT AND LICENSE" .IX Header "COPYRIGHT AND LICENSE" Copyright (C) 2012\-2016 by Mario E. Roy .PP \&\s-1MCE\s0 is released under the same license as Perl. .PP See for more information.