Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

Re^2: Use more than one threads for one file processing

by marioroy (Prior)
on Jun 18, 2016 at 00:08 UTC ( #1166014=note: print w/replies, xml ) Need Help??

in reply to Re: Use more than one threads for one file processing
in thread Use more than one threads for one file processing

The following preserves output order if desired. Here, the chunk_id value is used for ensuring ordered entry into the @found array. It is important for workers to gather even though sending an empty @results. The reason is that the Manager process must know that a given chunk_id has completed.

use strict; use warnings; use MCE::Loop; use MCE::Candy; my @patterns = ( "biopattern1", "biopattern2", "biopattern3" ); my $search = join('|', @patterns); my $regex = qr/$search/; open my $fh, "gunzip -c in.fastq.gz |" or die "open error: $!"; my @found; MCE::Loop->init( max_workers => 4, chunk_size => 50, RS => "\n@", gather => MCE::Candy::out_iter_array(\@found) ); MCE::Loop->run( sub { my ( $mce, $chunk_ref, $chunk_id ) = @_; my @results; for my $i ( 0 .. $#{ $chunk_ref } ) { if ( $chunk_ref->[$i] =~ /$regex/ ) { push @results, $chunk_ref->[$i]; } } MCE->gather( $chunk_id, @results ); }, $fh ); MCE::Loop->finish(); close $fh; print join('', @found);

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (2)
As of 2023-09-25 05:20 GMT
Find Nodes?
    Voting Booth?

    No recent polls found