The mce_forchunk keywords are working. Sometimes, it's preferably to process at the chunk level. So, here it is.

mce_forchunk

use MCE::Simple -strict, max_workers => 4, init_relay => ''; mce_forchunk (11..19) { my ($mce, $chunk_ref, $chunk_id) = @_; for my $i (@{ $chunk_ref }) { MCE->say($i); } } mce_forchunk (31..39) { for my $i (@{ $_ }) { MCE->say($i); } } mce_forchunk my $chunk (51..59) { for my $i (@{ $chunk }) { MCE->say($i); } } mce_forchunk my $chunk (71..79) { my $output = "From chunk_id: ".MCE->chunk_id."\n"; for my $i (@{ $chunk }) { $output .= "$i\n"; } MCE::relay { # write directly to STDOUT, not involve manager process print $output; }; }

Output

15 13 11 16 14 17 12 18 19 33 34 31 39 32 37 35 38 36 51 57 53 52 55 58 54 56 59 From chunk_id: 1 71 72 From chunk_id: 2 73 74 From chunk_id: 3 75 76 From chunk_id: 4 77 78 From chunk_id: 5 79

Spawn MCE asynchronously

MCE::Simple expands keywords at compile time to parallel code.

use MCE::Simple ( include => [qw/ -strict -signatures /], max_workers => 4, init_relay => '', ); MCE::Simple->init( on_finish => sub ( $pid, $exit, $ident, $signal, $error, @ret ) { say "MCE job ** $ident ** completed; status $exit."; print join('', @ret); }, ); spawn "foo", sub { my @results; MCE::Simple->init(gather => \@results); mce_forchunk my $chunk (91..99) { my $output = "From chunk_id: ".MCE->chunk_id."\n"; for my $i (@{ $chunk }) { $output .= "$i\n"; } MCE::relay { MCE->gather($output); }; } @results; }; # do something else sync;

Output

MCE job ** foo ** completed; status 0. From chunk_id: 1 91 92 From chunk_id: 2 93 94 From chunk_id: 3 95 96 From chunk_id: 4 97 98 From chunk_id: 5 99

In reply to Re^3: Code brewing for the upcoming MCE 10 year anniversary by marioroy
in thread Code brewing for the upcoming MCE 10 year anniversary by marioroy

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.