develooper Front page | perl.ithreads | Postings from December 2008

Re: No gain in speed with threads

Thread Previous
Jerry D. Hedden
December 31, 2008 07:06
Re: No gain in speed with threads
Message ID:
Blanchette, Marco wrote:
> my @thr;
> for (my $i=0;$i<=$#ARGV;$i++){
>  push @thr, threads->new(\&extractSeq, $ARGV[$i]);
>  if (scalar(@thr) == $opt_p || $i == $#ARGV){
>    print "Running ",scalar(@thr)," parallel jobs\n";
>    $_->join for @thr;
>    undef @thr;
>  }
> }

Your job control is running in batches of $opt_p with
each batch running until all jobs are complete.  This
is inefficient.  Try the following:

foreach my $arg (@ARGV) {
    # New parallel job
    threads->new(\&extractSeq, $arg);

    # If max parallel count, then wait for some threads to finish
    while (threads->list(threads::running) >= $opt_p) {
        if (my @thrs = threads->list(threads::joinable)) {
            $_->join() foreach @thrs;
        } else {
# Wait for all running threads to finish
$_->join() foreach threads->list();

Thread Previous Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About