Here is an example if how to make parallel calls using GRID::Machine::Group.

It Computes the number π (3.14159...) using numerical integration.

To understand it, take into account that the area under the curve 1/(1+x**2) between 0 and 1 is π/4:

#!/usr/bin/perl -w use strict; use GRID::Machine; use GRID::Machine::Group; use List::Util qw(sum); use Time::HiRes qw(time gettimeofday tv_interval); my @MACHINE_NAMES = split /\s+/, $ENV{MACHINES}; my @m = map { GRID::Machine->new(host => $_, wait => 5, survive => 1) +} @MACHINE_NAMES; my $c = GRID::Machine::Group->new(cluster => [ @m ]); $c->sub(suma_areas => q{ my ($id, $N, $np) = @_; my $sum = 0; for (my $i = $id; $i < $N; $i += $np) { my $x = ($i + 0.5) / $N; $sum += 4 / (1 + $x * $x); } $sum /= $N; }); my ($N, $np, $pi) = (1e7, 4, 0); my @args = map { [$_, $N, $np] } 0..$np-1; my $t0 = [gettimeofday]; $pi = sum($c->suma_areas(args => \@args)->Results); my $elapsed = tv_interval ($t0); print "Pi = $pi. N = $N Time = $elapsed\n";
When executed in a single machine, it took 5.387676 seconds:
~/grid-machine$ export MACHINES=local ~/grid-machine$ perl examples/pi.pl Pi = 3.14159265358969. N = 10000000 Time = 5.387676
When executed in a cluster with two nodes we get a speedup of 1.81 = 5.387676/2.977237:
~/grid-machine$ export MACHINES='local imac' ~/grid-machine$ echo $MACHINES local imac ~/grid-machine$ perl examples/pi.pl Pi = 3.14159265358969. N = 10000000 Time = 2.977237

In reply to Re: Parallel SSH by casiano
in thread Parallel SSH by solaris7

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.