Created
June 15, 2010 09:47
-
-
Save shelling/438917 to your computer and use it in GitHub Desktop.
Hello, Parallel::MPI
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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