31 lines
591 B
C++
31 lines
591 B
C++
|
|
#include <iostream.h>
|
|
#include <mpi.h>
|
|
using namespace std;
|
|
|
|
int main(int argc, char * argv[])
|
|
{
|
|
int my_rank;
|
|
|
|
MPI_Init(&argc, &argv);
|
|
MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);
|
|
|
|
if (my_rank == MASTER)
|
|
{
|
|
int buf = 0;
|
|
MPI_Recv(&buf, sizeof(buf), MPI_CHAR,
|
|
MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD);
|
|
cout << "Master received " << buf << endl;
|
|
}
|
|
else
|
|
{
|
|
int forty_two = 42;
|
|
MPI_Send(&forty_two, sizeof(forty_two), MPI_CHAR,
|
|
MASTER, 42, MPI_COMM_WORLD);
|
|
}
|
|
|
|
MPI_Finalize();
|
|
|
|
return 0;
|
|
}
|