-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmpi-bi-bandwidth.c
168 lines (129 loc) · 4.28 KB
/
mpi-bi-bandwidth.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#define BENCHMARK "OSU MPI Bi-Directional Bandwidth Test"
/*
* Copyright (C) 2002-2012 the Network-Based Computing Laboratory
* (NBCL), The Ohio State University.
*
* Contact: Dr. D. K. Panda ([email protected])
*
* For detailed copyright and licensing information, please refer to the
* copyright file COPYRIGHT in the top level OMB directory.
*/
#include <mpi.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
#define MAX_REQ_NUM 1000
#define MAX_ALIGNMENT 65536
#define MAX_MSG_SIZE (1<<22)
#define MYBUFSIZE (MAX_MSG_SIZE + MAX_ALIGNMENT)
#define LOOP_LARGE 20
#define WINDOW_SIZE_LARGE 64
#define SKIP_LARGE 2
int LARGE_MESSAGE_SIZE = 8192;
char s_buf_original[MYBUFSIZE];
char r_buf_original[MYBUFSIZE];
MPI_Request send_request[MAX_REQ_NUM];
MPI_Request recv_request[MAX_REQ_NUM];
MPI_Status reqstat[MAX_REQ_NUM];
#ifdef PACKAGE_VERSION
# define HEADER "# " BENCHMARK " v" PACKAGE_VERSION "\n"
#else
# define HEADER "# " BENCHMARK "\n"
#endif
#ifndef FIELD_WIDTH
# define FIELD_WIDTH 20
#endif
#ifndef FLOAT_PRECISION
# define FLOAT_PRECISION 2
#endif
int main(int argc, char *argv[])
{
int myid, numprocs, i, j;
int size, align_size;
char *s_buf, *r_buf;
double t_start = 0.0, t_end = 0.0, t = 0.0;
int loop = 100;
int window_size = 64;
int skip = 10;
MPI_Init(&argc, &argv);
MPI_Comm_size(MPI_COMM_WORLD, &numprocs);
MPI_Comm_rank(MPI_COMM_WORLD, &myid);
if(numprocs != 2) {
if(myid == 0) {
fprintf(stderr, "This test requires exactly two processes\n");
}
MPI_Finalize();
return EXIT_FAILURE;
}
align_size = getpagesize();
assert(align_size <= MAX_ALIGNMENT);
/**************Allocating Memory*********************/
s_buf =
(char *) (((unsigned long) s_buf_original + (align_size - 1)) /
align_size * align_size);
r_buf =
(char *) (((unsigned long) r_buf_original + (align_size - 1)) /
align_size * align_size);
/**************Memory Allocation Done*********************/
if(myid == 0) {
fprintf(stdout, HEADER);
fprintf(stdout, "%-*s%*s\n", 10, "# Size", FIELD_WIDTH,
"Bi-Bandwidth (MB/s)");
fflush(stdout);
}
for(size = 1; size <= MAX_MSG_SIZE; size *= 2) {
/* touch the data */
for(i = 0; i < size; i++) {
s_buf[i] = 'a';
r_buf[i] = 'b';
}
if(size > LARGE_MESSAGE_SIZE) {
loop = LOOP_LARGE;
skip = SKIP_LARGE;
window_size = WINDOW_SIZE_LARGE;
}
if(myid == 0) {
for(i = 0; i < loop + skip; i++) {
if(i == skip) {
t_start = MPI_Wtime();
}
for(j = 0; j < window_size; j++) {
MPI_Irecv(r_buf, size, MPI_CHAR, 1, 10, MPI_COMM_WORLD,
recv_request + j);
}
for(j = 0; j < window_size; j++) {
MPI_Isend(s_buf, size, MPI_CHAR, 1, 100, MPI_COMM_WORLD,
send_request + j);
}
MPI_Waitall(window_size, send_request, reqstat);
MPI_Waitall(window_size, recv_request, reqstat);
}
t_end = MPI_Wtime();
t = t_end - t_start;
}
else if(myid == 1) {
for(i = 0; i < loop + skip; i++) {
for(j = 0; j < window_size; j++) {
MPI_Irecv(r_buf, size, MPI_CHAR, 0, 100, MPI_COMM_WORLD,
recv_request + j);
}
for (j = 0; j < window_size; j++) {
MPI_Isend(s_buf, size, MPI_CHAR, 0, 10, MPI_COMM_WORLD,
send_request + j);
}
MPI_Waitall(window_size, send_request, reqstat);
MPI_Waitall(window_size, recv_request, reqstat);
}
}
if(myid == 0) {
double tmp = size / 1e6 * loop * window_size * 2;
fprintf(stdout, "%-*d%*.*f\n", 10, size, FIELD_WIDTH,
FLOAT_PRECISION, tmp / t);
fflush(stdout);
}
}
MPI_Finalize();
return EXIT_SUCCESS;
}
/* vi: set sw=4 sts=4 tw=80: */