<?xml version="1.0" encoding="windows-1252"?>
<node id="1005467" title="Re: Parallel running the process" created="2012-11-25 01:59:58" updated="2012-11-25 01:59:58">
<type id="11">
note</type>
<author id="1005295">
marioroy</author>
<data>
<field name="doctext">
&lt;p&gt;MCE is a new Perl module recently added to CPAN. This is how one may use MCE to process in Parallel. MCE is both a chunking and parallel engine. In this case, chunk_size is set to 1. That option is not needed as calling the foreach method will set it to 1 anyway.&lt;/p&gt;

&lt;p&gt;The sendto method can be used to serialize data from workers to a file. MCE also provides a do method as well to pass data to a callback function which runs from the main process.&lt;/p&gt;

&lt;p&gt;$chunk_ref is a reference to an array. MCE provides both foreach and forchunk methods. In this case, the array contains only 1 entry due to chunk_size being set to 1.&lt;/p&gt;

&lt;p&gt;The main page at http://code.google.com/p/many-core-engine-perl/ contains three images. The 2nd one shows the bank queuing model used in MCE with chunking applied to it.&lt;/p&gt;

&lt;code&gt;
use MCE;

## Parse command line argument for $database_list

my $mce = MCE-&gt;new(
   max_workers =&gt; 4,
   chunk_size  =&gt; 1
);

$mce-&gt;foreach("$database_list", sub {
   my ($self, $chunk_ref, $chunk_id) = @_;

   my $database = $chunk_ref-&gt;[0];
   my @result = ();

   ## Query the database

   $self-&gt;sendto('file:/path/to/result.out', @result);
});

&lt;/code&gt;</field>
<field name="root_node">
958144</field>
<field name="parent_node">
958144</field>
</data>
</node>
