Created
February 14, 2014 19:19
-
-
Save ofan/9007233 to your computer and use it in GitHub Desktop.
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> | |
#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