Created
November 19, 2013 16:26
-
-
Save jacquerie/7548078 to your computer and use it in GitHub Desktop.
My solution to: http://www.hpc.cineca.it/content/exercise-4
This file contains 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
#include <mpi.h> | |
#include <stdio.h> | |
int main (int argc, char** argv) { | |
int i, rank, size, left, right; | |
double A, B, SUM; | |
MPI_Status status; | |
MPI_Init(&argc, &argv); | |
MPI_Comm_rank(MPI_COMM_WORLD, &rank); | |
MPI_Comm_size(MPI_COMM_WORLD, &size); | |
A = rank; | |
left = (rank == 0) ? size - 1 : rank - 1; | |
right = (rank == size - 1) ? 0 : rank + 1; | |
for (i = 0; i < size; i++) { | |
MPI_Sendrecv(&A, 1, MPI_DOUBLE, right, 0, &B, 1, MPI_DOUBLE, left, 0, MPI_COMM_WORLD, &status); | |
SUM += B; | |
A = B; | |
} | |
printf("I am proc %d and SUM = %.2f\n", rank, SUM); | |
MPI_Finalize(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment