Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^4: Using MCE to write to multiple files.

by marioroy (Prior)
on Dec 13, 2014 at 01:42 UTC ( [id://1110232]=note: print w/replies, xml ) Need Help??


in reply to Re^3: Using MCE to write to multiple files.
in thread Using MCE to write to multiple files.

Hi etheleon,

It seems that output order is not necessary for the use-case. The issue mentioned may be coming from say $output (not appending \n to the file for me, instead getting a GLOB message to STDOUT).

Btw, I ran your code and it ran fine. I only changed say $output to print $output "\n"; All files had 10 results -- all identical -- all same size.

Back to MCE, the following processes @input_data in parallel. Am using the MCE::Loop Model versus using the Core API.

use MCE::Loop chunk_size => 1; my @input_data = (0 .. 100 - 1); mce_loop { my ($mce, $chunk_ref, $chunk_id) = @_; open my $output, '>', "/path/to/my/files/$chunk_id.txt"; foreach (1..10) { print $output "\t",fibonacci($_)}; print $output "\n"; close $output; } @input_data; sub fibonacci { my $n = shift; return undef if $n < 0; my $f; if ($n == 0) { $f = 0; } elsif ($n == 1) { $f = 1; } else { $f = fibonacci($n-1) + fibonacci($n-2); } return $f; }

Notice how mce_loop wraps around the serial code to enable parallelism.

Also see https://metacpan.org/pod/MCE::Loop#GATHERING-DATA if wanting to gather data back to the Manager process.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1110232]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (2)
As of 2024-04-26 03:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found