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
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Copyright by The HDF Group. *
* Copyright by the Board of Trustees of the University of Illinois. *
* 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. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#include "H5private.h"
#include "h5tools.h"
#include "h5tools_utils.h"
#include "h5diff.h"
#include "ph5diff.h"
#define DIFF_COUNT 128
int diff_count_limit = DIFF_COUNT;
int rank_diff_count = 0;
diff_instance_t **rank_diffs = NULL;
diff_instance_t * my_diffs = NULL;
diff_instance_t * current_diff = NULL;
hsize_t * local_diff_offsets = NULL;
hsize_t * local_diff_lengths = NULL;
hsize_t local_diff_total = 0;
static int h5diff_open(const char *fname1, const char *fname2, diff_opt_t *opts, hid_t *_file_id1,
hid_t *_file_id2);
static int h5diff_initialize_lists(const char *fname1, const char *fname2, const char *objname1,
const char *objname2, hid_t file1_id, hid_t file2_id, diff_opt_t *opts,
char **_obj1fullname, trav_info_t **_info1_lp, char **_obj2fullname,
trav_info_t **_info2_lp, int *_both_objs_grp, trav_table_t **_match_list);
static herr_t trav_grp_objs(const char *path, const H5O_info2_t *oinfo, const char *already_visited,
void *udata);
static herr_t trav_grp_symlinks(const char *path, const H5L_info2_t *linfo, void *udata);
static int check_dataset_sizes(hid_t file_id, trav_table_t *match_list);
static void ph5diff_gather_diffs(void);
static hsize_t hyperslab_pdiff(hid_t file1_id, const char *path1, hid_t file2_id, const char *path2,
diff_opt_t *opts, diff_args_t *argdata);
static hsize_t pdiff_match(hid_t file1_id, const char *grp1, trav_info_t *info1, hid_t file2_id,
const char *grp2, trav_info_t *info2, trav_table_t *table, diff_opt_t *opts);
/*-------------------------------------------------------------------------
* Function: print_objname
*
* Purpose: check if object name is to be printed, only when:
* 1) verbose mode
* 2) when diff was found (normal mode)
*-------------------------------------------------------------------------
*/
H5_ATTR_PURE int
print_objname(diff_opt_t *opts, hsize_t nfound)
{
return ((opts->mode_verbose || nfound) && !opts->mode_quiet) ? 1 : 0;
}
/*-------------------------------------------------------------------------
* Function: do_print_objname
*
* Purpose: print object name
*-------------------------------------------------------------------------
*/
void
do_print_objname(const char *OBJ, const char *path1, const char *path2, diff_opt_t *opts)
{
/* if verbose level is higher than 0, put space line before
* displaying any object or symbolic links. This improves
* readability of the output.
*/
if (opts->mode_verbose_level >= 1)
parallel_print("\n");
parallel_print("%-7s: <%s> and <%s>\n", OBJ, path1, path2);
}
/*-------------------------------------------------------------------------
* Function: do_print_attrname
*
* Purpose: print attribute name
*-------------------------------------------------------------------------
*/
void
do_print_attrname(const char *attr, const char *path1, const char *path2)
{
parallel_print("%-7s: <%s> and <%s>\n", attr, path1, path2);
}
/*-------------------------------------------------------------------------
* Function: print_warn
*
* Purpose: check print warning condition.
* Return:
* 1 if verbose mode
* 0 if not verbos mode
*-------------------------------------------------------------------------
*/
static int
print_warn(diff_opt_t *opts)
{
return ((opts->mode_verbose)) ? 1 : 0;
}
#if defined(H5_HAVE_PARALLEL) && defined(USE_ORIGINAL_CODE)
/*-------------------------------------------------------------------------
* Function: phdiff_dismiss_workers
*
* Purpose: tell all workers to end.
*
* Return: none
*-------------------------------------------------------------------------
*/
void
phdiff_dismiss_workers(void)
{
int i;
for (i = 1; i < g_nTasks; i++)
MPI_Send(NULL, 0, MPI_BYTE, i, MPI_TAG_END, MPI_COMM_WORLD);
}
/*-------------------------------------------------------------------------
* Function: print_incoming_data
*
* Purpose: special function that prints any output that has been sent to the manager
* and is currently sitting in the incoming message queue
*
* Return: none
*-------------------------------------------------------------------------
*/
static void
print_incoming_data(void)
{
char data[PRINT_DATA_MAX_SIZE + 1];
int incomingMessage;
MPI_Status Status;
do {
MPI_Iprobe(MPI_ANY_SOURCE, MPI_TAG_PRINT_DATA, MPI_COMM_WORLD, &incomingMessage, &Status);
if (incomingMessage) {
HDmemset(data, 0, PRINT_DATA_MAX_SIZE + 1);
MPI_Recv(data, PRINT_DATA_MAX_SIZE, MPI_CHAR, Status.MPI_SOURCE, MPI_TAG_PRINT_DATA,
MPI_COMM_WORLD, &Status);
HDprintf("%s", data);
}
} while (incomingMessage);
}
#endif /* USE_ORIGINAL_CODE */
/*-------------------------------------------------------------------------
* Function: is_valid_options
*
* Purpose: check if options are valid
*
* Return:
* 1 : Valid
* 0 : Not valid
*------------------------------------------------------------------------*/
static int
is_valid_options(diff_opt_t *opts)
{
int ret_value = 1; /* init to valid */
/*-----------------------------------------------
* no -q(quiet) with -v (verbose) or -r (report) */
if (opts->mode_quiet && (opts->mode_verbose || opts->mode_report)) {
#ifdef H5_HAVE_PARALLEL
/* Allow MPI RANK(0) to print. */
if (g_Parallel && (g_nID == 0)) {
g_Parallel = 0;
}
#endif
parallel_print("Error: -q (quiet mode) cannot be added to verbose or report modes\n");
opts->err_stat = H5DIFF_ERR;
H5TOOLS_GOTO_DONE(0);
}
/* -------------------------------------------------------
* only allow --no-dangling-links along with --follow-symlinks */
if (opts->no_dangle_links && !opts->follow_links) {
#ifdef H5_HAVE_PARALLEL
/* Allow MPI RANK(0) to print. */
if (g_Parallel && (g_nID == 0)) {
g_Parallel = 0;
}
#endif
parallel_print("Error: --no-dangling-links must be used along with --follow-symlinks option.\n");
opts->err_stat = H5DIFF_ERR;
H5TOOLS_GOTO_DONE(0);
}
done:
return ret_value;
} /* is_valid_options() */
/*-------------------------------------------------------------------------
* Function: is_exclude_path
*
* Purpose: check if 'paths' are part of exclude path list
*
* Return:
* 1 - excluded path
* 0 - not excluded path
*------------------------------------------------------------------------*/
static int
is_exclude_path(char *path, h5trav_type_t type, diff_opt_t *opts)
{
struct exclude_path_list *exclude_path_ptr;
int ret_cmp;
int ret_value = 0;
/* check if exclude path option is given */
if (!opts->exclude_path)
H5TOOLS_GOTO_DONE(0);
/* assign to local exclude list pointer */
exclude_path_ptr = opts->exclude;
/* search objects in exclude list */
while (NULL != exclude_path_ptr) {
/* if exclude path is is group, exclude its members as well */
if (exclude_path_ptr->obj_type == H5TRAV_TYPE_GROUP) {
ret_cmp = HDstrncmp(exclude_path_ptr->obj_path, path, HDstrlen(exclude_path_ptr->obj_path));
if (ret_cmp == 0) { /* found matching members */
size_t len_grp;
/* check if given path belong to an excluding group, if so
* exclude it as well.
* This verifies if “/grp1/dset1” is only under “/grp1”, but
* not under “/grp1xxx/” group.
*/
len_grp = HDstrlen(exclude_path_ptr->obj_path);
if (path[len_grp] == '/') {
/* belong to excluded group! */
ret_value = 1;
break; /* while */
}
}
}
/* exclude target is not group, just exclude the object */
else {
ret_cmp = HDstrcmp(exclude_path_ptr->obj_path, path);
if (ret_cmp == 0) { /* found matching object */
/* excluded non-group object */
ret_value = 1;
/* remember the type of this matching object.
* if it's group, it can be used for excluding its member
* objects in this while() loop */
exclude_path_ptr->obj_type = type;
break; /* while */
}
}
exclude_path_ptr = exclude_path_ptr->next;
}
done:
return ret_value;
} /* is_exclude_path */
/*-------------------------------------------------------------------------
* Function: is_exclude_attr
*
* Purpose: check if 'paths' are part of exclude path list
*
* Return:
* 1 - excluded path
* 0 - not excluded path
*------------------------------------------------------------------------*/
static int
is_exclude_attr(const char *path, h5trav_type_t type, diff_opt_t *opts)
{
struct exclude_path_list *exclude_ptr;
int ret_cmp;
int ret_value = 0;
/* check if exclude attr option is given */
if (!opts->exclude_attr_path)
H5TOOLS_GOTO_DONE(0);
/* assign to local exclude list pointer */
exclude_ptr = opts->exclude_attr;
/* search objects in exclude list */
while (NULL != exclude_ptr) {
/* if exclude path is is group, exclude its members as well */
if (exclude_ptr->obj_type == H5TRAV_TYPE_GROUP) {
ret_cmp = HDstrncmp(exclude_ptr->obj_path, path, HDstrlen(exclude_ptr->obj_path));
if (ret_cmp == 0) { /* found matching members */
size_t len_grp;
/* check if given path belong to an excluding group, if so
* exclude it as well.
* This verifies if “/grp1/dset1” is only under “/grp1”, but
* not under “/grp1xxx/” group.
*/
len_grp = HDstrlen(exclude_ptr->obj_path);
if (path[len_grp] == '/') {
/* belong to excluded group! */
ret_value = 1;
break; /* while */
}
}
}
/* exclude target is not group, just exclude the object */
else {
ret_cmp = HDstrcmp(exclude_ptr->obj_path, path);
if (ret_cmp == 0) { /* found matching object */
/* excluded non-group object */
ret_value = 1;
/* remember the type of this matching object.
* if it's group, it can be used for excluding its member
* objects in this while() loop */
exclude_ptr->obj_type = type;
break; /* while */
}
}
exclude_ptr = exclude_ptr->next;
}
done:
return ret_value;
} /* is_exclude_attr() */
/*-------------------------------------------------------------------------
* Function: free_exclude_path_list
*
* Purpose: free exclude object list from diff options
*------------------------------------------------------------------------*/
static void
free_exclude_path_list(diff_opt_t *opts)
{
struct exclude_path_list *curr = opts->exclude;
struct exclude_path_list *next;
while (NULL != curr) {
next = curr->next;
HDfree(curr);
curr = next;
}
} /* free_exclude_path_list() */
/*-------------------------------------------------------------------------
* Function: free_exclude_attr_list
*
* Purpose: free exclude object attribute list from diff options
*------------------------------------------------------------------------*/
static void
free_exclude_attr_list(diff_opt_t *opts)
{
struct exclude_path_list *curr = opts->exclude_attr;
struct exclude_path_list *next;
while (NULL != curr) {
next = curr->next;
HDfree(curr);
curr = next;
}
} /* free_exclude_attr_list() */
/*-------------------------------------------------------------------------
* Function: build_match_list
*
* Purpose: get list of matching path_name from info1 and info2
*
* Note:
* Find common objects; the algorithm used for this search is the
* cosequential match algorithm and is described in
* Folk, Michael; Zoellick, Bill. (1992). File Structures. Addison-Wesley.
* Moved out from diff_match() to make code more flexible.
*
* Parameter:
* table_out [OUT] : return the list
*------------------------------------------------------------------------*/
static void
build_match_list(const char *objname1, trav_info_t *info1, const char *objname2, trav_info_t *info2,
trav_table_t **table_out, diff_opt_t *opts)
{
size_t curr1 = 0;
size_t curr2 = 0;
unsigned infile[2];
char * path1_lp = NULL;
char * path2_lp = NULL;
h5trav_type_t type1_l;
h5trav_type_t type2_l;
size_t path1_offset = 0;
size_t path2_offset = 0;
int cmp;
trav_table_t *table = NULL;
size_t idx;
H5TOOLS_START_DEBUG(" - errstat:%d", opts->err_stat);
/* init */
trav_table_init(info1->fid, &table);
if (table == NULL) {
H5TOOLS_INFO("Cannot create traverse table");
H5TOOLS_GOTO_DONE_NO_RET();
}
/*
* This is necessary for the case that given objects are group and
* have different names (ex: obj1 is /grp1 and obj2 is /grp5).
* All the objects belong to given groups are the candidates.
* So prepare to compare paths without the group names.
*/
H5TOOLS_DEBUG("objname1 = %s objname2 = %s ", objname1, objname2);
/* if obj1 is not root */
if (HDstrcmp(objname1, "/") != 0)
path1_offset = HDstrlen(objname1);
/* if obj2 is not root */
if (HDstrcmp(objname2, "/") != 0)
path2_offset = HDstrlen(objname2);
/*--------------------------------------------------
* build the list
*/
while (curr1 < info1->nused && curr2 < info2->nused) {
path1_lp = (info1->paths[curr1].path) + path1_offset;
path2_lp = (info2->paths[curr2].path) + path2_offset;
type1_l = info1->paths[curr1].type;
type2_l = info2->paths[curr2].type;
/* criteria is string compare */
cmp = HDstrcmp(path1_lp, path2_lp);
if (cmp == 0) {
if (!is_exclude_path(path1_lp, type1_l, opts)) {
infile[0] = 1;
infile[1] = 1;
trav_table_addflags(infile, path1_lp, info1->paths[curr1].type, table);
/* if the two point to the same target object,
* mark that in table */
if (info1->paths[curr1].fileno == info2->paths[curr2].fileno) {
int token_cmp;
if (H5Otoken_cmp(info1->fid, &info1->paths[curr1].obj_token,
&info2->paths[curr2].obj_token, &token_cmp) < 0) {
H5TOOLS_INFO("Failed to compare object tokens");
opts->err_stat = H5DIFF_ERR;
H5TOOLS_GOTO_DONE_NO_RET();
}
if (!token_cmp) {
idx = table->nobjs - 1;
table->objs[idx].is_same_trgobj = 1;
}
}
}
curr1++;
curr2++;
} /* end if */
else if (cmp < 0) {
if (!is_exclude_path(path1_lp, type1_l, opts)) {
infile[0] = 1;
infile[1] = 0;
trav_table_addflags(infile, path1_lp, info1->paths[curr1].type, table);
}
curr1++;
} /* end else-if */
else {
if (!is_exclude_path(path2_lp, type2_l, opts)) {
infile[0] = 0;
infile[1] = 1;
trav_table_addflags(infile, path2_lp, info2->paths[curr2].type, table);
}
curr2++;
} /* end else */
} /* end while */
/* list1 did not end */
infile[0] = 1;
infile[1] = 0;
while (curr1 < info1->nused) {
path1_lp = (info1->paths[curr1].path) + path1_offset;
type1_l = info1->paths[curr1].type;
if (!is_exclude_path(path1_lp, type1_l, opts)) {
trav_table_addflags(infile, path1_lp, info1->paths[curr1].type, table);
}
curr1++;
} /* end while */
/* list2 did not end */
infile[0] = 0;
infile[1] = 1;
while (curr2 < info2->nused) {
path2_lp = (info2->paths[curr2].path) + path2_offset;
type2_l = info2->paths[curr2].type;
if (!is_exclude_path(path2_lp, type2_l, opts)) {
trav_table_addflags(infile, path2_lp, info2->paths[curr2].type, table);
}
curr2++;
} /* end while */
free_exclude_path_list(opts);
done:
*table_out = table;
H5TOOLS_ENDDEBUG(" ");
} /* build_match_list() */
static int
h5diff_initialize_lists(const char *fname1, const char *fname2, const char *objname1, const char *objname2,
hid_t file1_id, hid_t file2_id, diff_opt_t *opts, char **_obj1fullname,
trav_info_t **_info1_lp, char **_obj2fullname, trav_info_t **_info2_lp,
int *_both_objs_grp, trav_table_t **_match_list)
{
trav_info_t *info1_obj = NULL;
trav_info_t *info2_obj = NULL;
char * obj1fullname = NULL;
char * obj2fullname = NULL;
h5trav_type_t obj1type = H5TRAV_TYPE_GROUP;
h5trav_type_t obj2type = H5TRAV_TYPE_GROUP;
/* object info */
H5O_info2_t oinfo1;
H5O_info2_t oinfo2;
/* for group object */
trav_info_t *info1_grp = NULL;
trav_info_t *info2_grp = NULL;
/* local pointer */
trav_info_t *info1_lp = NULL;
trav_info_t *info2_lp = NULL;
/* link info from specified object */
H5L_info2_t src_linfo1;
H5L_info2_t src_linfo2;
/* local return checks */
int l_ret1 = -1;
int l_ret2 = -1;
/* link info from member object */
h5tool_link_info_t trg_linfo1;
h5tool_link_info_t trg_linfo2;
/* list for common objects */
trav_table_t *match_list = NULL;
diff_err_t ret_value = H5DIFF_NO_ERR;
/* flag the same object optimization */
int both_objs_grp = 0;
/* flag errors */
int errors = 0;
/* count/flag */
int nfound = 0;
/* init link info struct */
HDmemset(&trg_linfo1, 0, sizeof(h5tool_link_info_t));
HDmemset(&trg_linfo2, 0, sizeof(h5tool_link_info_t));
/*-------------------------------------------------------------------------
* Initialize the info structs
*-------------------------------------------------------------------------
*/
trav_info_init(fname1, file1_id, &info1_obj);
trav_info_init(fname2, file2_id, &info2_obj);
H5TOOLS_DEBUG("trav_info_init initialized");
/* if any object is specified */
if (objname1) {
/* make the given object1 fullpath, start with "/" */
if (HDstrncmp(objname1, "/", 1) != 0) {
#ifdef H5_HAVE_ASPRINTF
/* Use the asprintf() routine, since it does what we're trying to do below */
if (HDasprintf(&obj1fullname, "/%s", objname1) < 0) {
errors++;
H5TOOLS_GOTO_ERROR(H5DIFF_ERR, "name buffer allocation failed");
}
#else /* H5_HAVE_ASPRINTF */
/* (malloc 2 more for "/" and end-of-line) */
if ((obj1fullname = (char *)HDmalloc(HDstrlen(objname1) + 2)) == NULL) {
errors++;
H5TOOLS_GOTO_ERROR(H5DIFF_ERR, "name buffer allocation failed");
}
HDstrcpy(obj1fullname, "/");
HDstrcat(obj1fullname, objname1);
#endif /* H5_HAVE_ASPRINTF */
}
else
obj1fullname = HDstrdup(objname1);
H5TOOLS_DEBUG("obj1fullname = %s", obj1fullname);
/* make the given object2 fullpath, start with "/" */
if (HDstrncmp(objname2, "/", 1) != 0) {
#ifdef H5_HAVE_ASPRINTF
/* Use the asprintf() routine, since it does what we're trying to do below */
if (HDasprintf(&obj2fullname, "/%s", objname2) < 0) {
errors++;
H5TOOLS_GOTO_ERROR(H5DIFF_ERR, "name buffer allocation failed");
}
#else /* H5_HAVE_ASPRINTF */
/* (malloc 2 more for "/" and end-of-line) */
if ((obj2fullname = (char *)HDmalloc(HDstrlen(objname2) + 2)) == NULL) {
errors++;
H5TOOLS_GOTO_ERROR(H5DIFF_ERR, "name buffer allocation failed");
}
HDstrcpy(obj2fullname, "/");
HDstrcat(obj2fullname, objname2);
#endif /* H5_HAVE_ASPRINTF */
}
else
obj2fullname = HDstrdup(objname2);
H5TOOLS_DEBUG("obj2fullname = %s", obj2fullname);
/*----------------------------------------------------------
* check if obj1 is root, group, single object or symlink
*/
H5TOOLS_DEBUG("h5diff check if obj1=%s is root, group, single object or symlink", obj1fullname);
if (!HDstrcmp(obj1fullname, "/")) {
obj1type = H5TRAV_TYPE_GROUP;
}
else {
/* check if link itself exist */
if (H5Lexists(file1_id, obj1fullname, H5P_DEFAULT) <= 0) {
errors++;
#ifdef H5_HAVE_PARALLEL
unsigned char was_Parallel = g_Parallel;
if (g_Parallel && (g_nID == 0))
g_Parallel = 0;
#endif
parallel_print("Object <%s> could not be found in <%s>\n", obj1fullname, fname1);
#ifdef H5_HAVE_PARALLEL
g_Parallel = was_Parallel;
#endif
H5TOOLS_GOTO_ERROR(H5DIFF_ERR, "Error: Object could not be found");
}
/* get info from link */
if (H5Lget_info2(file1_id, obj1fullname, &src_linfo1, H5P_DEFAULT) < 0) {
errors++;
#ifdef H5_HAVE_PARALLEL
unsigned char was_Parallel = g_Parallel;
if (g_Parallel && (g_nID == 0))
g_Parallel = 0;
#endif
parallel_print("Unable to get link info from <%s>\n", obj1fullname);
#ifdef H5_HAVE_PARALLEL
g_Parallel = was_Parallel;
#endif
H5TOOLS_GOTO_ERROR(H5DIFF_ERR, "H5Lget_info failed");
}
info1_lp = info1_obj;
/*
* check the type of specified path for hard and symbolic links
*/
if (src_linfo1.type == H5L_TYPE_HARD) {
size_t idx;
/* optional data pass */
info1_obj->opts = (diff_opt_t *)opts;
if (H5Oget_info_by_name3(file1_id, obj1fullname, &oinfo1, H5O_INFO_BASIC, H5P_DEFAULT) < 0) {
errors++;
parallel_print("Error: Could not get file contents\n");
H5TOOLS_GOTO_ERROR(H5DIFF_ERR, "Error: Could not get file contents");
}
obj1type = (h5trav_type_t)oinfo1.type;
trav_info_add(info1_obj, obj1fullname, obj1type);
idx = info1_obj->nused - 1;
HDmemcpy(&info1_obj->paths[idx].obj_token, &oinfo1.token, sizeof(H5O_token_t));
info1_obj->paths[idx].fileno = oinfo1.fileno;
}
else if (src_linfo1.type == H5L_TYPE_SOFT) {
obj1type = H5TRAV_TYPE_LINK;
trav_info_add(info1_obj, obj1fullname, obj1type);
}
else if (src_linfo1.type == H5L_TYPE_EXTERNAL) {
obj1type = H5TRAV_TYPE_UDLINK;
trav_info_add(info1_obj, obj1fullname, obj1type);
}
}
/*----------------------------------------------------------
* check if obj2 is root, group, single object or symlink
*/
H5TOOLS_DEBUG("h5diff check if obj2=%s is root, group, single object or symlink", obj2fullname);
if (!HDstrcmp(obj2fullname, "/")) {
obj2type = H5TRAV_TYPE_GROUP;
}
else {
/* check if link itself exist */
if (H5Lexists(file2_id, obj2fullname, H5P_DEFAULT) <= 0) {
errors++;
parallel_print("Object <%s> could not be found in <%s>\n", obj2fullname, fname2);
H5TOOLS_GOTO_ERROR(H5DIFF_ERR, "Error: Object could not be found");
}
/* get info from link */
if (H5Lget_info2(file2_id, obj2fullname, &src_linfo2, H5P_DEFAULT) < 0) {
errors++;
parallel_print("Unable to get link info from <%s>\n", obj2fullname);
H5TOOLS_GOTO_ERROR(H5DIFF_ERR, "H5Lget_info failed");
}
info2_lp = info2_obj;
/*
* check the type of specified path for hard and symbolic links
*/
if (src_linfo2.type == H5L_TYPE_HARD) {
size_t idx;
/* optional data pass */
info2_obj->opts = (diff_opt_t *)opts;
if (H5Oget_info_by_name3(file2_id, obj2fullname, &oinfo2, H5O_INFO_BASIC, H5P_DEFAULT) < 0) {
errors++;
parallel_print("Error: Could not get file contents\n");
H5TOOLS_GOTO_ERROR(H5DIFF_ERR, "Error: Could not get file contents");
}
obj2type = (h5trav_type_t)oinfo2.type;
trav_info_add(info2_obj, obj2fullname, obj2type);
idx = info2_obj->nused - 1;
HDmemcpy(&info2_obj->paths[idx].obj_token, &oinfo2.token, sizeof(H5O_token_t));
info2_obj->paths[idx].fileno = oinfo2.fileno;
}
else if (src_linfo2.type == H5L_TYPE_SOFT) {
obj2type = H5TRAV_TYPE_LINK;
trav_info_add(info2_obj, obj2fullname, obj2type);
}
else if (src_linfo2.type == H5L_TYPE_EXTERNAL) {
obj2type = H5TRAV_TYPE_UDLINK;
trav_info_add(info2_obj, obj2fullname, obj2type);
}
}
}
/* if no object specified */
else {
H5TOOLS_DEBUG("h5diff no object specified");
/* set root group */
obj1fullname = (char *)HDstrdup("/");
obj1type = H5TRAV_TYPE_GROUP;
obj2fullname = (char *)HDstrdup("/");
obj2type = H5TRAV_TYPE_GROUP;
}
H5TOOLS_DEBUG("get any symbolic links info - errstat:%d", opts->err_stat);
/* get any symbolic links info */
l_ret1 = H5tools_get_symlink_info(file1_id, obj1fullname, &trg_linfo1, opts->follow_links);
l_ret2 = H5tools_get_symlink_info(file2_id, obj2fullname, &trg_linfo2, opts->follow_links);
/*---------------------------------------------
* check for following symlinks
*/
if (opts->follow_links) {
/* pass how to handle printing warning to linkinfo option */
if (print_warn(opts))
trg_linfo1.opt.msg_mode = trg_linfo2.opt.msg_mode = 1;
/*-------------------------------
* check symbolic link (object1)
*/
H5TOOLS_DEBUG("h5diff check symbolic link (object1)");
/* dangling link */
if (l_ret1 == 0) {
H5TOOLS_DEBUG("h5diff ... dangling link");
if (opts->no_dangle_links) {
errors++;
/* treat dangling link as error */
if (opts->mode_verbose) {
#ifdef H5_HAVE_PARALLEL
unsigned char was_Parallel = g_Parallel;
if (g_Parallel && (g_nID == 0))
g_Parallel = 0;
#endif
parallel_print("Warning: <%s> is a dangling link.\n", obj1fullname);
#ifdef H5_HAVE_PARALLEL
g_Parallel = was_Parallel;
#endif
}
H5TOOLS_GOTO_ERROR(H5DIFF_ERR, "treat dangling link as error");
}
else {
if (opts->mode_verbose) {
#ifdef H5_HAVE_PARALLEL
unsigned char was_Parallel = g_Parallel;
if (g_Parallel && (g_nID == 0))
g_Parallel = 0;
#endif
parallel_print("obj1 <%s> is a dangling link.\n", obj1fullname);
#ifdef H5_HAVE_PARALLEL
g_Parallel = was_Parallel;
#endif
}
if (l_ret1 != 0 || l_ret2 != 0) {
nfound++;
#ifdef H5_HAVE_PARALLEL
unsigned char was_Parallel = g_Parallel;
if (g_Parallel && (g_nID == 0))
g_Parallel = 0;
#endif
print_found((hsize_t)nfound);
#ifdef H5_HAVE_PARALLEL
g_Parallel = was_Parallel;
H5TOOLS_GOTO_DONE(H5PDIFF_NO_ERR);
#else
H5TOOLS_GOTO_DONE(H5DIFF_NO_ERR);
#endif
}
}
}
else if (l_ret1 < 0) { /* fail */
#ifdef H5_HAVE_PARALLEL
unsigned char was_Parallel = g_Parallel;
if (g_Parallel && (g_nID == 0))
g_Parallel = 0;
#endif
parallel_print("Object <%s> could not be found in <%s>\n", obj1fullname, fname1);
#ifdef H5_HAVE_PARALLEL
g_Parallel = was_Parallel;
#endif
H5TOOLS_GOTO_ERROR(H5DIFF_ERR, "Object could not be found");
}
else if (l_ret1 != 2) { /* symbolic link */
obj1type = (h5trav_type_t)trg_linfo1.trg_type;
H5TOOLS_DEBUG("h5diff ... ... trg_linfo1.trg_type == H5L_TYPE_HARD");
if (info1_lp != NULL) {
size_t idx = info1_lp->nused - 1;
H5TOOLS_DEBUG("h5diff ... ... ... info1_obj not null");
HDmemcpy(&info1_lp->paths[idx].obj_token, &trg_linfo1.obj_token, sizeof(H5O_token_t));
info1_lp->paths[idx].type = (h5trav_type_t)trg_linfo1.trg_type;
info1_lp->paths[idx].fileno = trg_linfo1.fileno;
}
H5TOOLS_DEBUG("h5diff check symbolic link (object1) finished");
}
/*-------------------------------
* check symbolic link (object2)
*/
H5TOOLS_DEBUG("h5diff check symbolic link (object2)");
/* dangling link */
if (l_ret2 == 0) {
H5TOOLS_DEBUG("h5diff ... dangling link");
if (opts->no_dangle_links) {
errors++;
/* treat dangling link as error */
if (opts->mode_verbose) {
#ifdef H5_HAVE_PARALLEL
unsigned char was_Parallel = g_Parallel;
if (g_Parallel && (g_nID == 0))
g_Parallel = 0;
#endif
parallel_print("Warning: <%s> is a dangling link.\n", obj2fullname);
#ifdef H5_HAVE_PARALLEL
g_Parallel = was_Parallel;
#endif
}
H5TOOLS_GOTO_ERROR(H5DIFF_ERR, "treat dangling link as error");
}
else {
if (opts->mode_verbose) {
#ifdef H5_HAVE_PARALLEL
unsigned char was_Parallel = g_Parallel;
if (g_Parallel && (g_nID == 0))
g_Parallel = 0;
#endif
parallel_print("obj2 <%s> is a dangling link.\n", obj2fullname);
#ifdef H5_HAVE_PARALLEL
g_Parallel = was_Parallel;
#endif
}
if (l_ret1 != 0 || l_ret2 != 0) {
nfound++;
#ifdef H5_HAVE_PARALLEL
unsigned char was_Parallel = g_Parallel;
if (g_Parallel && (g_nID == 0))
g_Parallel = 0;
#endif
print_found((hsize_t)nfound);
#ifdef H5_HAVE_PARALLEL
g_Parallel = was_Parallel;
H5TOOLS_GOTO_DONE(H5PDIFF_NO_ERR);
#else
H5TOOLS_GOTO_DONE(H5DIFF_NO_ERR);
#endif
}
}
}
else if (l_ret2 < 0) { /* fail */
errors++;
#ifdef H5_HAVE_PARALLEL
unsigned char was_Parallel = g_Parallel;
if (g_Parallel && (g_nID == 0))
g_Parallel = 0;
#endif
parallel_print("Object <%s> could not be found in <%s>\n", obj2fullname, fname2);
#ifdef H5_HAVE_PARALLEL
g_Parallel = was_Parallel;
#endif
H5TOOLS_GOTO_ERROR(H5DIFF_ERR, "Object could not be found");
}
else if (l_ret2 != 2) { /* symbolic link */
obj2type = (h5trav_type_t)trg_linfo2.trg_type;
if (info2_lp != NULL) {
size_t idx = info2_lp->nused - 1;
H5TOOLS_DEBUG("h5diff ... ... ... info2_obj not null");
HDmemcpy(&info2_lp->paths[idx].obj_token, &trg_linfo2.obj_token, sizeof(H5O_token_t));
info2_lp->paths[idx].type = (h5trav_type_t)trg_linfo2.trg_type;
info2_lp->paths[idx].fileno = trg_linfo2.fileno;
}
H5TOOLS_DEBUG("h5diff check symbolic link (object1) finished");
}
} /* end of if follow symlinks */
/*
* If verbose options is not used, don't need to traverse through the list
* of objects in the group to display objects information,
* So use h5tools_is_obj_same() to improve performance by skipping
* comparing details of same objects.
*/
if (!(opts->mode_verbose || opts->mode_report)) {
H5TOOLS_DEBUG("h5diff NOT (opts->mode_verbose || opts->mode_report)");
/* if no danglink links */
if (l_ret1 > 0 && l_ret2 > 0)
if (h5tools_is_obj_same(file1_id, obj1fullname, file2_id, obj2fullname) != 0)
H5TOOLS_GOTO_DONE(H5DIFF_NO_ERR);
}
both_objs_grp = (obj1type == H5TRAV_TYPE_GROUP && obj2type == H5TRAV_TYPE_GROUP);
if (both_objs_grp) {
H5TOOLS_DEBUG("h5diff both_objs_grp TRUE");
/*
* traverse group1
*/
trav_info_init(fname1, file1_id, &info1_grp);
/* optional data pass */
info1_grp->opts = (diff_opt_t *)opts;
if (h5trav_visit(file1_id, obj1fullname, TRUE, TRUE, trav_grp_objs, trav_grp_symlinks, info1_grp,
H5O_INFO_BASIC) < 0) {
errors++;
parallel_print("Error: Could not get file contents\n");
H5TOOLS_GOTO_ERROR(H5DIFF_ERR, "Could not get file contents");
}
info1_lp = info1_grp;
/*
* traverse group2
*/
trav_info_init(fname2, file2_id, &info2_grp);
/* optional data pass */
info2_grp->opts = (diff_opt_t *)opts;
if (h5trav_visit(file2_id, obj2fullname, TRUE, TRUE, trav_grp_objs, trav_grp_symlinks, info2_grp,
H5O_INFO_BASIC) < 0) {
errors++;
parallel_print("Error: Could not get file contents\n");
H5TOOLS_GOTO_ERROR(H5DIFF_ERR, "Could not get file contents");
} /* end if */
info2_lp = info2_grp;
}
H5TOOLS_DEBUG("groups traversed - errstat:%d", opts->err_stat);
H5TOOLS_DEBUG("build_match_list next - errstat:%d", opts->err_stat);
/* process the objects */
build_match_list(obj1fullname, info1_lp, obj2fullname, info2_lp, &match_list, opts);
#ifdef H5_HAVE_PARALLEL
if (g_Parallel)
check_dataset_sizes(file1_id, match_list);
#endif
H5TOOLS_DEBUG("build_match_list finished - errstat:%d", opts->err_stat);
*_obj1fullname = obj1fullname;
*_obj2fullname = obj2fullname;
*_info1_lp = info1_lp;
*_info2_lp = info2_lp;
*_both_objs_grp = both_objs_grp;
*_match_list = match_list;
done:
opts->err_stat = opts->err_stat | ret_value;
/* free link info buffer */
if (trg_linfo1.trg_path) {
HDfree(trg_linfo1.trg_path);
trg_linfo1.trg_path = NULL;
}
if (trg_linfo2.trg_path) {
HDfree(trg_linfo2.trg_path);
trg_linfo2.trg_path = NULL;
}
H5TOOLS_ENDDEBUG(" - errstat:%d", opts->err_stat);
#ifdef H5_HAVE_PARALLEL
if ((ret_value == H5PDIFF_ERR) || (ret_value == H5PDIFF_NO_ERR))
return -1;
#endif
if (errors)
return -1;
return nfound;
}
static int
h5diff_open(const char *fname1, const char *fname2, diff_opt_t *opts, hid_t *_file_id1, hid_t *_file_id2)
{
int ret_value = 0;
hid_t fapl1_id = H5P_DEFAULT;
hid_t fapl2_id = H5P_DEFAULT;
hid_t file1_id = H5I_INVALID_HID;
hid_t file2_id = H5I_INVALID_HID;
/*-------------------------------------------------------------------------
* open the files first; if they are not valid, no point in continuing
*-------------------------------------------------------------------------
*/
/* open file 1 */
if (opts->custom_vol[0] || opts->custom_vfd[0]) {
if ((fapl1_id = h5tools_get_fapl(H5P_DEFAULT, opts->custom_vol[0] ? &(opts->vol_info[0]) : NULL,
opts->custom_vfd[0] ? &(opts->vfd_info[0]) : NULL)) < 0) {
ret_value = -1;
parallel_print("%s: unable to create fapl for input file\n", __func__);
H5TOOLS_GOTO_ERROR(H5DIFF_ERR, "unable to create input fapl\n");
}
}
if ((file1_id = h5tools_fopen(fname1, H5F_ACC_RDONLY, fapl1_id, (fapl1_id != H5P_DEFAULT), NULL,
(size_t)0)) < 0) {
ret_value = -1;
parallel_print("%s: <%s>: unable to open file\n", __func__, fname1);
H5TOOLS_GOTO_ERROR(H5DIFF_ERR, "<%s>: unable to open file\n", fname1);
}
*_file_id1 = file1_id;
H5TOOLS_DEBUG("file1_id = %s", fname1);
if (opts->custom_vol[1] || opts->custom_vfd[1]) {
if ((fapl2_id = h5tools_get_fapl(H5P_DEFAULT, opts->custom_vol[1] ? &(opts->vol_info[1]) : NULL,
opts->custom_vfd[1] ? &(opts->vfd_info[1]) : NULL)) < 0) {
ret_value = -2;
parallel_print("%s: unable to create fapl for input file\n", __func__);
H5TOOLS_GOTO_ERROR(H5DIFF_ERR, "unable to create input fapl\n");
}
}
if ((file2_id = h5tools_fopen(fname2, H5F_ACC_RDONLY, fapl2_id, (fapl2_id != H5P_DEFAULT), NULL,
(size_t)0)) < 0) {
ret_value = -2;
parallel_print("%s: <%s>: unable to open file\n", __func__, fname2);
H5TOOLS_GOTO_ERROR(H5DIFF_ERR, "<%s>: unable to open file\n", fname2);
}
*_file_id2 = file2_id;
H5TOOLS_DEBUG("file2_id = %s", fname2);
done:
if (fapl1_id != H5P_DEFAULT)
H5Pclose(fapl1_id);
if (fapl2_id != H5P_DEFAULT)
H5Pclose(fapl2_id);
return ret_value;
}
/*-------------------------------------------------------------------------
* Function: trav_grp_objs
*
* Purpose: Call back function from h5trav_visit().
*------------------------------------------------------------------------*/
static herr_t
trav_grp_objs(const char *path, const H5O_info2_t *oinfo, const char *already_visited, void *udata)
{
trav_info_visit_obj(path, oinfo, already_visited, udata);
return 0;
}
/*-------------------------------------------------------------------------
* Function: trav_grp_symlinks
*
* Purpose: Call back function from h5trav_visit().
* Track and extra checkings while visiting all symbolic-links.
*------------------------------------------------------------------------*/
static herr_t
trav_grp_symlinks(const char *path, const H5L_info2_t *linfo, void *udata)
{
trav_info_t * tinfo = (trav_info_t *)udata;
diff_opt_t * opts = (diff_opt_t *)tinfo->opts;
h5tool_link_info_t lnk_info;
const char * ext_fname;
const char * ext_path;
herr_t ret_value = SUCCEED;
H5TOOLS_START_DEBUG(" ");
/* init linkinfo struct */
HDmemset(&lnk_info, 0, sizeof(h5tool_link_info_t));
if (!opts->follow_links) {
trav_info_visit_lnk(path, linfo, tinfo);
H5TOOLS_GOTO_DONE(SUCCEED);
}
switch (linfo->type) {
case H5L_TYPE_SOFT:
if ((ret_value = H5tools_get_symlink_info(tinfo->fid, path, &lnk_info, opts->follow_links)) < 0) {
H5TOOLS_GOTO_DONE(FAIL);
}
else if (ret_value == 0) {
/* no dangling link option given and detect dangling link */
tinfo->symlink_visited.dangle_link = TRUE;
trav_info_visit_lnk(path, linfo, tinfo);
if (opts->no_dangle_links)
opts->err_stat = H5DIFF_ERR; /* make dangling link is error */
H5TOOLS_GOTO_DONE(SUCCEED);
}
/* check if already visit the target object */
if (symlink_is_visited(&(tinfo->symlink_visited), linfo->type, NULL, lnk_info.trg_path))
H5TOOLS_GOTO_DONE(SUCCEED);
/* add this link as visited link */
if (symlink_visit_add(&(tinfo->symlink_visited), linfo->type, NULL, lnk_info.trg_path) < 0)
H5TOOLS_GOTO_DONE(SUCCEED);
if (h5trav_visit(tinfo->fid, path, TRUE, TRUE, trav_grp_objs, trav_grp_symlinks, tinfo,
H5O_INFO_BASIC) < 0) {
parallel_print("Error: Could not get file contents\n");
opts->err_stat = H5DIFF_ERR;
H5TOOLS_GOTO_ERROR(FAIL, "Error: Could not get file contents");
}
break;
case H5L_TYPE_EXTERNAL:
if ((ret_value = H5tools_get_symlink_info(tinfo->fid, path, &lnk_info, opts->follow_links)) < 0) {
H5TOOLS_GOTO_DONE(FAIL);
}
else if (ret_value == 0) {
/* no dangling link option given and detect dangling link */
tinfo->symlink_visited.dangle_link = TRUE;
trav_info_visit_lnk(path, linfo, tinfo);
if (opts->no_dangle_links)
opts->err_stat = H5DIFF_ERR; /* make dangling link is error */
H5TOOLS_GOTO_DONE(SUCCEED);
}
if (H5Lunpack_elink_val(lnk_info.trg_path, linfo->u.val_size, NULL, &ext_fname, &ext_path) < 0)
H5TOOLS_GOTO_DONE(SUCCEED);
/* check if already visit the target object */
if (symlink_is_visited(&(tinfo->symlink_visited), linfo->type, ext_fname, ext_path))
H5TOOLS_GOTO_DONE(SUCCEED);
/* add this link as visited link */
if (symlink_visit_add(&(tinfo->symlink_visited), linfo->type, ext_fname, ext_path) < 0)
H5TOOLS_GOTO_DONE(SUCCEED);
if (h5trav_visit(tinfo->fid, path, TRUE, TRUE, trav_grp_objs, trav_grp_symlinks, tinfo,
H5O_INFO_BASIC) < 0) {
parallel_print("Error: Could not get file contents\n");
opts->err_stat = H5DIFF_ERR;
H5TOOLS_GOTO_ERROR(FAIL, "Error: Could not get file contents\n");
}
break;
case H5L_TYPE_HARD:
case H5L_TYPE_MAX:
case H5L_TYPE_ERROR:
default:
parallel_print("Error: Invalid link type\n");
opts->err_stat = H5DIFF_ERR;
H5TOOLS_GOTO_ERROR(FAIL, "Error: Invalid link type");
break;
} /* end of switch */
done:
if (lnk_info.trg_path)
HDfree(lnk_info.trg_path);
H5TOOLS_ENDDEBUG(" ");
return ret_value;
}
#ifdef H5_HAVE_PARALLEL
#define DEFAULT_LARGE_DSET_SIZE 1048576
static hsize_t
hyperslab_pdiff(hid_t file1_id, const char *path1, hid_t file2_id, const char *path2, diff_opt_t *opts,
diff_args_t *argdata)
{
int i, j;
int status = -1;
hid_t dset1_id = H5I_INVALID_HID;
hid_t dset2_id = H5I_INVALID_HID;
hid_t m_tid1 = H5I_INVALID_HID;
hid_t m_tid2 = H5I_INVALID_HID;
hid_t sid1 = H5I_INVALID_HID;
hid_t sid2 = H5I_INVALID_HID;
hid_t sm_space1 = H5I_INVALID_HID; /*stripmine data space */
hid_t sm_space2 = H5I_INVALID_HID; /*stripmine data space */
hid_t f_tid1 = H5I_INVALID_HID;
hid_t f_tid2 = H5I_INVALID_HID;
size_t m_size1;
size_t m_size2;
H5T_sign_t sign1;
H5T_sign_t sign2;
hbool_t is_dangle_link1 = FALSE;
hbool_t is_dangle_link2 = FALSE;
hbool_t is_hard_link = FALSE;
void *buf1 = NULL;
void *buf2 = NULL;
void *sm_buf1 = NULL;
void *sm_buf2 = NULL;
hsize_t nfound = 0;
int can_compare = 1; /* do diff or not */
h5trav_type_t object_type;
diff_err_t ret_value = opts->err_stat;
unsigned int vl_data1 = 0; /*contains VL datatypes */
unsigned int vl_data2 = 0; /*contains VL datatypes */
/* to get link info (COVERING options ...) */
h5tool_link_info_t linkinfo1;
h5tool_link_info_t linkinfo2;
dataset_context_t *hs_context1 = NULL;
dataset_context_t *hs_context2 = NULL;
/*init link info struct */
HDmemset(&linkinfo1, 0, sizeof(h5tool_link_info_t));
HDmemset(&linkinfo2, 0, sizeof(h5tool_link_info_t));
/* pass how to handle printing warnings to linkinfo option */
if (print_warn(opts))
linkinfo1.opt.msg_mode = linkinfo2.opt.msg_mode = 1;
/* for symbolic links, take care follow symlink and no dangling link
* options */
if (argdata->type[0] == H5TRAV_TYPE_LINK || argdata->type[0] == H5TRAV_TYPE_UDLINK ||
argdata->type[1] == H5TRAV_TYPE_LINK || argdata->type[1] == H5TRAV_TYPE_UDLINK) {
/*
* check dangling links for path1 and path2
*/
H5TOOLS_DEBUG("diff links");
/* target object1 - get type and name */
if ((status = H5tools_get_symlink_info(file1_id, path1, &linkinfo1, opts->follow_links)) < 0)
H5TOOLS_GOTO_ERROR(H5DIFF_ERR, "H5tools_get_symlink_info failed");
/* dangling link */
if (status == 0) {
if (opts->no_dangle_links) {
/* dangling link is error */
if (opts->mode_verbose)
parallel_print("Warning: <%s> is a dangling link.\n", path1);
H5TOOLS_GOTO_ERROR(H5DIFF_ERR, "dangling link is error");
}
else
is_dangle_link1 = TRUE;
}
/* target object2 - get type and name */
if ((status = H5tools_get_symlink_info(file2_id, path2, &linkinfo2, opts->follow_links)) < 0)
H5TOOLS_GOTO_ERROR(H5DIFF_ERR, "H5tools_get_symlink_info failed");
/* dangling link */
if (status == 0) {
if (opts->no_dangle_links) {
/* dangling link is error */
if (opts->mode_verbose)
parallel_print("Warning: <%s> is a dangling link.\n", path2);
H5TOOLS_GOTO_ERROR(H5DIFF_ERR, "dangling link is error");
}
else
is_dangle_link2 = TRUE;
}
/* found dangling link */
if (is_dangle_link1 || is_dangle_link2) {
H5TOOLS_GOTO_DONE(H5DIFF_NO_ERR);
}
/* follow symbolic link option */
if (opts->follow_links) {
if (linkinfo1.linfo.type == H5L_TYPE_SOFT || linkinfo1.linfo.type == H5L_TYPE_EXTERNAL)
argdata->type[0] = (h5trav_type_t)linkinfo1.trg_type;
if (linkinfo2.linfo.type == H5L_TYPE_SOFT || linkinfo2.linfo.type == H5L_TYPE_EXTERNAL)
argdata->type[1] = (h5trav_type_t)linkinfo2.trg_type;
}
}
/* if objects are not the same type */
if (argdata->type[0] != argdata->type[1]) {
H5TOOLS_DEBUG("diff objects are not the same");
if (opts->mode_verbose || opts->mode_list_not_cmp) {
parallel_print("Not comparable: <%s> is of type %s and <%s> is of type %s\n", path1,
get_type(argdata->type[0]), path2, get_type(argdata->type[1]));
}
opts->not_cmp = 1;
/* TODO: will need to update non-comparable is different
* opts->contents = 0;
*/
H5TOOLS_GOTO_DONE(H5DIFF_NO_ERR);
}
else /* now both object types are same */
object_type = argdata->type[0];
/*
* If both points to the same target object, skip comparing details inside
* of the objects to improve performance.
* Always check for the hard links, otherwise if follow symlink option is
* specified.
*
* Perform this to match the outputs as bypassing.
*/
if (argdata->is_same_trgobj) {
H5TOOLS_DEBUG("argdata->is_same_trgobj");
is_hard_link = (object_type == H5TRAV_TYPE_DATASET || object_type == H5TRAV_TYPE_NAMED_DATATYPE ||
object_type == H5TRAV_TYPE_GROUP);
if (opts->follow_links || is_hard_link) {
/* print information is only verbose option is used */
if (opts->mode_verbose || opts->mode_report) {
switch (object_type) {
case H5TRAV_TYPE_DATASET:
do_print_objname("dataset", path1, path2, opts);
break;
case H5TRAV_TYPE_NAMED_DATATYPE:
do_print_objname("datatype", path1, path2, opts);
break;
case H5TRAV_TYPE_GROUP:
do_print_objname("group", path1, path2, opts);
break;
case H5TRAV_TYPE_LINK:
do_print_objname("link", path1, path2, opts);
break;
case H5TRAV_TYPE_UDLINK:
if (linkinfo1.linfo.type == H5L_TYPE_EXTERNAL &&
linkinfo2.linfo.type == H5L_TYPE_EXTERNAL)
do_print_objname("external link", path1, path2, opts);
else
do_print_objname("user defined link", path1, path2, opts);
break;
case H5TRAV_TYPE_UNKNOWN:
default:
parallel_print("Comparison not supported: <%s> and <%s> are of type %s\n", path1,
path2, get_type(object_type));
opts->not_cmp = 1;
break;
} /* switch(type)*/
print_found(nfound);
} /* if(opts->mode_verbose || opts->mode_report) */
/* exact same, so comparison is done */
H5TOOLS_GOTO_DONE(H5DIFF_NO_ERR);
}
}
switch (object_type) {
/*----------------------------------------------------------------------
* H5TRAV_TYPE_DATASET
* This should be the princpal use case for this function.
* We may may also deal with links.
* NOTE: This particular function is ONLY called when we have identified
* the specific input object as a dataset which contain a moderately
* large number of elements (DEFAULT_LARGE_DSET_SIZE = 1M). The concern
* is two fold. 1) By utilizing parallelism, we can improve performance;
* and 2) The memory footprint utilized for processing the dataset
* is minimized. With regards to the latter, we also implement the
* strip mining approach used by serial version for large datasets.
*----------------------------------------------------------------------
*/
case H5TRAV_TYPE_DATASET:
if ((dset1_id = H5Dopen2(file1_id, path1, H5P_DEFAULT)) < 0)
H5TOOLS_GOTO_ERROR(H5DIFF_ERR, "H5Dopen2 failed");
if (h5tools_initialize_hyperslab_context(dset1_id, &hs_context1) < 0)
H5TOOLS_GOTO_ERROR(H5DIFF_ERR, "hyperslab_context failed");
if ((dset2_id = H5Dopen2(file2_id, path2, H5P_DEFAULT)) < 0)
H5TOOLS_GOTO_ERROR(H5DIFF_ERR, "H5Dopen2 failed");
if (h5tools_initialize_hyperslab_context(dset2_id, &hs_context2) < 0)
H5TOOLS_GOTO_ERROR(H5DIFF_ERR, "hyperslab_context failed");
f_tid1 = hs_context1->t_id;
f_tid2 = hs_context2->t_id;
/*-------------------------------------------------------------------------
* check for comparable TYPE and SPACE
*-------------------------------------------------------------------------
*/
if (diff_can_type(hs_context1->t_id, hs_context2->t_id, hs_context1->ds_rank,
hs_context2->ds_rank, hs_context1->dims, hs_context2->dims,
hs_context1->maxdims, hs_context2->maxdims, opts, 0) != 1)
can_compare = 0;
/*-------------------------------------------------------------------------
* memory type and sizes
*-------------------------------------------------------------------------
*/
if (H5Tget_class(hs_context1->t_id) == H5T_REFERENCE) {
if ((m_tid1 = H5Tcopy(H5T_STD_REF)) < 0)
H5TOOLS_GOTO_ERROR(H5DIFF_ERR, "H5Tcopy(H5T_STD_REF) first ftype failed");
}
else {
if ((m_tid1 = H5Tget_native_type(hs_context1->t_id, H5T_DIR_DEFAULT)) < 0)
H5TOOLS_GOTO_ERROR(H5DIFF_ERR, "H5Tget_native_type first ftype failed");
}
if (H5Tget_class(hs_context2->t_id) == H5T_REFERENCE) {
if ((m_tid2 = H5Tcopy(H5T_STD_REF)) < 0)
H5TOOLS_GOTO_ERROR(H5DIFF_ERR, "H5Tcopy(H5T_STD_REF) second ftype failed");
}
else {
if ((m_tid2 = H5Tget_native_type(hs_context2->t_id, H5T_DIR_DEFAULT)) < 0)
H5TOOLS_GOTO_ERROR(H5DIFF_ERR, "H5Tget_native_type second ftype failed");
}
m_size1 = H5Tget_size(m_tid1);
m_size2 = H5Tget_size(m_tid2);
H5TOOLS_DEBUG("type size: %ld - %ld", m_size1, m_size2);
/*-------------------------------------------------------------------------
* check for different signed/unsigned types
*-------------------------------------------------------------------------
*/
if (can_compare) {
H5TOOLS_DEBUG("can_compare for sign");
sign1 = H5Tget_sign(m_tid1);
sign2 = H5Tget_sign(m_tid2);
if (sign1 != sign2) {
H5TOOLS_DEBUG("sign1 != sign2");
if ((opts->mode_verbose || opts->mode_list_not_cmp) && path1 && path2) {
parallel_print("Not comparable: <%s> has sign %s ", path1, get_sign(sign1));
parallel_print("and <%s> has sign %s\n", path2, get_sign(sign2));
}
can_compare = 0;
opts->not_cmp = 1;
}
H5TOOLS_DEBUG("can_compare for sign - can_compare=%d opts->not_cmp=%d", can_compare,
opts->not_cmp);
}
/* Check if type is either VLEN-data or VLEN-string to reclaim any
* VLEN memory buffer later
*/
if (TRUE == h5tools_detect_vlen(m_tid1))
vl_data1 = TRUE;
if (TRUE == h5tools_detect_vlen(m_tid2))
vl_data2 = TRUE;
H5TOOLS_DEBUG("h5tools_detect_vlen %d:%d - errstat:%d", vl_data1, vl_data2, opts->err_stat);
/*------------------------------------------------------------------------
* only attempt to compare if possible
*-------------------------------------------------------------------------
*/
if (can_compare) { /* it is possible to compare */
hsize_t need;
hsize_t nelmts1 = hs_context1->hs_nelmts;
hsize_t nelmts2 = hs_context2->hs_nelmts;
int rank1 = hs_context1->ds_rank;
int rank2 = hs_context2->ds_rank;
hsize_t * dims1 = &hs_context1->dims[0];
hsize_t * dims2 = &hs_context1->dims[0];
H5T_class_t tclass = H5Tget_class(hs_context1->t_id);
if ((sid1 = H5Dget_space(dset1_id)) < 0)
H5TOOLS_GOTO_ERROR(H5DIFF_ERR, "H5Dget_space failed");
if ((sid2 = H5Dget_space(dset2_id)) < 0)
H5TOOLS_GOTO_ERROR(H5DIFF_ERR, "H5Dget_space failed");
if (tclass != H5T_ARRAY) {
/*-----------------------------------------------------------------
* "upgrade" the smaller memory size
*------------------------------------------------------------------
*/
H5TOOLS_DEBUG("NOT H5T_ARRAY, upgrade the smaller memory size?");
if (FAIL == match_up_memsize(f_tid1, f_tid2, &m_tid1, &m_tid2, &m_size1, &m_size2))
H5TOOLS_GOTO_ERROR(H5DIFF_ERR, "match_up_memsize failed");
H5TOOLS_DEBUG("m_size: %ld - %ld", m_size1, m_size2);
opts->rank = rank1;
for (i = 0; i < rank1; i++)
opts->dims[i] = dims1[i];
opts->m_size = m_size1;
opts->m_tid = m_tid1;
opts->nelmts = nelmts1;
need = (size_t)(nelmts1 * m_size1); /* bytes needed */
}
else {
H5TOOLS_DEBUG("Array dims: %d - %d", dims1[0], dims2[0]);
/* Compare the smallest array, but create the largest buffer */
if (m_size1 <= m_size2) {
opts->rank = rank1;
for (i = 0; i < rank1; i++)
opts->dims[i] = dims1[i];
opts->m_size = m_size1;
opts->m_tid = m_tid1;
opts->nelmts = nelmts1;
need = (size_t)(nelmts2 * m_size2); /* bytes needed */
}
else {
opts->rank = rank2;
for (i = 0; i < rank2; i++)
opts->dims[i] = dims2[i];
opts->m_size = m_size2;
opts->m_tid = m_tid2;
opts->nelmts = nelmts2;
need = (size_t)(nelmts1 * m_size1); /* bytes needed */
}
}
opts->hs_nelmts = opts->nelmts;
/*----------------------------------------------------------------
* read/compare
*-----------------------------------------------------------------
*/
if (need < H5TOOLS_MALLOCSIZE) {
buf1 = HDmalloc(need);
buf2 = HDmalloc(need);
} /* end if */
/* Assume entire data space to be printed */
init_acc_pos((unsigned)opts->rank, opts->dims, opts->acc, opts->pos, opts->p_min_idx);
for (i = 0; i < opts->rank; i++) {
opts->p_max_idx[i] = opts->dims[i];
}
if (buf1 != NULL && buf2 != NULL && opts->sset[0] == NULL && opts->sset[1] == NULL) {
H5TOOLS_DEBUG("buf1 != NULL && buf2 != NULL");
H5TOOLS_DEBUG("H5Dread did1");
if (H5Dread(dset1_id, m_tid1, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf1) < 0)
H5TOOLS_GOTO_ERROR(H5DIFF_ERR, "H5Dread failed");
H5TOOLS_DEBUG("H5Dread did2");
if (H5Dread(dset2_id, m_tid2, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf2) < 0)
H5TOOLS_GOTO_ERROR(H5DIFF_ERR, "H5Dread failed");
/* initialize the current stripmine position; this is necessary to print the array indices
*/
for (j = 0; j < opts->rank; j++)
opts->sm_pos[j] = (hsize_t)0;
/* array diff */
nfound = diff_array(buf1, buf2, opts, dset1_id, dset2_id);
H5TOOLS_DEBUG("diff_array ret nfound:%d - errstat:%d", nfound, opts->err_stat);
/* reclaim any VL memory, if necessary */
H5TOOLS_DEBUG("check vl_data1:%d", vl_data1);
if (vl_data1)
H5Treclaim(m_tid1, sid1, H5P_DEFAULT, buf1);
H5TOOLS_DEBUG("check vl_data2:%d", vl_data2);
if (vl_data2)
H5Treclaim(m_tid2, sid2, H5P_DEFAULT, buf2);
if (buf1 != NULL) {
HDfree(buf1);
buf1 = NULL;
}
if (buf2 != NULL) {
HDfree(buf2);
buf2 = NULL;
}
} /* end if */
else { /* possibly not enough memory, read/compare by hyperslabs */
hsize_t elmtno; /* counter */
int carry; /* counter carry value */
/* stripmine info */
hsize_t sm_size[H5S_MAX_RANK]; /* stripmine size */
hsize_t sm_block[H5S_MAX_RANK]; /* stripmine block size */
hsize_t sm_nbytes; /* bytes per stripmine */
hsize_t sm_nelmts1; /* elements per stripmine */
hsize_t sm_nelmts2; /* elements per stripmine */
hsize_t ssm_limit;
hsize_t ssm_remaining;
hssize_t ssm_nelmts; /* elements temp */
/* hyperslab info */
hsize_t hs_offset1[H5S_MAX_RANK]; /* starting offset */
hsize_t hs_count1[H5S_MAX_RANK]; /* number of blocks */
hsize_t hs_block1[H5S_MAX_RANK]; /* size of blocks */
hsize_t hs_stride1[H5S_MAX_RANK]; /* stride */
hsize_t hs_size1[H5S_MAX_RANK]; /* size this pass */
hsize_t hs_offset2[H5S_MAX_RANK]; /* starting offset */
hsize_t hs_count2[H5S_MAX_RANK]; /* number of blocks */
hsize_t hs_block2[H5S_MAX_RANK]; /* size of blocks */
hsize_t hs_stride2[H5S_MAX_RANK]; /* stride */
hsize_t hs_size2[H5S_MAX_RANK]; /* size this pass */
hsize_t hs_nelmts1 = 0; /* elements in request */
hsize_t hs_nelmts2 = 0; /* elements in request */
hsize_t hs_extra1; /* temp for strip mining */
hsize_t zero[8]; /* vector of zeros */
hsize_t low[H5S_MAX_RANK]; /* low bound of hyperslab */
hsize_t high[H5S_MAX_RANK]; /* higher bound of hyperslab */
H5TOOLS_DEBUG("reclaim any VL memory and free unused buffers");
if (buf1 != NULL) {
/* reclaim any VL memory, if necessary */
if (vl_data1)
H5Treclaim(m_tid1, sid1, H5P_DEFAULT, buf1);
HDfree(buf1);
buf1 = NULL;
}
if (buf2 != NULL) {
/* reclaim any VL memory, if necessary */
if (vl_data2)
H5Treclaim(m_tid2, sid2, H5P_DEFAULT, buf2);
HDfree(buf2);
buf2 = NULL;
}
/* the stripmine loop */
HDmemset(hs_offset1, 0, sizeof hs_offset1);
HDmemset(hs_stride1, 0, sizeof hs_stride1);
HDmemset(hs_count1, 0, sizeof hs_count1);
HDmemset(hs_block1, 0, sizeof hs_block1);
HDmemset(hs_size1, 0, sizeof hs_size1);
HDmemset(hs_offset2, 0, sizeof hs_offset2);
HDmemset(hs_stride2, 0, sizeof hs_stride2);
HDmemset(hs_count2, 0, sizeof hs_count2);
HDmemset(hs_block2, 0, sizeof hs_block2);
HDmemset(hs_size2, 0, sizeof hs_size2);
HDmemset(zero, 0, sizeof zero);
for (i = 0; i < hs_context1->ds_rank; i++) {
hs_offset1[i] = hs_context1->hs_offset[i];
hs_offset2[i] = hs_context2->hs_offset[i];
}
/* IF subsetting was requested - initialize the subsetting variables */
/* CAUTION!! I haven't verified this portion of the code for parallel execution!
* It is my belief that the user subsetting specification doesn't account for
* parallelism and thus the approach here, should probably be done by a single
* rank. In particular, our parallel assumptions might be unjustfied since
* the subsetting was NOT accounted for when sizing the dataset vs. the
* size limit over which, we feel justified for multiple MPI ranks to share
* the work.
*
* [RAW] December 2021
*/
H5TOOLS_DEBUG("compare by hyperslabs: opts->nelmts=%ld - opts->m_size=%ld", opts->nelmts,
opts->m_size);
if (opts->sset[0] != NULL) {
H5TOOLS_DEBUG("opts->sset[0] != NULL");
/* Check for valid settings - default if not specified */
if (!opts->sset[0]->start.data || !opts->sset[0]->stride.data ||
!opts->sset[0]->count.data || !opts->sset[0]->block.data) {
/* they didn't specify a ``stride'' or ``block''. default to 1 in all
* dimensions */
if (!opts->sset[0]->start.data) {
/* default to (0, 0, ...) for the start coord */
opts->sset[0]->start.data =
(hsize_t *)HDcalloc((size_t)rank1, sizeof(hsize_t));
opts->sset[0]->start.len = (unsigned)rank1;
}
if (!opts->sset[0]->stride.data) {
opts->sset[0]->stride.data =
(hsize_t *)HDcalloc((size_t)rank1, sizeof(hsize_t));
opts->sset[0]->stride.len = (unsigned)rank1;
for (i = 0; i < rank1; i++)
opts->sset[0]->stride.data[i] = 1;
}
if (!opts->sset[0]->count.data) {
opts->sset[0]->count.data =
(hsize_t *)HDcalloc((size_t)rank1, sizeof(hsize_t));
opts->sset[0]->count.len = (unsigned)rank1;
for (i = 0; i < rank1; i++)
opts->sset[0]->count.data[i] = 1;
}
if (!opts->sset[0]->block.data) {
opts->sset[0]->block.data =
(hsize_t *)HDcalloc((size_t)rank1, sizeof(hsize_t));
opts->sset[0]->block.len = (unsigned)rank1;
for (i = 0; i < rank1; i++)
opts->sset[0]->block.data[i] = 1;
}
/*-------------------------------------------------------------------------
* check for block overlap
*-------------------------------------------------------------------------
*/
for (i = 0; i < rank1; i++) {
if (opts->sset[0]->count.data[i] > 1) {
if (opts->sset[0]->stride.data[i] < opts->sset[0]->block.data[i]) {
H5TOOLS_GOTO_ERROR(H5DIFF_ERR,
"wrong subset selection[0]; blocks overlap");
} /* end if */
} /* end if */
} /* end for */
}
/* Reset the total number of elements to the subset from the command */
opts->nelmts = 1;
for (i = 0; i < rank1; i++) {
hs_offset1[i] = opts->sset[0]->start.data[i];
hs_stride1[i] = opts->sset[0]->stride.data[i];
hs_count1[i] = opts->sset[0]->count.data[i];
hs_block1[i] = opts->sset[0]->block.data[i];
opts->nelmts *= hs_count1[i] * hs_block1[i];
hs_size1[i] = 0;
H5TOOLS_DEBUG("[%d]hs_offset1:%ld, hs_stride1:%ld, hs_count1:%ld, hs_block1:%ld",
i, hs_offset1[i], hs_stride1[i], hs_count1[i], hs_block1[i]);
}
}
if (opts->sset[1] != NULL) {
H5TOOLS_DEBUG("opts->sset[1] != NULL");
/* Check for valid settings - default if not specified */
if (!opts->sset[1]->start.data || !opts->sset[1]->stride.data ||
!opts->sset[1]->count.data || !opts->sset[1]->block.data) {
/* they didn't specify a ``stride'' or ``block''. default to 1 in all
* dimensions */
if (!opts->sset[1]->start.data) {
/* default to (0, 0, ...) for the start coord */
opts->sset[1]->start.data =
(hsize_t *)HDcalloc((size_t)rank2, sizeof(hsize_t));
opts->sset[1]->start.len = (unsigned)rank2;
}
if (!opts->sset[1]->stride.data) {
opts->sset[1]->stride.data =
(hsize_t *)HDcalloc((size_t)rank2, sizeof(hsize_t));
opts->sset[1]->stride.len = (unsigned)rank2;
for (i = 0; i < rank2; i++)
opts->sset[1]->stride.data[i] = 1;
}
if (!opts->sset[1]->count.data) {
opts->sset[1]->count.data =
(hsize_t *)HDcalloc((size_t)rank2, sizeof(hsize_t));
opts->sset[1]->count.len = (unsigned)rank2;
for (i = 0; i < rank2; i++)
opts->sset[1]->count.data[i] = 1;
}
if (!opts->sset[1]->block.data) {
opts->sset[1]->block.data =
(hsize_t *)HDcalloc((size_t)rank2, sizeof(hsize_t));
opts->sset[1]->block.len = (unsigned)rank2;
for (i = 0; i < rank2; i++)
opts->sset[1]->block.data[i] = 1;
}
/*-------------------------------------------------------------------------
* check for block overlap
*-------------------------------------------------------------------------
*/
for (i = 0; i < rank2; i++) {
if (opts->sset[1]->count.data[i] > 1) {
if (opts->sset[1]->stride.data[i] < opts->sset[1]->block.data[i]) {
H5TOOLS_GOTO_ERROR(H5DIFF_ERR,
"wrong subset selection[1]; blocks overlap");
} /* end if */
} /* end if */
} /* end for */
}
for (i = 0; i < rank2; i++) {
hs_offset2[i] = opts->sset[1]->start.data[i];
hs_stride2[i] = opts->sset[1]->stride.data[i];
hs_count2[i] = opts->sset[1]->count.data[i];
hs_block2[i] = opts->sset[1]->block.data[i];
hs_size2[i] = 0;
H5TOOLS_DEBUG("[%d]hs_offset2:%ld, hs_stride2:%ld, hs_count2:%ld, hs_block2:%ld",
i, hs_offset2[i], hs_stride2[i], hs_count2[i], hs_block2[i]);
}
} /* End subsetting */
/*
* determine the strip mine size and allocate a buffer. The strip mine is
* a hyperslab whose size is manageable.
*/
if (opts->mode_verbose || opts->mode_report) {
if (hs_context1->mpi_rank == 0)
do_print_objname("dataset", path1, path2, opts);
}
sm_nbytes = opts->m_size;
for (i = 0; i < hs_context1->ds_rank; i++) {
hs_block1[i] = hs_context1->hs_block[i];
hs_block2[i] = hs_context2->hs_block[i];
}
if (opts->rank > 0) {
for (i = hs_context1->ds_rank; i > 0; --i) {
hsize_t size = H5TOOLS_BUFSIZE / sm_nbytes;
if (size == 0) /* datum size > H5TOOLS_BUFSIZE */
size = 1;
H5TOOLS_DEBUG("opts->dims[%d]: %ld - size: %ld", i - 1, opts->dims[i - 1], size);
if (opts->sset[1] != NULL) {
sm_size[i - 1] = MIN(hs_block1[i - 1] * hs_count1[i - 1], size);
sm_block[i - 1] = MIN(hs_block1[i - 1], sm_size[i - 1]);
}
else {
sm_size[i - 1] = MIN(hs_context1->hs_block[i - 1], size);
sm_block[i - 1] = sm_size[i - 1];
}
H5TOOLS_DEBUG("sm_size[%d]: %ld - sm_block:%ld", i - 1, sm_size[i - 1],
sm_block[i - 1]);
sm_nbytes *= sm_size[i - 1];
H5TOOLS_DEBUG("sm_nbytes: %ld", sm_nbytes);
}
}
H5TOOLS_DEBUG("opts->nelmts: %ld", opts->nelmts);
hs_nelmts1 = sm_nbytes / hs_context1->dt_size;
ssm_limit = hs_nelmts1 * 2;
for (elmtno = 0; elmtno < opts->nelmts; elmtno += hs_nelmts1) {
H5TOOLS_DEBUG("elmtno: %ld - hs_nelmts1: %ld", elmtno, hs_nelmts1);
ssm_remaining = opts->nelmts - elmtno;
if (ssm_remaining < ssm_limit) {
hsize_t elmts_per_row = 1;
hsize_t extra_rows;
hs_nelmts1 = sm_nbytes / hs_context1->dt_size;
hs_extra1 = ssm_remaining - hs_nelmts1;
for (i = 1; i < opts->rank; i++)
elmts_per_row *= sm_block[i];
extra_rows = hs_extra1 / elmts_per_row;
sm_nbytes += (extra_rows * elmts_per_row);
sm_block[0] += extra_rows;
hs_block1[0] += extra_rows;
hs_block2[0] += extra_rows;
}
if (NULL == (sm_buf1 = (unsigned char *)HDmalloc((size_t)sm_nbytes)))
H5TOOLS_GOTO_ERROR(H5DIFF_ERR, "Could not allocate buffer for strip-mine");
if (NULL == (sm_buf2 = (unsigned char *)HDmalloc((size_t)sm_nbytes)))
H5TOOLS_GOTO_ERROR(H5DIFF_ERR, "Could not allocate buffer for strip-mine");
/* calculate the hyperslab size */
/* initialize subset */
if (opts->rank > 0) {
if (opts->sset[0] != NULL) {
H5TOOLS_DEBUG("sset1 has data");
/* calculate the potential number of elements */
for (i = 0; i < rank1; i++) {
H5TOOLS_DEBUG("[%d]opts->dims: %ld - hs_offset1: %ld - sm_block: %ld", i,
opts->dims[i], hs_offset1[i], sm_block[i]);
hs_size1[i] = MIN(opts->dims[i] - hs_offset1[i], sm_block[i]);
H5TOOLS_DEBUG("hs_size1[%d]: %ld", i, hs_size1[i]);
}
if (H5Sselect_hyperslab(sid1, H5S_SELECT_SET, hs_offset1, hs_stride1,
hs_count1, hs_size1) < 0)
H5TOOLS_GOTO_ERROR(H5DIFF_ERR, "H5Sselect_hyperslab sid1 failed");
}
else {
for (i = 0, hs_nelmts1 = 1; i < rank1; i++) {
/* Use the hyperslab context values rather than the serial hyperslab
* implementation (opts->xxx values)
*/
H5TOOLS_DEBUG("[%d]opts->dims: %ld - hs_offset1: %ld - sm_block: %ld", i,
opts->dims[i], hs_offset1[i], sm_block[i]);
hs_size1[i] = MIN(hs_block1[i] - hs_offset1[i], sm_block[i]);
H5TOOLS_DEBUG("hs_size1[%d]: %ld", i, hs_size1[i]);
hs_nelmts1 *= hs_size1[i];
H5TOOLS_DEBUG("hs_nelmts1:%ld *= hs_size1[%d]: %ld", hs_nelmts1, i,
hs_size1[i]);
}
if (H5Sselect_hyperslab(sid1, H5S_SELECT_SET, hs_offset1, NULL, hs_size1,
NULL) < 0)
H5TOOLS_GOTO_ERROR(H5DIFF_ERR, "H5Sselect_hyperslab sid1 failed");
}
if ((ssm_nelmts = H5Sget_select_npoints(sid1)) < 0)
H5TOOLS_GOTO_ERROR(H5DIFF_ERR, "H5Sget_select_npoints failed");
sm_nelmts1 = (hsize_t)ssm_nelmts;
H5TOOLS_DEBUG("sm_nelmts1: %ld", sm_nelmts1);
hs_nelmts1 = sm_nelmts1;
if ((sm_space1 = H5Screate_simple(1, &sm_nelmts1, NULL)) < 0)
H5TOOLS_GOTO_ERROR(H5DIFF_ERR, "H5Screate_simple failed");
if (H5Sselect_hyperslab(sm_space1, H5S_SELECT_SET, zero, NULL, &sm_nelmts1,
NULL) < 0)
H5TOOLS_GOTO_ERROR(H5DIFF_ERR, "H5Sselect_hyperslab failed");
if (opts->sset[1] != NULL) {
H5TOOLS_DEBUG("sset2 has data");
for (i = 0; i < rank2; i++) {
H5TOOLS_DEBUG("[%d]opts->dims: %ld - hs_offset2: %ld - sm_block: %ld", i,
opts->dims[i], hs_offset2[i], sm_block[i]);
hs_size2[i] = MIN(opts->dims[i] - hs_offset2[i], sm_block[i]);
H5TOOLS_DEBUG("hs_size2[%d]: %ld", i, hs_size2[i]);
}
if (H5Sselect_hyperslab(sid2, H5S_SELECT_SET, hs_offset2, hs_stride2,
hs_count2, hs_size2) < 0)
H5TOOLS_GOTO_ERROR(H5DIFF_ERR, "H5Sselect_hyperslab sid2 failed");
}
else {
for (i = 0, hs_nelmts2 = 1; i < rank2; i++) {
/* Use the hyperslab context values rather than the serial hyperslab
* implementation (opts->xxx values)
*/
H5TOOLS_DEBUG("[%d]opts->dims: %ld - hs_offset2: %ld - sm_block: %ld", i,
opts->dims[i], hs_offset2[i], sm_block[i]);
hs_size2[i] = MIN(hs_block2[i] - hs_offset2[i], sm_block[i]);
H5TOOLS_DEBUG("hs_size2[%d]: %ld", i, hs_size2[i]);
hs_nelmts2 *= hs_size2[i];
H5TOOLS_DEBUG("hs_nelmts2:%ld *= hs_size2[%d]: %ld", hs_nelmts2, i,
hs_size2[i]);
}
if (H5Sselect_hyperslab(sid2, H5S_SELECT_SET, hs_offset2, NULL, hs_size2,
NULL) < 0)
H5TOOLS_GOTO_ERROR(H5DIFF_ERR, "H5Sselect_hyperslab sid2 failed");
}
if ((ssm_nelmts = H5Sget_select_npoints(sid2)) < 0)
H5TOOLS_GOTO_ERROR(H5DIFF_ERR, "H5Sget_select_npoints failed");
sm_nelmts2 = (hsize_t)ssm_nelmts;
H5TOOLS_DEBUG("sm_nelmts2: %ld", sm_nelmts2);
hs_nelmts2 = sm_nelmts2;
if ((sm_space2 = H5Screate_simple(1, &sm_nelmts2, NULL)) < 0)
H5TOOLS_GOTO_ERROR(H5DIFF_ERR, "H5Screate_simple failed");
if (H5Sselect_hyperslab(sm_space2, H5S_SELECT_SET, zero, NULL, &sm_nelmts2,
NULL) < 0)
H5TOOLS_GOTO_ERROR(H5DIFF_ERR, "H5Sselect_hyperslab failed");
}
else
hs_nelmts1 = 1;
opts->hs_nelmts = hs_nelmts1;
H5TOOLS_DEBUG("hs_nelmts: %ld", opts->hs_nelmts);
/* read the data */
if (H5Dread(dset1_id, m_tid1, sm_space1, sid1, H5P_DEFAULT, sm_buf1) < 0)
H5TOOLS_GOTO_ERROR(H5DIFF_ERR, "H5Dread failed");
if (H5Dread(dset2_id, m_tid2, sm_space2, sid2, H5P_DEFAULT, sm_buf2) < 0)
H5TOOLS_GOTO_ERROR(H5DIFF_ERR, "H5Dread failed");
/* print array indices. get the lower bound of the hyperslab and calculate
the element position at the start of hyperslab */
if (H5Sget_select_bounds(sid1, low, high) < 0)
H5TOOLS_GOTO_ERROR(H5DIFF_ERR, "H5Sget_select_bounds failed");
/* initialize the current stripmine position; this is necessary to print the array
* indices */
for (j = 0; j < opts->rank; j++)
opts->sm_pos[j] = low[j];
/* Assume entire data space to be printed */
init_acc_pos((unsigned)opts->rank, opts->dims, opts->acc, opts->pos, opts->p_min_idx);
/* get array differences. in the case of hyperslab read, increment the number of
differences found in each hyperslab and pass the position at the beginning for
printing */
nfound += diff_array(sm_buf1, sm_buf2, opts, dset1_id, dset2_id);
if (sm_buf1 != NULL) {
/* reclaim any VL memory, if necessary */
if (vl_data1)
H5Treclaim(m_tid1, sm_space1, H5P_DEFAULT, sm_buf1);
HDfree(sm_buf1);
sm_buf1 = NULL;
}
if (sm_buf2 != NULL) {
/* reclaim any VL memory, if necessary */
if (vl_data2)
H5Treclaim(m_tid2, sm_space2, H5P_DEFAULT, sm_buf2);
HDfree(sm_buf2);
sm_buf2 = NULL;
}
H5Sclose(sm_space1);
H5Sclose(sm_space2);
/* calculate the next hyperslab offset */
for (i = opts->rank, carry = 1; i > 0 && carry; --i) {
if (opts->sset[0] != NULL) {
H5TOOLS_DEBUG("[%d]hs_size1:%ld - hs_block1:%ld - hs_stride1:%ld", i - 1,
hs_size1[i - 1], hs_block1[i - 1], hs_stride1[i - 1]);
if (hs_size1[i - 1] >= hs_block1[i - 1]) {
hs_offset1[i - 1] += hs_size1[i - 1];
}
else {
hs_offset1[i - 1] += hs_stride1[i - 1];
}
}
else
hs_offset1[i - 1] += hs_size1[i - 1];
H5TOOLS_DEBUG("[%d]hs_offset1:%ld - opts->dims:%ld", i - 1, hs_offset1[i - 1],
opts->dims[i - 1]);
if (hs_offset1[i - 1] >= opts->dims[i - 1])
hs_offset1[i - 1] = 0;
else
carry = 0;
H5TOOLS_DEBUG("[%d]hs_offset1:%ld", i - 1, hs_offset1[i - 1]);
if (opts->sset[1] != NULL) {
H5TOOLS_DEBUG("[%d]hs_size2:%ld - hs_block2:%ld - hs_stride2:%ld", i - 1,
hs_size2[i - 1], hs_block2[i - 1], hs_stride2[i - 1]);
if (hs_size2[i - 1] >= hs_block2[i - 1]) {
hs_offset2[i - 1] += hs_size2[i - 1];
}
else {
hs_offset2[i - 1] += hs_stride2[i - 1];
}
}
else
hs_offset2[i - 1] += hs_size2[i - 1];
H5TOOLS_DEBUG("[%d]hs_offset2:%ld - opts->dims:%ld", i - 1, hs_offset2[i - 1],
opts->dims[i - 1]);
if (hs_offset2[i - 1] >= opts->dims[i - 1])
hs_offset2[i - 1] = 0;
H5TOOLS_DEBUG("[%d]hs_offset2:%ld", i - 1, hs_offset2[i - 1]);
}
} /* elmtno for loop */
} /* hyperslab read */
H5TOOLS_DEBUG("can compare complete");
} /*can_compare*/
H5E_BEGIN_TRY
{
H5Sclose(sid1);
H5Sclose(sid2);
H5Sclose(sm_space1);
H5Sclose(sm_space2);
H5Pclose(hs_context1->dcpl);
H5Pclose(hs_context2->dcpl);
H5Tclose(f_tid1);
H5Tclose(f_tid2);
H5Tclose(m_tid1);
H5Tclose(m_tid2);
/* enable error reporting */
}
H5E_END_TRY;
HDfree(hs_context1);
HDfree(hs_context2);
break;
/*----------------------------------------------------------------------
* H5TRAV_TYPE_LINK
*----------------------------------------------------------------------
*/
case H5TRAV_TYPE_LINK: {
H5TOOLS_DEBUG("H5TRAV_TYPE_LINK 1:%s 2:%s ", path1, path2);
status = HDstrcmp(linkinfo1.trg_path, linkinfo2.trg_path);
/* if the target link name is not same then the links are "different" */
nfound = (status != 0) ? 1 : 0;
if (print_objname(opts, nfound))
do_print_objname("link", path1, path2, opts);
/* always print the number of differences found in verbose mode */
if (opts->mode_verbose)
print_found(nfound);
} break;
/*----------------------------------------------------------------------
* H5TRAV_TYPE_UDLINK
*----------------------------------------------------------------------
*/
case H5TRAV_TYPE_UDLINK: {
H5TOOLS_DEBUG("H5TRAV_TYPE_UDLINK 1:%s 2:%s ", path1, path2);
/* Only external links will have a query function registered */
if (linkinfo1.linfo.type == H5L_TYPE_EXTERNAL && linkinfo2.linfo.type == H5L_TYPE_EXTERNAL) {
/* If the buffers are the same size, compare them */
if (linkinfo1.linfo.u.val_size == linkinfo2.linfo.u.val_size) {
status = HDmemcmp(linkinfo1.trg_path, linkinfo2.trg_path, linkinfo1.linfo.u.val_size);
}
else
status = 1;
/* if "linkinfo1.trg_path" != "linkinfo2.trg_path" then the links
* are "different" extlinkinfo#.path is combination string of
* file_name and obj_name
*/
nfound = (status != 0) ? 1 : 0;
if (print_objname(opts, nfound))
do_print_objname("external link", path1, path2, opts);
} /* end if */
else {
/* If one or both of these links isn't an external link, we can only
* compare information from H5Lget_info since we don't have a query
* function registered for them.
*
* If the link classes or the buffer length are not the
* same, the links are "different"
*/
if ((linkinfo1.linfo.type != linkinfo2.linfo.type) ||
(linkinfo1.linfo.u.val_size != linkinfo2.linfo.u.val_size))
nfound = 1;
else
nfound = 0;
if (print_objname(opts, nfound))
do_print_objname("user defined link", path1, path2, opts);
} /* end else */
/* always print the number of differences found in verbose mode */
if (opts->mode_verbose)
print_found(nfound);
} break;
case H5TRAV_TYPE_UNKNOWN:
default:
if (opts->mode_verbose)
parallel_print("Comparison not supported: <%s> and <%s> are of type %s\n", path1, path2,
get_type(object_type));
opts->not_cmp = 1;
break;
}
done:
opts->err_stat = opts->err_stat | ret_value;
return nfound;
} /* end hyperslab_pdiff() */
/*-------------------------------------------------------------------------
* Function: check_dataset_sizes
*
* Purpose: Compare dataset sizes to a known size limit. If the size
* exceeds the limit then the dataset is marked for utilizing
* hyperslabs to subdivide the diff operation between parallel
* ranks.
*
* TODO: Maybe we should also be checking link objects which
* in turn could point to a dataset?
* Return: none
*-------------------------------------------------------------------------
*/
static int
check_dataset_sizes(hid_t fidin, trav_table_t *travt)
{
size_t i;
hsize_t dims[H5S_MAX_RANK]; /* dimensions of dataset */
static size_t large_dset_size = 0;
int j, ret_value = 0;
if (large_dset_size == 0) {
char *envValue;
if ((envValue = HDgetenv("H5_PARALLEL_DSET_SIZE")) != NULL) {
size_t value_check = (size_t)HDatol(envValue);
if (value_check > 0) {
large_dset_size = value_check;
}
}
else
large_dset_size = DEFAULT_LARGE_DSET_SIZE;
}
for (i = 0; i < travt->nobjs; i++) {
if (travt->objs[i].type == H5TRAV_TYPE_DATASET) {
size_t nelmts;
int rank;
hid_t dset_in = H5I_INVALID_HID;
hid_t f_space_id = H5I_INVALID_HID;
if ((dset_in = H5Dopen2(fidin, travt->objs[i].name, H5P_DEFAULT)) < 0)
H5TOOLS_GOTO_ERROR((-1), "H5Dopen2 failed");
if ((f_space_id = H5Dget_space(dset_in)) < 0)
H5TOOLS_GOTO_ERROR((-1), "H5Dget_space failed");
if ((rank = H5Sget_simple_extent_ndims(f_space_id)) < 0)
H5TOOLS_GOTO_ERROR((-1), "H5Sget_simple_extent_ndims failed");
H5Sget_simple_extent_dims(f_space_id, dims, NULL);
nelmts = 1;
for (j = 0; j < rank; j++)
nelmts *= dims[j];
if (nelmts >= large_dset_size)
travt->objs[i].use_hyperslab = true;
if (H5Sclose(f_space_id) < 0)
H5TOOLS_GOTO_ERROR((-1), "H5Sclose failed");
if (H5Dclose(dset_in) < 0)
H5TOOLS_GOTO_ERROR((-1), "H5Dclose failed");
}
}
done:
return ret_value;
}
static int
compare_objIDs(const void *h1, const void *h2)
{
const print_objs_t *obj1 = (const print_objs_t *)h1;
const print_objs_t *obj2 = (const print_objs_t *)h2;
return (obj1->obj_idx > obj2->obj_idx);
}
/*-------------------------------------------------------------------------
* Function: phdiff_gather_diffs
*
* Purpose: print all saved buffers
*
* Return: none
*-------------------------------------------------------------------------
*/
static void
ph5diff_gather_diffs(void)
{
int mpi_rank, mpi_size;
int total_bytes = 0, total_diff_count = 0;
int k, my_size = (int)((local_diff_total > 0) ? (int)local_diff_total + rank_diff_count : 0);
int send_offset = 0;
int local_counts[2] = {(int)my_size, rank_diff_count};
int * recvcounts = NULL;
int * recvtuples = NULL;
int * rankIDs = NULL;
int * displs = NULL;
int * indices = NULL;
int * next = NULL;
char *sendbuf = NULL;
char *recvbuf = NULL;
MPI_Comm_rank(MPI_COMM_WORLD, &mpi_rank);
MPI_Comm_size(MPI_COMM_WORLD, &mpi_size);
if (mpi_rank == 0) {
displs = (int *)malloc((size_t)((size_t)mpi_size * sizeof(int)));
recvcounts = (int *)malloc((size_t)((size_t)mpi_size * sizeof(int)));
recvtuples = (int *)malloc((size_t)((size_t)mpi_size * 2 * sizeof(int)));
}
MPI_Gather(local_counts, 2, MPI_INT, recvtuples, 2, MPI_INT, 0, MPI_COMM_WORLD);
/* Maybe create a contiguous buffer to send to the root */
if (rank_diff_count > 1) {
int len;
rankIDs = (int *)malloc((size_t)((size_t)rank_diff_count * sizeof(int)));
sendbuf = (char *)malloc((size_t)((size_t)local_diff_total + (size_t)rank_diff_count));
memset(sendbuf, 0, local_diff_total + (size_t)rank_diff_count);
for (k = 0; k < rank_diff_count; k++) {
if ((len = (int)rank_diffs[k]->outbuffoffset) > 0) {
strncpy(&sendbuf[send_offset], rank_diffs[k]->outbuff, (size_t)len);
send_offset += len;
sendbuf[send_offset++] = 0; /* Null terminiate the text */
}
rankIDs[k] = rank_diffs[k]->obj_idx;
}
}
else if (rank_diff_count > 0) {
rankIDs = (int *)malloc((size_t)rank_diff_count * sizeof(int));
rankIDs[0] = rank_diffs[0]->obj_idx;
/* If ONLY a single outbuff, then use it rather than malloc and copy */
sendbuf = rank_diffs[0]->outbuff;
}
/*------------------------------------------------------------
* RECVTUPLES:
* Each tuple contains:
* 0: size (in bytes) of the diff message
* 1: Number of diff messages packed into the diff message
*
* +-------+-------+-------~+-------+
* | rank0 | rank0 | rank0 ~ rankN |
* +-------+-------+-------~+-------+
* | 0 1 2 3 4 5 ... |
* +-------+-------+-------~+-------+
*
* We utilize the size portion from each tuple to flag
* valid object IDs
*------------------------------------------------------------
*/
if (mpi_rank == 0) {
int prevdisp = 0;
int prevrecv = 0;
next = (int *)recvtuples;
displs[0] = 0;
for (k = 0; k < mpi_size; k++) {
recvcounts[k] = next[0]; /* tuple[k,0] (length of diff text) */
total_diff_count += next[1]; /* tuple[k,1] (number of diffs (always 1 or more)) */
total_bytes += recvcounts[k];
displs[k] = prevdisp + prevrecv;
prevdisp = displs[k];
prevrecv = recvcounts[k];
next += 2;
}
if (total_bytes > 0) {
recvbuf = (char *)malloc((size_t)(total_bytes));
memset(recvbuf, 0, (size_t)total_bytes);
}
else
recvbuf = (char *)calloc((size_t)mpi_size, 1);
}
MPI_Gatherv(sendbuf, my_size, MPI_CHAR, recvbuf, recvcounts, displs, MPI_CHAR, 0, MPI_COMM_WORLD);
/* The 'recvcounts' and 'displs' variables can be reallocated
* for the next MPI_Gatherv operation...
*/
if (mpi_rank == 0) {
next = (int *)recvtuples;
displs = (int *)realloc(displs, (size_t)((size_t)total_diff_count * sizeof(int)));
recvcounts = (int *)realloc(recvcounts, (size_t)((size_t)total_diff_count * sizeof(int)));
indices = (int *)malloc((size_t)total_diff_count * sizeof(int));
memset(indices, 0, ((size_t)total_diff_count * sizeof(int)));
displs[0] = 0;
recvcounts[0] = rank_diff_count;
next += 2;
for (k = 1; k < mpi_size; k++) {
recvcounts[k] = next[1];
displs[k] = displs[k - 1] + recvcounts[k - 1];
next += 2;
}
}
/*------------------------------------------------------------
* At this point, the root has received all of the diff messages
* from the MPI ranks into a single 'recvbuf'. Since each
* rank specific sendbuf message consists of 1 or more object
* differences, the root needs to extract each diff string in
* the order it would have been printed by the serial version
* (h5diff).
* To aid that process, each MPI rank sends 1 or more
* count values to the root which further describe the sub
* components of their previously sent diff message.
* We also reference the original tuples which tell us
* whether an MPI rank contains any diff text to print
* even though EVERY rank has an initial diff allocation
* (index 0). In many/most cases these index 0 instances
* don't contain any diff text that requires printing.
*------------------------------------------------------------
*/
MPI_Gatherv(rankIDs, rank_diff_count, MPI_INT, indices, recvcounts, displs, MPI_INT, 0, MPI_COMM_WORLD);
if (mpi_rank == 0) {
int nexti = 0;
int * nextTuple = recvtuples;
char * nextdiff = recvbuf;
print_objs_t *ordered_objs = (print_objs_t *)HDcalloc((size_t)total_diff_count, sizeof(print_objs_t));
for (k = 0; k < total_diff_count; k++) {
ordered_objs[k].obj_idx = indices[k];
ordered_objs[k].obj_len = nextTuple[0];
ordered_objs[k].obj_diffs = nextdiff;
if (++nexti == nextTuple[1]) {
nextTuple += 2;
nexti = 0;
}
if (ordered_objs[k].obj_len > 0) {
size_t len = strlen(nextdiff) + 1;
nextdiff += len;
}
}
qsort(ordered_objs, (size_t)total_diff_count, sizeof(print_objs_t), compare_objIDs);
for (k = 0; k < total_diff_count; k++) {
if (ordered_objs[k].obj_len > 0)
printf("%s", ordered_objs[k].obj_diffs);
}
HDfree(ordered_objs);
}
fflush(stdout);
MPI_Barrier(MPI_COMM_WORLD);
if (displs)
HDfree(displs);
if (recvcounts)
HDfree(recvcounts);
if (recvtuples)
HDfree(recvtuples);
if (indices)
HDfree(indices);
if (rankIDs)
HDfree(rankIDs);
if ((rank_diff_count > 1) && sendbuf)
HDfree(sendbuf);
if (recvbuf)
HDfree(recvbuf);
}
/*
* NEWER Version of the ph5diff implementation
*/
hsize_t
ph5diff(const char *fname1, const char *fname2, const char *objname1, const char *objname2, diff_opt_t *opts)
{
hid_t file1_id = H5I_INVALID_HID;
hid_t file2_id = H5I_INVALID_HID;
hid_t fapl1_id = H5P_DEFAULT;
hid_t fapl2_id = H5P_DEFAULT;
char filenames[2][MAX_FILENAME];
hsize_t nfound = 0;
char *obj1fullname = NULL;
char *obj2fullname = NULL;
int both_objs_grp = 0;
/* for group object */
trav_info_t *info1_grp = NULL;
trav_info_t *info2_grp = NULL;
/* local pointer */
trav_info_t * info1_lp = NULL;
trav_info_t * info2_lp = NULL;
h5tool_link_info_t trg_linfo1;
h5tool_link_info_t trg_linfo2;
/* list for common objects */
trav_table_t *match_list = NULL;
diff_err_t ret_value = H5DIFF_NO_ERR;
H5TOOLS_START_DEBUG(" ");
/* init filenames */
HDmemset(filenames, 0, MAX_FILENAME * 2);
/* init link info struct */
HDmemset(&trg_linfo1, 0, sizeof(h5tool_link_info_t));
HDmemset(&trg_linfo2, 0, sizeof(h5tool_link_info_t));
/*-------------------------------------------------------------------------
* check invalid combination of options
*-----------------------------------------------------------------------*/
if (!is_valid_options(opts))
H5TOOLS_GOTO_DONE(0);
opts->cmn_objs = 1; /* eliminate warning */
opts->err_stat = H5DIFF_NO_ERR; /* initialize error status */
if (h5diff_open(fname1, fname2, opts, &file1_id, &file2_id) < 0) {
H5TOOLS_GOTO_ERROR(H5DIFF_ERR, "file open failure\n");
}
if (h5diff_initialize_lists(fname1, fname2, objname1, objname2, file1_id, file2_id, opts, &obj1fullname,
&info1_lp, &obj2fullname, &info2_lp, &both_objs_grp, &match_list) < 0) {
goto done;
}
if (both_objs_grp) {
/*------------------------------------------------------
* print the list
*/
if (g_Parallel) {
char * outbuff = NULL;
diff_instance_t *new_diff = NULL;
int previous = ((rank_diff_count > 0) ? rank_diff_count - 1 : 0);
if (rank_diffs == NULL) {
rank_diffs = (diff_instance_t **)calloc(DIFF_COUNT, sizeof(void *));
}
if ((rank_diff_count == 0) || (rank_diffs[previous]->outbuffoffset > 0)) {
new_diff = (diff_instance_t *)malloc(sizeof(diff_instance_t));
HDassert((new_diff != NULL));
outbuff = (char *)malloc(OUTBUFF_SIZE);
HDassert((outbuff != NULL));
memset(outbuff, 0, OUTBUFF_SIZE);
new_diff->obj_idx = 0;
new_diff->outbuff_size = OUTBUFF_SIZE;
new_diff->outbuffoffset = 0;
new_diff->baseOffset = 0;
new_diff->outbuff = outbuff;
rank_diffs[rank_diff_count++] = new_diff;
}
else
new_diff = rank_diffs[previous];
current_diff = new_diff;
}
if (opts->mode_verbose) {
unsigned u;
if (g_nID == 0) {
if (opts->mode_verbose_level > 2) {
parallel_print("file1: %s\n", fname1);
parallel_print("file2: %s\n", fname2);
}
parallel_print("\n");
/* if given objects is group under root */
if (HDstrcmp(obj1fullname, "/") != 0 || HDstrcmp(obj2fullname, "/") != 0)
parallel_print("group1 group2\n");
else
parallel_print("file1 file2\n");
parallel_print("---------------------------------------\n");
for (u = 0; u < match_list->nobjs; u++) {
int c1, c2;
c1 = (match_list->objs[u].flags[0]) ? 'x' : ' ';
c2 = (match_list->objs[u].flags[1]) ? 'x' : ' ';
parallel_print("%5c %6c %-15s\n", c1, c2, match_list->objs[u].name);
} /* end for */
parallel_print("\n");
}
} /* end if (opts->mode_verbose) */
}
H5TOOLS_DEBUG("diff_match next - errstat:%d", opts->err_stat);
nfound = diff_match(file1_id, obj1fullname, info1_lp, file2_id, obj2fullname, info2_lp, match_list, opts);
H5TOOLS_DEBUG("diff_match nfound: %d - errstat:%d", nfound, opts->err_stat);
ph5diff_gather_diffs();
done:
opts->err_stat = opts->err_stat | ret_value;
if (info1_grp)
trav_info_free(info1_grp);
if (info2_grp)
trav_info_free(info2_grp);
/* free buffers */
if (obj1fullname)
HDfree(obj1fullname);
if (obj2fullname)
HDfree(obj2fullname);
/* free link info buffer */
if (trg_linfo1.trg_path)
HDfree(trg_linfo1.trg_path);
if (trg_linfo2.trg_path)
HDfree(trg_linfo2.trg_path);
/* close */
H5E_BEGIN_TRY
{
H5Fclose(file1_id);
H5Fclose(file2_id);
if (fapl1_id != H5P_DEFAULT)
H5Pclose(fapl1_id);
if (fapl2_id != H5P_DEFAULT)
H5Pclose(fapl2_id);
}
H5E_END_TRY;
H5TOOLS_ENDDEBUG(" - errstat:%d", opts->err_stat);
return nfound;
}
#endif
/*-------------------------------------------------------------------------
* Function: h5diff
*
* Purpose: public function, can be called in an application program.
* return differences between 2 HDF5 files
*
* Return: Number of differences found.
*-------------------------------------------------------------------------
*/
hsize_t
h5diff(const char *fname1, const char *fname2, const char *objname1, const char *objname2, diff_opt_t *opts)
{
hid_t file1_id = H5I_INVALID_HID;
hid_t file2_id = H5I_INVALID_HID;
hid_t fapl1_id = H5P_DEFAULT;
hid_t fapl2_id = H5P_DEFAULT;
char filenames[2][MAX_FILENAME];
hsize_t nfound = 0;
int l_ret1 = -1;
int l_ret2 = -1;
char * obj1fullname = NULL;
char * obj2fullname = NULL;
int both_objs_grp = 0;
/* init to group type */
h5trav_type_t obj1type = H5TRAV_TYPE_GROUP;
h5trav_type_t obj2type = H5TRAV_TYPE_GROUP;
/* for single object */
H5O_info2_t oinfo1, oinfo2; /* object info */
trav_info_t *info1_obj = NULL;
trav_info_t *info2_obj = NULL;
/* for group object */
trav_info_t *info1_grp = NULL;
trav_info_t *info2_grp = NULL;
/* local pointer */
trav_info_t *info1_lp = NULL;
trav_info_t *info2_lp = NULL;
/* link info from specified object */
H5L_info2_t src_linfo1;
H5L_info2_t src_linfo2;
/* link info from member object */
h5tool_link_info_t trg_linfo1;
h5tool_link_info_t trg_linfo2;
/* list for common objects */
trav_table_t *match_list = NULL;
diff_err_t ret_value = H5DIFF_NO_ERR;
H5TOOLS_START_DEBUG(" ");
/* init filenames */
HDmemset(filenames, 0, MAX_FILENAME * 2);
/* init link info struct */
HDmemset(&trg_linfo1, 0, sizeof(h5tool_link_info_t));
HDmemset(&trg_linfo2, 0, sizeof(h5tool_link_info_t));
/*-------------------------------------------------------------------------
* check invalid combination of options
*-----------------------------------------------------------------------*/
if (!is_valid_options(opts))
H5TOOLS_GOTO_DONE(0);
opts->cmn_objs = 1; /* eliminate warning */
opts->err_stat = H5DIFF_NO_ERR; /* initialize error status */
/*-------------------------------------------------------------------------
* open the files first; if they are not valid, no point in continuing
*-------------------------------------------------------------------------
*/
/* open file 1 */
if (opts->custom_vol[0] || opts->custom_vfd[0]) {
if ((fapl1_id = h5tools_get_fapl(H5P_DEFAULT, opts->custom_vol[0] ? &(opts->vol_info[0]) : NULL,
opts->custom_vfd[0] ? &(opts->vfd_info[0]) : NULL)) < 0) {
parallel_print("h5diff: unable to create fapl for input file\n");
H5TOOLS_GOTO_ERROR(H5DIFF_ERR, "unable to create input fapl\n");
}
}
if ((file1_id = h5tools_fopen(fname1, H5F_ACC_RDONLY, fapl1_id, (fapl1_id != H5P_DEFAULT), NULL,
(size_t)0)) < 0) {
parallel_print("h5diff: <%s>: unable to open file\n", fname1);
H5TOOLS_GOTO_ERROR(H5DIFF_ERR, "<%s>: unable to open file\n", fname1);
}
H5TOOLS_DEBUG("file1_id = %s", fname1);
/* open file 2 */
if (opts->custom_vol[1] || opts->custom_vfd[1]) {
if ((fapl2_id = h5tools_get_fapl(H5P_DEFAULT, opts->custom_vol[1] ? &(opts->vol_info[1]) : NULL,
opts->custom_vfd[1] ? &(opts->vfd_info[1]) : NULL)) < 0) {
parallel_print("h5diff: unable to create fapl for output file\n");
H5TOOLS_GOTO_ERROR(H5DIFF_ERR, "unable to create output fapl\n");
}
}
if ((file2_id = h5tools_fopen(fname2, H5F_ACC_RDONLY, fapl2_id, (fapl2_id != H5P_DEFAULT), NULL,
(size_t)0)) < 0) {
parallel_print("h5diff: <%s>: unable to open file\n", fname2);
H5TOOLS_GOTO_ERROR(H5DIFF_ERR, "<%s>: unable to open file\n", fname2);
}
H5TOOLS_DEBUG("file2_id = %s", fname2);
/*-------------------------------------------------------------------------
* Initialize the info structs
*-------------------------------------------------------------------------
*/
trav_info_init(fname1, file1_id, &info1_obj);
trav_info_init(fname2, file2_id, &info2_obj);
H5TOOLS_DEBUG("trav_info_init initialized");
/* if any object is specified */
if (objname1) {
/* make the given object1 fullpath, start with "/" */
if (HDstrncmp(objname1, "/", 1) != 0) {
#ifdef H5_HAVE_ASPRINTF
/* Use the asprintf() routine, since it does what we're trying to do below */
if (HDasprintf(&obj1fullname, "/%s", objname1) < 0)
H5TOOLS_GOTO_ERROR(H5DIFF_ERR, "name buffer allocation failed");
#else /* H5_HAVE_ASPRINTF */
/* (malloc 2 more for "/" and end-of-line) */
if ((obj1fullname = (char *)HDmalloc(HDstrlen(objname1) + 2)) == NULL)
H5TOOLS_GOTO_ERROR(H5DIFF_ERR, "name buffer allocation failed");
HDstrcpy(obj1fullname, "/");
HDstrcat(obj1fullname, objname1);
#endif /* H5_HAVE_ASPRINTF */
}
else
obj1fullname = HDstrdup(objname1);
H5TOOLS_DEBUG("obj1fullname = %s", obj1fullname);
/* make the given object2 fullpath, start with "/" */
if (HDstrncmp(objname2, "/", 1) != 0) {
#ifdef H5_HAVE_ASPRINTF
/* Use the asprintf() routine, since it does what we're trying to do below */
if (HDasprintf(&obj2fullname, "/%s", objname2) < 0)
H5TOOLS_GOTO_ERROR(H5DIFF_ERR, "name buffer allocation failed");
#else /* H5_HAVE_ASPRINTF */
/* (malloc 2 more for "/" and end-of-line) */
if ((obj2fullname = (char *)HDmalloc(HDstrlen(objname2) + 2)) == NULL)
H5TOOLS_GOTO_ERROR(H5DIFF_ERR, "name buffer allocation failed");
HDstrcpy(obj2fullname, "/");
HDstrcat(obj2fullname, objname2);
#endif /* H5_HAVE_ASPRINTF */
}
else
obj2fullname = HDstrdup(objname2);
H5TOOLS_DEBUG("obj2fullname = %s", obj2fullname);
/*----------------------------------------------------------
* check if obj1 is root, group, single object or symlink
*/
H5TOOLS_DEBUG("h5diff check if obj1=%s is root, group, single object or symlink", obj1fullname);
if (!HDstrcmp(obj1fullname, "/")) {
obj1type = H5TRAV_TYPE_GROUP;
}
else {
/* check if link itself exist */
if (H5Lexists(file1_id, obj1fullname, H5P_DEFAULT) <= 0) {
parallel_print("Object <%s> could not be found in <%s>\n", obj1fullname, fname1);
H5TOOLS_GOTO_ERROR(H5DIFF_ERR, "Error: Object could not be found");
}
/* get info from link */
if (H5Lget_info2(file1_id, obj1fullname, &src_linfo1, H5P_DEFAULT) < 0) {
parallel_print("Unable to get link info from <%s>\n", obj1fullname);
H5TOOLS_GOTO_ERROR(H5DIFF_ERR, "H5Lget_info failed");
}
info1_lp = info1_obj;
/*
* check the type of specified path for hard and symbolic links
*/
if (src_linfo1.type == H5L_TYPE_HARD) {
size_t idx;
/* optional data pass */
info1_obj->opts = (diff_opt_t *)opts;
if (H5Oget_info_by_name3(file1_id, obj1fullname, &oinfo1, H5O_INFO_BASIC, H5P_DEFAULT) < 0) {
parallel_print("Error: Could not get file contents\n");
H5TOOLS_GOTO_ERROR(H5DIFF_ERR, "Error: Could not get file contents");
}
obj1type = (h5trav_type_t)oinfo1.type;
trav_info_add(info1_obj, obj1fullname, obj1type);
idx = info1_obj->nused - 1;
HDmemcpy(&info1_obj->paths[idx].obj_token, &oinfo1.token, sizeof(H5O_token_t));
info1_obj->paths[idx].fileno = oinfo1.fileno;
}
else if (src_linfo1.type == H5L_TYPE_SOFT) {
obj1type = H5TRAV_TYPE_LINK;
trav_info_add(info1_obj, obj1fullname, obj1type);
}
else if (src_linfo1.type == H5L_TYPE_EXTERNAL) {
obj1type = H5TRAV_TYPE_UDLINK;
trav_info_add(info1_obj, obj1fullname, obj1type);
}
}
/*----------------------------------------------------------
* check if obj2 is root, group, single object or symlink
*/
H5TOOLS_DEBUG("h5diff check if obj2=%s is root, group, single object or symlink", obj2fullname);
if (!HDstrcmp(obj2fullname, "/")) {
obj2type = H5TRAV_TYPE_GROUP;
}
else {
/* check if link itself exist */
if (H5Lexists(file2_id, obj2fullname, H5P_DEFAULT) <= 0) {
parallel_print("Object <%s> could not be found in <%s>\n", obj2fullname, fname2);
H5TOOLS_GOTO_ERROR(H5DIFF_ERR, "Error: Object could not be found");
}
/* get info from link */
if (H5Lget_info2(file2_id, obj2fullname, &src_linfo2, H5P_DEFAULT) < 0) {
parallel_print("Unable to get link info from <%s>\n", obj2fullname);
H5TOOLS_GOTO_ERROR(H5DIFF_ERR, "H5Lget_info failed");
}
info2_lp = info2_obj;
/*
* check the type of specified path for hard and symbolic links
*/
if (src_linfo2.type == H5L_TYPE_HARD) {
size_t idx;
/* optional data pass */
info2_obj->opts = (diff_opt_t *)opts;
if (H5Oget_info_by_name3(file2_id, obj2fullname, &oinfo2, H5O_INFO_BASIC, H5P_DEFAULT) < 0) {
parallel_print("Error: Could not get file contents\n");
H5TOOLS_GOTO_ERROR(H5DIFF_ERR, "Error: Could not get file contents");
}
obj2type = (h5trav_type_t)oinfo2.type;
trav_info_add(info2_obj, obj2fullname, obj2type);
idx = info2_obj->nused - 1;
HDmemcpy(&info2_obj->paths[idx].obj_token, &oinfo2.token, sizeof(H5O_token_t));
info2_obj->paths[idx].fileno = oinfo2.fileno;
}
else if (src_linfo2.type == H5L_TYPE_SOFT) {
obj2type = H5TRAV_TYPE_LINK;
trav_info_add(info2_obj, obj2fullname, obj2type);
}
else if (src_linfo2.type == H5L_TYPE_EXTERNAL) {
obj2type = H5TRAV_TYPE_UDLINK;
trav_info_add(info2_obj, obj2fullname, obj2type);
}
}
}
/* if no object specified */
else {
H5TOOLS_DEBUG("h5diff no object specified");
/* set root group */
obj1fullname = (char *)HDstrdup("/");
obj1type = H5TRAV_TYPE_GROUP;
obj2fullname = (char *)HDstrdup("/");
obj2type = H5TRAV_TYPE_GROUP;
}
H5TOOLS_DEBUG("get any symbolic links info - errstat:%d", opts->err_stat);
/* get any symbolic links info */
l_ret1 = H5tools_get_symlink_info(file1_id, obj1fullname, &trg_linfo1, opts->follow_links);
l_ret2 = H5tools_get_symlink_info(file2_id, obj2fullname, &trg_linfo2, opts->follow_links);
/*---------------------------------------------
* check for following symlinks
*/
if (opts->follow_links) {
/* pass how to handle printing warning to linkinfo option */
if (print_warn(opts))
trg_linfo1.opt.msg_mode = trg_linfo2.opt.msg_mode = 1;
/*-------------------------------
* check symbolic link (object1)
*/
H5TOOLS_DEBUG("h5diff check symbolic link (object1)");
/* dangling link */
if (l_ret1 == 0) {
H5TOOLS_DEBUG("h5diff ... dangling link");
if (opts->no_dangle_links) {
/* treat dangling link as error */
if (opts->mode_verbose)
parallel_print("Warning: <%s> is a dangling link.\n", obj1fullname);
H5TOOLS_GOTO_ERROR(H5DIFF_ERR, "treat dangling link as error");
}
else {
if (opts->mode_verbose)
parallel_print("obj1 <%s> is a dangling link.\n", obj1fullname);
if (l_ret1 != 0 || l_ret2 != 0) {
nfound++;
print_found(nfound);
H5TOOLS_GOTO_DONE(H5DIFF_NO_ERR);
}
}
}
else if (l_ret1 < 0) { /* fail */
parallel_print("Object <%s> could not be found in <%s>\n", obj1fullname, fname1);
H5TOOLS_GOTO_ERROR(H5DIFF_ERR, "Object could not be found");
}
else if (l_ret1 != 2) { /* symbolic link */
obj1type = (h5trav_type_t)trg_linfo1.trg_type;
H5TOOLS_DEBUG("h5diff ... ... trg_linfo1.trg_type == H5L_TYPE_HARD");
if (info1_lp != NULL) {
size_t idx = info1_lp->nused - 1;
H5TOOLS_DEBUG("h5diff ... ... ... info1_obj not null");
HDmemcpy(&info1_lp->paths[idx].obj_token, &trg_linfo1.obj_token, sizeof(H5O_token_t));
info1_lp->paths[idx].type = (h5trav_type_t)trg_linfo1.trg_type;
info1_lp->paths[idx].fileno = trg_linfo1.fileno;
}
H5TOOLS_DEBUG("h5diff check symbolic link (object1) finished");
}
/*-------------------------------
* check symbolic link (object2)
*/
H5TOOLS_DEBUG("h5diff check symbolic link (object2)");
/* dangling link */
if (l_ret2 == 0) {
H5TOOLS_DEBUG("h5diff ... dangling link");
if (opts->no_dangle_links) {
/* treat dangling link as error */
if (opts->mode_verbose)
parallel_print("Warning: <%s> is a dangling link.\n", obj2fullname);
H5TOOLS_GOTO_ERROR(H5DIFF_ERR, "treat dangling link as error");
}
else {
if (opts->mode_verbose)
parallel_print("obj2 <%s> is a dangling link.\n", obj2fullname);
if (l_ret1 != 0 || l_ret2 != 0) {
nfound++;
print_found(nfound);
H5TOOLS_GOTO_DONE(H5DIFF_NO_ERR);
}
}
}
else if (l_ret2 < 0) { /* fail */
parallel_print("Object <%s> could not be found in <%s>\n", obj2fullname, fname2);
H5TOOLS_GOTO_ERROR(H5DIFF_ERR, "Object could not be found");
}
else if (l_ret2 != 2) { /* symbolic link */
obj2type = (h5trav_type_t)trg_linfo2.trg_type;
if (info2_lp != NULL) {
size_t idx = info2_lp->nused - 1;
H5TOOLS_DEBUG("h5diff ... ... ... info2_obj not null");
HDmemcpy(&info2_lp->paths[idx].obj_token, &trg_linfo2.obj_token, sizeof(H5O_token_t));
info2_lp->paths[idx].type = (h5trav_type_t)trg_linfo2.trg_type;
info2_lp->paths[idx].fileno = trg_linfo2.fileno;
}
H5TOOLS_DEBUG("h5diff check symbolic link (object1) finished");
}
} /* end of if follow symlinks */
/*
* If verbose options is not used, don't need to traverse through the list
* of objects in the group to display objects information,
* So use h5tools_is_obj_same() to improve performance by skipping
* comparing details of same objects.
*/
if (!(opts->mode_verbose || opts->mode_report)) {
H5TOOLS_DEBUG("h5diff NOT (opts->mode_verbose || opts->mode_report)");
/* if no danglink links */
if (l_ret1 > 0 && l_ret2 > 0)
if (h5tools_is_obj_same(file1_id, obj1fullname, file2_id, obj2fullname) != 0)
H5TOOLS_GOTO_DONE(H5DIFF_NO_ERR);
}
both_objs_grp = (obj1type == H5TRAV_TYPE_GROUP && obj2type == H5TRAV_TYPE_GROUP);
if (both_objs_grp) {
H5TOOLS_DEBUG("h5diff both_objs_grp TRUE");
/*
* traverse group1
*/
trav_info_init(fname1, file1_id, &info1_grp);
/* optional data pass */
info1_grp->opts = (diff_opt_t *)opts;
if (h5trav_visit(file1_id, obj1fullname, TRUE, TRUE, trav_grp_objs, trav_grp_symlinks, info1_grp,
H5O_INFO_BASIC) < 0) {
parallel_print("Error: Could not get file contents\n");
H5TOOLS_GOTO_ERROR(H5DIFF_ERR, "Could not get file contents");
}
info1_lp = info1_grp;
/*
* traverse group2
*/
trav_info_init(fname2, file2_id, &info2_grp);
/* optional data pass */
info2_grp->opts = (diff_opt_t *)opts;
if (h5trav_visit(file2_id, obj2fullname, TRUE, TRUE, trav_grp_objs, trav_grp_symlinks, info2_grp,
H5O_INFO_BASIC) < 0) {
parallel_print("Error: Could not get file contents\n");
H5TOOLS_GOTO_ERROR(H5DIFF_ERR, "Could not get file contents");
} /* end if */
info2_lp = info2_grp;
}
H5TOOLS_DEBUG("groups traversed - errstat:%d", opts->err_stat);
#if defined(H5_HAVE_PARALLEL) && defined(USE_ORIGINAL_CODE)
if (g_Parallel) {
int i;
if ((HDstrlen(fname1) > MAX_FILENAME) || (HDstrlen(fname2) > MAX_FILENAME)) {
HDfprintf(stderr, "The parallel diff only supports path names up to %d characters\n",
MAX_FILENAME);
MPI_Abort(MPI_COMM_WORLD, 0);
} /* end if */
HDstrcpy(filenames[0], fname1);
HDstrcpy(filenames[1], fname2);
/* Alert the worker tasks that there's going to be work. */
for (i = 1; i < g_nTasks; i++)
MPI_Send(filenames, (MAX_FILENAME * 2), MPI_CHAR, i, MPI_TAG_PARALLEL, MPI_COMM_WORLD);
} /* end if */
#endif
H5TOOLS_DEBUG("build_match_list next - errstat:%d", opts->err_stat);
/* process the objects */
build_match_list(obj1fullname, info1_lp, obj2fullname, info2_lp, &match_list, opts);
H5TOOLS_DEBUG("build_match_list finished - errstat:%d", opts->err_stat);
if (both_objs_grp) {
/*------------------------------------------------------
* print the list
*/
if (opts->mode_verbose) {
unsigned u;
if (opts->mode_verbose_level > 2) {
parallel_print("file1: %s\n", fname1);
parallel_print("file2: %s\n", fname2);
}
parallel_print("\n");
/* if given objects is group under root */
if (HDstrcmp(obj1fullname, "/") != 0 || HDstrcmp(obj2fullname, "/") != 0)
parallel_print("group1 group2\n");
else
parallel_print("file1 file2\n");
parallel_print("---------------------------------------\n");
for (u = 0; u < match_list->nobjs; u++) {
int c1, c2;
c1 = (match_list->objs[u].flags[0]) ? 'x' : ' ';
c2 = (match_list->objs[u].flags[1]) ? 'x' : ' ';
parallel_print("%5c %6c %-15s\n", c1, c2, match_list->objs[u].name);
} /* end for */
parallel_print("\n");
} /* end if */
}
H5TOOLS_DEBUG("diff_match next - errstat:%d", opts->err_stat);
nfound = diff_match(file1_id, obj1fullname, info1_lp, file2_id, obj2fullname, info2_lp, match_list, opts);
H5TOOLS_DEBUG("diff_match nfound: %d - errstat:%d", nfound, opts->err_stat);
done:
opts->err_stat = opts->err_stat | ret_value;
#if defined(H5_HAVE_PARALLEL) && defined(USE_ORIGINAL_CODE)
if (g_Parallel)
/* All done at this point, let tasks know that they won't be needed */
phdiff_dismiss_workers();
#endif
/* free buffers in trav_info structures */
if (info1_obj)
trav_info_free(info1_obj);
if (info2_obj)
trav_info_free(info2_obj);
if (info1_grp)
trav_info_free(info1_grp);
if (info2_grp)
trav_info_free(info2_grp);
/* free buffers */
if (obj1fullname)
HDfree(obj1fullname);
if (obj2fullname)
HDfree(obj2fullname);
/* free link info buffer */
if (trg_linfo1.trg_path)
HDfree(trg_linfo1.trg_path);
if (trg_linfo2.trg_path)
HDfree(trg_linfo2.trg_path);
/* close */
H5E_BEGIN_TRY
{
H5Fclose(file1_id);
H5Fclose(file2_id);
if (fapl1_id != H5P_DEFAULT)
H5Pclose(fapl1_id);
if (fapl2_id != H5P_DEFAULT)
H5Pclose(fapl2_id);
}
H5E_END_TRY;
H5TOOLS_ENDDEBUG(" - errstat:%d", opts->err_stat);
return nfound;
}
#ifdef H5_HAVE_PARALLEL
hsize_t
pdiff_match(hid_t file1_id, const char *grp1, trav_info_t *info1, hid_t file2_id, const char *grp2,
trav_info_t *info2, trav_table_t *table, diff_opt_t *opts)
{
hsize_t nfound = 0;
unsigned i;
const char *grp1_path = "";
const char *grp2_path = "";
char * obj1_fullpath = NULL;
char * obj2_fullpath = NULL;
diff_args_t argdata;
size_t idx1 = 0;
size_t idx2 = 0;
diff_err_t ret_value = opts->err_stat;
int mpi_rank = 0, mpi_size = 1;
int diff_count = 0;
int mod_rank = -1;
if (g_Parallel) {
MPI_Comm_rank(MPI_COMM_WORLD, &mpi_rank);
MPI_Comm_size(MPI_COMM_WORLD, &mpi_size);
}
H5TOOLS_START_DEBUG(" - errstat:%d", opts->err_stat);
/*
* if not root, prepare object name to be pre-appended to group path to
* make full path
*/
if (HDstrcmp(grp1, "/") != 0)
grp1_path = grp1;
if (HDstrcmp(grp2, "/") != 0)
grp2_path = grp2;
/*-------------------------------------------------------------------------
* regarding the return value of h5diff (0, no difference in files, 1 difference )
* 1) the number of objects in file1 must be the same as in file2
* 2) the graph must match, i.e same names (absolute path)
* 3) objects with the same name must be of the same type
*-------------------------------------------------------------------------
*/
H5TOOLS_DEBUG("exclude_path opts->contents:%d", opts->contents);
/* not valid compare used when --exclude-path option is used */
if (!opts->exclude_path) {
/* number of different objects */
if (info1->nused != info2->nused) {
opts->contents = 0;
}
H5TOOLS_DEBUG("opts->exclude_path opts->contents:%d", opts->contents);
}
/* objects in one file and not the other */
for (i = 0; i < table->nobjs; i++) {
if (table->objs[i].flags[0] != table->objs[i].flags[1]) {
opts->contents = 0;
break;
}
H5TOOLS_DEBUG("table->nobjs[%d] opts->contents:%d", i, opts->contents);
}
/*-------------------------------------------------------------------------
* do the diff for common objects
*-------------------------------------------------------------------------
*/
for (i = 0; i < table->nobjs; i++) {
H5TOOLS_DEBUG("diff for common objects[%d] - errstat:%d", i, opts->err_stat);
if (table->objs[i].flags[0] && table->objs[i].flags[1]) {
/* make full path for obj1 */
#ifdef H5_HAVE_ASPRINTF
/* Use the asprintf() routine, since it does what we're trying to do below */
if (HDasprintf(&obj1_fullpath, "%s%s", grp1_path, table->objs[i].name) < 0) {
H5TOOLS_ERROR(H5DIFF_ERR, "name buffer allocation failed");
}
#else /* H5_HAVE_ASPRINTF */
if ((obj1_fullpath = (char *)HDmalloc(HDstrlen(grp1_path) + HDstrlen(table->objs[i].name) + 1)) ==
NULL) {
H5TOOLS_ERROR(H5DIFF_ERR, "name buffer allocation failed");
}
else {
HDstrcpy(obj1_fullpath, grp1_path);
HDstrcat(obj1_fullpath, table->objs[i].name);
}
#endif /* H5_HAVE_ASPRINTF */
H5TOOLS_DEBUG("diff_match path1 - %s", obj1_fullpath);
/* make full path for obj2 */
#ifdef H5_HAVE_ASPRINTF
/* Use the asprintf() routine, since it does what we're trying to do below */
if (HDasprintf(&obj2_fullpath, "%s%s", grp2_path, table->objs[i].name) < 0) {
H5TOOLS_ERROR(H5DIFF_ERR, "name buffer allocation failed");
}
#else /* H5_HAVE_ASPRINTF */
if ((obj2_fullpath = (char *)HDmalloc(HDstrlen(grp2_path) + HDstrlen(table->objs[i].name) + 1)) ==
NULL) {
H5TOOLS_ERROR(H5DIFF_ERR, "name buffer allocation failed");
}
else {
HDstrcpy(obj2_fullpath, grp2_path);
HDstrcat(obj2_fullpath, table->objs[i].name);
}
#endif /* H5_HAVE_ASPRINTF */
H5TOOLS_DEBUG("diff_match path2 - %s", obj2_fullpath);
/* get index to figure out type of the object in file1 */
while (info1->paths[idx1].path && (HDstrcmp(obj1_fullpath, info1->paths[idx1].path) != 0))
idx1++;
/* get index to figure out type of the object in file2 */
while (info2->paths[idx2].path && (HDstrcmp(obj2_fullpath, info2->paths[idx2].path) != 0))
idx2++;
/* Set argdata to pass other args into diff() */
argdata.type[0] = info1->paths[idx1].type;
argdata.type[1] = info2->paths[idx2].type;
argdata.is_same_trgobj = table->objs[i].is_same_trgobj;
opts->cmn_objs = 1;
mod_rank = diff_count % mpi_size;
if (mod_rank == mpi_rank) {
char * outbuff = NULL;
diff_instance_t *new_diff = NULL;
int previous = ((rank_diff_count > 0) ? rank_diff_count - 1 : 0);
if (rank_diffs == NULL) {
rank_diffs = (diff_instance_t **)calloc(DIFF_COUNT, sizeof(void *));
}
if ((rank_diff_count == 0) || (rank_diffs[previous]->outbuffoffset > 0)) {
new_diff = (diff_instance_t *)malloc(sizeof(diff_instance_t));
HDassert((new_diff != NULL));
outbuff = (char *)malloc(OUTBUFF_SIZE);
HDassert((outbuff != NULL));
new_diff->obj_idx = diff_count;
new_diff->outbuff_size = OUTBUFF_SIZE;
new_diff->outbuffoffset = 0;
new_diff->baseOffset = 0;
new_diff->outbuff = outbuff;
if (rank_diff_count == diff_count_limit) {
diff_count_limit += DIFF_COUNT;
rank_diffs = (diff_instance_t **)realloc(rank_diffs, (size_t)diff_count_limit);
}
rank_diffs[rank_diff_count++] = new_diff;
}
else
new_diff = rank_diffs[previous];
my_diffs = new_diff;
/* Add a previous outbuff (length) into the accumulated total for this rank */
if (current_diff)
local_diff_total += current_diff->outbuffoffset;
/* Assign a new diff to be the current (working) outbuff */
current_diff = new_diff;
nfound += diff(file1_id, obj1_fullpath, file2_id, obj2_fullpath, opts, &argdata);
}
diff_count++;
if (obj1_fullpath) {
HDfree(obj1_fullpath);
obj1_fullpath = NULL;
}
if (obj2_fullpath) {
HDfree(obj2_fullpath);
obj2_fullpath = NULL;
}
}
} /* end for (common objects) */
H5TOOLS_DEBUG("done with for loop - errstat:%d", opts->err_stat);
/* Update the final 'local_diff_total' */
if (current_diff != NULL) {
local_diff_total += current_diff->outbuffoffset;
}
opts->err_stat = opts->err_stat | ret_value;
free_exclude_attr_list(opts);
/* free table */
if (table)
trav_table_free(table);
H5TOOLS_ENDDEBUG(" diffs=%d - errstat:%d", nfound, opts->err_stat);
return nfound;
}
#endif /* H5_HAVE_PARALLEL */
/*-------------------------------------------------------------------------
* Function: diff_match
*
* Purpose: Compare common objects in given groups according to table structure.
* The table structure has flags which can be used to find common objects
* and will be compared.
* Common object means same name (absolute path) objects in both location.
*
* Return: Number of differences found
*
* Modifications: Compare the graph and make h5diff return 1 for difference if
* 1) the number of objects in file1 is not the same as in file2
* 2) the graph does not match, i.e same names (absolute path)
* 3) objects with the same name are not of the same type
*-------------------------------------------------------------------------
*/
hsize_t
diff_match(hid_t file1_id, const char *grp1, trav_info_t *info1, hid_t file2_id, const char *grp2,
trav_info_t *info2, trav_table_t *table, diff_opt_t *opts)
{
#if defined(H5_HAVE_PARALLEL) && !defined(USE_ORIGINAL_CODE)
if (g_Parallel)
return pdiff_match(file1_id, grp1, info1, file2_id, grp2, info2, table, opts);
#endif
hsize_t nfound = 0;
unsigned i;
const char *grp1_path = "";
const char *grp2_path = "";
char * obj1_fullpath = NULL;
char * obj2_fullpath = NULL;
diff_args_t argdata;
size_t idx1 = 0;
size_t idx2 = 0;
diff_err_t ret_value = opts->err_stat;
H5TOOLS_START_DEBUG(" - errstat:%d", opts->err_stat);
/*
* if not root, prepare object name to be pre-appended to group path to
* make full path
*/
if (HDstrcmp(grp1, "/") != 0)
grp1_path = grp1;
if (HDstrcmp(grp2, "/") != 0)
grp2_path = grp2;
/*-------------------------------------------------------------------------
* regarding the return value of h5diff (0, no difference in files, 1 difference )
* 1) the number of objects in file1 must be the same as in file2
* 2) the graph must match, i.e same names (absolute path)
* 3) objects with the same name must be of the same type
*-------------------------------------------------------------------------
*/
H5TOOLS_DEBUG("exclude_path opts->contents:%d", opts->contents);
/* not valid compare used when --exclude-path option is used */
if (!opts->exclude_path) {
/* number of different objects */
if (info1->nused != info2->nused) {
opts->contents = 0;
}
H5TOOLS_DEBUG("opts->exclude_path opts->contents:%d", opts->contents);
}
/* objects in one file and not the other */
for (i = 0; i < table->nobjs; i++) {
if (table->objs[i].flags[0] != table->objs[i].flags[1]) {
opts->contents = 0;
break;
}
H5TOOLS_DEBUG("table->nobjs[%d] opts->contents:%d", i, opts->contents);
}
/*-------------------------------------------------------------------------
* do the diff for common objects
*-------------------------------------------------------------------------
*/
#if defined(H5_HAVE_PARALLEL) && defined(USE_ORIGINAL_CODE)
{
char * workerTasks = (char *)HDmalloc((size_t)(g_nTasks - 1) * sizeof(char));
int n;
int busyTasks = 0;
struct diffs_found nFoundbyWorker;
struct diff_mpi_args args;
int havePrintToken = 1;
MPI_Status Status;
/*set all tasks as free */
HDmemset(workerTasks, 1, (size_t)(g_nTasks - 1) * sizeof(char));
#endif
for (i = 0; i < table->nobjs; i++) {
H5TOOLS_DEBUG("diff for common objects[%d] - errstat:%d", i, opts->err_stat);
if (table->objs[i].flags[0] && table->objs[i].flags[1]) {
/* make full path for obj1 */
#ifdef H5_HAVE_ASPRINTF
/* Use the asprintf() routine, since it does what we're trying to do below */
if (HDasprintf(&obj1_fullpath, "%s%s", grp1_path, table->objs[i].name) < 0) {
H5TOOLS_ERROR(H5DIFF_ERR, "name buffer allocation failed");
}
#else /* H5_HAVE_ASPRINTF */
if ((obj1_fullpath = (char *)HDmalloc(HDstrlen(grp1_path) + HDstrlen(table->objs[i].name) + 1)) ==
NULL) {
H5TOOLS_ERROR(H5DIFF_ERR, "name buffer allocation failed");
}
else {
HDstrcpy(obj1_fullpath, grp1_path);
HDstrcat(obj1_fullpath, table->objs[i].name);
}
#endif /* H5_HAVE_ASPRINTF */
H5TOOLS_DEBUG("diff_match path1 - %s", obj1_fullpath);
/* make full path for obj2 */
#ifdef H5_HAVE_ASPRINTF
/* Use the asprintf() routine, since it does what we're trying to do below */
if (HDasprintf(&obj2_fullpath, "%s%s", grp2_path, table->objs[i].name) < 0) {
H5TOOLS_ERROR(H5DIFF_ERR, "name buffer allocation failed");
}
#else /* H5_HAVE_ASPRINTF */
if ((obj2_fullpath = (char *)HDmalloc(HDstrlen(grp2_path) + HDstrlen(table->objs[i].name) + 1)) ==
NULL) {
H5TOOLS_ERROR(H5DIFF_ERR, "name buffer allocation failed");
}
else {
HDstrcpy(obj2_fullpath, grp2_path);
HDstrcat(obj2_fullpath, table->objs[i].name);
}
#endif /* H5_HAVE_ASPRINTF */
H5TOOLS_DEBUG("diff_match path2 - %s", obj2_fullpath);
/* get index to figure out type of the object in file1 */
while (info1->paths[idx1].path && (HDstrcmp(obj1_fullpath, info1->paths[idx1].path) != 0))
idx1++;
/* get index to figure out type of the object in file2 */
while (info2->paths[idx2].path && (HDstrcmp(obj2_fullpath, info2->paths[idx2].path) != 0))
idx2++;
/* Set argdata to pass other args into diff() */
argdata.type[0] = info1->paths[idx1].type;
argdata.type[1] = info2->paths[idx2].type;
argdata.is_same_trgobj = table->objs[i].is_same_trgobj;
opts->cmn_objs = 1;
if (!g_Parallel) {
H5TOOLS_DEBUG("diff paths - errstat:%d", opts->err_stat);
nfound += diff(file1_id, obj1_fullpath, file2_id, obj2_fullpath, opts, &argdata);
} /* end if */
#if defined(H5_HAVE_PARALLEL) && defined(USE_ORIGINAL_CODE)
else {
int workerFound = 0;
H5TOOLS_DEBUG("Beginning of big else block");
/* We're in parallel mode */
/* Since the data type of diff value is hsize_t which can
* be arbitrary large such that there is no MPI type that
* matches it, the value is passed between processes as
* an array of bytes in order to be portable. But this
* may not work in non-homogeneous MPI environments.
*/
/*Set up args to pass to worker task. */
if (HDstrlen(obj1_fullpath) > 255 || HDstrlen(obj2_fullpath) > 255) {
HDprintf("The parallel diff only supports object names up to 255 characters\n");
MPI_Abort(MPI_COMM_WORLD, 0);
} /* end if */
/* set args struct to pass */
HDstrcpy(args.name1, obj1_fullpath);
HDstrcpy(args.name2, obj2_fullpath);
args.opts = *opts;
args.argdata.type[0] = info1->paths[idx1].type;
args.argdata.type[1] = info2->paths[idx2].type;
args.argdata.is_same_trgobj = table->objs[i].is_same_trgobj;
/* if there are any outstanding print requests, let's handle one. */
if (busyTasks > 0) {
int incomingMessage;
/* check if any tasks freed up, and didn't need to print. */
MPI_Iprobe(MPI_ANY_SOURCE, MPI_TAG_DONE, MPI_COMM_WORLD, &incomingMessage, &Status);
/* first block*/
if (incomingMessage) {
workerTasks[Status.MPI_SOURCE - 1] = 1;
MPI_Recv(&nFoundbyWorker, sizeof(nFoundbyWorker), MPI_BYTE, Status.MPI_SOURCE,
MPI_TAG_DONE, MPI_COMM_WORLD, &Status);
nfound += nFoundbyWorker.nfound;
opts->not_cmp = opts->not_cmp | nFoundbyWorker.not_cmp;
busyTasks--;
} /* end if */
/* check to see if the print token was returned. */
if (!havePrintToken) {
/* If we don't have the token, someone is probably sending us output */
print_incoming_data();
/* check incoming queue for token */
MPI_Iprobe(MPI_ANY_SOURCE, MPI_TAG_TOK_RETURN, MPI_COMM_WORLD, &incomingMessage,
&Status);
/* incoming token implies free task. */
if (incomingMessage) {
workerTasks[Status.MPI_SOURCE - 1] = 1;
MPI_Recv(&nFoundbyWorker, sizeof(nFoundbyWorker), MPI_BYTE, Status.MPI_SOURCE,
MPI_TAG_TOK_RETURN, MPI_COMM_WORLD, &Status);
nfound += nFoundbyWorker.nfound;
opts->not_cmp = opts->not_cmp | nFoundbyWorker.not_cmp;
busyTasks--;
havePrintToken = 1;
} /* end if */
} /* end if */
/* check to see if anyone needs the print token. */
if (havePrintToken) {
/* check incoming queue for print token requests */
MPI_Iprobe(MPI_ANY_SOURCE, MPI_TAG_TOK_REQUEST, MPI_COMM_WORLD, &incomingMessage,
&Status);
if (incomingMessage) {
MPI_Recv(NULL, 0, MPI_BYTE, Status.MPI_SOURCE, MPI_TAG_TOK_REQUEST,
MPI_COMM_WORLD, &Status);
MPI_Send(NULL, 0, MPI_BYTE, Status.MPI_SOURCE, MPI_TAG_PRINT_TOK,
MPI_COMM_WORLD);
havePrintToken = 0;
} /* end if */
} /* end if */
} /* end if */
/* check array of tasks to see which ones are free.
* Manager task never does work, so freeTasks[0] is really
* worker task 0. */
for (n = 1; (n < g_nTasks) && !workerFound; n++) {
if (workerTasks[n - 1]) {
/* send file id's and names to first free worker */
MPI_Send(&args, sizeof(args), MPI_BYTE, n, MPI_TAG_ARGS, MPI_COMM_WORLD);
/* increment counter for total number of prints. */
busyTasks++;
/* mark worker as busy */
workerTasks[n - 1] = 0;
workerFound = 1;
} /* end if */
} /* end for */
if (!workerFound) {
/* if they were all busy, we've got to wait for one free up
* before we can move on. If we don't have the token, some
* task is currently printing so we'll wait for that task to
* return it.
*/
if (!havePrintToken) {
while (!havePrintToken) {
int incomingMessage;
print_incoming_data();
MPI_Iprobe(MPI_ANY_SOURCE, MPI_TAG_TOK_RETURN, MPI_COMM_WORLD,
&incomingMessage, &Status);
if (incomingMessage) {
MPI_Recv(&nFoundbyWorker, sizeof(nFoundbyWorker), MPI_BYTE,
MPI_ANY_SOURCE, MPI_TAG_TOK_RETURN, MPI_COMM_WORLD, &Status);
havePrintToken = 1;
nfound += nFoundbyWorker.nfound;
opts->not_cmp = opts->not_cmp | nFoundbyWorker.not_cmp;
/* send this task the work unit. */
MPI_Send(&args, sizeof(args), MPI_BYTE, Status.MPI_SOURCE, MPI_TAG_ARGS,
MPI_COMM_WORLD);
} /* end if */
} /* end while */
} /* end if */
/* if we do have the token, check for task to free up, or wait for a task to request
* it */
else {
/* But first print all the data in our incoming queue */
print_incoming_data();
MPI_Probe(MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, &Status);
if (Status.MPI_TAG == MPI_TAG_DONE) {
MPI_Recv(&nFoundbyWorker, sizeof(nFoundbyWorker), MPI_BYTE, Status.MPI_SOURCE,
MPI_TAG_DONE, MPI_COMM_WORLD, &Status);
nfound += nFoundbyWorker.nfound;
opts->not_cmp = opts->not_cmp | nFoundbyWorker.not_cmp;
MPI_Send(&args, sizeof(args), MPI_BYTE, Status.MPI_SOURCE, MPI_TAG_ARGS,
MPI_COMM_WORLD);
} /* end if */
else if (Status.MPI_TAG == MPI_TAG_TOK_REQUEST) {
int incomingMessage;
MPI_Recv(NULL, 0, MPI_BYTE, Status.MPI_SOURCE, MPI_TAG_TOK_REQUEST,
MPI_COMM_WORLD, &Status);
MPI_Send(NULL, 0, MPI_BYTE, Status.MPI_SOURCE, MPI_TAG_PRINT_TOK,
MPI_COMM_WORLD);
do {
MPI_Iprobe(MPI_ANY_SOURCE, MPI_TAG_TOK_RETURN, MPI_COMM_WORLD,
&incomingMessage, &Status);
print_incoming_data();
} while (!incomingMessage);
MPI_Recv(&nFoundbyWorker, sizeof(nFoundbyWorker), MPI_BYTE, Status.MPI_SOURCE,
MPI_TAG_TOK_RETURN, MPI_COMM_WORLD, &Status);
nfound += nFoundbyWorker.nfound;
opts->not_cmp = opts->not_cmp | nFoundbyWorker.not_cmp;
MPI_Send(&args, sizeof(args), MPI_BYTE, Status.MPI_SOURCE, MPI_TAG_ARGS,
MPI_COMM_WORLD);
} /* end else-if */
else {
HDprintf("ERROR: Invalid tag (%d) received \n", Status.MPI_TAG);
MPI_Abort(MPI_COMM_WORLD, 0);
MPI_Finalize();
} /* end else */
} /* end else */
} /* end if */
} /* end else */
#endif /* USE_ORIGINAL_CODE (PARALLEL) */
if (obj1_fullpath)
HDfree(obj1_fullpath);
if (obj2_fullpath)
HDfree(obj2_fullpath);
} /* end if */
} /* end for */
H5TOOLS_DEBUG("done with for loop - errstat:%d", opts->err_stat);
#if defined(H5_HAVE_PARALLEL) && defined(USE_ORIGINAL_CODE)
if (g_Parallel) {
/* make sure all tasks are done */
while (busyTasks > 0) {
MPI_Probe(MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, &Status);
if (Status.MPI_TAG == MPI_TAG_DONE) {
MPI_Recv(&nFoundbyWorker, sizeof(nFoundbyWorker), MPI_BYTE, Status.MPI_SOURCE,
MPI_TAG_DONE, MPI_COMM_WORLD, &Status);
nfound += nFoundbyWorker.nfound;
opts->not_cmp = opts->not_cmp | nFoundbyWorker.not_cmp;
busyTasks--;
} /* end if */
else if (Status.MPI_TAG == MPI_TAG_TOK_REQUEST) {
MPI_Recv(NULL, 0, MPI_BYTE, Status.MPI_SOURCE, MPI_TAG_TOK_REQUEST, MPI_COMM_WORLD,
&Status);
if (havePrintToken) {
int incomingMessage;
MPI_Send(NULL, 0, MPI_BYTE, Status.MPI_SOURCE, MPI_TAG_PRINT_TOK, MPI_COMM_WORLD);
do {
MPI_Iprobe(MPI_ANY_SOURCE, MPI_TAG_TOK_RETURN, MPI_COMM_WORLD, &incomingMessage,
&Status);
print_incoming_data();
} while (!incomingMessage);
MPI_Recv(&nFoundbyWorker, sizeof(nFoundbyWorker), MPI_BYTE, Status.MPI_SOURCE,
MPI_TAG_TOK_RETURN, MPI_COMM_WORLD, &Status);
nfound += nFoundbyWorker.nfound;
opts->not_cmp = opts->not_cmp | nFoundbyWorker.not_cmp;
busyTasks--;
} /* end if */
/* someone else must have it...wait for them to return it, then give it to the task that
* just asked for it. */
else {
int source = Status.MPI_SOURCE;
int incomingMessage;
do {
MPI_Iprobe(MPI_ANY_SOURCE, MPI_TAG_TOK_RETURN, MPI_COMM_WORLD, &incomingMessage,
&Status);
print_incoming_data();
} while (!incomingMessage);
MPI_Recv(&nFoundbyWorker, sizeof(nFoundbyWorker), MPI_BYTE, MPI_ANY_SOURCE,
MPI_TAG_TOK_RETURN, MPI_COMM_WORLD, &Status);
nfound += nFoundbyWorker.nfound;
opts->not_cmp = opts->not_cmp | nFoundbyWorker.not_cmp;
busyTasks--;
MPI_Send(NULL, 0, MPI_BYTE, source, MPI_TAG_PRINT_TOK, MPI_COMM_WORLD);
} /* end else */
} /* end else-if */
else if (Status.MPI_TAG == MPI_TAG_TOK_RETURN) {
MPI_Recv(&nFoundbyWorker, sizeof(nFoundbyWorker), MPI_BYTE, Status.MPI_SOURCE,
MPI_TAG_TOK_RETURN, MPI_COMM_WORLD, &Status);
nfound += nFoundbyWorker.nfound;
opts->not_cmp = opts->not_cmp | nFoundbyWorker.not_cmp;
busyTasks--;
havePrintToken = 1;
} /* end else-if */
else if (Status.MPI_TAG == MPI_TAG_PRINT_DATA) {
char data[PRINT_DATA_MAX_SIZE + 1];
HDmemset(data, 0, PRINT_DATA_MAX_SIZE + 1);
MPI_Recv(data, PRINT_DATA_MAX_SIZE, MPI_CHAR, Status.MPI_SOURCE, MPI_TAG_PRINT_DATA,
MPI_COMM_WORLD, &Status);
HDprintf("%s", data);
} /* end else-if */
else {
HDprintf("ph5diff-manager: ERROR!! Invalid tag (%d) received \n", Status.MPI_TAG);
MPI_Abort(MPI_COMM_WORLD, 0);
} /* end else */
} /* end while */
for (i = 1; (int)i < g_nTasks; i++)
MPI_Send(NULL, 0, MPI_BYTE, (int)i, MPI_TAG_END, MPI_COMM_WORLD);
/* Print any final data waiting in our queue */
print_incoming_data();
} /* end if */
H5TOOLS_DEBUG("done with if block");
HDfree(workerTasks);
}
#endif /* USE_ORIGINAL_CODE (PARALLEL) */
opts->err_stat = opts->err_stat | ret_value;
free_exclude_attr_list(opts);
/* free table */
if (table)
trav_table_free(table);
H5TOOLS_ENDDEBUG(" diffs=%d - errstat:%d", nfound, opts->err_stat);
return nfound;
}
/*-------------------------------------------------------------------------
* Function: diff
*
* Purpose: switch between types and choose the diff function
* TYPE is either
* H5G_GROUP Object is a group
* H5G_DATASET Object is a dataset
* H5G_TYPE Object is a named data type
* H5G_LINK Object is a symbolic link
*
* Return: Number of differences found
*-------------------------------------------------------------------------
*/
hsize_t
diff(hid_t file1_id, const char *path1, hid_t file2_id, const char *path2, diff_opt_t *opts,
diff_args_t *argdata)
{
int status = -1;
hid_t dset1_id = H5I_INVALID_HID;
hid_t dset2_id = H5I_INVALID_HID;
hid_t type1_id = H5I_INVALID_HID;
hid_t type2_id = H5I_INVALID_HID;
hid_t grp1_id = H5I_INVALID_HID;
hid_t grp2_id = H5I_INVALID_HID;
hbool_t is_dangle_link1 = FALSE;
hbool_t is_dangle_link2 = FALSE;
hbool_t is_hard_link = FALSE;
hsize_t nfound = 0;
h5trav_type_t object_type;
diff_err_t ret_value = opts->err_stat;
/* to get link info */
h5tool_link_info_t linkinfo1;
h5tool_link_info_t linkinfo2;
H5TOOLS_START_DEBUG(" - errstat:%d", opts->err_stat);
/*init link info struct */
HDmemset(&linkinfo1, 0, sizeof(h5tool_link_info_t));
HDmemset(&linkinfo2, 0, sizeof(h5tool_link_info_t));
/* pass how to handle printing warnings to linkinfo option */
if (print_warn(opts))
linkinfo1.opt.msg_mode = linkinfo2.opt.msg_mode = 1;
/* for symbolic links, take care follow symlink and no dangling link
* options */
if (argdata->type[0] == H5TRAV_TYPE_LINK || argdata->type[0] == H5TRAV_TYPE_UDLINK ||
argdata->type[1] == H5TRAV_TYPE_LINK || argdata->type[1] == H5TRAV_TYPE_UDLINK) {
/*
* check dangling links for path1 and path2
*/
H5TOOLS_DEBUG("diff links");
/* target object1 - get type and name */
if ((status = H5tools_get_symlink_info(file1_id, path1, &linkinfo1, opts->follow_links)) < 0)
H5TOOLS_GOTO_ERROR(H5DIFF_ERR, "H5tools_get_symlink_info failed");
/* dangling link */
if (status == 0) {
if (opts->no_dangle_links) {
/* dangling link is error */
if (opts->mode_verbose)
parallel_print("Warning: <%s> is a dangling link.\n", path1);
H5TOOLS_GOTO_ERROR(H5DIFF_ERR, "dangling link is error");
}
else
is_dangle_link1 = TRUE;
}
/* target object2 - get type and name */
if ((status = H5tools_get_symlink_info(file2_id, path2, &linkinfo2, opts->follow_links)) < 0)
H5TOOLS_GOTO_ERROR(H5DIFF_ERR, "H5tools_get_symlink_info failed");
/* dangling link */
if (status == 0) {
if (opts->no_dangle_links) {
/* dangling link is error */
if (opts->mode_verbose)
parallel_print("Warning: <%s> is a dangling link.\n", path2);
H5TOOLS_GOTO_ERROR(H5DIFF_ERR, "dangling link is error");
}
else
is_dangle_link2 = TRUE;
}
/* found dangling link */
if (is_dangle_link1 || is_dangle_link2) {
H5TOOLS_GOTO_DONE(H5DIFF_NO_ERR);
}
/* follow symbolic link option */
if (opts->follow_links) {
if (linkinfo1.linfo.type == H5L_TYPE_SOFT || linkinfo1.linfo.type == H5L_TYPE_EXTERNAL)
argdata->type[0] = (h5trav_type_t)linkinfo1.trg_type;
if (linkinfo2.linfo.type == H5L_TYPE_SOFT || linkinfo2.linfo.type == H5L_TYPE_EXTERNAL)
argdata->type[1] = (h5trav_type_t)linkinfo2.trg_type;
}
}
/* if objects are not the same type */
if (argdata->type[0] != argdata->type[1]) {
H5TOOLS_DEBUG("diff objects are not the same");
if (opts->mode_verbose || opts->mode_list_not_cmp) {
parallel_print("Not comparable: <%s> is of type %s and <%s> is of type %s\n", path1,
get_type(argdata->type[0]), path2, get_type(argdata->type[1]));
}
opts->not_cmp = 1;
/* TODO: will need to update non-comparable is different
* opts->contents = 0;
*/
H5TOOLS_GOTO_DONE(H5DIFF_NO_ERR);
}
else /* now both object types are same */
object_type = argdata->type[0];
/*
* If both points to the same target object, skip comparing details inside
* of the objects to improve performance.
* Always check for the hard links, otherwise if follow symlink option is
* specified.
*
* Perform this to match the outputs as bypassing.
*/
if (argdata->is_same_trgobj) {
H5TOOLS_DEBUG("argdata->is_same_trgobj");
is_hard_link = (object_type == H5TRAV_TYPE_DATASET || object_type == H5TRAV_TYPE_NAMED_DATATYPE ||
object_type == H5TRAV_TYPE_GROUP);
if (opts->follow_links || is_hard_link) {
/* print information is only verbose option is used */
if (opts->mode_verbose || opts->mode_report) {
switch (object_type) {
case H5TRAV_TYPE_DATASET:
do_print_objname("dataset", path1, path2, opts);
break;
case H5TRAV_TYPE_NAMED_DATATYPE:
do_print_objname("datatype", path1, path2, opts);
break;
case H5TRAV_TYPE_GROUP:
do_print_objname("group", path1, path2, opts);
break;
case H5TRAV_TYPE_LINK:
do_print_objname("link", path1, path2, opts);
break;
case H5TRAV_TYPE_UDLINK:
if (linkinfo1.linfo.type == H5L_TYPE_EXTERNAL &&
linkinfo2.linfo.type == H5L_TYPE_EXTERNAL)
do_print_objname("external link", path1, path2, opts);
else
do_print_objname("user defined link", path1, path2, opts);
break;
case H5TRAV_TYPE_UNKNOWN:
default:
parallel_print("Comparison not supported: <%s> and <%s> are of type %s\n", path1,
path2, get_type(object_type));
opts->not_cmp = 1;
break;
} /* switch(type)*/
print_found(nfound);
} /* if(opts->mode_verbose || opts->mode_report) */
/* exact same, so comparison is done */
H5TOOLS_GOTO_DONE(H5DIFF_NO_ERR);
}
}
switch (object_type) {
/*----------------------------------------------------------------------
* H5TRAV_TYPE_DATASET
*----------------------------------------------------------------------
*/
case H5TRAV_TYPE_DATASET:
H5TOOLS_DEBUG("diff object type H5TRAV_TYPE_DATASET - errstat:%d", opts->err_stat);
if ((dset1_id = H5Dopen2(file1_id, path1, H5P_DEFAULT)) < 0)
H5TOOLS_GOTO_ERROR(H5DIFF_ERR, "H5Dopen2 failed");
if ((dset2_id = H5Dopen2(file2_id, path2, H5P_DEFAULT)) < 0)
H5TOOLS_GOTO_ERROR(H5DIFF_ERR, "H5Dopen2 failed");
H5TOOLS_DEBUG("paths: %s - %s", path1, path2);
/* verbose (-v) and report (-r) mode */
if (opts->mode_verbose || opts->mode_report) {
do_print_objname("dataset", path1, path2, opts);
H5TOOLS_DEBUG("call diff_dataset 1:%s 2:%s ", path1, path2);
nfound = diff_dataset(file1_id, file2_id, path1, path2, opts);
print_found(nfound);
}
/* quiet mode (-q), just count differences */
else if (opts->mode_quiet) {
nfound = diff_dataset(file1_id, file2_id, path1, path2, opts);
}
/* the rest (-c, none, ...) */
else {
nfound = diff_dataset(file1_id, file2_id, path1, path2, opts);
/* print info if difference found */
if (nfound) {
do_print_objname("dataset", path1, path2, opts);
print_found(nfound);
}
}
H5TOOLS_DEBUG("diff after dataset:%d - errstat:%d", nfound, opts->err_stat);
/*---------------------------------------------------------
* compare attributes
* if condition refers to cases when the dataset is a
* referenced object
*---------------------------------------------------------
*/
if (path1 && !is_exclude_attr(path1, object_type, opts)) {
H5TOOLS_DEBUG("call diff_attr 1:%s 2:%s ", path1, path2);
nfound += diff_attr(dset1_id, dset2_id, path1, path2, opts);
}
if (H5Dclose(dset1_id) < 0)
H5TOOLS_GOTO_ERROR(H5DIFF_ERR, "H5Dclose failed");
if (H5Dclose(dset2_id) < 0)
H5TOOLS_GOTO_ERROR(H5DIFF_ERR, "H5Dclose failed");
break;
/*----------------------------------------------------------------------
* H5TRAV_TYPE_NAMED_DATATYPE
*----------------------------------------------------------------------
*/
case H5TRAV_TYPE_NAMED_DATATYPE:
H5TOOLS_DEBUG("H5TRAV_TYPE_NAMED_DATATYPE 1:%s 2:%s ", path1, path2);
if ((type1_id = H5Topen2(file1_id, path1, H5P_DEFAULT)) < 0)
H5TOOLS_GOTO_ERROR(H5DIFF_ERR, "H5Topen2 failed");
if ((type2_id = H5Topen2(file2_id, path2, H5P_DEFAULT)) < 0)
H5TOOLS_GOTO_ERROR(H5DIFF_ERR, "H5Topen2 failed");
if ((status = H5Tequal(type1_id, type2_id)) < 0)
H5TOOLS_GOTO_ERROR(H5DIFF_ERR, "H5Tequal failed");
/* if H5Tequal is > 0 then the datatypes refer to the same datatype */
nfound = (status > 0) ? 0 : 1;
if (print_objname(opts, nfound))
do_print_objname("datatype", path1, path2, opts);
/* always print the number of differences found in verbose mode */
if (opts->mode_verbose)
print_found(nfound);
/*-----------------------------------------------------------------
* compare attributes
* the if condition refers to cases when the dataset is a
* referenced object
*-----------------------------------------------------------------
*/
if (path1 && !is_exclude_attr(path1, object_type, opts)) {
H5TOOLS_DEBUG("call diff_attr 1:%s 2:%s ", path1, path2);
nfound += diff_attr(type1_id, type2_id, path1, path2, opts);
}
if (H5Tclose(type1_id) < 0)
H5TOOLS_GOTO_ERROR(H5DIFF_ERR, "H5Tclose failed");
if (H5Tclose(type2_id) < 0)
H5TOOLS_GOTO_ERROR(H5DIFF_ERR, "H5Tclose failed");
break;
/*----------------------------------------------------------------------
* H5TRAV_TYPE_GROUP
*----------------------------------------------------------------------
*/
case H5TRAV_TYPE_GROUP:
H5TOOLS_DEBUG("H5TRAV_TYPE_GROUP 1:%s 2:%s ", path1, path2);
if (print_objname(opts, nfound))
do_print_objname("group", path1, path2, opts);
/* always print the number of differences found in verbose mode */
if (opts->mode_verbose)
print_found(nfound);
if ((grp1_id = H5Gopen2(file1_id, path1, H5P_DEFAULT)) < 0)
H5TOOLS_GOTO_ERROR(H5DIFF_ERR, "H5Gclose failed");
if ((grp2_id = H5Gopen2(file2_id, path2, H5P_DEFAULT)) < 0)
H5TOOLS_GOTO_ERROR(H5DIFF_ERR, "H5Gclose failed");
/*-----------------------------------------------------------------
* compare attributes
* the if condition refers to cases when the dataset is a
* referenced object
*-----------------------------------------------------------------
*/
if (path1 && !is_exclude_attr(path1, object_type, opts)) {
H5TOOLS_DEBUG("call diff_attr 1:%s 2:%s ", path1, path2);
nfound += diff_attr(grp1_id, grp2_id, path1, path2, opts);
}
if (H5Gclose(grp1_id) < 0)
H5TOOLS_GOTO_ERROR(H5DIFF_ERR, "H5Gclose failed");
if (H5Gclose(grp2_id) < 0)
H5TOOLS_GOTO_ERROR(H5DIFF_ERR, "H5Gclose failed");
break;
/*----------------------------------------------------------------------
* H5TRAV_TYPE_LINK
*----------------------------------------------------------------------
*/
case H5TRAV_TYPE_LINK: {
H5TOOLS_DEBUG("H5TRAV_TYPE_LINK 1:%s 2:%s ", path1, path2);
status = HDstrcmp(linkinfo1.trg_path, linkinfo2.trg_path);
/* if the target link name is not same then the links are "different" */
nfound = (status != 0) ? 1 : 0;
if (print_objname(opts, nfound))
do_print_objname("link", path1, path2, opts);
/* always print the number of differences found in verbose mode */
if (opts->mode_verbose)
print_found(nfound);
} break;
/*----------------------------------------------------------------------
* H5TRAV_TYPE_UDLINK
*----------------------------------------------------------------------
*/
case H5TRAV_TYPE_UDLINK: {
H5TOOLS_DEBUG("H5TRAV_TYPE_UDLINK 1:%s 2:%s ", path1, path2);
/* Only external links will have a query function registered */
if (linkinfo1.linfo.type == H5L_TYPE_EXTERNAL && linkinfo2.linfo.type == H5L_TYPE_EXTERNAL) {
/* If the buffers are the same size, compare them */
if (linkinfo1.linfo.u.val_size == linkinfo2.linfo.u.val_size) {
status = HDmemcmp(linkinfo1.trg_path, linkinfo2.trg_path, linkinfo1.linfo.u.val_size);
}
else
status = 1;
/* if "linkinfo1.trg_path" != "linkinfo2.trg_path" then the links
* are "different" extlinkinfo#.path is combination string of
* file_name and obj_name
*/
nfound = (status != 0) ? 1 : 0;
if (print_objname(opts, nfound))
do_print_objname("external link", path1, path2, opts);
} /* end if */
else {
/* If one or both of these links isn't an external link, we can only
* compare information from H5Lget_info since we don't have a query
* function registered for them.
*
* If the link classes or the buffer length are not the
* same, the links are "different"
*/
if ((linkinfo1.linfo.type != linkinfo2.linfo.type) ||
(linkinfo1.linfo.u.val_size != linkinfo2.linfo.u.val_size))
nfound = 1;
else
nfound = 0;
if (print_objname(opts, nfound))
do_print_objname("user defined link", path1, path2, opts);
} /* end else */
/* always print the number of differences found in verbose mode */
if (opts->mode_verbose)
print_found(nfound);
} break;
case H5TRAV_TYPE_UNKNOWN:
default:
if (opts->mode_verbose)
parallel_print("Comparison not supported: <%s> and <%s> are of type %s\n", path1, path2,
get_type(object_type));
opts->not_cmp = 1;
break;
}
done:
opts->err_stat = opts->err_stat | ret_value;
/*-----------------------------------
* handle dangling link(s)
*/
/* both path1 and path2 are dangling links */
if (is_dangle_link1 && is_dangle_link2) {
if (print_objname(opts, nfound)) {
do_print_objname("dangling link", path1, path2, opts);
print_found(nfound);
}
}
/* path1 is dangling link */
else if (is_dangle_link1) {
if (opts->mode_verbose)
parallel_print("obj1 <%s> is a dangling link.\n", path1);
nfound++;
if (print_objname(opts, nfound))
print_found(nfound);
}
/* path2 is dangling link */
else if (is_dangle_link2) {
if (opts->mode_verbose)
parallel_print("obj2 <%s> is a dangling link.\n", path2);
nfound++;
if (print_objname(opts, nfound))
print_found(nfound);
}
/* free link info buffer */
if (linkinfo1.trg_path)
HDfree(linkinfo1.trg_path);
if (linkinfo2.trg_path)
HDfree(linkinfo2.trg_path);
/* close */
/* disable error reporting */
H5E_BEGIN_TRY
{
H5Dclose(dset1_id);
H5Dclose(dset2_id);
H5Tclose(type1_id);
H5Tclose(type2_id);
H5Gclose(grp1_id);
H5Gclose(grp2_id);
/* enable error reporting */
}
H5E_END_TRY;
H5TOOLS_ENDDEBUG(": %d - errstat:%d", nfound, opts->err_stat);
return nfound;
}
#ifdef H5_HAVE_PARALLEL
int
h5diff_get_global(int *flag)
{
int global_flag;
MPI_Reduce(flag, &global_flag, 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD);
return global_flag;
}
#endif
|