-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_mmpi.c
185 lines (152 loc) · 4.05 KB
/
test_mmpi.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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
/*
* test_mmpi.c
*
* Copyright 2007 Jean-Marc Saffroy <[email protected]>
* This file is part of the Driller library.
* Driller is free software, distributed under the terms of the
* GNU Lesser General Public License version 2.1.
*
*/
#include <stdio.h>
#include <sys/types.h>
#include <sys/time.h>
#include <time.h>
#include <assert.h>
#include <malloc.h>
#include "mmpi.h"
#include "log.h"
#define THRTEST_MIN_CHUNK_SIZE (1ULL << 8) /* 256 bytes */
#define THRTEST_MAX_CHUNK_SIZE (1ULL << 23) /* 8 MB */
#define THRTEST_VOLUME (1ULL << 27) /* 128 MB */
static void usage(char *progname) {
err("usage: %s <job id> <job size> <rank> <iter>", progname);
}
int main(int argc, char**argv) {
int jobid, nprocs, rank, iter;
char *buf;
/* parse args */
if(argc != 5)
usage(argv[0]);
jobid = atoi(argv[1]);
nprocs = atoi(argv[2]);
rank = atoi(argv[3]);
iter = atoi(argv[4]);
mmpi_init(jobid, nprocs, rank);
/* demonstrate barrier */
printf("rank %d enters barrier\n", rank);
mmpi_barrier();
printf("rank %d exits barrier\n", rank);
/* simple benchmark */
if(rank != 0) {
int i;
for(i = 0; i < iter; i++)
mmpi_barrier();
} else {
int i;
struct timeval tv1, tv2;
long delta;
printf("now time barrier latency (%d iterations)...\n",
iter);
gettimeofday(&tv1, NULL);
for(i = 0; i < iter; i++)
mmpi_barrier();
gettimeofday(&tv2, NULL);
delta = (tv2.tv_sec - tv1.tv_sec) * 1000000
+ tv2.tv_usec - tv1.tv_usec;
printf("average barrier latency: %.2fusec\n",
(float)delta/(float)iter);
}
mmpi_barrier();
/* test send/recv */
if(rank != 0) {
int i;
printf("%d: send to %d\n", rank, 0);
for(i = 0; i < iter; i++)
mmpi_send(0, &rank, sizeof(rank));
} else {
int i, j;
struct timeval tv1, tv2;
long delta;
printf("now time send/recv latency (%d iterations)...\n",
iter);
gettimeofday(&tv1, NULL);
for(j = 1; j < nprocs; j++) {
int r;
size_t sz;
printf("%d: recv from %d\n", rank, j);
for(i = 0; i < iter; i++) {
mmpi_recv(j, &r, &sz);
assert(sz == sizeof(r));
assert(r == j);
}
gettimeofday(&tv2, NULL);
delta = (tv2.tv_sec - tv1.tv_sec) * 1000000
+ tv2.tv_usec - tv1.tv_usec;
printf("average send/recv latency: %.2fusec\n",
(float)delta/(float)iter);
}
}
mmpi_barrier();
/* test throughput */
#if 1 && defined(linux)
/* increase the odds that buf is allocated with mmap
* (it won't be if there is enough free space in the heap) */
mallopt(M_MMAP_THRESHOLD, THRTEST_MAX_CHUNK_SIZE);
#endif
buf = malloc(THRTEST_MAX_CHUNK_SIZE);
if(rank != 0) {
int i, size, count;
for(size = THRTEST_MIN_CHUNK_SIZE;
size <= THRTEST_MAX_CHUNK_SIZE; size <<= 1) {
count = THRTEST_VOLUME / size;
for(i = 0; i < count; i++) {
#if 0
memset(buf, (char)i, size);
#else
/* we don't necessarily want to benchmark memset */
buf[0] = buf[size-1] = (char)i;
#endif
mmpi_send(0, buf, size);
#if 0
/* if buf is allocated with mmap, this will force
* invalidation of the fd and its memory mapping */
free(buf);
buf = malloc(size);
#endif
}
mmpi_barrier();
}
} else { /* in rank 0 */
int i, j, size, count;
struct timeval tv1, tv2;
float delta;
printf("now time send/recv throughput (%lld MB per iteration)...\n",
THRTEST_VOLUME >> 20);
for(size = THRTEST_MIN_CHUNK_SIZE;
size <= THRTEST_MAX_CHUNK_SIZE; size <<= 1) {
count = THRTEST_VOLUME / size;
gettimeofday(&tv1, NULL);
for(j = 1; j < nprocs; j++) {
size_t sz;
//printf("%d: recv from %d\n", rank, j);
for(i = 0; i < count; i++) {
mmpi_recv(j, buf, &sz);
assert(sz == size);
assert(buf[0] == (char)i);
assert(buf[size-1] == (char)i);
}
}
gettimeofday(&tv2, NULL);
delta = (float)(tv2.tv_usec - tv1.tv_usec) / 1E6
+ (float)(tv2.tv_sec - tv1.tv_sec);
printf("throughput: %6.1f MB/s (%.2fs) chunk % 8d\n",
(float)((nprocs-1) * (THRTEST_VOLUME >> 20)) / delta,
delta, size);
mmpi_barrier();
}
}
free(buf);
mmpi_barrier();
printf("SUCCESS! rank %d exits\n", rank);
return 0;
}