Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

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

by marioroy (Prior)
on Jun 18, 2016 at 00:08 UTC ( [id://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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (4)
As of 2024-03-29 10:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found