-
Notifications
You must be signed in to change notification settings - Fork 12
/
vol_file_test_parallel.c
367 lines (302 loc) · 9.99 KB
/
vol_file_test_parallel.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
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Copyright by The HDF Group. *
* All rights reserved. *
* *
* This file is part of HDF5. The full HDF5 copyright notice, including *
* terms governing use, modification, and redistribution, is contained in *
* the COPYING file, which can be found at the root of the source code *
* distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases. *
* If you do not have access to either file, you may request a copy from *
* help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#include "vol_file_test_parallel.h"
static int test_create_file(void);
static int test_open_file(void);
static int test_split_comm_file_access(void);
/*
* The array of parallel file tests to be performed.
*/
static int (*par_file_tests[])(void) = {
test_create_file,
test_open_file,
test_split_comm_file_access,
};
/*
* A test to ensure that a file can be created in parallel.
*/
#define FILE_CREATE_TEST_FILENAME "test_file_parallel.h5"
static int
test_create_file(void)
{
hid_t file_id = H5I_INVALID_HID;
hid_t fapl_id = H5I_INVALID_HID;
TESTING("H5Fcreate");
/* Make sure the connector supports the API functions being tested */
if (!(vol_cap_flags_g & H5VL_CAP_FLAG_FILE_BASIC)) {
SKIPPED();
HDprintf(" API functions for basic file aren't supported with this connector\n");
return 0;
}
if ((fapl_id = create_mpi_fapl(MPI_COMM_WORLD, MPI_INFO_NULL, TRUE)) < 0)
TEST_ERROR;
if ((file_id = H5Fcreate(FILE_CREATE_TEST_FILENAME, H5F_ACC_TRUNC, H5P_DEFAULT, fapl_id)) < 0) {
H5_FAILED();
HDprintf(" couldn't create file '%s'\n", FILE_CREATE_TEST_FILENAME);
goto error;
}
if (H5Pclose(fapl_id) < 0)
TEST_ERROR;
if (H5Fclose(file_id) < 0)
TEST_ERROR;
PASSED();
return 0;
error:
H5E_BEGIN_TRY
{
H5Pclose(fapl_id);
H5Fclose(file_id);
}
H5E_END_TRY;
return 1;
}
/*
* A test to ensure that a file can be opened in parallel.
*/
static int
test_open_file(void)
{
hid_t file_id = H5I_INVALID_HID;
hid_t fapl_id = H5I_INVALID_HID;
TESTING_MULTIPART("H5Fopen");
/* Make sure the connector supports the API functions being tested */
if (!(vol_cap_flags_g & H5VL_CAP_FLAG_FILE_BASIC)) {
SKIPPED();
HDprintf(" API functions for basic file aren't supported with this connector\n");
return 0;
}
TESTING_2("test setup");
if ((fapl_id = create_mpi_fapl(MPI_COMM_WORLD, MPI_INFO_NULL, TRUE)) < 0)
TEST_ERROR;
PASSED();
BEGIN_MULTIPART
{
PART_BEGIN(H5Fopen_rdonly)
{
TESTING_2("H5Fopen in read-only mode");
if ((file_id = H5Fopen(vol_test_parallel_filename, H5F_ACC_RDONLY, fapl_id)) < 0) {
H5_FAILED();
HDprintf(" unable to open file '%s' in read-only mode\n", vol_test_parallel_filename);
PART_ERROR(H5Fopen_rdonly);
}
PASSED();
}
PART_END(H5Fopen_rdonly);
if (file_id >= 0) {
H5E_BEGIN_TRY
{
H5Fclose(file_id);
}
H5E_END_TRY;
file_id = H5I_INVALID_HID;
}
PART_BEGIN(H5Fopen_rdwrite)
{
TESTING_2("H5Fopen in read-write mode");
if ((file_id = H5Fopen(vol_test_parallel_filename, H5F_ACC_RDWR, fapl_id)) < 0) {
H5_FAILED();
HDprintf(" unable to open file '%s' in read-write mode\n", vol_test_parallel_filename);
PART_ERROR(H5Fopen_rdwrite);
}
PASSED();
}
PART_END(H5Fopen_rdwrite);
if (file_id >= 0) {
H5E_BEGIN_TRY
{
H5Fclose(file_id);
}
H5E_END_TRY;
file_id = H5I_INVALID_HID;
}
/*
* XXX: SWMR open flags
*/
}
END_MULTIPART;
TESTING_2("test cleanup");
if (H5Pclose(fapl_id) < 0)
TEST_ERROR;
PASSED();
return 0;
error:
H5E_BEGIN_TRY
{
H5Pclose(fapl_id);
H5Fclose(file_id);
}
H5E_END_TRY;
return 1;
}
/*
* Tests file access by a communicator other than MPI_COMM_WORLD.
*
* Splits MPI_COMM_WORLD into two groups, where one (even_comm) contains
* the original processes of even ranks. The other (odd_comm) contains
* the original processes of odd ranks. Processes in even_comm create a
* file, then close it, using even_comm. Processes in old_comm just do
* a barrier using odd_comm. Then they all do a barrier using MPI_COMM_WORLD.
* If the file creation and close does not do correct collective action
* according to the communicator argument, the processes will freeze up
* sooner or later due to MPI_Barrier calls being mixed up.
*/
#define SPLIT_FILE_COMM_TEST_FILE_NAME "split_comm_file.h5"
static int
test_split_comm_file_access(void)
{
MPI_Comm comm;
MPI_Info info = MPI_INFO_NULL;
hid_t file_id = H5I_INVALID_HID;
hid_t fapl_id = H5I_INVALID_HID;
int is_old;
int newrank;
int err_occurred = 0;
TESTING("file access with a split communicator");
/* Make sure the connector supports the API functions being tested */
if (!(vol_cap_flags_g & H5VL_CAP_FLAG_FILE_BASIC)) {
SKIPPED();
HDprintf(" API functions for basic file aren't supported with this connector\n");
return 0;
}
/* set up MPI parameters */
MPI_Comm_rank(MPI_COMM_WORLD, &mpi_rank);
is_old = mpi_rank % 2;
if (MPI_SUCCESS != MPI_Comm_split(MPI_COMM_WORLD, is_old, mpi_rank, &comm)) {
H5_FAILED();
HDprintf(" failed to split communicator!\n");
goto error;
}
MPI_Comm_rank(comm, &newrank);
if (is_old) {
/* odd-rank processes */
if (MPI_SUCCESS != MPI_Barrier(comm)) {
err_occurred = 1;
goto access_end;
}
}
else {
/* even-rank processes */
int sub_mpi_rank; /* rank in the sub-comm */
MPI_Comm_rank(comm, &sub_mpi_rank);
/* setup file access template */
if ((fapl_id = create_mpi_fapl(comm, info, TRUE)) < 0) {
err_occurred = 1;
goto access_end;
}
/* create the file collectively */
if ((file_id = H5Fcreate(SPLIT_FILE_COMM_TEST_FILE_NAME, H5F_ACC_TRUNC, H5P_DEFAULT, fapl_id)) < 0) {
H5_FAILED();
HDprintf(" couldn't create file '%s'\n", SPLIT_FILE_COMM_TEST_FILE_NAME);
err_occurred = 1;
goto access_end;
}
/* close the file */
if (H5Fclose(file_id) < 0) {
H5_FAILED();
HDprintf(" failed to close file '%s'\n", SPLIT_FILE_COMM_TEST_FILE_NAME);
err_occurred = 1;
goto access_end;
}
/* delete the test file */
if (H5Fdelete(SPLIT_FILE_COMM_TEST_FILE_NAME, fapl_id) < 0) {
H5_FAILED();
HDprintf(" failed to delete file '%s'\n", SPLIT_FILE_COMM_TEST_FILE_NAME);
err_occurred = 1;
goto access_end;
}
/* Release file-access template */
if (H5Pclose(fapl_id) < 0) {
err_occurred = 1;
goto access_end;
}
}
access_end:
/* Get the collective results about whether an error occurred */
if (MPI_SUCCESS != MPI_Allreduce(MPI_IN_PLACE, &err_occurred, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD)) {
H5_FAILED();
HDprintf(" MPI_Allreduce failed\n");
goto error;
}
if (err_occurred) {
H5_FAILED();
HDprintf(" an error occurred on only some ranks during split-communicator file access! - "
"collectively failing\n");
goto error;
}
if (MPI_SUCCESS != MPI_Comm_free(&comm)) {
H5_FAILED();
HDprintf(" MPI_Comm_free failed\n");
goto error;
}
if (MPI_SUCCESS != MPI_Barrier(MPI_COMM_WORLD)) {
H5_FAILED();
HDprintf(" MPI_Barrier on MPI_COMM_WORLD failed\n");
goto error;
}
PASSED();
return 0;
error:
H5E_BEGIN_TRY
{
H5Pclose(fapl_id);
H5Fclose(file_id);
}
H5E_END_TRY;
return 1;
}
/*
* Cleanup temporary test files
*/
static void
cleanup_files(void)
{
hid_t fapl_id = H5I_INVALID_HID;
if ((fapl_id = create_mpi_fapl(MPI_COMM_WORLD, MPI_INFO_NULL, TRUE)) < 0) {
if (MAINPROCESS)
HDprintf(" failed to create FAPL for deleting test files\n");
return;
}
H5Fdelete(FILE_CREATE_TEST_FILENAME, fapl_id);
/* The below file is deleted as part of the test */
/* H5Fdelete(SPLIT_FILE_COMM_TEST_FILE_NAME, H5P_DEFAULT); */
if (H5Pclose(fapl_id) < 0) {
if (MAINPROCESS)
HDprintf(" failed to close FAPL used for deleting test files\n");
return;
}
}
int
vol_file_test_parallel(void)
{
size_t i;
int nerrors;
if (MAINPROCESS) {
HDprintf("**********************************************\n");
HDprintf("* *\n");
HDprintf("* VOL Parallel File Tests *\n");
HDprintf("* *\n");
HDprintf("**********************************************\n\n");
}
for (i = 0, nerrors = 0; i < ARRAY_LENGTH(par_file_tests); i++) {
nerrors += (*par_file_tests[i])() ? 1 : 0;
if (MPI_SUCCESS != MPI_Barrier(MPI_COMM_WORLD)) {
if (MAINPROCESS)
HDprintf(" MPI_Barrier() failed!\n");
}
}
if (MAINPROCESS) {
HDprintf("\n");
HDprintf("Cleaning up testing files\n");
}
cleanup_files();
return nerrors;
}