Skip to content

Instantly share code, notes, and snippets.

@shelling
Created June 15, 2010 09:47
Show Gist options
  • Select an option

  • Save shelling/438917 to your computer and use it in GitHub Desktop.

Select an option

Save shelling/438917 to your computer and use it in GitHub Desktop.
Hello, Parallel::MPI
#!/usr/bin/env perl
use 5.010;
use Parallel::MPI::Simple;
$total = 0;
MPI_Init();
$rank = MPI_Comm_rank( MPI_COMM_WORLD );
$size = MPI_Comm_size( MPI_COMM_WORLD );
$host = `hostname`;
say "I am process $rank of $size at $host";
MPI_Barrier( MPI_COMM_WORLD );
my $total = MPI_Reduce( $rank, sub { $_[0] + $_[1] } , MPI_COMM_WORLD );
if ( $rank == 0 ) {
say $total;
}
if ( $rank < $size-1 ) {
MPI_Send( $rank, $rank+1, 0, MPI_COMM_WORLD );
}
MPI_Barrier( MPI_COMM_WORLD );
if ( $rank > 0 ) {
my $received_data = MPI_Recv( $rank-1, 0, MPI_COMM_WORLD );
say "my rank is $rank and receive data from $received_data";
}
MPI_Finalize();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment