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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* 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://www.hdfgroup.org/licenses. *
* If you do not have access to either file, you may request a copy from *
* help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/*
* 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 "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 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;
/* 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, hbool_t custom_config,
H5FD_subfiling_params_t *custom_cfg, int32_t thread_pool_size);
/* 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_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_h5fuse(void);
static test_func tests[] = {
test_create_and_close,
test_ioc_only_fail,
test_config_file,
test_stripe_sizes,
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_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, hbool_t 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;
}
/*
* 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;
long 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;
VRFY((HDstat(SUBF_FILENAME, &file_info) >= 0), "HDstat succeeded");
config_filename = malloc(PATH_MAX);
VRFY(config_filename, "malloc succeeded");
HDsnprintf(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 = HDstrstr(config_buf, "stripe_size");
VRFY(substr, "HDstrstr succeeded");
VRFY((HDsscanf(substr, "stripe_size=%" PRId64, &read_stripe_size) == 1), "HDsscanf succeeded");
VRFY((read_stripe_size == cfg.stripe_size), "Stripe size comparison succeeded");
/* Check the aggregator_count field in the configuration file */
substr = HDstrstr(config_buf, "aggregator_count");
VRFY(substr, "HDstrstr succeeded");
VRFY((HDsscanf(substr, "aggregator_count=%d", &read_aggr_count) == 1), "HDsscanf 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 = HDstrstr(config_buf, "subfile_count");
VRFY(substr, "HDstrstr succeeded");
VRFY((HDsscanf(substr, "subfile_count=%d", &read_stripe_count) == 1), "HDsscanf 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 = HDstrstr(config_buf, "hdf5_file");
VRFY(substr, "HDstrstr succeeded");
HDsnprintf(scan_format, sizeof(scan_format), "hdf5_file=%%%zus", (size_t)(PATH_MAX - 1));
VRFY((HDsscanf(substr, scan_format, tmp_buf) == 1), "HDsscanf succeeded");
VRFY((HDstrcmp(tmp_buf, resolved_path) == 0), "HDstrcmp succeeded");
substr = HDstrstr(config_buf, "subfile_dir");
VRFY(substr, "HDstrstr succeeded");
HDsnprintf(scan_format, sizeof(scan_format), "subfile_dir=%%%zus", (size_t)(PATH_MAX - 1));
VRFY((HDsscanf(substr, scan_format, tmp_buf) == 1), "HDsscanf succeeded");
VRFY((HDstrcmp(tmp_buf, subfile_dir) == 0), "HDstrcmp 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)(HDlog10(cfg.stripe_count) + 1);
for (size_t i = 0; i < (size_t)cfg.stripe_count; i++) {
HDsnprintf(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 = HDstrstr(config_buf, subfile_name);
VRFY(substr, "HDstrstr succeeded");
}
/* Verify that there aren't too many subfiles */
HDsnprintf(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 = HDstrstr(config_buf, subfile_name);
VRFY(substr == NULL, "HDstrstr 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)(HDlog10(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
*/
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;
HDsnprintf(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 */
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 */
HDsnprintf(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;
HDsnprintf(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 */
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 */
HDsnprintf(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)(HDlog10(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) {
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;
HDsnprintf(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 */
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 */
HDsnprintf(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;
HDsnprintf(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 */
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 */
HDsnprintf(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 different I/O Concentator selection strategies
* for the Subfiling VFD
*/
#define SUBF_FILENAME "test_subfiling_selection_strategies.h5"
#define NUM_RANKS_CHOICES 2
#define NUM_CRITERIA_FORMATS 2
static void
test_selection_strategies(void)
{
H5FD_subfiling_params_t cfg;
hid_t file_id = H5I_INVALID_HID;
hid_t fapl_id = H5I_INVALID_HID;
char *tmp_filename = NULL;
curr_nerrors = nerrors;
if (MAINPROCESS)
TESTING_2("I/O concentrator selection strategies");
tmp_filename = malloc(PATH_MAX);
VRFY(tmp_filename, "malloc succeeded");
for (H5FD_subfiling_ioc_select_t strategy = 0; strategy < ioc_selection_options; strategy++) {
/* Skip 1 IOC per node strategy since we assume it's
* the default strategy tested in this file. Skip
* "with config" strategy since it isn't supported.
*/
if (strategy == SELECT_IOC_ONE_PER_NODE || strategy == SELECT_IOC_WITH_CONFIG)
continue;
/* Test with 1 MPI rank and then all MPI ranks */
for (size_t num_ranks_choice = 0; num_ranks_choice < NUM_RANKS_CHOICES; num_ranks_choice++) {
int num_active_ranks = mpi_size;
if (num_ranks_choice == 0)
num_active_ranks = 1;
/* Test with a selection strategy criteria string
* in the 'integer:[integer|string]' form and in
* the form of just a single value.
*/
for (size_t criteria_format_choice = 0; criteria_format_choice < NUM_CRITERIA_FORMATS;
criteria_format_choice++) {
MPI_Comm file_comm = comm_g;
char criteria_buf[256];
char sel_criteria[128]; /* Use char buffer for criteria as we may support
the "with config" strategy in the future */
int expected_num_subfiles;
cfg.ioc_selection = strategy;
cfg.stripe_size = H5FD_SUBFILING_DEFAULT_STRIPE_SIZE;
cfg.stripe_count = H5FD_SUBFILING_DEFAULT_STRIPE_COUNT;
switch (strategy) {
case SELECT_IOC_EVERY_NTH_RANK: {
int stride;
/* Try to select a reasonable stride value */
if (num_active_ranks <= 2)
stride = 1;
else if (num_active_ranks <= 8)
stride = 2;
else if (num_active_ranks <= 32)
stride = 4;
else if (num_active_ranks <= 128)
stride = 8;
else
stride = 16;
HDsnprintf(sel_criteria, 128, "%d", stride);
expected_num_subfiles = ((num_active_ranks - 1) / stride) + 1;
break;
}
case SELECT_IOC_TOTAL: {
int n_iocs;
/* Try to select a reasonable number of IOCs */
if (num_active_ranks <= 2)
n_iocs = 1;
else if (num_active_ranks <= 8)
n_iocs = 2;
else if (num_active_ranks <= 32)
n_iocs = 4;
else if (num_active_ranks <= 128)
n_iocs = 8;
else
n_iocs = 16;
HDsnprintf(sel_criteria, 128, "%d", n_iocs);
expected_num_subfiles = n_iocs;
break;
}
case SELECT_IOC_ONE_PER_NODE:
case SELECT_IOC_WITH_CONFIG:
case ioc_selection_options:
default:
printf("invalid IOC selection strategy\n");
MPI_Abort(comm_g, -1);
}
if (criteria_format_choice == 0) {
HDsnprintf(criteria_buf, 256, "%d:%s", strategy, sel_criteria);
}
else if (criteria_format_choice == 1) {
HDsnprintf(criteria_buf, 256, "%s", sel_criteria);
}
VRFY(HDsetenv(H5FD_SUBFILING_IOC_SELECTION_CRITERIA, criteria_buf, 1) >= 0,
"HDsetenv succeeded");
assert(num_active_ranks == mpi_size || num_active_ranks == 1);
if ((num_active_ranks == mpi_size) || (mpi_rank == 0)) {
h5_stat_t file_info;
FILE *subfile_ptr;
int num_digits;
if (num_active_ranks < mpi_size)
file_comm = MPI_COMM_SELF;
fapl_id = create_subfiling_ioc_fapl(file_comm, 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");
/*
* Get the file inode value so we can construct the subfile names
*/
VRFY((HDstat(SUBF_FILENAME, &file_info) >= 0), "HDstat succeeded");
num_digits = (int)(HDlog10(expected_num_subfiles) + 1);
/* Ensure all the subfiles are present */
for (int i = 0; i < expected_num_subfiles; i++) {
HDsnprintf(tmp_filename, PATH_MAX, H5FD_SUBFILING_FILENAME_TEMPLATE, SUBF_FILENAME,
(uint64_t)file_info.st_ino, num_digits, i + 1, expected_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");
}
/* Ensure no extra subfiles are present */
HDsnprintf(tmp_filename, PATH_MAX, H5FD_SUBFILING_FILENAME_TEMPLATE, SUBF_FILENAME,
(uint64_t)file_info.st_ino, num_digits, expected_num_subfiles + 1,
expected_num_subfiles);
/* Ensure file doesn't exist */
subfile_ptr = fopen(tmp_filename, "r");
VRFY(subfile_ptr == NULL, "fopen on subfile correctly failed");
VRFY((H5Fclose(file_id) >= 0), "File close succeeded");
mpi_code_g = MPI_Barrier(file_comm);
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");
VRFY(HDunsetenv(H5FD_SUBFILING_IOC_SELECTION_CRITERIA) >= 0, "HDunsetenv succeeded");
}
mpi_code_g = MPI_Barrier(comm_g);
VRFY((mpi_code_g == MPI_SUCCESS), "MPI_Barrier succeeded");
}
}
}
mpi_code_g = MPI_Barrier(comm_g);
VRFY((mpi_code_g == MPI_SUCCESS), "MPI_Barrier succeeded");
free(tmp_filename);
CHECK_PASSED();
}
#undef SUBF_FILENAME
#undef NUM_RANKS_CHOICES
#undef NUM_CRITERIA_FORMATS
/*
* Test that opening a file with a different stripe
* size/count than was used when creating the file
* results in the original stripe size/count being
* used. As there is currently no API to check the
* exact values used, we rely on the assumption that
* using a different stripe size/count would result
* in data verification failures.
*/
#define SUBF_FILENAME "test_subfiling_read_different_stripe_sizes.h5"
#define SUBF_HDF5_TYPE H5T_NATIVE_INT
#define SUBF_C_TYPE int
static void
test_read_different_stripe_size(void)
{
H5FD_subfiling_params_t cfg;
hsize_t start[1];
hsize_t count[1];
hsize_t dset_dims[1];
size_t target_size;
hid_t file_id = H5I_INVALID_HID;
hid_t fapl_id = H5I_INVALID_HID;
hid_t dset_id = H5I_INVALID_HID;
hid_t dxpl_id = H5I_INVALID_HID;
hid_t fspace_id = H5I_INVALID_HID;
char *tmp_filename = NULL;
void *buf = NULL;
curr_nerrors = nerrors;
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");
if (MAINPROCESS)
TESTING_2("file re-opening with different stripe size");
tmp_filename = malloc(PATH_MAX);
VRFY(tmp_filename, "malloc succeeded");
/* Use a 1MiB stripe size and a subfile for each IOC */
cfg.ioc_selection = SELECT_IOC_ONE_PER_NODE;
cfg.stripe_size = (stripe_size_g > 0) ? stripe_size_g : 1048576;
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");
file_id = H5Fcreate(SUBF_FILENAME, H5F_ACC_TRUNC, H5P_DEFAULT, fapl_id);
VRFY((file_id >= 0), "H5Fcreate succeeded");
VRFY((H5Pclose(fapl_id) >= 0), "FAPL close succeeded");
target_size = (size_t)cfg.stripe_size;
/* Nudge stripe size to be multiple of C type size */
if ((target_size % sizeof(SUBF_C_TYPE)) != 0)
target_size += sizeof(SUBF_C_TYPE) - (target_size % sizeof(SUBF_C_TYPE));
target_size *= (size_t)mpi_size;
VRFY(((target_size % sizeof(SUBF_C_TYPE)) == 0), "target size check succeeded");
dset_dims[0] = (hsize_t)(target_size / sizeof(SUBF_C_TYPE));
fspace_id = H5Screate_simple(1, dset_dims, NULL);
VRFY((fspace_id >= 0), "H5Screate_simple succeeded");
dset_id = H5Dcreate2(file_id, "DSET", SUBF_HDF5_TYPE, fspace_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
VRFY((dset_id >= 0), "Dataset creation succeeded");
/* Select hyperslab */
count[0] = dset_dims[0] / (hsize_t)mpi_size;
start[0] = (hsize_t)mpi_rank * count[0];
VRFY((H5Sselect_hyperslab(fspace_id, H5S_SELECT_SET, start, NULL, count, NULL) >= 0),
"H5Sselect_hyperslab succeeded");
buf = malloc(count[0] * sizeof(SUBF_C_TYPE));
VRFY(buf, "malloc succeeded");
for (size_t i = 0; i < count[0]; i++)
((SUBF_C_TYPE *)buf)[i] = (SUBF_C_TYPE)((size_t)mpi_rank + i);
VRFY((H5Dwrite(dset_id, SUBF_HDF5_TYPE, H5S_BLOCK, fspace_id, dxpl_id, buf) >= 0),
"Dataset write succeeded");
free(buf);
buf = NULL;
VRFY((H5Sclose(fspace_id) >= 0), "File dataspace close succeeded");
VRFY((H5Dclose(dset_id) >= 0), "Dataset close succeeded");
VRFY((H5Fclose(file_id) >= 0), "File close succeeded");
/* Ensure all the subfiles are present */
if (MAINPROCESS) {
h5_stat_t file_info;
FILE *subfile_ptr;
int num_subfiles = cfg.stripe_count;
int num_digits = (int)(HDlog10(num_subfiles) + 1);
VRFY((HDstat(SUBF_FILENAME, &file_info) >= 0), "HDstat succeeded");
for (int j = 0; j < num_subfiles; j++) {
h5_stat_size_t subfile_size;
h5_stat_t subfile_info;
HDsnprintf(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 */
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");
}
}
mpi_code_g = MPI_Barrier(comm_g);
VRFY((mpi_code_g == MPI_SUCCESS), "MPI_Barrier succeeded");
/* Add a bit to the stripe size and specify a few more subfiles */
cfg.stripe_size += (cfg.stripe_size / 2);
cfg.stripe_count *= 2;
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 = H5Fopen(SUBF_FILENAME, H5F_ACC_RDONLY, fapl_id);
VRFY((file_id >= 0), "H5Fopen succeeded");
dset_id = H5Dopen2(file_id, "DSET", H5P_DEFAULT);
VRFY((dset_id >= 0), "Dataset open succeeded");
fspace_id = H5Dget_space(dset_id);
VRFY((fspace_id >= 0), "Dataspace retrieval succeeded");
/* Select hyperslab */
count[0] = dset_dims[0] / (hsize_t)mpi_size;
start[0] = (hsize_t)mpi_rank * count[0];
VRFY((H5Sselect_hyperslab(fspace_id, H5S_SELECT_SET, start, NULL, count, NULL) >= 0),
"H5Sselect_hyperslab succeeded");
buf = calloc(1, count[0] * sizeof(SUBF_C_TYPE));
VRFY(buf, "calloc succeeded");
VRFY((H5Dread(dset_id, SUBF_HDF5_TYPE, H5S_BLOCK, fspace_id, dxpl_id, buf) >= 0),
"Dataset read succeeded");
for (size_t i = 0; i < count[0]; i++) {
SUBF_C_TYPE buf_value = ((SUBF_C_TYPE *)buf)[i];
VRFY((buf_value == (SUBF_C_TYPE)((size_t)mpi_rank + i)), "data verification succeeded");
}
free(buf);
buf = NULL;
VRFY((H5Sclose(fspace_id) >= 0), "File dataspace close succeeded");
VRFY((H5Dclose(dset_id) >= 0), "Dataset close succeeded");
VRFY((H5Fclose(file_id) >= 0), "File close succeeded");
/* Ensure only the original subfiles are present */
if (MAINPROCESS) {
h5_stat_t file_info;
FILE *subfile_ptr;
int num_subfiles = cfg.stripe_count;
int num_digits = (int)(HDlog10(num_subfiles / 2) + 1);
VRFY((HDstat(SUBF_FILENAME, &file_info) >= 0), "HDstat succeeded");
for (int j = 0; j < num_subfiles; j++) {
HDsnprintf(tmp_filename, PATH_MAX, H5FD_SUBFILING_FILENAME_TEMPLATE, SUBF_FILENAME,
(uint64_t)file_info.st_ino, num_digits, j + 1, num_subfiles / 2);
if (j < (num_subfiles / 2)) {
/* 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");
}
else {
/* 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");
H5E_BEGIN_TRY
{
H5Fdelete(SUBF_FILENAME, fapl_id);
}
H5E_END_TRY
VRFY((H5Pclose(dxpl_id) >= 0), "DXPL close succeeded");
VRFY((H5Pclose(fapl_id) >= 0), "FAPL close succeeded");
free(tmp_filename);
CHECK_PASSED();
}
#undef SUBF_FILENAME
#undef SUBF_HDF5_TYPE
#undef SUBF_C_TYPE
/*
* Test that everything works correctly when a file is
* pre-created on rank 0 with a specified target number
* of subfiles and then read back on all ranks.
*/
#define SUBF_FILENAME "test_subfiling_precreate_rank_0.h5"
#define SUBF_HDF5_TYPE H5T_NATIVE_INT
#define SUBF_C_TYPE int
static void
test_subfiling_precreate_rank_0(void)
{
hsize_t start[1];
hsize_t count[1];
hsize_t dset_dims[1];
size_t target_size;
size_t n_elements_per_rank;
hid_t file_id = H5I_INVALID_HID;
hid_t fapl_id = H5I_INVALID_HID;
hid_t dset_id = H5I_INVALID_HID;
hid_t dxpl_id = H5I_INVALID_HID;
hid_t fspace_id = H5I_INVALID_HID;
void *buf = NULL;
curr_nerrors = nerrors;
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");
if (MAINPROCESS)
TESTING_2("file pre-creation on rank 0");
/* Calculate target size for dataset to stripe it across available IOCs */
target_size = (stripe_size_g > 0) ? (size_t)stripe_size_g : H5FD_SUBFILING_DEFAULT_STRIPE_SIZE;
/* Nudge stripe size to be multiple of C type size */
if ((target_size % sizeof(SUBF_C_TYPE)) != 0)
target_size += sizeof(SUBF_C_TYPE) - (target_size % sizeof(SUBF_C_TYPE));
target_size *= (size_t)mpi_size;
VRFY(((target_size % sizeof(SUBF_C_TYPE)) == 0), "target size check succeeded");
if (stripe_size_g > 0) {
VRFY((target_size >= (size_t)stripe_size_g), "target size check succeeded");
}
else {
VRFY((target_size >= H5FD_SUBFILING_DEFAULT_STRIPE_SIZE), "target size check succeeded");
}
dset_dims[0] = (hsize_t)(target_size / sizeof(SUBF_C_TYPE));
n_elements_per_rank = (dset_dims[0] / (size_t)mpi_size);
/* Create and populate file on rank 0 only */
if (MAINPROCESS) {
H5FD_subfiling_params_t cfg;
h5_stat_size_t file_size;
h5_stat_t file_info;
FILE *subfile_ptr;
char *tmp_filename = NULL;
int num_subfiles;
int num_digits;
/* Create a file consisting of 1 subfile per application I/O concentrator */
cfg.ioc_selection = SELECT_IOC_ONE_PER_NODE;
cfg.stripe_size = (stripe_size_g > 0) ? stripe_size_g : H5FD_SUBFILING_DEFAULT_STRIPE_SIZE;
cfg.stripe_count = num_iocs_g;
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");
file_id = H5Fcreate(SUBF_FILENAME, H5F_ACC_TRUNC, H5P_DEFAULT, fapl_id);
VRFY((file_id >= 0), "H5Fcreate succeeded");
fspace_id = H5Screate_simple(1, dset_dims, NULL);
VRFY((fspace_id >= 0), "H5Screate_simple succeeded");
dset_id =
H5Dcreate2(file_id, "DSET", SUBF_HDF5_TYPE, fspace_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
VRFY((dset_id >= 0), "Dataset creation succeeded");
buf = malloc(dset_dims[0] * sizeof(SUBF_C_TYPE));
VRFY(buf, "malloc succeeded");
for (size_t i = 0; i < dset_dims[0]; i++)
((SUBF_C_TYPE *)buf)[i] = (SUBF_C_TYPE)((i / n_elements_per_rank) + (i % n_elements_per_rank));
VRFY((H5Dwrite(dset_id, SUBF_HDF5_TYPE, H5S_BLOCK, fspace_id, dxpl_id, buf) >= 0),
"Dataset write succeeded");
free(buf);
buf = NULL;
VRFY((H5Sclose(fspace_id) >= 0), "File dataspace close succeeded");
VRFY((H5Dclose(dset_id) >= 0), "Dataset close succeeded");
VRFY((H5Pclose(fapl_id) >= 0), "FAPL close succeeded");
VRFY((H5Fclose(file_id) >= 0), "H5Fclose succeeded");
/*
* Ensure that all the subfiles are present
*/
num_subfiles = cfg.stripe_count;
num_digits = (int)(HDlog10(num_subfiles) + 1);
VRFY((HDstat(SUBF_FILENAME, &file_info) >= 0), "HDstat succeeded");
tmp_filename = malloc(PATH_MAX);
VRFY(tmp_filename, "malloc succeeded");
for (int i = 0; i < num_subfiles; i++) {
h5_stat_t subfile_info;
HDsnprintf(tmp_filename, PATH_MAX, H5FD_SUBFILING_FILENAME_TEMPLATE, SUBF_FILENAME,
(uint64_t)file_info.st_ino, num_digits, i + 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 */
VRFY((HDstat(tmp_filename, &subfile_info) >= 0), "HDstat succeeded");
file_size = (h5_stat_size_t)subfile_info.st_size;
VRFY((file_size >= cfg.stripe_size), "File size verification succeeded");
}
/* Verify that there aren't too many subfiles */
HDsnprintf(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(tmp_filename);
tmp_filename = NULL;
}
mpi_code_g = MPI_Barrier(comm_g);
VRFY((mpi_code_g == MPI_SUCCESS), "MPI_Barrier succeeded");
/* Open the file on all ranks */
fapl_id = create_subfiling_ioc_fapl(comm_g, info_g, FALSE, NULL, 0);
VRFY((fapl_id >= 0), "FAPL creation succeeded");
file_id = H5Fopen(SUBF_FILENAME, H5F_ACC_RDONLY, fapl_id);
VRFY((file_id >= 0), "H5Fopen succeeded");
dset_id = H5Dopen2(file_id, "DSET", H5P_DEFAULT);
VRFY((dset_id >= 0), "Dataset open succeeded");
fspace_id = H5Dget_space(dset_id);
VRFY((fspace_id >= 0), "Dataset dataspace retrieval succeeded");
/* Select hyperslab */
count[0] = n_elements_per_rank;
start[0] = (hsize_t)mpi_rank * count[0];
VRFY((H5Sselect_hyperslab(fspace_id, H5S_SELECT_SET, start, NULL, count, NULL) >= 0),
"H5Sselect_hyperslab succeeded");
buf = calloc(1, count[0] * sizeof(SUBF_C_TYPE));
VRFY(buf, "calloc succeeded");
VRFY((H5Dread(dset_id, SUBF_HDF5_TYPE, H5S_BLOCK, fspace_id, dxpl_id, buf) >= 0),
"Dataset read succeeded");
for (size_t i = 0; i < n_elements_per_rank; i++) {
SUBF_C_TYPE buf_value = ((SUBF_C_TYPE *)buf)[i];
VRFY((buf_value == (SUBF_C_TYPE)((size_t)mpi_rank + i)), "data verification succeeded");
}
free(buf);
buf = NULL;
VRFY((H5Sclose(fspace_id) >= 0), "File dataspace close succeeded");
VRFY((H5Dclose(dset_id) >= 0), "Dataset close succeeded");
VRFY((H5Fclose(file_id) >= 0), "H5Fclose succeeded");
H5E_BEGIN_TRY
{
H5Fdelete(SUBF_FILENAME, fapl_id);
}
H5E_END_TRY
VRFY((H5Pclose(fapl_id) >= 0), "FAPL close succeeded");
VRFY((H5Pclose(dxpl_id) >= 0), "DXPL close succeeded");
CHECK_PASSED();
}
#undef SUBF_FILENAME
#undef SUBF_HDF5_TYPE
#undef SUBF_C_TYPE
/*
* Test to check that an HDF5 file created with the
* Subfiling VFD can be read back with a single MPI
* rank
*/
#define SUBF_FILENAME "test_subfiling_write_many_read_one.h5"
#define SUBF_HDF5_TYPE H5T_NATIVE_INT
#define SUBF_C_TYPE int
static void
test_subfiling_write_many_read_one(void)
{
hsize_t start[1];
hsize_t count[1];
hsize_t dset_dims[1];
size_t target_size;
hid_t file_id = H5I_INVALID_HID;
hid_t fapl_id = H5I_INVALID_HID;
hid_t dset_id = H5I_INVALID_HID;
hid_t dxpl_id = H5I_INVALID_HID;
hid_t fspace_id = H5I_INVALID_HID;
void *buf = NULL;
curr_nerrors = nerrors;
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");
if (MAINPROCESS)
TESTING_2("reading back file with single MPI rank");
/* 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");
/* Create file on all ranks */
file_id = H5Fcreate(SUBF_FILENAME, H5F_ACC_TRUNC, H5P_DEFAULT, fapl_id);
VRFY((file_id >= 0), "H5Fcreate succeeded");
VRFY((H5Pclose(fapl_id) >= 0), "FAPL close succeeded");
/* Calculate target size for dataset to stripe it across available IOCs */
target_size = (stripe_size_g > 0) ? (size_t)stripe_size_g : H5FD_SUBFILING_DEFAULT_STRIPE_SIZE;
/* Nudge stripe size to be multiple of C type size */
if ((target_size % sizeof(SUBF_C_TYPE)) != 0)
target_size += sizeof(SUBF_C_TYPE) - (target_size % sizeof(SUBF_C_TYPE));
target_size *= (size_t)mpi_size;
VRFY(((target_size % sizeof(SUBF_C_TYPE)) == 0), "target size check succeeded");
if (stripe_size_g > 0) {
VRFY((target_size >= (size_t)stripe_size_g), "target size check succeeded");
}
else {
VRFY((target_size >= H5FD_SUBFILING_DEFAULT_STRIPE_SIZE), "target size check succeeded");
}
dset_dims[0] = (hsize_t)(target_size / sizeof(SUBF_C_TYPE));
fspace_id = H5Screate_simple(1, dset_dims, NULL);
VRFY((fspace_id >= 0), "H5Screate_simple succeeded");
dset_id = H5Dcreate2(file_id, "DSET", SUBF_HDF5_TYPE, fspace_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
VRFY((dset_id >= 0), "Dataset creation succeeded");
/* Select hyperslab */
count[0] = dset_dims[0] / (hsize_t)mpi_size;
start[0] = (hsize_t)mpi_rank * count[0];
VRFY((H5Sselect_hyperslab(fspace_id, H5S_SELECT_SET, start, NULL, count, NULL) >= 0),
"H5Sselect_hyperslab succeeded");
buf = malloc(count[0] * sizeof(SUBF_C_TYPE));
VRFY(buf, "malloc succeeded");
for (size_t i = 0; i < count[0]; i++)
((SUBF_C_TYPE *)buf)[i] = (SUBF_C_TYPE)((size_t)mpi_rank + i);
VRFY((H5Dwrite(dset_id, SUBF_HDF5_TYPE, H5S_BLOCK, fspace_id, dxpl_id, buf) >= 0),
"Dataset write succeeded");
free(buf);
buf = NULL;
VRFY((H5Dclose(dset_id) >= 0), "Dataset close succeeded");
VRFY((H5Fclose(file_id) >= 0), "File close succeeded");
mpi_code_g = MPI_Barrier(comm_g);
VRFY((mpi_code_g == MPI_SUCCESS), "MPI_Barrier succeeded");
if (MAINPROCESS) {
fapl_id = create_subfiling_ioc_fapl(MPI_COMM_SELF, MPI_INFO_NULL, FALSE, NULL, 0);
VRFY((fapl_id >= 0), "FAPL creation succeeded");
file_id = H5Fopen(SUBF_FILENAME, H5F_ACC_RDONLY, fapl_id);
VRFY((file_id >= 0), "H5Fopen succeeded");
dset_id = H5Dopen2(file_id, "DSET", H5P_DEFAULT);
VRFY((dset_id >= 0), "Dataset open succeeded");
buf = calloc(1, target_size);
VRFY(buf, "calloc succeeded");
VRFY((H5Dread(dset_id, SUBF_HDF5_TYPE, H5S_BLOCK, H5S_ALL, dxpl_id, buf) >= 0),
"Dataset read succeeded");
for (size_t i = 0; i < (size_t)mpi_size; i++) {
for (size_t j = 0; j < count[0]; j++) {
SUBF_C_TYPE buf_value = ((SUBF_C_TYPE *)buf)[(i * count[0]) + j];
VRFY((buf_value == (SUBF_C_TYPE)(j + i)), "data verification succeeded");
}
}
free(buf);
buf = NULL;
VRFY((H5Dclose(dset_id) >= 0), "Dataset close 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");
}
mpi_code_g = MPI_Barrier(comm_g);
VRFY((mpi_code_g == MPI_SUCCESS), "MPI_Barrier succeeded");
VRFY((H5Sclose(fspace_id) >= 0), "File dataspace close succeeded");
VRFY((H5Pclose(dxpl_id) >= 0), "DXPL close succeeded");
CHECK_PASSED();
}
#undef SUBF_FILENAME
#undef SUBF_HDF5_TYPE
#undef SUBF_C_TYPE
/*
* Test to check that an HDF5 file created with the
* Subfiling VFD can be read back with less MPI ranks
* than the file was written with
*/
#define SUBF_FILENAME "test_subfiling_write_many_read_few.h5"
#define SUBF_HDF5_TYPE H5T_NATIVE_INT
#define SUBF_C_TYPE int
static void
test_subfiling_write_many_read_few(void)
{
MPI_Comm sub_comm = MPI_COMM_NULL;
hsize_t start[1];
hsize_t count[1];
hsize_t dset_dims[1];
hbool_t reading_file = FALSE;
size_t target_size;
hid_t file_id = H5I_INVALID_HID;
hid_t fapl_id = H5I_INVALID_HID;
hid_t dset_id = H5I_INVALID_HID;
hid_t dxpl_id = H5I_INVALID_HID;
hid_t fspace_id = H5I_INVALID_HID;
void *buf = NULL;
curr_nerrors = nerrors;
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");
if (MAINPROCESS)
TESTING_2("reading back file with fewer MPI ranks than written with");
/*
* Skip this test for an MPI communicator size of 1,
* as the test wouldn't really be meaningful
*/
if (mpi_size == 1) {
if (MAINPROCESS)
SKIPPED();
return;
}
/* 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");
/* Create file on all ranks */
file_id = H5Fcreate(SUBF_FILENAME, H5F_ACC_TRUNC, H5P_DEFAULT, fapl_id);
VRFY((file_id >= 0), "H5Fcreate succeeded");
VRFY((H5Pclose(fapl_id) >= 0), "FAPL close succeeded");
/* Calculate target size for dataset to stripe it across available IOCs */
target_size = (stripe_size_g > 0) ? (size_t)stripe_size_g : H5FD_SUBFILING_DEFAULT_STRIPE_SIZE;
/* Nudge stripe size to be multiple of C type size */
if ((target_size % sizeof(SUBF_C_TYPE)) != 0)
target_size += sizeof(SUBF_C_TYPE) - (target_size % sizeof(SUBF_C_TYPE));
target_size *= (size_t)mpi_size;
VRFY(((target_size % sizeof(SUBF_C_TYPE)) == 0), "target size check succeeded");
if (stripe_size_g > 0) {
VRFY((target_size >= (size_t)stripe_size_g), "target size check succeeded");
}
else {
VRFY((target_size >= H5FD_SUBFILING_DEFAULT_STRIPE_SIZE), "target size check succeeded");
}
dset_dims[0] = (hsize_t)(target_size / sizeof(SUBF_C_TYPE));
fspace_id = H5Screate_simple(1, dset_dims, NULL);
VRFY((fspace_id >= 0), "H5Screate_simple succeeded");
dset_id = H5Dcreate2(file_id, "DSET", SUBF_HDF5_TYPE, fspace_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
VRFY((dset_id >= 0), "Dataset creation succeeded");
/* Select hyperslab */
count[0] = dset_dims[0] / (hsize_t)mpi_size;
start[0] = (hsize_t)mpi_rank * count[0];
VRFY((H5Sselect_hyperslab(fspace_id, H5S_SELECT_SET, start, NULL, count, NULL) >= 0),
"H5Sselect_hyperslab succeeded");
buf = malloc(count[0] * sizeof(SUBF_C_TYPE));
VRFY(buf, "malloc succeeded");
for (size_t i = 0; i < count[0]; i++)
((SUBF_C_TYPE *)buf)[i] = (SUBF_C_TYPE)((size_t)mpi_rank + i);
VRFY((H5Dwrite(dset_id, SUBF_HDF5_TYPE, H5S_BLOCK, fspace_id, dxpl_id, buf) >= 0),
"Dataset write succeeded");
free(buf);
buf = NULL;
VRFY((H5Dclose(dset_id) >= 0), "Dataset close succeeded");
VRFY((H5Fclose(file_id) >= 0), "File close succeeded");
/*
* If only using 1 node, read file back with a
* few ranks from that node. Otherwise, read file
* back with 1 MPI rank per node
*/
if (num_nodes_g == 1) {
int color;
if (mpi_size < 2) {
color = 1;
}
else if (mpi_size < 4) {
color = (mpi_rank < (mpi_size / 2));
}
else {
color = (mpi_rank < (mpi_size / 4));
}
if (mpi_size > 1) {
mpi_code_g = MPI_Comm_split(comm_g, color, mpi_rank, &sub_comm);
VRFY((mpi_code_g == MPI_SUCCESS), "MPI_Comm_split succeeded");
}
if (color)
reading_file = TRUE;
}
else {
if (node_local_rank == 0) {
sub_comm = ioc_comm;
reading_file = TRUE;
}
}
if (reading_file) {
fapl_id = create_subfiling_ioc_fapl(sub_comm, MPI_INFO_NULL, FALSE, NULL, 0);
VRFY((fapl_id >= 0), "FAPL creation succeeded");
file_id = H5Fopen(SUBF_FILENAME, H5F_ACC_RDONLY, fapl_id);
VRFY((file_id >= 0), "H5Fopen succeeded");
dset_id = H5Dopen2(file_id, "DSET", H5P_DEFAULT);
VRFY((dset_id >= 0), "Dataset open succeeded");
buf = calloc(1, target_size);
VRFY(buf, "calloc succeeded");
VRFY((H5Dread(dset_id, SUBF_HDF5_TYPE, H5S_BLOCK, H5S_ALL, dxpl_id, buf) >= 0),
"Dataset read succeeded");
for (size_t i = 0; i < (size_t)mpi_size; i++) {
for (size_t j = 0; j < count[0]; j++) {
SUBF_C_TYPE buf_value = ((SUBF_C_TYPE *)buf)[(i * count[0]) + j];
VRFY((buf_value == (SUBF_C_TYPE)(j + i)), "data verification succeeded");
}
}
free(buf);
buf = NULL;
VRFY((H5Dclose(dset_id) >= 0), "Dataset close 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");
}
if ((sub_comm != MPI_COMM_NULL) && (num_nodes_g == 1)) {
mpi_code_g = MPI_Comm_free(&sub_comm);
VRFY((mpi_code_g == MPI_SUCCESS), "MPI_Comm_free succeeded");
}
mpi_code_g = MPI_Barrier(comm_g);
VRFY((mpi_code_g == MPI_SUCCESS), "MPI_Barrier succeeded");
VRFY((H5Sclose(fspace_id) >= 0), "File dataspace close succeeded");
VRFY((H5Pclose(dxpl_id) >= 0), "DXPL close succeeded");
CHECK_PASSED();
}
#undef SUBF_FILENAME
#undef SUBF_HDF5_TYPE
#undef SUBF_C_TYPE
/*
* Test that the subfiling file can be read with the
* sec2 driver after being fused back together with
* the h5fuse utility
*/
#define SUBF_FILENAME "test_subfiling_h5fuse.h5"
#define SUBF_HDF5_TYPE H5T_NATIVE_INT
#define SUBF_C_TYPE int
static void
test_subfiling_h5fuse(void)
{
#if defined(H5_HAVE_FORK) && defined(H5_HAVE_WAITPID)
h5_stat_t file_info;
uint64_t file_inode;
hsize_t start[1];
hsize_t count[1];
hsize_t dset_dims[1];
size_t target_size;
hid_t file_id = H5I_INVALID_HID;
hid_t fapl_id = H5I_INVALID_HID;
hid_t dset_id = H5I_INVALID_HID;
hid_t dxpl_id = H5I_INVALID_HID;
hid_t fspace_id = H5I_INVALID_HID;
void *buf = NULL;
int skip_test = 0;
#endif
curr_nerrors = nerrors;
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");
if (MAINPROCESS)
TESTING_2("h5fuse utility");
#if defined(H5_HAVE_FORK) && defined(H5_HAVE_WAITPID)
/*
* Check if h5fuse script exists in current directory;
* Skip test if it doesn't
*/
if (MAINPROCESS) {
FILE *h5fuse_script;
h5fuse_script = fopen("h5fuse.sh", "r");
if (h5fuse_script)
fclose(h5fuse_script);
else
skip_test = 1;
}
if (mpi_size > 1) {
mpi_code_g = MPI_Bcast(&skip_test, 1, MPI_INT, 0, comm_g);
VRFY((mpi_code_g == MPI_SUCCESS), "MPI_Bcast succeeded");
}
if (skip_test) {
if (MAINPROCESS)
SKIPPED();
return;
}
/* 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");
/* Create file on all ranks */
file_id = H5Fcreate(SUBF_FILENAME, H5F_ACC_TRUNC, H5P_DEFAULT, fapl_id);
VRFY((file_id >= 0), "H5Fcreate succeeded");
/*
* Retrieve the HDF5 file's inode number before operating on
* it, since it might change after fusing
*/
HDcompile_assert(sizeof(uint64_t) >= sizeof(ino_t));
if (MAINPROCESS) {
VRFY((HDstat(SUBF_FILENAME, &file_info) >= 0), "HDstat succeeded");
file_inode = (uint64_t)file_info.st_ino;
}
if (mpi_size > 1) {
mpi_code_g = MPI_Bcast(&file_inode, 1, MPI_UINT64_T, 0, comm_g);
VRFY((mpi_code_g == MPI_SUCCESS), "MPI_Bcast succeeded");
}
/* Calculate target size for dataset to stripe it across available IOCs */
target_size = (stripe_size_g > 0) ? (size_t)stripe_size_g : H5FD_SUBFILING_DEFAULT_STRIPE_SIZE;
/* Nudge stripe size to be multiple of C type size */
if ((target_size % sizeof(SUBF_C_TYPE)) != 0)
target_size += sizeof(SUBF_C_TYPE) - (target_size % sizeof(SUBF_C_TYPE));
target_size *= (size_t)mpi_size;
VRFY(((target_size % sizeof(SUBF_C_TYPE)) == 0), "target size check succeeded");
if (stripe_size_g > 0) {
VRFY((target_size >= (size_t)stripe_size_g), "target size check succeeded");
}
else {
VRFY((target_size >= H5FD_SUBFILING_DEFAULT_STRIPE_SIZE), "target size check succeeded");
}
dset_dims[0] = (hsize_t)(target_size / sizeof(SUBF_C_TYPE));
fspace_id = H5Screate_simple(1, dset_dims, NULL);
VRFY((fspace_id >= 0), "H5Screate_simple succeeded");
dset_id = H5Dcreate2(file_id, "DSET", SUBF_HDF5_TYPE, fspace_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
VRFY((dset_id >= 0), "Dataset creation succeeded");
/* Select hyperslab */
count[0] = dset_dims[0] / (hsize_t)mpi_size;
start[0] = (hsize_t)mpi_rank * count[0];
VRFY((H5Sselect_hyperslab(fspace_id, H5S_SELECT_SET, start, NULL, count, NULL) >= 0),
"H5Sselect_hyperslab succeeded");
buf = malloc(count[0] * sizeof(SUBF_C_TYPE));
VRFY(buf, "malloc succeeded");
for (size_t i = 0; i < count[0]; i++)
((SUBF_C_TYPE *)buf)[i] = (SUBF_C_TYPE)((size_t)mpi_rank + i);
VRFY((H5Dwrite(dset_id, SUBF_HDF5_TYPE, H5S_BLOCK, fspace_id, dxpl_id, buf) >= 0),
"Dataset write succeeded");
free(buf);
buf = NULL;
VRFY((H5Sclose(fspace_id) >= 0), "File dataspace close succeeded");
VRFY((H5Dclose(dset_id) >= 0), "Dataset close succeeded");
VRFY((H5Fclose(file_id) >= 0), "File close succeeded");
if (MAINPROCESS) {
pid_t pid = 0;
pid_t tmppid;
int status;
pid = fork();
VRFY(pid >= 0, "fork succeeded");
if (pid == 0) {
char *tmp_filename;
char *args[7];
tmp_filename = malloc(PATH_MAX);
VRFY(tmp_filename, "malloc succeeded");
/* Generate name for configuration file */
HDsnprintf(tmp_filename, PATH_MAX, "%s/" H5FD_SUBFILING_CONFIG_FILENAME_TEMPLATE, config_dir,
SUBF_FILENAME, file_inode);
args[0] = HDstrdup("env");
args[1] = HDstrdup("sh");
args[2] = HDstrdup("h5fuse.sh");
args[3] = HDstrdup("-q");
args[4] = HDstrdup("-f");
args[5] = tmp_filename;
args[6] = NULL;
/* Call h5fuse script from MPI rank 0 */
execvp("env", args);
}
else {
tmppid = waitpid(pid, &status, 0);
VRFY(tmppid >= 0, "waitpid succeeded");
if (WIFEXITED(status)) {
int ret;
if ((ret = WEXITSTATUS(status)) != 0) {
printf("h5fuse process exited with error code %d\n", ret);
fflush(stdout);
MPI_Abort(comm_g, -1);
}
}
else {
printf("h5fuse process terminated abnormally\n");
fflush(stdout);
MPI_Abort(comm_g, -1);
}
}
/* Verify the size of the fused file */
VRFY((HDstat(SUBF_FILENAME, &file_info) >= 0), "HDstat succeeded");
VRFY(((size_t)file_info.st_size >= target_size), "File size verification succeeded");
/* Re-open file with sec2 driver and verify the data */
file_id = H5Fopen(SUBF_FILENAME, H5F_ACC_RDONLY, H5P_DEFAULT);
VRFY((file_id >= 0), "H5Fopen succeeded");
dset_id = H5Dopen2(file_id, "DSET", H5P_DEFAULT);
VRFY((dset_id >= 0), "Dataset open succeeded");
buf = calloc(1, target_size);
VRFY(buf, "calloc succeeded");
VRFY((H5Dread(dset_id, SUBF_HDF5_TYPE, H5S_BLOCK, H5S_ALL, dxpl_id, buf) >= 0),
"Dataset read succeeded");
for (size_t i = 0; i < (size_t)mpi_size; i++) {
for (size_t j = 0; j < count[0]; j++) {
SUBF_C_TYPE buf_value = ((SUBF_C_TYPE *)buf)[(i * count[0]) + j];
VRFY((buf_value == (SUBF_C_TYPE)(j + i)), "data verification succeeded");
}
}
free(buf);
buf = NULL;
VRFY((H5Dclose(dset_id) >= 0), "Dataset close succeeded");
VRFY((H5Fclose(file_id) >= 0), "File close succeeded");
}
mpi_code_g = MPI_Barrier(comm_g);
VRFY((mpi_code_g == MPI_SUCCESS), "MPI_Barrier succeeded");
/*
* Since we've now fused the file back together, the Subfiling
* VFD will no longer be able to work with it. The main HDF5
* file should be able to be deleted using the sec2 VFD, but we
* have to delete the extra files manually.
*/
if (MAINPROCESS) {
char *filename_buf;
int num_subfiles = num_iocs_g;
int num_digits = (int)(HDlog10(num_subfiles) + 1);
/* Delete the regular HDF5 file */
H5Pset_fapl_sec2(fapl_id);
H5E_BEGIN_TRY
{
H5Fdelete(SUBF_FILENAME, fapl_id);
}
H5E_END_TRY;
filename_buf = malloc(PATH_MAX);
VRFY(filename_buf, "malloc succeeded");
/* Generate name for configuration file */
HDsnprintf(filename_buf, PATH_MAX, "%s/" H5FD_SUBFILING_CONFIG_FILENAME_TEMPLATE, config_dir,
SUBF_FILENAME, file_inode);
/* Delete the configuration file */
if (HDremove(filename_buf) < 0) {
printf("couldn't remove Subfiling VFD configuration file '%s'\n", filename_buf);
nerrors++;
}
for (int i = 0; i < num_subfiles; i++) {
/* Generate name for each subfile */
HDsnprintf(filename_buf, PATH_MAX, H5FD_SUBFILING_FILENAME_TEMPLATE, SUBF_FILENAME, file_inode,
num_digits, i + 1, num_subfiles);
/* Delete the subfile */
if (HDremove(filename_buf) < 0) {
printf("couldn't remove subfile '%s'\n", filename_buf);
nerrors++;
}
}
free(filename_buf);
}
VRFY((H5Pclose(fapl_id) >= 0), "FAPL close succeeded");
VRFY((H5Pclose(dxpl_id) >= 0), "DXPL close succeeded");
mpi_code_g = MPI_Barrier(comm_g);
VRFY((mpi_code_g == MPI_SUCCESS), "MPI_Barrier succeeded");
CHECK_PASSED();
#else
SKIPPED();
#endif
}
#undef SUBF_FILENAME
#undef SUBF_HDF5_TYPE
#undef SUBF_C_TYPE
static void
parse_subfiling_env_vars(void)
{
char *env_value;
if (NULL != (env_value = HDgetenv(H5FD_SUBFILING_STRIPE_SIZE))) {
stripe_size_g = strtoll(env_value, NULL, 0);
if ((ERANGE == errno) || (stripe_size_g <= 0))
stripe_size_g = -1;
}
if (NULL != (env_value = HDgetenv(H5FD_SUBFILING_IOC_PER_NODE))) {
ioc_per_node_g = strtol(env_value, NULL, 0);
if ((ERANGE == errno) || (ioc_per_node_g <= 0))
ioc_per_node_g = -1;
else if (ioc_per_node_g * num_nodes_g > mpi_size)
/*
* If the number of IOCs per node from the environment
* causes the total number of IOCs to exceed the number
* of MPI ranks available, the Subfiling VFD will simply
* use all of the MPI ranks on a node as IOCs
*/
ioc_per_node_g = node_local_size;
}
if (NULL != (env_value = HDgetenv(H5FD_IOC_THREAD_POOL_SIZE))) {
ioc_thread_pool_size_g = atoi(env_value);
if (ioc_thread_pool_size_g <= 0)
ioc_thread_pool_size_g = -1;
}
if (NULL != (env_value = HDgetenv(H5FD_SUBFILING_CONFIG_FILE_PREFIX))) {
assert(config_dir);
HDstrncpy(config_dir, env_value, PATH_MAX);
/* Just in case.. */
config_dir[PATH_MAX - 1] = '\0';
if (*config_dir == '\0') {
*config_dir = '.';
*(config_dir + 1) = '\0';
}
}
}
int
main(int argc, char **argv)
{
unsigned seed;
hbool_t must_unset_stripe_size_env = FALSE;
hbool_t must_unset_ioc_per_node_env = FALSE;
hbool_t must_unset_ioc_thread_count_env = FALSE;
hbool_t must_unset_config_dir_env = FALSE;
char *env_value = NULL;
int required = MPI_THREAD_MULTIPLE;
int provided = 0;
HDcompile_assert(SUBFILING_MIN_STRIPE_SIZE <= H5FD_SUBFILING_DEFAULT_STRIPE_SIZE);
/* Initialize MPI */
if (MPI_SUCCESS != (mpi_code_g = MPI_Init_thread(&argc, &argv, required, &provided))) {
printf("MPI_Init_thread failed with error code %d\n", mpi_code_g);
nerrors++;
goto exit;
}
if (MPI_SUCCESS != (mpi_code_g = MPI_Comm_rank(comm_g, &mpi_rank))) {
printf("MPI_Comm_rank failed with error code %d\n", mpi_code_g);
nerrors++;
goto exit;
}
if (provided != required) {
if (MAINPROCESS)
printf("MPI doesn't support MPI_Init_thread with MPI_THREAD_MULTIPLE\n");
nerrors++;
goto exit;
}
if (MPI_SUCCESS != (mpi_code_g = MPI_Comm_size(comm_g, &mpi_size))) {
if (MAINPROCESS)
printf("MPI_Comm_size failed with error code %d\n", mpi_code_g);
nerrors++;
goto exit;
}
/* Split communicator according to node-local ranks */
if (MPI_SUCCESS != (mpi_code_g = MPI_Comm_split_type(comm_g, MPI_COMM_TYPE_SHARED, mpi_rank,
MPI_INFO_NULL, &node_local_comm))) {
if (MAINPROCESS)
printf("MPI_Comm_split_type failed with error code %d\n", mpi_code_g);
nerrors++;
goto exit;
}
if (MPI_SUCCESS != (mpi_code_g = MPI_Comm_size(node_local_comm, &node_local_size))) {
if (MAINPROCESS)
printf("MPI_Comm_size failed with error code %d\n", mpi_code_g);
nerrors++;
goto exit;
}
if (MPI_SUCCESS != (mpi_code_g = MPI_Comm_rank(node_local_comm, &node_local_rank))) {
if (MAINPROCESS)
printf("MPI_Comm_rank failed with error code %d\n", mpi_code_g);
nerrors++;
goto exit;
}
/* Get the number of nodes being run on */
num_nodes_g = (node_local_rank == 0) ? 1 : 0;
if (MPI_SUCCESS !=
(mpi_code_g = MPI_Allreduce(MPI_IN_PLACE, &num_nodes_g, 1, MPI_INT, MPI_SUM, comm_g))) {
if (MAINPROCESS)
printf("MPI_Allreduce failed with error code %d\n", mpi_code_g);
nerrors++;
goto exit;
}
/*
* Split communicator according to rank value across nodes.
* If the SELECT_IOC_ONE_PER_NODE IOC selection strategy is
* used, each rank with a node local rank value of 0 will
* be an IOC in the new communicator.
*/
if (MPI_SUCCESS != (mpi_code_g = MPI_Comm_split(comm_g, node_local_rank, mpi_rank, &ioc_comm))) {
if (MAINPROCESS)
printf("MPI_Comm_split failed with error code %d\n", mpi_code_g);
nerrors++;
goto exit;
}
if (MPI_SUCCESS != (mpi_code_g = MPI_Comm_size(ioc_comm, &ioc_comm_size))) {
if (MAINPROCESS)
printf("MPI_Comm_size failed with error code %d\n", mpi_code_g);
nerrors++;
goto exit;
}
if (MPI_SUCCESS != (mpi_code_g = MPI_Comm_rank(ioc_comm, &ioc_comm_rank))) {
if (MAINPROCESS)
printf("MPI_Comm_rank failed with error code %d\n", mpi_code_g);
nerrors++;
goto exit;
}
if (H5dont_atexit() < 0) {
if (MAINPROCESS)
printf("Failed to turn off atexit processing. Continue.\n");
}
H5open();
if (MAINPROCESS) {
printf("Testing Subfiling VFD functionality\n");
}
TestAlarmOn();
/*
* Obtain and broadcast seed value since ranks
* aren't guaranteed to arrive here at exactly
* the same time and could end up out of sync
* with each other in regards to random number
* generation
*/
if (mpi_rank == 0)
seed = (unsigned)time(NULL);
if (mpi_size > 1) {
if (MPI_SUCCESS != (mpi_code_g = MPI_Bcast(&seed, 1, MPI_UNSIGNED, 0, comm_g))) {
if (MAINPROCESS)
printf("MPI_Bcast failed with error code %d\n", mpi_code_g);
nerrors++;
goto exit;
}
}
srand(seed);
if (MAINPROCESS)
printf("Using seed: %u\n\n", seed);
/* Allocate buffer for possible config file directory specified */
config_dir = malloc(PATH_MAX);
if (!config_dir) {
if (MAINPROCESS)
printf("couldn't allocate space for subfiling config file directory buffer\n");
nerrors++;
goto exit;
}
/* Initialize to current working directory for now */
HDsnprintf(config_dir, PATH_MAX, ".");
/* Grab values from environment variables if set */
parse_subfiling_env_vars();
/*
* Assume that we use the "one IOC per node" selection
* strategy by default, with a possibly modified
* number of IOCs per node value
*/
num_iocs_g = (ioc_per_node_g > 0) ? (int)ioc_per_node_g * num_nodes_g : num_nodes_g;
if (num_iocs_g > mpi_size)
num_iocs_g = mpi_size;
for (size_t i = 0; i < ARRAY_SIZE(tests); i++) {
if (MPI_SUCCESS == (mpi_code_g = MPI_Barrier(comm_g))) {
(*tests[i])();
}
else {
if (MAINPROCESS)
MESG("MPI_Barrier failed");
nerrors++;
}
}
if (MAINPROCESS)
HDputs("");
/*
* Set any unset Subfiling environment variables and re-run
* the tests as a quick smoke check of whether those are
* working correctly
*/
if (stripe_size_g < 0) {
int64_t stripe_size;
char tmp[64];
/*
* 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");
}
HDsnprintf(tmp, sizeof(tmp), "%" PRId64, stripe_size);
if (HDsetenv(H5FD_SUBFILING_STRIPE_SIZE, tmp, 1) < 0) {
if (MAINPROCESS)
printf("HDsetenv failed\n");
nerrors++;
goto exit;
}
must_unset_stripe_size_env = TRUE;
}
if (ioc_per_node_g < 0) {
const char *ioc_per_node_str;
if (2 * num_nodes_g <= mpi_size)
ioc_per_node_str = "2";
else
ioc_per_node_str = "1";
if (HDsetenv(H5FD_SUBFILING_IOC_PER_NODE, ioc_per_node_str, 1) < 0) {
if (MAINPROCESS)
printf("HDsetenv failed\n");
nerrors++;
goto exit;
}
must_unset_ioc_per_node_env = TRUE;
}
if (ioc_thread_pool_size_g < 0) {
if (HDsetenv(H5FD_IOC_THREAD_POOL_SIZE, "2", 1) < 0) {
if (MAINPROCESS)
printf("HDsetenv failed\n");
nerrors++;
goto exit;
}
must_unset_ioc_thread_count_env = TRUE;
}
if (!(env_value = HDgetenv(H5FD_SUBFILING_CONFIG_FILE_PREFIX))) {
int rand_value = 0;
if (MAINPROCESS)
rand_value = rand() % 2;
mpi_code_g = MPI_Bcast(&rand_value, 1, MPI_INT, 0, comm_g);
VRFY((mpi_code_g == MPI_SUCCESS), "MPI_Bcast succeeded");
/* Randomly set config file prefix to either "." or a real
* directory to test both cases
*/
if (rand_value == 0) {
int mkdir_success = 0;
if (MAINPROCESS) {
if ((HDmkdir(SUBFILING_CONFIG_FILE_DIR, (mode_t)0755) < 0) && (errno != EEXIST)) {
printf("couldn't create temporary testing directory\n");
mkdir_success = 0;
}
else
mkdir_success = 1;
}
mpi_code_g = MPI_Bcast(&mkdir_success, 1, MPI_INT, 0, comm_g);
VRFY((mpi_code_g == MPI_SUCCESS), "MPI_Bcast succeeded");
if (!mkdir_success) {
if (MAINPROCESS)
printf("HDmkdir failed\n");
nerrors++;
goto exit;
}
if (HDsetenv(H5FD_SUBFILING_CONFIG_FILE_PREFIX, SUBFILING_CONFIG_FILE_DIR, 1) < 0) {
if (MAINPROCESS)
printf("HDsetenv failed\n");
nerrors++;
goto exit;
}
}
else {
if (HDsetenv(H5FD_SUBFILING_CONFIG_FILE_PREFIX, ".", 1) < 0) {
if (MAINPROCESS)
printf("HDsetenv failed\n");
nerrors++;
goto exit;
}
}
must_unset_config_dir_env = TRUE;
}
/* Grab values from environment variables */
parse_subfiling_env_vars();
/*
* Assume that we use the "one IOC per node" selection
* strategy by default, with a possibly modified
* number of IOCs per node value
*/
num_iocs_g = (ioc_per_node_g > 0) ? (int)ioc_per_node_g * num_nodes_g : num_nodes_g;
if (num_iocs_g > mpi_size)
num_iocs_g = mpi_size;
if (MAINPROCESS) {
printf("Re-running tests with environment variables set\n");
}
for (size_t i = 0; i < ARRAY_SIZE(tests); i++) {
if (MPI_SUCCESS == (mpi_code_g = MPI_Barrier(comm_g))) {
(*tests[i])();
}
else {
if (MAINPROCESS)
MESG("MPI_Barrier failed");
nerrors++;
}
}
if (MAINPROCESS)
HDputs("");
if (nerrors)
goto exit;
if (MAINPROCESS)
HDputs("All Subfiling VFD tests passed\n");
exit:
if (must_unset_stripe_size_env)
HDunsetenv(H5FD_SUBFILING_STRIPE_SIZE);
if (must_unset_ioc_per_node_env)
HDunsetenv(H5FD_SUBFILING_IOC_PER_NODE);
if (must_unset_ioc_thread_count_env)
HDunsetenv(H5FD_IOC_THREAD_POOL_SIZE);
if (must_unset_config_dir_env)
HDunsetenv(H5FD_SUBFILING_CONFIG_FILE_PREFIX);
if (MAINPROCESS) {
if (HDrmdir(SUBFILING_CONFIG_FILE_DIR) < 0 && (errno != ENOENT)) {
printf("couldn't remove temporary testing directory\n");
nerrors++;
}
}
if (nerrors) {
if (MAINPROCESS)
printf("*** %d TEST ERROR%s OCCURRED ***\n", nerrors, nerrors > 1 ? "S" : "");
}
TestAlarmOff();
H5close();
if (MPI_COMM_WORLD != ioc_comm)
MPI_Comm_free(&ioc_comm);
if (MPI_COMM_WORLD != node_local_comm)
MPI_Comm_free(&node_local_comm);
MPI_Finalize();
exit(nerrors ? EXIT_FAILURE : EXIT_SUCCESS);
}
#else /* H5_HAVE_SUBFILING_VFD */
int
main(void)
{
h5_reset();
printf("Testing Subfiling VFD functionality\n");
printf("SKIPPED - Subfiling VFD not built\n");
exit(EXIT_SUCCESS);
}
#endif /* H5_HAVE_SUBFILING_VFD */
|