-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLab_3.cpp
45 lines (34 loc) · 899 Bytes
/
Lab_3.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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// Purpose: MPI program to demonstrate point-to-point communication
#include <iostream>
#include <mpi.h>
using namespace std;
int main()
{
// initialize MPI
MPI_Init(NULL, NULL);
// get the number of processes
int world_size;
MPI_Comm_size(MPI_COMM_WORLD, &world_size);
// get the rank of the process
int rank;
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
if (rank == 0)
{
int x = 0;
MPI_Send(&x, 1, MPI_INT, 1, 0, MPI_COMM_WORLD);
MPI_Recv(&x, 1, MPI_INT, 1, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
cout << "PONG"
<< "\n";
}
if (rank == 1)
{
int x;
MPI_Recv(&x, 1, MPI_INT, 0, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
cout << "PING"
<< "\n";
MPI_Send(&x, 1, MPI_INT, 0, 0, MPI_COMM_WORLD);
}
// finalize MPI
MPI_Finalize();
return 0;
}