-
Notifications
You must be signed in to change notification settings - Fork 0
/
Q1_Bcast.c
32 lines (28 loc) · 780 Bytes
/
Q1_Bcast.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
#include <mpi.h>
#include <stdio.h>
int main(int argc, char **argv)
{
int rank = -1;
int nprocs = 0;
MPI_Init(&argc, &argv);
MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Request request = MPI_REQUEST_NULL;
MPI_Status status;
char rdata[] = "";
if (rank == 0)
{
char sdata[] = "Hello PDC";
for(int itr=1; itr<nprocs; itr++){
MPI_Isend(&sdata, 9, MPI_CHAR, itr, (itr+1), MPI_COMM_WORLD, &request);
}
}else if (rank>0){
MPI_Irecv(&rdata, 9, MPI_CHAR, 0, MPI_ANY_TAG, MPI_COMM_WORLD, &request);
}
MPI_Wait(&request,&status);
if(rank>0){
printf("Process %d Received: %s\n", rank, rdata);
}
MPI_Finalize();
return 0;
}