-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRsend.c
52 lines (45 loc) · 1.55 KB
/
Rsend.c
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
46
47
48
49
50
51
52
#include <stdio.h>
#include <stdlib.h>
#include <mpi.h>
int main(int argc, char* argv[])
{
printf("Done by Maitreyee Paliwal \n\n");
MPI_Init(&argc, &argv);
int size;
MPI_Comm_size(MPI_COMM_WORLD, &size);
if(size != 2)
{
printf("This application is meant to be run with 2 processes.\n");
MPI_Abort(MPI_COMM_WORLD, EXIT_FAILURE);
}
enum role_ranks { SENDER, RECEIVER };
int my_rank;
MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);
switch(my_rank)
{
case SENDER:
{
printf("MPI process ID %d hits the barrier to wait for the matching MPI_Recv to be posted.\n\n", my_rank);
MPI_Barrier(MPI_COMM_WORLD);
printf("MPI_Rsend can now be issued.\n\n");
int buffer_sent = 2401;
printf("MPI process ID %d sends value %d.\n\n", my_rank, buffer_sent);
MPI_Rsend(&buffer_sent, 1, MPI_INT, RECEIVER, 0, MPI_COMM_WORLD);
break;
}
case RECEIVER:
{
int received;
MPI_Request request;
MPI_Irecv(&received, 1, MPI_INT, SENDER, 0, MPI_COMM_WORLD, &request);
printf("MPI process ID %d issued the MPI_Irecv, moved on and hit the barrier.\n\n", my_rank);
MPI_Barrier(MPI_COMM_WORLD);
// Wait for the underlying MPI_Recv to complete.
MPI_Wait(&request, MPI_STATUS_IGNORE);
printf("MPI process ID %d receives value %d.\n\n", my_rank, received);
break;
}
}
MPI_Finalize();
return EXIT_SUCCESS;
}