-
-
Notifications
You must be signed in to change notification settings - Fork 265
/
t_subfiling_vfd.c
3482 lines (2751 loc) · 125 KB
/
t_subfiling_vfd.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
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* 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 LICENSE file, which can be found at the root of the source code *
* distribution tree, or in https://www.hdfgroup.org/licenses. *
* If you do not have access to either file, you may request a copy from *
* [email protected]. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/*
* HDF5 Subfiling VFD tests
*
* NOTE: these tests currently assume that the default I/O concentrator
* selection strategy for the Subfiling VFD is to use 1 I/O
* concentrator per node. If that changes in the future, some of
* these tests will need updating.
*/
#include <mpi.h>
#include "testpar.h"
#include "H5srcdir.h"
#include "H5MMprivate.h"
#ifdef H5_HAVE_SUBFILING_VFD
/* Include testing framework functionality -- currently just for test alarm timer */
#include "testframe.h"
#include "H5FDsubfiling.h"
#include "H5FDioc.h"
/* The smallest Subfiling stripe size used for testing */
#define SUBFILING_MIN_STRIPE_SIZE 128
/* Temporary test directory */
#define SUBFILING_CONFIG_FILE_DIR "subfiling_config_file_dir"
#ifndef PATH_MAX
#define PATH_MAX 4096
#endif
#define DEFAULT_DEFLATE_LEVEL 4
#define ARRAY_SIZE(a) sizeof(a) / sizeof(a[0])
#define CHECK_PASSED() \
do { \
int err_result = (nerrors > curr_nerrors); \
\
mpi_code_g = MPI_Allreduce(MPI_IN_PLACE, &err_result, 1, MPI_INT, MPI_MAX, comm_g); \
VRFY((mpi_code_g == MPI_SUCCESS), "MPI_Allreduce succeeded"); \
\
if (MAINPROCESS) { \
if (err_result == 0) \
PASSED(); \
else \
H5_FAILED(); \
} \
} while (0)
static MPI_Comm comm_g = MPI_COMM_WORLD;
static MPI_Info info_g = MPI_INFO_NULL;
static int mpi_rank;
static int mpi_size;
static int mpi_code_g;
static int num_nodes_g;
static int num_iocs_g;
static MPI_Comm node_local_comm = MPI_COMM_WORLD;
static int node_local_rank;
static int node_local_size;
static MPI_Comm ioc_comm = MPI_COMM_WORLD;
static int ioc_comm_rank;
static int ioc_comm_size;
static long long stripe_size_g = -1;
static long ioc_per_node_g = -1;
static int ioc_thread_pool_size_g = -1;
static char *config_dir = NULL;
int nerrors = 0;
int curr_nerrors = 0;
bool enable_compression = false;
/* Function pointer typedef for test functions */
typedef void (*test_func)(void);
/* Utility functions */
static hid_t create_subfiling_ioc_fapl(MPI_Comm comm, MPI_Info info, bool custom_config,
H5FD_subfiling_params_t *custom_cfg, int32_t thread_pool_size);
static hid_t create_dcpl_id(int rank, const hsize_t dims[], hid_t dxpl_id);
/* Test functions */
static void test_create_and_close(void);
static void test_ioc_only_fail(void);
static void test_config_file(void);
static void test_stripe_sizes(void);
static void test_iovec_translation(void);
static void test_selection_strategies(void);
static void test_read_different_stripe_size(void);
static void test_subfiling_precreate_rank_0(void);
static void test_subfiling_write_many_read_one(void);
static void test_subfiling_write_many_read_few(void);
static void test_subfiling_vector_io_extension(void);
static void test_subfiling_h5fuse(void);
static test_func tests[] = {
test_create_and_close,
test_ioc_only_fail,
test_config_file,
test_stripe_sizes,
test_iovec_translation,
test_selection_strategies,
test_read_different_stripe_size,
test_subfiling_precreate_rank_0,
test_subfiling_write_many_read_one,
test_subfiling_write_many_read_few,
test_subfiling_vector_io_extension,
test_subfiling_h5fuse,
};
/* ---------------------------------------------------------------------------
* Function: create_subfiling_ioc_fapl
*
* Purpose: Create and populate a subfiling FAPL ID.
*
* Return: Success: HID of the top-level (subfiling) FAPL, a non-negative
* value.
* Failure: H5I_INVALID_HID, a negative value.
* ---------------------------------------------------------------------------
*/
static hid_t
create_subfiling_ioc_fapl(MPI_Comm comm, MPI_Info info, bool custom_config,
H5FD_subfiling_params_t *custom_cfg, int32_t thread_pool_size)
{
H5FD_subfiling_config_t subfiling_conf;
H5FD_ioc_config_t ioc_conf;
hid_t ret_value = H5I_INVALID_HID;
assert(!custom_config || custom_cfg);
if ((ret_value = H5Pcreate(H5P_FILE_ACCESS)) < 0)
TEST_ERROR;
if (H5Pset_mpi_params(ret_value, comm, info) < 0)
TEST_ERROR;
if (!custom_config) {
if (H5Pset_fapl_subfiling(ret_value, NULL) < 0)
TEST_ERROR;
}
else {
/* Get defaults for Subfiling configuration */
if (H5Pget_fapl_subfiling(ret_value, &subfiling_conf) < 0)
TEST_ERROR;
/* Set custom configuration */
subfiling_conf.shared_cfg = *custom_cfg;
if (subfiling_conf.require_ioc) {
/* Get IOC VFD defaults */
if (H5Pget_fapl_ioc(ret_value, &ioc_conf) < 0)
TEST_ERROR;
/* Set custom configuration */
ioc_conf.thread_pool_size = thread_pool_size;
if (H5Pset_fapl_ioc(subfiling_conf.ioc_fapl_id, &ioc_conf) < 0)
TEST_ERROR;
}
else {
if (H5Pset_fapl_sec2(subfiling_conf.ioc_fapl_id) < 0)
TEST_ERROR;
}
if (H5Pset_fapl_subfiling(ret_value, &subfiling_conf) < 0)
TEST_ERROR;
}
return ret_value;
error:
if ((H5I_INVALID_HID != ret_value) && (H5Pclose(ret_value) < 0)) {
H5_FAILED();
AT();
}
return H5I_INVALID_HID;
}
/* ---------------------------------------------------------------------------
* Function: create_dcpl_id
*
* Purpose: Creates dataset creation property list identifier with
* chunking and compression, and enforces the
* required collective IO.
*
* Return: Success: HID Dataset creation property list identifier,
* a non-negative value.
* Failure: H5I_INVALID_HID, a negative value.
* ---------------------------------------------------------------------------
*/
static hid_t
create_dcpl_id(int rank, const hsize_t dset_dims[], hid_t dxpl_id)
{
hsize_t chunk_dims[1];
hid_t ret_value = H5I_INVALID_HID;
if ((ret_value = H5Pcreate(H5P_DATASET_CREATE)) < 0)
TEST_ERROR;
if (enable_compression) {
if (H5Pset_dxpl_mpio(dxpl_id, H5FD_MPIO_COLLECTIVE) < 0)
TEST_ERROR;
chunk_dims[0] = dset_dims[0] / 2;
if (H5Pset_chunk(ret_value, rank, chunk_dims) < 0)
TEST_ERROR;
if (H5Pset_deflate(ret_value, DEFAULT_DEFLATE_LEVEL) < 0)
TEST_ERROR;
}
return ret_value;
error:
if ((H5I_INVALID_HID != ret_value) && (H5Pclose(ret_value) < 0)) {
H5_FAILED();
AT();
}
return H5I_INVALID_HID;
}
/*
* A simple test that creates and closes a file with the
* subfiling VFD
*/
#define SUBF_FILENAME "test_subfiling_basic_create.h5"
static void
test_create_and_close(void)
{
hid_t file_id = H5I_INVALID_HID;
hid_t fapl_id = H5I_INVALID_HID;
curr_nerrors = nerrors;
if (MAINPROCESS)
TESTING_2("file creation and immediate close");
/* Get a default Subfiling FAPL */
fapl_id = create_subfiling_ioc_fapl(comm_g, info_g, false, NULL, 0);
VRFY((fapl_id >= 0), "FAPL creation succeeded");
file_id = H5Fcreate(SUBF_FILENAME, H5F_ACC_TRUNC, H5P_DEFAULT, fapl_id);
VRFY((file_id >= 0), "H5Fcreate succeeded");
VRFY((H5Fclose(file_id) >= 0), "File close succeeded");
H5E_BEGIN_TRY
{
H5Fdelete(SUBF_FILENAME, fapl_id);
}
H5E_END_TRY
VRFY((H5Pclose(fapl_id) >= 0), "FAPL close succeeded");
CHECK_PASSED();
}
#undef SUBF_FILENAME
/*
* A simple test that ensures file creation fails when
* attempting to use the IOC VFD by itself, without it
* being stacked under the Subfiling VFD. This is
* currently unsupported.
*/
#define SUBF_FILENAME "test_subfiling_only_ioc_fail.h5"
static void
test_ioc_only_fail(void)
{
hid_t file_id = H5I_INVALID_HID;
hid_t fapl_id = H5I_INVALID_HID;
curr_nerrors = nerrors;
if (MAINPROCESS)
TESTING_2("invalid use of IOC VFD by itself");
/* Setup a FAPL using only the IOC VFD */
fapl_id = H5Pcreate(H5P_FILE_ACCESS);
VRFY((fapl_id >= 0), "H5Pcreate succeeded");
VRFY((H5Pset_mpi_params(fapl_id, comm_g, info_g) >= 0), "H5Pset_mpi_params succeeded");
VRFY((H5Pset_fapl_ioc(fapl_id, NULL) >= 0), "H5Pset_fapl_ioc succeeded");
H5E_BEGIN_TRY
{
file_id = H5Fcreate(SUBF_FILENAME, H5F_ACC_TRUNC, H5P_DEFAULT, fapl_id);
}
H5E_END_TRY
VRFY((file_id < 0), "H5Fcreate failed successfully");
VRFY((H5Pclose(fapl_id) >= 0), "FAPL close succeeded");
CHECK_PASSED();
}
#undef SUBF_FILENAME
/*
* Test to check that Subfiling configuration file matches
* what is expected for a given configuration
*/
#define SUBF_FILENAME "test_subfiling_config_file.h5"
static void
test_config_file(void)
{
H5FD_subfiling_params_t cfg;
int64_t stripe_size;
int64_t read_stripe_size;
FILE *config_file;
char *config_filename = NULL;
char *config_buf = NULL;
HDoff_t config_file_len;
hid_t file_id = H5I_INVALID_HID;
hid_t fapl_id = H5I_INVALID_HID;
int read_stripe_count;
int read_aggr_count;
curr_nerrors = nerrors;
if (MAINPROCESS)
TESTING_2("subfiling configuration file format");
/*
* Choose a random Subfiling stripe size between
* the smallest allowed value and 32MiB
*/
if (mpi_rank == 0) {
stripe_size = (rand() % (H5FD_SUBFILING_DEFAULT_STRIPE_SIZE - SUBFILING_MIN_STRIPE_SIZE + 1)) +
SUBFILING_MIN_STRIPE_SIZE;
}
if (mpi_size > 1) {
mpi_code_g = MPI_Bcast(&stripe_size, 1, MPI_INT64_T, 0, comm_g);
VRFY((mpi_code_g == MPI_SUCCESS), "MPI_Bcast succeeded");
}
cfg.ioc_selection = SELECT_IOC_ONE_PER_NODE;
cfg.stripe_size = (stripe_size_g > 0) ? stripe_size_g : stripe_size;
cfg.stripe_count = num_iocs_g > 1 ? (num_iocs_g / 2) : 1;
fapl_id = create_subfiling_ioc_fapl(comm_g, info_g, true, &cfg, H5FD_IOC_DEFAULT_THREAD_POOL_SIZE);
VRFY((fapl_id >= 0), "FAPL creation succeeded");
file_id = H5Fcreate(SUBF_FILENAME, H5F_ACC_TRUNC, H5P_DEFAULT, fapl_id);
VRFY((file_id >= 0), "H5Fcreate succeeded");
VRFY((H5Fclose(file_id) >= 0), "File close succeeded");
if (MAINPROCESS) {
h5_stat_t file_info;
char *resolved_path;
char *subfile_dir;
char *subfile_name;
char *tmp_buf;
char *substr;
char scan_format[256];
int num_digits;
memset(&file_info, 0, sizeof(h5_stat_t));
VRFY((HDstat(SUBF_FILENAME, &file_info) >= 0), "HDstat succeeded");
config_filename = malloc(PATH_MAX);
VRFY(config_filename, "malloc succeeded");
snprintf(config_filename, PATH_MAX, "%s/" H5FD_SUBFILING_CONFIG_FILENAME_TEMPLATE, config_dir,
SUBF_FILENAME, (uint64_t)file_info.st_ino);
config_file = fopen(config_filename, "r");
VRFY(config_file, "fopen succeeded");
free(config_filename);
VRFY((HDfseek(config_file, 0, SEEK_END) >= 0), "HDfseek succeeded");
config_file_len = HDftell(config_file);
VRFY((config_file_len > 0), "HDftell succeeded");
VRFY((HDfseek(config_file, 0, SEEK_SET) >= 0), "HDfseek succeeded");
config_buf = malloc((size_t)config_file_len + 1);
VRFY(config_buf, "malloc succeeded");
VRFY((fread(config_buf, (size_t)config_file_len, 1, config_file) == 1), "fread succeeded");
config_buf[config_file_len] = '\0';
/* Check the stripe_size field in the configuration file */
substr = strstr(config_buf, "stripe_size");
VRFY(substr, "strstr succeeded");
VRFY((sscanf(substr, "stripe_size=%" PRId64, &read_stripe_size) == 1), "sscanf succeeded");
VRFY((read_stripe_size == cfg.stripe_size), "Stripe size comparison succeeded");
/* Check the aggregator_count field in the configuration file */
substr = strstr(config_buf, "aggregator_count");
VRFY(substr, "strstr succeeded");
VRFY((sscanf(substr, "aggregator_count=%d", &read_aggr_count) == 1), "sscanf succeeded");
if (cfg.stripe_count < num_iocs_g)
VRFY((read_aggr_count == cfg.stripe_count), "Aggregator count comparison succeeded");
else
VRFY((read_aggr_count == num_iocs_g), "Aggregator count comparison succeeded");
/* Check the subfile_count field in the configuration file */
substr = strstr(config_buf, "subfile_count");
VRFY(substr, "strstr succeeded");
VRFY((sscanf(substr, "subfile_count=%d", &read_stripe_count) == 1), "sscanf succeeded");
VRFY((read_stripe_count == cfg.stripe_count), "Stripe count comparison succeeded");
/* Check the hdf5_file and subfile_dir fields in the configuration file */
resolved_path = HDrealpath(SUBF_FILENAME, NULL);
VRFY(resolved_path, "HDrealpath succeeded");
VRFY((H5_dirname(resolved_path, &subfile_dir) >= 0), "H5_dirname succeeded");
tmp_buf = malloc(PATH_MAX);
VRFY(tmp_buf, "malloc succeeded");
substr = strstr(config_buf, "hdf5_file");
VRFY(substr, "strstr succeeded");
H5_GCC_CLANG_DIAG_OFF("format-nonliteral")
snprintf(scan_format, sizeof(scan_format), "hdf5_file=%%%zus", (size_t)(PATH_MAX - 1));
VRFY((sscanf(substr, scan_format, tmp_buf) == 1), "sscanf succeeded");
H5_GCC_CLANG_DIAG_ON("format-nonliteral")
VRFY((strcmp(tmp_buf, resolved_path) == 0), "strcmp succeeded");
substr = strstr(config_buf, "subfile_dir");
VRFY(substr, "strstr succeeded");
H5_GCC_CLANG_DIAG_OFF("format-nonliteral")
snprintf(scan_format, sizeof(scan_format), "subfile_dir=%%%zus", (size_t)(PATH_MAX - 1));
VRFY((sscanf(substr, scan_format, tmp_buf) == 1), "sscanf succeeded");
H5_GCC_CLANG_DIAG_ON("format-nonliteral")
VRFY((strcmp(tmp_buf, subfile_dir) == 0), "strcmp succeeded");
free(tmp_buf);
H5MM_free(subfile_dir);
free(resolved_path);
subfile_name = malloc(PATH_MAX);
VRFY(subfile_name, "malloc succeeded");
/* Verify the name of each subfile is in the configuration file */
num_digits = (int)(log10(cfg.stripe_count) + 1);
for (size_t i = 0; i < (size_t)cfg.stripe_count; i++) {
snprintf(subfile_name, PATH_MAX, H5FD_SUBFILING_FILENAME_TEMPLATE, SUBF_FILENAME,
(uint64_t)file_info.st_ino, num_digits, (int)i + 1, cfg.stripe_count);
substr = strstr(config_buf, subfile_name);
VRFY(substr, "strstr succeeded");
}
/* Verify that there aren't too many subfiles */
snprintf(subfile_name, PATH_MAX, H5FD_SUBFILING_FILENAME_TEMPLATE, SUBF_FILENAME,
(uint64_t)file_info.st_ino, num_digits, (int)cfg.stripe_count + 1, cfg.stripe_count);
substr = strstr(config_buf, subfile_name);
VRFY(substr == NULL, "strstr correctly failed");
free(subfile_name);
free(config_buf);
VRFY((fclose(config_file) >= 0), "fclose on configuration file succeeded");
}
mpi_code_g = MPI_Barrier(comm_g);
VRFY((mpi_code_g == MPI_SUCCESS), "MPI_Barrier succeeded");
H5E_BEGIN_TRY
{
H5Fdelete(SUBF_FILENAME, fapl_id);
}
H5E_END_TRY
VRFY((H5Pclose(fapl_id) >= 0), "FAPL close succeeded");
CHECK_PASSED();
}
#undef SUBF_FILENAME
/*
* Test a few different Subfiling stripe sizes with a fixed
* stripe count
*/
/* TODO: Test collective I/O as well when support is implemented */
#define SUBF_FILENAME "test_subfiling_stripe_sizes.h5"
#define SUBF_NITER 10
static void
test_stripe_sizes(void)
{
H5FD_t *file_ptr = NULL;
void *write_buf = NULL;
char *tmp_filename = NULL;
hid_t dxpl_id = H5I_INVALID_HID;
int num_subfiles;
int num_digits;
hid_t fapl_id = H5I_INVALID_HID;
curr_nerrors = nerrors;
if (MAINPROCESS)
TESTING_2("random subfiling stripe sizes");
tmp_filename = malloc(PATH_MAX);
VRFY(tmp_filename, "malloc succeeded");
dxpl_id = H5Pcreate(H5P_DATASET_XFER);
VRFY((dxpl_id >= 0), "DXPL creation succeeded");
/* Set selection I/O mode on DXPL */
VRFY((H5Pset_selection_io(dxpl_id, H5D_SELECTION_IO_MODE_ON) >= 0), "H5Pset_selection_io succeeded");
for (size_t i = 0; i < SUBF_NITER; i++) {
H5FD_subfiling_params_t cfg;
h5_stat_size_t file_size;
const void *c_write_buf;
h5_stat_t file_info;
int64_t file_size64;
int64_t stripe_size;
haddr_t file_end_addr;
haddr_t write_addr;
size_t nbytes;
herr_t write_status;
hid_t file_id;
/*
* Choose a random Subfiling stripe size between
* the smallest allowed value and the default value
*/
if (mpi_rank == 0) {
stripe_size = (rand() % (H5FD_SUBFILING_DEFAULT_STRIPE_SIZE - SUBFILING_MIN_STRIPE_SIZE + 1)) +
SUBFILING_MIN_STRIPE_SIZE;
}
if (mpi_size > 1) {
mpi_code_g = MPI_Bcast(&stripe_size, 1, MPI_INT64_T, 0, comm_g);
VRFY((mpi_code_g == MPI_SUCCESS), "MPI_Bcast succeeded");
}
cfg.ioc_selection = SELECT_IOC_ONE_PER_NODE;
cfg.stripe_size = (stripe_size_g > 0) ? stripe_size_g : stripe_size;
cfg.stripe_count = 1;
/* First, try I/O with a single rank */
if (MAINPROCESS) {
FILE *subfile_ptr;
num_subfiles = 1;
num_digits = (int)(log10(num_subfiles) + 1);
nbytes = (size_t)(cfg.stripe_size * num_subfiles);
write_buf = malloc(nbytes);
VRFY(write_buf, "malloc succeeded");
memset(write_buf, 255, nbytes);
c_write_buf = write_buf;
fapl_id = create_subfiling_ioc_fapl(MPI_COMM_SELF, MPI_INFO_NULL, true, &cfg,
H5FD_IOC_DEFAULT_THREAD_POOL_SIZE);
VRFY((fapl_id >= 0), "FAPL creation succeeded");
/* Create and close file with H5Fcreate to setup superblock */
file_id = H5Fcreate(SUBF_FILENAME, H5F_ACC_TRUNC, H5P_DEFAULT, fapl_id);
VRFY((file_id >= 0), "H5Fcreate succeeded");
VRFY((H5Fclose(file_id) >= 0), "H5Fclose succeeded");
/* Re-open file through H5FDopen for direct writes */
file_ptr = H5FDopen(SUBF_FILENAME, H5F_ACC_RDWR, fapl_id, HADDR_UNDEF);
VRFY(file_ptr, "H5FDopen succeeded");
/*
* Get the current file size to see where we can safely
* write to in the file without overwriting the superblock
*/
memset(&file_info, 0, sizeof(h5_stat_t));
VRFY((HDstat(SUBF_FILENAME, &file_info) >= 0), "HDstat succeeded");
file_size = (h5_stat_size_t)file_info.st_size;
H5_CHECK_OVERFLOW(file_size, h5_stat_size_t, haddr_t);
file_end_addr = (haddr_t)file_size;
/* Set independent I/O on DXPL */
VRFY((H5Pset_dxpl_mpio(dxpl_id, H5FD_MPIO_INDEPENDENT) >= 0), "H5Pset_dxpl_mpio succeeded");
/* Set EOA for following write call */
VRFY((H5FDset_eoa(file_ptr, H5FD_MEM_DEFAULT, file_end_addr + nbytes) >= 0),
"H5FDset_eoa succeeded");
/*
* Write "number of IOCs" X "stripe size" bytes to the file
* and ensure that we have "number of IOCs" subfiles, each
* with a size of at least "stripe size" bytes. The first
* (few) subfile(s) may be a bit larger due to file metadata.
*/
write_addr = file_end_addr;
write_status = H5FDwrite(file_ptr, H5FD_MEM_DRAW, dxpl_id, write_addr, nbytes, c_write_buf);
VRFY((write_status >= 0), "H5FDwrite succeeded");
file_end_addr += nbytes;
VRFY((H5FDtruncate(file_ptr, dxpl_id, 0) >= 0), "H5FDtruncate succeeded");
for (int j = 0; j < num_subfiles; j++) {
h5_stat_size_t subfile_size;
h5_stat_t subfile_info;
snprintf(tmp_filename, PATH_MAX, H5FD_SUBFILING_FILENAME_TEMPLATE, SUBF_FILENAME,
(uint64_t)file_info.st_ino, num_digits, j + 1, num_subfiles);
/* Ensure file exists */
subfile_ptr = fopen(tmp_filename, "r");
VRFY(subfile_ptr, "fopen on subfile succeeded");
VRFY((fclose(subfile_ptr) >= 0), "fclose on subfile succeeded");
/* Check file size */
memset(&subfile_info, 0, sizeof(h5_stat_t));
VRFY((HDstat(tmp_filename, &subfile_info) >= 0), "HDstat succeeded");
subfile_size = (h5_stat_size_t)subfile_info.st_size;
VRFY((subfile_size >= cfg.stripe_size), "File size verification succeeded");
}
/* Verify that there aren't too many subfiles */
snprintf(tmp_filename, PATH_MAX, H5FD_SUBFILING_FILENAME_TEMPLATE, SUBF_FILENAME,
(uint64_t)file_info.st_ino, num_digits, num_subfiles + 1, num_subfiles);
/* Ensure file doesn't exist */
subfile_ptr = fopen(tmp_filename, "r");
VRFY(subfile_ptr == NULL, "fopen on subfile correctly failed");
/* Set EOA for following write call */
VRFY((H5FDset_eoa(file_ptr, H5FD_MEM_DEFAULT, file_end_addr + nbytes) >= 0),
"H5FDset_eoa succeeded");
/*
* Write another round of "number of IOCs" X "stripe size"
* bytes to the file using vector I/O and ensure we have
* "number of IOCs" subfiles, each with a size of at least
* 2 * "stripe size" bytes. The first (few) subfile(s) may
* be a bit larger due to file metadata.
*/
H5FD_mem_t write_type = H5FD_MEM_DRAW;
write_addr = file_end_addr;
write_status =
H5FDwrite_vector(file_ptr, dxpl_id, 1, &write_type, &write_addr, &nbytes, &c_write_buf);
VRFY((write_status >= 0), "H5FDwrite_vector succeeded");
VRFY((H5FDtruncate(file_ptr, dxpl_id, 0) >= 0), "H5FDtruncate succeeded");
for (int j = 0; j < num_subfiles; j++) {
h5_stat_size_t subfile_size;
h5_stat_t subfile_info;
snprintf(tmp_filename, PATH_MAX, H5FD_SUBFILING_FILENAME_TEMPLATE, SUBF_FILENAME,
(uint64_t)file_info.st_ino, num_digits, j + 1, num_subfiles);
/* Ensure file exists */
subfile_ptr = fopen(tmp_filename, "r");
VRFY(subfile_ptr, "fopen on subfile succeeded");
VRFY((fclose(subfile_ptr) >= 0), "fclose on subfile succeeded");
/* Check file size */
memset(&subfile_info, 0, sizeof(h5_stat_t));
VRFY((HDstat(tmp_filename, &subfile_info) >= 0), "HDstat succeeded");
subfile_size = (h5_stat_size_t)subfile_info.st_size;
VRFY((subfile_size >= 2 * cfg.stripe_size), "File size verification succeeded");
}
/* Verify that there aren't too many subfiles */
snprintf(tmp_filename, PATH_MAX, H5FD_SUBFILING_FILENAME_TEMPLATE, SUBF_FILENAME,
(uint64_t)file_info.st_ino, num_digits, num_subfiles + 1, num_subfiles);
/* Ensure file doesn't exist */
subfile_ptr = fopen(tmp_filename, "r");
VRFY(subfile_ptr == NULL, "fopen on subfile correctly failed");
free(write_buf);
write_buf = NULL;
VRFY((H5FDclose(file_ptr) >= 0), "H5FDclose succeeded");
H5E_BEGIN_TRY
{
H5Fdelete(SUBF_FILENAME, fapl_id);
}
H5E_END_TRY
VRFY((H5Pclose(fapl_id) >= 0), "FAPL close succeeded");
}
mpi_code_g = MPI_Barrier(comm_g);
VRFY((mpi_code_g == MPI_SUCCESS), "MPI_Barrier succeeded");
/* Next, try I/O with all ranks */
cfg.stripe_count = num_iocs_g;
fapl_id = create_subfiling_ioc_fapl(comm_g, info_g, true, &cfg, H5FD_IOC_DEFAULT_THREAD_POOL_SIZE);
VRFY((fapl_id >= 0), "FAPL creation succeeded");
/* Create and close file with H5Fcreate to setup superblock */
file_id = H5Fcreate(SUBF_FILENAME, H5F_ACC_TRUNC, H5P_DEFAULT, fapl_id);
VRFY((file_id >= 0), "H5Fcreate succeeded");
VRFY((H5Fclose(file_id) >= 0), "H5Fclose succeeded");
/* Re-open file through H5FDopen for direct writes */
file_ptr = H5FDopen(SUBF_FILENAME, H5F_ACC_RDWR, fapl_id, HADDR_UNDEF);
VRFY(file_ptr, "H5FDopen succeeded");
num_subfiles = num_iocs_g;
num_digits = (int)(log10(num_subfiles) + 1);
nbytes = (size_t)(cfg.stripe_size * num_subfiles);
write_buf = malloc(nbytes);
VRFY(write_buf, "malloc succeeded");
memset(write_buf, 255, nbytes);
c_write_buf = write_buf;
/*
* Get the current file size to see where we can safely
* write to in the file without overwriting the superblock
*/
if (MAINPROCESS) {
memset(&file_info, 0, sizeof(h5_stat_t));
VRFY((HDstat(SUBF_FILENAME, &file_info) >= 0), "HDstat succeeded");
file_size = (h5_stat_size_t)file_info.st_size;
H5_CHECK_OVERFLOW(file_size, h5_stat_size_t, int64_t);
file_size64 = (int64_t)file_size;
}
if (mpi_size > 1) {
mpi_code_g = MPI_Bcast(&file_size64, 1, MPI_INT64_T, 0, comm_g);
VRFY((mpi_code_g == MPI_SUCCESS), "MPI_Bcast succeeded");
}
H5_CHECK_OVERFLOW(file_size64, int64_t, haddr_t);
file_end_addr = (haddr_t)file_size64;
/* Set independent I/O on DXPL */
VRFY((H5Pset_dxpl_mpio(dxpl_id, H5FD_MPIO_INDEPENDENT) >= 0), "H5Pset_dxpl_mpio succeeded");
/* Set EOA for following write call */
VRFY((H5FDset_eoa(file_ptr, H5FD_MEM_DEFAULT, file_end_addr + ((size_t)mpi_size * nbytes)) >= 0),
"H5FDset_eoa succeeded");
/*
* Write "number of IOCs" X "stripe size" bytes to the file
* from each rank and ensure that we have "number of IOCs"
* subfiles, each with a size of at least "mpi size" * "stripe size"
* bytes. The first (few) subfile(s) may be a bit larger
* due to file metadata.
*/
write_addr = file_end_addr + ((size_t)mpi_rank * nbytes);
write_status = H5FDwrite(file_ptr, H5FD_MEM_DRAW, dxpl_id, write_addr, nbytes, c_write_buf);
VRFY((write_status >= 0), "H5FDwrite succeeded");
file_end_addr += ((size_t)mpi_size * nbytes);
VRFY((H5FDtruncate(file_ptr, dxpl_id, 0) >= 0), "H5FDtruncate succeeded");
mpi_code_g = MPI_Barrier(comm_g);
VRFY((mpi_code_g == MPI_SUCCESS), "MPI_Barrier succeeded");
if (MAINPROCESS) {
FILE *subfile_ptr;
for (int j = 0; j < num_subfiles; j++) {
h5_stat_size_t subfile_size;
h5_stat_t subfile_info;
snprintf(tmp_filename, PATH_MAX, H5FD_SUBFILING_FILENAME_TEMPLATE, SUBF_FILENAME,
(uint64_t)file_info.st_ino, num_digits, j + 1, num_subfiles);
/* Ensure file exists */
subfile_ptr = fopen(tmp_filename, "r");
VRFY(subfile_ptr, "fopen on subfile succeeded");
VRFY((fclose(subfile_ptr) >= 0), "fclose on subfile succeeded");
/* Check file size */
memset(&subfile_info, 0, sizeof(h5_stat_t));
VRFY((HDstat(tmp_filename, &subfile_info) >= 0), "HDstat succeeded");
subfile_size = (h5_stat_size_t)subfile_info.st_size;
VRFY((subfile_size >= (mpi_size * cfg.stripe_size)), "File size verification succeeded");
}
/* Verify that there aren't too many subfiles */
snprintf(tmp_filename, PATH_MAX, H5FD_SUBFILING_FILENAME_TEMPLATE, SUBF_FILENAME,
(uint64_t)file_info.st_ino, num_digits, num_subfiles + 1, num_subfiles);
/* Ensure file doesn't exist */
subfile_ptr = fopen(tmp_filename, "r");
VRFY(subfile_ptr == NULL, "fopen on subfile correctly failed");
}
mpi_code_g = MPI_Barrier(comm_g);
VRFY((mpi_code_g == MPI_SUCCESS), "MPI_Barrier succeeded");
/* Set EOA for following write call */
VRFY((H5FDset_eoa(file_ptr, H5FD_MEM_DEFAULT, file_end_addr + ((size_t)mpi_size * nbytes)) >= 0),
"H5FDset_eoa succeeded");
/*
* Write another round of "number of IOCs" X "stripe size"
* bytes to the file from each rank using vector I/O and
* ensure we have "number of IOCs" subfiles, each with a
* size of at least 2 * "mpi size" * "stripe size" bytes.
* The first (few) subfile(s) may be a bit larger due to
* file metadata.
*/
H5FD_mem_t write_type = H5FD_MEM_DRAW;
write_addr = file_end_addr + ((size_t)mpi_rank * nbytes);
write_status =
H5FDwrite_vector(file_ptr, dxpl_id, 1, &write_type, &write_addr, &nbytes, &c_write_buf);
VRFY((write_status >= 0), "H5FDwrite_vector succeeded");
VRFY((H5FDtruncate(file_ptr, dxpl_id, 0) >= 0), "H5FDtruncate succeeded");
mpi_code_g = MPI_Barrier(comm_g);
VRFY((mpi_code_g == MPI_SUCCESS), "MPI_Barrier succeeded");
if (MAINPROCESS) {
FILE *subfile_ptr;
for (int j = 0; j < num_subfiles; j++) {
h5_stat_size_t subfile_size;
h5_stat_t subfile_info;
snprintf(tmp_filename, PATH_MAX, H5FD_SUBFILING_FILENAME_TEMPLATE, SUBF_FILENAME,
(uint64_t)file_info.st_ino, num_digits, j + 1, num_subfiles);
/* Ensure file exists */
subfile_ptr = fopen(tmp_filename, "r");
VRFY(subfile_ptr, "fopen on subfile succeeded");
VRFY((fclose(subfile_ptr) >= 0), "fclose on subfile succeeded");
/* Check file size */
memset(&subfile_info, 0, sizeof(h5_stat_t));
VRFY((HDstat(tmp_filename, &subfile_info) >= 0), "HDstat succeeded");
subfile_size = (h5_stat_size_t)subfile_info.st_size;
VRFY((subfile_size >= (2 * mpi_size * cfg.stripe_size)), "File size verification succeeded");
}
/* Verify that there aren't too many subfiles */
snprintf(tmp_filename, PATH_MAX, H5FD_SUBFILING_FILENAME_TEMPLATE, SUBF_FILENAME,
(uint64_t)file_info.st_ino, num_digits, num_subfiles + 1, num_subfiles);
/* Ensure file doesn't exist */
subfile_ptr = fopen(tmp_filename, "r");
VRFY(subfile_ptr == NULL, "fopen on subfile correctly failed");
}
VRFY((H5FDclose(file_ptr) >= 0), "H5FDclose succeeded");
mpi_code_g = MPI_Barrier(comm_g);
VRFY((mpi_code_g == MPI_SUCCESS), "MPI_Barrier succeeded");
H5E_BEGIN_TRY
{
H5Fdelete(SUBF_FILENAME, fapl_id);
}
H5E_END_TRY
free(write_buf);
VRFY((H5Pclose(fapl_id) >= 0), "FAPL close succeeded");
}
free(tmp_filename);
VRFY((H5Pclose(dxpl_id) >= 0), "DXPL close succeeded");
CHECK_PASSED();
}
#undef SUBF_FILENAME
#undef SUBF_NITER
/*
* Test the I/O vector translation code by writing with some
* different specific I/O patterns
*/
#define SUBF_FILENAME "test_subfiling_iovec_translation.h5"
static void
test_iovec_translation(void)
{
H5FD_subfiling_params_t cfg;
const void *c_write_buf;
h5_stat_t file_info;
int64_t stripe_size;
haddr_t write_addr;
size_t nbytes;
size_t buf_size;
herr_t status;
hid_t file_id;
H5FD_t *file_ptr = NULL;
FILE *subfile_ptr = NULL;
void *write_buf = NULL;
void *read_buf = NULL;
char *tmp_filename = NULL;
hid_t dxpl_id = H5I_INVALID_HID;
hid_t fapl_id = H5I_INVALID_HID;
bool skip = false;
int num_subfiles;
int num_digits;
curr_nerrors = nerrors;
if (MAINPROCESS)
TESTING_2("I/O vector translation");
/*
* Don't run this test if subfiling configuration
* environment variables have been set since we
* want to use fixed configurations for testing.
*/
if (getenv(H5FD_SUBFILING_STRIPE_SIZE) || getenv(H5FD_SUBFILING_IOC_PER_NODE))
skip = true;
/* I/O only needs to be done from a single rank */
if (MAINPROCESS && !skip) {
/* Use a fixed configuration for these tests */
stripe_size = 1048576;
num_subfiles = 4;
num_digits = (int)(log10(num_subfiles) + 1);
/* Allocate enough buffer space for up to 2 "subfile blocks" of I/O */
buf_size = (size_t)(2 * stripe_size * num_subfiles);
write_buf = malloc(buf_size);
VRFY(write_buf, "malloc succeeded");
read_buf = malloc(buf_size);
VRFY(read_buf, "malloc succeeded");
c_write_buf = write_buf;
tmp_filename = malloc(PATH_MAX);
VRFY(tmp_filename, "malloc succeeded");
dxpl_id = H5Pcreate(H5P_DATASET_XFER);
VRFY((dxpl_id >= 0), "DXPL creation succeeded");
/* Set selection I/O mode on DXPL */
VRFY((H5Pset_selection_io(dxpl_id, H5D_SELECTION_IO_MODE_ON) >= 0), "H5Pset_selection_io succeeded");
cfg.ioc_selection = SELECT_IOC_ONE_PER_NODE;
cfg.stripe_size = stripe_size;
cfg.stripe_count = 4;
fapl_id = create_subfiling_ioc_fapl(MPI_COMM_SELF, MPI_INFO_NULL, true, &cfg,
H5FD_IOC_DEFAULT_THREAD_POOL_SIZE);
VRFY((fapl_id >= 0), "FAPL creation succeeded");
/* Set independent I/O on DXPL */
VRFY((H5Pset_dxpl_mpio(dxpl_id, H5FD_MPIO_INDEPENDENT) >= 0), "H5Pset_dxpl_mpio succeeded");
/*
* Test the case where the index value of the last subfile
* touched by I/O is greater than or equal to the index
* value of the first subfile touched by I/O, and this results
* in "thin" I/O segments directed to the subfiles with index
* values greater than the index values of the first and
* last subfiles. This might appear as the following I/O
* pattern:
*
* SUBFILE 0 SUBFILE 1 SUBFILE 2 SUBFILE 3
* _______________________________________________
* | XXXXX | XXXXX | XXXXX | XXXXX | ROW 0
* | XXXXX | XXXXX | | | ROW 1
* | | | | | ROW 2
* | | | | | ROW ...
* | | | | |
* | | | | |
* | | | | |
* |___________|___________|___________|___________|