-
Notifications
You must be signed in to change notification settings - Fork 0
/
t4.c
49 lines (42 loc) · 1.38 KB
/
t4.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
#include <stdio.h>
#include "mpi.h"
#include <math.h>
int main(int argc, char *argv[])
{
int i, j, n, myrank, numranks, rc, partner_rank;
MPI_Status status;
char hostname[128];
MPI_Init(NULL,NULL);
MPI_Comm_rank(MPI_COMM_WORLD,&myrank);
MPI_Comm_size(MPI_COMM_WORLD,&numranks);
gethostname(hostname,128);
printf("%d: size %d onhost %s\n",myrank,numranks,hostname);
partner_rank = numranks - myrank - 1;
if (myrank < partner_rank)
{
n = 0;
rc = MPI_Recv(&n,1,MPI_INT,MPI_ANY_SOURCE,MPI_ANY_TAG,MPI_COMM_WORLD,&status);
printf("%d: recvrc=%d n=%d from=%d tag=%d\n",
myrank, rc, n, status.MPI_SOURCE, status.MPI_TAG);
if (status.MPI_SOURCE != partner_rank)
{
printf("OOPS wrong sender %d expected %d\n",status.MPI_SOURCE,partner_rank);
}
n = 88;
rc = MPI_Send(&n,1,MPI_INT,partner_rank,44,MPI_COMM_WORLD);
}
else
{
n = 99;
rc = MPI_Send(&n,1,MPI_INT,partner_rank,44,MPI_COMM_WORLD);
n = 0;
rc = MPI_Recv(&n,1,MPI_INT,MPI_ANY_SOURCE,MPI_ANY_TAG,MPI_COMM_WORLD,&status);
printf("%d: recvrc=%d n=%d from=%d tag=%d\n",
myrank, rc, n, status.MPI_SOURCE, status.MPI_TAG);
if (status.MPI_SOURCE != partner_rank)
{
printf("OOPS wrong sender %d expected %d\n",status.MPI_SOURCE,partner_rank);
}
}
MPI_Finalize();
}