-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhello.c
41 lines (31 loc) · 894 Bytes
/
hello.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
#include "mpi.h"
#include <stdio.h>
int main(argc,argv)
int argc;
char **argv;
{
int MyProc, tag=1;
char msg='A', msg_recpt;
MPI_Status status;
MPI_Init(&argc, &argv);
MPI_Comm_rank(MPI_COMM_WORLD, &MyProc);
printf("Process # %d started \n", MyProc);
MPI_Barrier(MPI_COMM_WORLD);
if (MyProc == 0)
{
printf("Sending message to Proc #1 \n") ;
MPI_Send(&msg, 1, MPI_CHAR, 1, tag, MPI_COMM_WORLD);
MPI_Recv(&msg_recpt, 1, MPI_CHAR, 1, tag, MPI_COMM_WORLD, &status);
printf("Recv'd message from Proc #1 \n") ;
}
else
{
MPI_Recv(&msg_recpt, 1, MPI_CHAR, 0, tag, MPI_COMM_WORLD, &status);
printf("Recv'd message from Proc #0 \n") ;
printf("Sending message to Proc #0 \n") ;
MPI_Send(&msg, 1, MPI_CHAR, 0, tag, MPI_COMM_WORLD);
}
printf("Finishing proc %d\n", MyProc);
MPI_Barrier(MPI_COMM_WORLD);
MPI_Finalize();
}