Skip to content

Instantly share code, notes, and snippets.

@ofan
Created February 14, 2014 19:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ofan/9007233 to your computer and use it in GitHub Desktop.
Save ofan/9007233 to your computer and use it in GitHub Desktop.
#include <mpi.h>
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char* argv[]){
MPI_Init(&argc, &argv);
int size, rank;
MPI_Comm_size(MPI_COMM_WORLD, &size);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
int data;
if(rank == 0){
// We the monitor process
for(int i=1; i < size; ++i){
data = rand();
// Sending out data
MPI_Send(&data, 1, MPI_INT, i, 0, MPI_COMM_WORLD);
}
MPI_Barrier(MPI_COMM_WORLD);
}else{
MPI_Recv(&data, 1, MPI_INT, 0, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
printf("Process %d received numbr %d\n", rank, data);
MPI_Barrier(MPI_COMM_WORLD);
}
MPI_Finalize();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment