since the array @data_input held 10 elements, i should get 10 files output but i don't.

Um, there is @input_data, and it has 100 elements, :)

But ok, are you using fork or threads? Try getting MCE to choose fork, then repeat your test with treads ... if there is a difference between the two, then there is a bug in one of the backends, or it hasn't finished running

If both fork/threads backends behave the same, then there might be a problem with your logic

I've not scrutinized your code, but  $tmp{$chunk_id} stuff looks like it will never make any difference :)

But if you want something to compare, try

$ perl threads-jobadder-jobworker-fibonacci.pl $ dir /b fibojob* |wc --lines 100
#!/usr/bin/perl -- ## threads-jobadder-jobworker-fibonacci.pl ## ## ## ## ## ## perltidy -olq -csc -csci=3 -cscl="sub : BEGIN END " -otr -opr -ce +-nibc -i=4 -pt=0 "-nsak=*" ## perltidy -olq -csc -csci=10 -cscl="sub : BEGIN END if " -otr -opr +-ce -nibc -i=4 -pt=0 "-nsak=*" ## perltidy -olq -csc -csci=10 -cscl="sub : BEGIN END if while " -otr + -opr -ce -nibc -i=4 -pt=0 "-nsak=*" #!/usr/bin/perl -- use strict; use warnings; use threads stack_size => 4096; use Thread::Queue; Main( @ARGV ); exit( 0 ); sub Main { use autodie qw/ chdir /; chdir "/path/to/my/files/" ; my $maxJobs = 8; my $q = Thread::Queue->new; for( 1 .. $maxJobs ) { ## threads->create( \&JobWorker, $queue, \&TheJob ); threads->create( \&JobWorker, $q, \&GetFibby ); } threads->create( \&JobAdder, $q, $maxJobs, [ 0 .. 99 ] ); $_->join for threads->list; ## wait for threads to finish } ## end sub Main sub JobWorker { my( $q, $callBack ) = @_; while( defined( my $argRef = $q->dequeue ) ) { ## GetFibby( @$argRef ); $callBack->( @$argRef ); } return; } ## end sub JobWorker sub GetFibby { my( $chunkId ) = @_; use autodie qw/ open close /; open my( $outfh ), '>', "fibojob-$chunkId.txt"; print $outfh "\t", fibonacci( $_ ) for 1 .. 10; print $outfh "\n"; close $outfh; } ## end sub GetFibby sub JobAdder { my( $q, $maxJobs, $inputs ) = @_; while( @$inputs ) { AddJob( $q, shift @$inputs ); } SignalNoMoreJobs( $q, $maxJobs ); } ## end sub JobAdder sub SignalNoMoreJobs { my( $q, $maxJobs ) = @_; $q->enqueue( undef ) for 1 .. $maxJobs; return; } ## end sub SignalNoMoreJobs sub AddJob { my $q = shift; $q->enqueue( [@_] ); return; } ## end sub AddJob 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; } ## end sub fibonacci

In reply to Re^3: Using MCE to write to multiple files. by Anonymous Monk
in thread Using MCE to write to multiple files. by etheleon

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.