GRID-Cluster
view release on metacpan or search on metacpan
lib/GRID/Cluster.pm view on Meta::CPAN
$readset->remove($handle) if eof($handle);
close $handle;
} until (++$count == $np);
return \@result;
}
sub close2 {
my ($self, $cluster_handle) = @_;
my $readset = $cluster_handle->get_readset();
my @wproc = @{$cluster_handle->get_wproc()};
my %id = %{$cluster_handle->get_id()};
my $np = values(%id);
my $count = 0;
my @ready;
my @result;
do {
push @ready, $readset->can_read unless @ready;
my $handle = shift @ready;
my $me = $id{0 + $handle};
my ($aux, $bytes, $r);
while ((!defined($bytes)) || ($bytes)) {
$bytes = sysread($handle, $aux, BUFFERSIZE);
$r .= $aux if ((defined($bytes)) && ($bytes));
}
$result[$me] = $r;
$readset->remove($handle) if eof($handle);
$handle->close();
$wproc[$count]->close();
} until (++$count == $np);
return \@result;
}
1;
__END__
=head1 NAME
GRID::Cluster - Virtual clusters using SSH links
=head1 SYNOPSIS
use GRID::Cluster;
my $np = 4; # Number of processes
my $N = 1000; # Number of iterations
my $clean = 0; # The files are not removed when the execution is finished
my $machine = [ 'host1', 'host2', 'host3' ]; # Hosts
my $debug = { host1 => 0, host2 => 0, host3 => 0 }; # Debug mode in every host
my $max_num_np = { host1 => 1, host2 => 1, host3 => 1 }; # Maximum number of processes supported by every host
my $c = GRID::Cluster->new(host_names => $machine, debug => $debug, max_num_np => $max_num_np);
|| die "No machines has been initialized in the cluster";
# Transference of files to remote hosts
$c->copyandmake(
dir => 'pi',
makeargs => 'pi',
files => [ qw{pi.c Makefile} ],
cleanfiles => $clean,
cleandirs => $clean, # remove the whole directory at the end
keepdir => 1,
);
# This method changes the remote working directory of all hosts
$c->chdir("pi/") || die "Can't change to pi/\n";
# Tasks are created and executed in remote machines using the method 'qx'
my @commands = map { "./pi $_ $N $np |" } 0..$np-1
print "Pi Value: ".sum @{$c->qx(@commands)}."\n";
=head1 DESCRIPTION
This module is based on the module L<GRID::Machine>. It provides a set
of methods to create 'virtual' clusters by the use of SSH links for
communications among different remote hosts.
Since main features of C<GRID::Machine> are zero administration and minimal
installation, L<GRID::Cluster> directly inherites these features.
Mainly, C<GRID::Cluster> provides:
=over
=item *
An extension of the Perl C<qx> method. Instead of a single command it receives a
list of commands. Commands are executed - via SSH - using the master-worker paradigm.
=item *
Services for the transference of files among machines.
=back
=head1 DEPENDENCIES
This module requires these other modules and libraries:
=over
=item * L<GRID::Machine> module by Casiano Rodriguez Leon
=item * L<Term::Prompt> module by Allen Smith
( run in 1.647 second using v1.01-cache-2.11-cpan-71847e10f99 )