Skip to content

Instantly share code, notes, and snippets.

@jciechowski
Created October 12, 2012 08:13
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save jciechowski/3877947 to your computer and use it in GitHub Desktop.
ping MPI
#include <stdio.h>
#include <mpi.h>
int main( int argc, char **argv) {
int size, rank;
int msg = 0;
MPI_Status status;
MPI_Init(&argc, &argv);
// ilosc procesow
MPI_Comm_size(MPI_COMM_WORLD,&size);
// numer procesu
MPI_Comm_rank(MPI_COMM_WORLD,&rank);
// wysylam do nastepnego procesu
if(!MPI_Send(&msg, 1, MPI_INT, (rank+1)%size, 666, MPI_COMM_WORLD)) {
printf("rank%i wyslal do %d wartosc %d\n",rank,(rank+1)%size, msg);
msg++; // zwiekszam przed wyslaniem, nie dziala
}
// odbieram z poprzedniego
if(!MPI_Recv(&msg, 1, MPI_INT, (rank-1)%size, 666, MPI_COMM_WORLD, &status)) {
printf("rank%i received %d\n",rank,msg);
msg++; // zwiekszam po odebraniu, nie dziala
}
MPI_Finalize();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment