-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHomeTask1.c
More file actions
52 lines (46 loc) · 1 KB
/
HomeTask1.c
File metadata and controls
52 lines (46 loc) · 1 KB
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 "mpi.h"
#define BUFFSIZE 8
#define TAG 0
#define ITERS 1e7
int main(int argc, char* argv[])
{
int rank, numtasks, res;
long i = ITERS;
char buff[BUFFSIZE];
MPI_Status stat;
res = MPI_Init(&argc, &argv);
if (res != MPI_SUCCESS)
{
printf("Initilization failed\n");
MPI_Abort(MPI_COMM_WORLD, res);
}
MPI_Comm_size(MPI_COMM_WORLD, &numtasks);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
double time = 0.0;
if (rank == 0)
time = MPI_Wtime();
while(i)
{
if (rank == 0)
{
MPI_Send(buff, BUFFSIZE, MPI_CHAR, 1, TAG, MPI_COMM_WORLD);
MPI_Recv(buff, BUFFSIZE, MPI_CHAR, 1, TAG, MPI_COMM_WORLD, &stat);
i--;
}
if (rank == 1)
{
MPI_Recv(buff, BUFFSIZE, MPI_CHAR, 0, TAG, MPI_COMM_WORLD, &stat);
MPI_Send(buff, BUFFSIZE, MPI_CHAR, 0, TAG, MPI_COMM_WORLD);
i--;
}
}
if (rank == 0)
{
time = MPI_Wtime() - time;
printf("time: %.1f s\n", time);
printf("channel capacity: %f Mb/s\n", ((BUFFSIZE*ITERS)/time)/(1024*1024));
}
MPI_Finalize();
return 0;
}