-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
29 lines (22 loc) · 838 Bytes
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include "mpi.h"
#include<iostream>
#include<string>
using namespace std;
int main(int argc, char* argv[])
{
MPI_Init(&argc, &argv);
int myRank{}, worldSize{};
MPI_Comm_rank(MPI_COMM_WORLD, &myRank);
MPI_Comm_size(MPI_COMM_WORLD, &worldSize);
char msg[100];
sprintf(msg, "Hi, I am CPU %d!", myRank);
MPI_Send(msg, strlen(msg) + 1, MPI_CHAR, (myRank + 1) % worldSize, 0, MPI_COMM_WORLD);
MPI_Status status;
MPI_Recv(msg, 100, MPI_CHAR, MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, &status);
cout << "\nI am CPU " << myRank << ". The CPU " << status.MPI_SOURCE << " told me: " << msg
<< "\nStatus.MPI_SOURCE = " << status.MPI_SOURCE
<< "\nStatus.MPI_TAG = "<< status.MPI_TAG
<< "\nStatus.MPI_ERROR = "<< status.MPI_ERROR << endl;
MPI_Finalize();
return 0;
}