ChainMake::Parallel - Check requirements in parallel


ChainMake documentation Contained in the ChainMake distribution.

Index


Code Index:

NAME

Top

ChainMake::Parallel - Check requirements in parallel

SYNOPSIS

Top

DESCRIPTION

Top

This module works just like the ChainMake module and may be used as a drop-in replacement.

The only difference is that this module adds an additional parameter to the targets in ChainMake method: parameter parallel.

parallel

Top

  %description = (
      parallel    => 5,
  );

The parallel field defines whether or not requirements should be checked in parallel. A non-zero number will be used as the number of parallel threads.

Currently experimental and only available if perl has been compiled with ithreads.

CAVEATS/BUGS

Top

SEE ALSO

Top

ChainMake

AUTHOR/COPYRIGHT

Top


ChainMake documentation Contained in the ChainMake distribution.

package ChainMake::Parallel;

use strict;
use Data::Dumper;
use threads;
use base 'ChainMake';

our $VERSION = $ChainMake::VERSION;

$ChainMake::TARGETTYPE_PARAMS{parallel} = sub { (shift >= 0) };

sub _check_requirements {
    # Alle Requirements checken (d.h. make darauf ausführen),
    # ob eines der Requirements jünger als unser ältestes timestamps-File ($oldest) ist.
    my ($self,$req,$insistent,$parallel)=@_;
    return $self->SUPER::_check_requirements($req,$insistent) unless ($parallel);
    my ($youngest,$cannot);
    print "Parallel mode - output will be scrambled!\n";
    my @threads;
    $parallel=scalar @$req if ($parallel > scalar @$req);
    for my $tnum (0..($parallel-1)) {
        my $num_per_thread=int((scalar @$req)/($parallel-$tnum));
        my @thrd_req=splice @$req,0,$num_per_thread;
        $threads[$tnum]=threads->create(sub {
#           print "Ich bin Thread ".threads->self->tid(), " und stelle folgendes her: ", join(", ",@thrd_req),"\n";
            $self->SUPER::_check_requirements(\@thrd_req,$insistent)
        });
    }
    for my $thrd (@threads) {
        my ($youngest_req,$cant,$cant_name)=$thrd->join();
        if ($youngest_req) {
            $youngest=$youngest_req if (!($youngest) || ($youngest_req > $youngest));
        }
        else {
            $cannot=1;
        }
    }
    return ($cannot ? 0 : $youngest);
}

1;

__END__