-
Notifications
You must be signed in to change notification settings - Fork 23
/
large_coalesce.c
326 lines (271 loc) · 9.45 KB
/
large_coalesce.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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
/*********************************************************************
*
* Copyright (C) 2017, Northwestern University and Argonne National Laboratory
* See COPYRIGHT notice in top-level directory.
*
*********************************************************************/
/* $Id$ */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* Given two large nonblocking requests and they are actually contiguous in
* fileview and buffer type, this program tests whether filetype and buftype
* coalescing is skipped when calling MPI_Type_create_hindexed internally.
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#include <stdio.h>
#include <stdlib.h>
#include <string.h> /* strcpy() */
#include <libgen.h> /* basename() */
#include <mpi.h>
#include <pnetcdf.h>
#include <testutils.h>
#define FOUR_G 4294967296LL
#define TWO_G 2147483648LL
#define ONE_G 1073741824LL
int main(int argc, char** argv)
{
char filename[256];
unsigned char *buf;
int rank, nprocs, err, nerrs=0;
int ncid, cmode, varid, dimid[2], req[3], st[3];
MPI_Offset start[2], count[2];
MPI_Info info;
size_t i;
int bb_enabled=0;
MPI_Init(&argc, &argv);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
/* get command-line arguments */
if (argc > 2) {
if (!rank) printf("Usage: %s [filename]\n",argv[0]);
MPI_Finalize();
return 1;
}
if (argc == 2) snprintf(filename, 256, "%s", argv[1]);
else strcpy(filename, "testfile.nc");
MPI_Bcast(filename, 256, MPI_CHAR, 0, MPI_COMM_WORLD);
if (rank == 0) {
char *cmd_str = (char*)malloc(strlen(argv[0]) + 256);
sprintf(cmd_str, "*** TESTING C %s for skip filetype buftype coalesce ", basename(argv[0]));
printf("%-66s ------ ", cmd_str); fflush(stdout);
free(cmd_str);
}
buf = (unsigned char*) calloc(TWO_G+1024,1);
if (buf == NULL) {
printf("malloc failed for size %lld\n", TWO_G+1024);
MPI_Finalize();
return 1;
}
MPI_Info_create(&info);
MPI_Info_set(info, "romio_cb_write", "enable");
MPI_Info_set(info, "romio_ds_read", "disable"); /* run slow without it */
#if defined(ENABLE_LARGE_SINGLE_REQ) || defined(ENABLE_BURST_BUFFER)
#else
/* silence iternal debug messages */
setenv("PNETCDF_SAFE_MODE", "0", 1);
#endif
#ifdef ENABLE_NETCDF4
/* Test for NetCDF 4 first as ncvalidator checks only read classic files */
/* create a new file for writing ----------------------------------------*/
cmode = NC_CLOBBER | NC_NETCDF4;
err = ncmpi_create(MPI_COMM_WORLD, filename, cmode, info, &ncid);
CHECK_ERR
/* define dimensions */
err = ncmpi_def_dim(ncid, "NPROCS", nprocs, &dimid[0]);
CHECK_ERR
err = ncmpi_def_dim(ncid, "X", TWO_G+1024, &dimid[1]);
CHECK_ERR
/* define a big 1D variable of ubyte type */
err = ncmpi_def_var(ncid, "big_var", NC_UBYTE, 2, dimid, &varid);
CHECK_ERR
/* do not forget to exit define mode */
err = ncmpi_enddef(ncid);
CHECK_ERR
/* now we are in data mode */
for (i=0; i<20; i++) buf[ONE_G-10+i] = 'a'+i;
for (i=0; i<20; i++) buf[TWO_G-10+i] = 'A'+i;
start[0] = rank;
count[0] = 1;
start[1] = 0;
count[1] = 10;
err = ncmpi_put_vara_uchar_all(ncid, varid, start, count, buf);
CHECK_ERR
/* 2nd request is not contiguous from the first */
start[1] = 1024;
count[1] = ONE_G-1024;
err = ncmpi_put_vara_uchar_all(ncid, varid, start, count, buf+1024);
CHECK_ERR
/* make file access and write buffer of 3rd request contiguous from the 2nd
* request to check whether the internal fileview and buftype coalescing
* are skipped */
start[1] = ONE_G;
count[1] = ONE_G+1024;
err = ncmpi_put_vara_uchar_all(ncid, varid, start, count, buf+ONE_G);
CHECK_ERR
start[1] = 0;
count[1] = 10;
err = ncmpi_get_vara_uchar_all(ncid, varid, start, count, buf);
CHECK_ERR
start[1] = 1024;
count[1] = ONE_G-1024;
err = ncmpi_get_vara_uchar_all(ncid, varid, start, count, buf+1024);
CHECK_ERR
start[1] = ONE_G;
count[1] = ONE_G+1024;
err = ncmpi_get_vara_uchar_all(ncid, varid, start, count, buf+ONE_G);
CHECK_ERR
err = ncmpi_close(ncid); CHECK_ERR
/* check if open to read header fine */
err = ncmpi_open(MPI_COMM_WORLD, filename, NC_NOWRITE, MPI_INFO_NULL, &ncid); CHECK_ERR
err = ncmpi_close(ncid); CHECK_ERR
#endif
/* Test classic format */
/* create a new file for writing ----------------------------------------*/
cmode = NC_CLOBBER | NC_64BIT_DATA;
err = ncmpi_create(MPI_COMM_WORLD, filename, cmode, info, &ncid);
CHECK_ERR
MPI_Info_free(&info);
{
int flag;
char hint[MPI_MAX_INFO_VAL];
MPI_Info infoused;
ncmpi_inq_file_info(ncid, &infoused);
MPI_Info_get(infoused, "nc_burst_buf", MPI_MAX_INFO_VAL - 1, hint, &flag);
if (flag && strcasecmp(hint, "enable") == 0)
bb_enabled = 1;
MPI_Info_free(&infoused);
}
/* define dimensions */
err = ncmpi_def_dim(ncid, "NPROCS", nprocs, &dimid[0]);
CHECK_ERR
err = ncmpi_def_dim(ncid, "X", TWO_G+1024, &dimid[1]);
CHECK_ERR
/* define a big 1D variable of ubyte type */
err = ncmpi_def_var(ncid, "big_var", NC_UBYTE, 2, dimid, &varid);
CHECK_ERR
/* do not forget to exit define mode */
err = ncmpi_enddef(ncid);
CHECK_ERR
/* now we are in data mode */
#if defined(ENABLE_LARGE_SINGLE_REQ) || defined(ENABLE_BURST_BUFFER)
#ifndef ENABLE_LARGE_SINGLE_REQ
if (bb_enabled) {
#endif
for (i=0; i<20; i++) buf[ONE_G-10+i] = 'a'+i;
for (i=0; i<20; i++) buf[TWO_G-10+i] = 'A'+i;
#ifndef ENABLE_LARGE_SINGLE_REQ
}
#endif
#endif
start[0] = rank;
count[0] = 1;
start[1] = 0;
count[1] = 10;
err = ncmpi_iput_vara_uchar(ncid, varid, start, count, buf, &req[0]);
CHECK_ERR
/* 2nd request is not contiguous from the first */
start[1] = 1024;
count[1] = ONE_G-1024;
err = ncmpi_iput_vara_uchar(ncid, varid, start, count, buf+1024, &req[1]);
CHECK_ERR
/* make file access and write buffer of 3rd request contiguous from the 2nd
* request to check whether the internal fileview and buftype coalescing
* are skipped */
start[1] = ONE_G;
count[1] = ONE_G+1024;
err = ncmpi_iput_vara_uchar(ncid, varid, start, count, buf+ONE_G, &req[2]);
CHECK_ERR
err = ncmpi_wait_all(ncid, 3, req, st);
#if defined(ENABLE_LARGE_SINGLE_REQ) || defined(ENABLE_BURST_BUFFER)
#ifndef ENABLE_LARGE_SINGLE_REQ
if (bb_enabled) {
#endif
CHECK_ERR
/* read back to check contents */
start[1] = ONE_G-10;
count[1] = 20;
err = ncmpi_get_vara_uchar_all(ncid, varid, start, count, buf);
CHECK_ERR
for (i=0; i<20; i++) {
if (buf[i] != 'a'+i) {
printf("%d (at line %d): expect buf[%lld]=%zd but got %d\n",
rank, __LINE__, ONE_G-10+i, i+'a', buf[i]);
nerrs++;
}
}
/* read back to check contents */
start[1] = TWO_G-10;
count[1] = 20;
err = ncmpi_get_vara_uchar_all(ncid, varid, start, count, buf);
CHECK_ERR
for (i=0; i<20; i++) {
if (buf[i] != 'A'+i) {
printf("%d (at line %d): expect buf[%lld]=%zd but got %d\n",
rank, __LINE__, TWO_G-10+i, i+'A', buf[i]);
nerrs++;
}
}
/* test the same pattern but for iget */
for (i=0; i<TWO_G+1024; i++) buf[i] = 0;
#ifndef ENABLE_LARGE_SINGLE_REQ
}
else
EXP_ERR(NC_EMAX_REQ)
#endif
#else
EXP_ERR(NC_EMAX_REQ)
#endif
start[1] = 0;
count[1] = 10;
err = ncmpi_iget_vara_uchar(ncid, varid, start, count, buf, &req[0]);
CHECK_ERR
start[1] = 1024;
count[1] = ONE_G-1024;
err = ncmpi_iget_vara_uchar(ncid, varid, start, count, buf+1024, &req[1]);
CHECK_ERR
start[1] = ONE_G;
count[1] = ONE_G+1024;
err = ncmpi_iget_vara_uchar(ncid, varid, start, count, buf+ONE_G, &req[2]);
CHECK_ERR
err = ncmpi_wait_all(ncid, 3, req, st);
#ifndef ENABLE_LARGE_SINGLE_REQ
EXP_ERR(NC_EMAX_REQ)
#else
CHECK_ERR
for (i=0; i<20; i++) {
if (buf[ONE_G-10+i] != 'a'+i) {
printf("%d (at line %d): expect buf[%lld]=%zd but got %d\n",
rank, __LINE__, ONE_G-10+i, i+'a', buf[i]);
nerrs++;
}
}
for (i=0; i<20; i++) {
if (buf[TWO_G-10+i] != 'A'+i) {
printf("%d (at line %d): expect buf[%lld]=%zd but got %d\n",
rank, __LINE__, TWO_G-10+i, i+'A', buf[i]);
nerrs++;
}
}
#endif
err = ncmpi_close(ncid); CHECK_ERR
/* check if open for reading header */
err = ncmpi_open(MPI_COMM_WORLD, filename, NC_NOWRITE, MPI_INFO_NULL, &ncid); CHECK_ERR
err = ncmpi_close(ncid); CHECK_ERR
free(buf);
/* check if PnetCDF freed all internal malloc */
MPI_Offset malloc_size, sum_size;
err = ncmpi_inq_malloc_size(&malloc_size);
if (err == NC_NOERR) {
MPI_Reduce(&malloc_size, &sum_size, 1, MPI_OFFSET, MPI_SUM, 0, MPI_COMM_WORLD);
if (rank == 0 && sum_size > 0)
printf("heap memory allocated by PnetCDF internally has %lld bytes yet to be freed\n",
sum_size);
}
MPI_Allreduce(MPI_IN_PLACE, &nerrs, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD);
if (rank == 0) {
if (nerrs) printf(FAIL_STR,nerrs);
else printf(PASS_STR);
}
MPI_Finalize();
return (nerrs > 0);
}