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
#include "iMeshP.h"
#include "moab_mpi.h"
#include <iostream>
#include <algorithm>
#include <vector>
#include <sstream>
#include <cassert>
#include <cmath>
#include <map>
#include <cstring>
#include <cstdio>  // remove()

#if !defined( _MSC_VER ) && !defined( __MINGW32__ )
#include <unistd.h>
#endif

#define STRINGIFY_( X ) #X
#define STRINGIFY( X )  STRINGIFY_( X )
const char* const FILENAME = "iMeshP_test_file";

/**************************************************************************
                              Error Checking
 **************************************************************************/

#define CHKERR                                                                                         \
    do                                                                                                 \
    {                                                                                                  \
        if( ierr )                                                                                     \
        {                                                                                              \
            std::cerr << "Error code  " << ierr << " at " << __FILE__ << ":" << __LINE__ << std::endl; \
            return ierr;                                                                               \
        }                                                                                              \
    } while( false )

#define PCHECK                            \
    do                                    \
    {                                     \
        ierr = is_any_proc_error( ierr ); \
        CHKERR;                           \
    } while( false )

// Use my_rank instead of rank to avoid shadowed declaration
#define ASSERT( A )                                                                                                 \
    do                                                                                                              \
    {                                                                                                               \
        if( is_any_proc_error( !( A ) ) )                                                                           \
        {                                                                                                           \
            int my_rank = 0;                                                                                        \
            MPI_Comm_rank( MPI_COMM_WORLD, &my_rank );                                                              \
            if( 0 == my_rank )                                                                                      \
                std::cerr << "Failed assertion: " #A << std::endl << "  at " __FILE__ ":" << __LINE__ << std::endl; \
            return 1;                                                                                               \
        }                                                                                                           \
    } while( false )

// Test if is_my_error is non-zero on any processor in MPI_COMM_WORLD
int is_any_proc_error( int is_my_error )
{
    int result;
    int err = MPI_Allreduce( &is_my_error, &result, 1, MPI_INT, MPI_MAX, MPI_COMM_WORLD );
    return err || result;
}

/**************************************************************************
                           Test  Declarations
 **************************************************************************/

class PartMap;

/**\brief Consistency check for parallel load
 *
 * All other tests depend on this one.
 */
int test_load( iMesh_Instance, iMeshP_PartitionHandle prtn, PartMap& map, int comm_size );

/**\brief Test partition query methods
 *
 * Test:
 * - iMeshP_getPartitionComm
 * - iMeshP_getNumPartitions
 * - iMeshP_getPartitions
 */
int test_get_partitions( iMesh_Instance, iMeshP_PartitionHandle prtn, const PartMap& );

/**\brief Test part quyery methods
 *
 * Test:
 * - iMeshP_getNumGlobalParts
 * - iMeshP_getNumLocalParts
 * - iMeshP_getLocalParts
 */
int test_get_parts( iMesh_Instance, iMeshP_PartitionHandle prtn, const PartMap& );

/**\brief Test query by entity type
 *
 * Test:
 * - iMeshP_getNumOfTypeAll
 * - iMeshP_getNumOfType
 * - iMeshP_getEntities
 * -
 */
int test_get_by_type( iMesh_Instance, iMeshP_PartitionHandle prtn, const PartMap& );

/**\brief Test query by entity topology
 *
 * Test:
 * - iMeshP_getNumOfTopoAll
 * - iMeshP_getNumOfTopo
 * - iMeshP_getEntities
 * -
 */
int test_get_by_topo( iMesh_Instance, iMeshP_PartitionHandle prtn, const PartMap& );

/**\brief Test mapping from part id to part handle
 *
 * Test:
 * - iMeshP_getPartIdFromPartHandle
 * - iMeshP_getPartIdsFromPartHandlesArr
 * - iMeshP_getPartHandleFromPartId
 * - iMeshP_getPartHandlesFromPartsIdsArr
 * - iMeshP_getRankOfPart
 * - iMeshP_getRankOfPartArr
 */
int test_part_id_handle( iMesh_Instance, iMeshP_PartitionHandle prtn, const PartMap& );

/**\brief Test get part rank
 *
 * Tests:
 * - iMeshP_getRankOfPart
 * - iMeshP_getRankOfPartArr
 */
int test_part_rank( iMesh_Instance, iMeshP_PartitionHandle prtn, const PartMap& );

/**\brief Test querying of part neighbors
 *
 * Test:
 * - iMeshP_getNumPartNbors
 * - iMeshP_getNumPartNborsArr
 * - iMeshP_getPartNbors
 * - iMeshP_getPartNborsArr
 */
int test_get_neighbors( iMesh_Instance, iMeshP_PartitionHandle prtn, const PartMap& );

/**\brief Test querying of part boundary entities
 *
 * Test:
 * - iMeshP_getNumPartBdryEnts
 * - iMeshP_getPartBdryEnts
 */
int test_get_part_boundary( iMesh_Instance, iMeshP_PartitionHandle prtn, const PartMap& );

/**\brief Test querying of part boundary entities
 *
 * Test:
 * - iMeshP_initPartBdryEntIter
 * - iMeshP_initPartBdryEntArrIter
 */
int test_part_boundary_iter( iMesh_Instance, iMeshP_PartitionHandle prtn, const PartMap& );

/**\brief Test adjacent entity query
 *
 * Test:
 * - iMeshP_getAdjEntities
 */
int test_get_adjacencies( iMesh_Instance, iMeshP_PartitionHandle prtn, const PartMap& );

/**\brief Test entity iterators
 *
 * Test:
 * - iMeshP_initEntIter
 * - iMeshP_initEntArrIter
 */
int test_entity_iterator( iMesh_Instance, iMeshP_PartitionHandle prtn, const PartMap& );

/**\brief Test entity owner queries
 *
 * Test:
 * - iMeshP_getEntOwnerPart
 * - iMeshP_getEntOwnerPartArr
 * - iMeshP_isEntOwner
 * - iMeshP_isEntOwnerArr
 */
int test_entity_owner( iMesh_Instance, iMeshP_PartitionHandle prtn, const PartMap& );

/**\brief Test entity status
 *
 * Test:
 * - iMeshP_getEntStatus
 * - iMeshP_getEntStatusArr
 */
int test_entity_status( iMesh_Instance, iMeshP_PartitionHandle prtn, const PartMap& );

/**\brief Test information about entity copies for interface entities
 *
 * Test:
 * - iMeshP_getNumCopies
 * - iMeshP_getCopyParts
 */
int test_entity_copy_parts( iMesh_Instance, iMeshP_PartitionHandle prtn, const PartMap& );

/**\brief Test information about entity copies for interface entities
 *
 * Test:
 * - iMeshP_getCopies
 * - iMeshP_getCopyOnPart
 * - iMeshP_getOwnerCopy
 */
int test_entity_copies( iMesh_Instance, iMeshP_PartitionHandle prtn, const PartMap& );

/**\brief Test creation of ghost entities
 *
 * Test:
 * - iMeshP_createGhostEntsAll
 */
int test_create_ghost_ents( iMesh_Instance, iMeshP_PartitionHandle prtn, const PartMap& );

/**\brief Test commuinication of tag data
 *
 * Test:
 * - iMeshP_pushTags
 * - iMeshP_pushTagsEnt
 */
int test_push_tag_data_iface( iMesh_Instance, iMeshP_PartitionHandle prtn, const PartMap& );
int test_push_tag_data_ghost( iMesh_Instance, iMeshP_PartitionHandle prtn, const PartMap& );

int test_exchange_ents( iMesh_Instance imesh, iMeshP_PartitionHandle prtn, const PartMap& map );

/**************************************************************************
                              Helper Funcions
 **************************************************************************/

class PartMap
{
  public:
    int num_parts() const
    {
        return sortedPartList.size();
    }

    iMeshP_Part part_id_from_local_id( int local_id ) const
    {
        return sortedPartList[idx_from_local_id( local_id )];
    }

    int local_id_from_part_id( iMeshP_Part part ) const
    {
        return partLocalIds[idx_from_part_id( part )];
    }

    int rank_from_part_id( iMeshP_Part part ) const<--- The function 'rank_from_part_id' is never used.
    {
        return partRanks[idx_from_part_id( part )];
    }

    int rank_from_local_id( int id ) const<--- The function 'rank_from_local_id' is never used.
    {
        return partRanks[idx_from_local_id( id )];
    }

    int count_from_rank( int rank ) const
    {
        return std::count( partRanks.begin(), partRanks.end(), rank );
    }

    void part_id_from_rank( int rank, std::vector< iMeshP_Part >& parts ) const;

    void local_id_from_rank( int rank, std::vector< int >& ids ) const;

    const std::vector< iMeshP_Part >& get_parts() const
    {
        return sortedPartList;
    }

    const std::vector< int >& get_ranks() const
    {
        return partRanks;
    }

    int build_map( iMesh_Instance imesh, iMeshP_PartitionHandle partition, int num_expected_parts );

    static int part_from_coords( iMesh_Instance imesh, iMeshP_PartHandle part, int& id_out );

  private:
    inline int idx_from_part_id( iMeshP_Part id ) const
    {
        return std::lower_bound( sortedPartList.begin(), sortedPartList.end(), id ) - sortedPartList.begin();
    }
    inline int idx_from_local_id( int id ) const
    {
        return localIdReverseMap[id];
    }

    std::vector< iMeshP_Part > sortedPartList;
    std::vector< int > partRanks;
    std::vector< int > partLocalIds;
    std::vector< int > localIdReverseMap;
};

/**\brief Create mesh for use in parallel tests */
int create_mesh( const char* filename, int num_parts );

int create_mesh_in_memory( int rank, int size, iMesh_Instance imesh, iMeshP_PartitionHandle& prtn, PartMap& map );

/**\brief get unique identifier for each vertex */
int vertex_tag( iMesh_Instance imesh, iBase_EntityHandle vertex, int& tag );

int get_local_parts( iMesh_Instance instance,
                     iMeshP_PartitionHandle prtn,
                     std::vector< iMeshP_PartHandle >& handles,
                     std::vector< iMeshP_Part >* ids = 0 )
{
    iMeshP_PartHandle* arr = 0;
    int ierr, alloc = 0, size;
    iMeshP_getLocalParts( instance, prtn, &arr, &alloc, &size, &ierr );CHKERR;<--- Skipping configuration 'MOAB_FC_FUNC' since the value of 'MOAB_FC_FUNC' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'MOAB_FC_FUNC_' since the value of 'MOAB_FC_FUNC_' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
    handles.resize( size );
    std::copy( arr, arr + size, handles.begin() );
    free( arr );
    if( !ids ) return iBase_SUCCESS;

    ids->resize( size );
    alloc            = size;
    iMeshP_Part* ptr = &( *ids )[0];
    iMeshP_getPartIdsFromPartHandlesArr( instance, prtn, &handles[0], handles.size(), &ptr, &alloc, &size, &ierr );CHKERR;<--- Skipping configuration 'MOAB_FC_FUNC' since the value of 'MOAB_FC_FUNC' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'MOAB_FC_FUNC_' since the value of 'MOAB_FC_FUNC_' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
    assert( size == (int)ids->size() );
    assert( ptr == &( *ids )[0] );
    return iBase_SUCCESS;
}

static int get_entities( iMesh_Instance imesh,
                         iBase_EntitySetHandle set,
                         iBase_EntityType type,
                         iMesh_EntityTopology topo,
                         std::vector< iBase_EntityHandle >& entities )
{
    iBase_EntityHandle* array = 0;
    int junk = 0, size = 0, err;
    iMesh_getEntities( imesh, set, type, topo, &array, &junk, &size, &err );<--- Skipping configuration 'MOAB_FC_FUNC' since the value of 'MOAB_FC_FUNC' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'MOAB_FC_FUNC_' since the value of 'MOAB_FC_FUNC_' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
    if( !err )
    {
        entities.clear();
        entities.resize( size );
        std::copy( array, array + size, entities.begin() );
        free( array );
    }
    return err;
}

static int get_part_quads_and_verts( iMesh_Instance imesh,
                                     iMeshP_PartHandle part,
                                     std::vector< iBase_EntityHandle >& elems,
                                     std::vector< iBase_EntityHandle >& verts )
{
    int ierr = get_entities( imesh, part, iBase_FACE, iMesh_QUADRILATERAL, elems );CHKERR;

    verts.resize( 4 * elems.size() );
    std::vector< int > junk( elems.size() + 1 );
    int junk1 = verts.size(), count, junk2 = junk.size(), junk3;
    iBase_EntityHandle* junk4 = &verts[0];
    int* junk5                = &junk[0];
    iMesh_getEntArrAdj( imesh, &elems[0], elems.size(), iBase_VERTEX, &junk4, &junk1, &count, &junk5, &junk2, &junk3,<--- Skipping configuration 'MOAB_FC_FUNC' since the value of 'MOAB_FC_FUNC' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'MOAB_FC_FUNC_' since the value of 'MOAB_FC_FUNC_' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
                        &ierr );CHKERR;
    assert( junk1 == (int)verts.size() );
    assert( count == (int)( 4 * elems.size() ) );
    assert( junk2 == (int)junk.size() );
    assert( junk4 == &verts[0] );
    assert( junk5 == &junk[0] );
    std::sort( verts.begin(), verts.end() );
    verts.erase( std::unique( verts.begin(), verts.end() ), verts.end() );
    return iBase_SUCCESS;
}

static int get_coords( iMesh_Instance imesh, const iBase_EntityHandle* verts, int num_verts, double* coords )
{
    double* junk1 = coords;
    int junk2     = 3 * num_verts;
    int junk3;
    int ierr;
    iMesh_getVtxArrCoords( imesh, verts, num_verts, iBase_INTERLEAVED, &junk1, &junk2, &junk3, &ierr );<--- Skipping configuration 'MOAB_FC_FUNC' since the value of 'MOAB_FC_FUNC' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'MOAB_FC_FUNC_' since the value of 'MOAB_FC_FUNC_' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
    if( iBase_SUCCESS != ierr ) return ierr;
    assert( junk1 == coords );
    assert( junk2 == 3 * num_verts );
    assert( junk3 == 3 * num_verts );
    return iBase_SUCCESS;
}

/**************************************************************************
                              Main Method
 **************************************************************************/

#define RUN_TEST( A ) run_test( &( A ), #A )

int run_test( int ( *func )( iMesh_Instance, iMeshP_PartitionHandle, const PartMap& ), const char* func_name )
{
    int rank, size, ierr;
    MPI_Comm_rank( MPI_COMM_WORLD, &rank );
    MPI_Comm_size( MPI_COMM_WORLD, &size );
    iMesh_Instance imesh;
    iMesh_newMesh( 0, &imesh, &ierr, 0 );<--- Skipping configuration 'MOAB_FC_FUNC' since the value of 'MOAB_FC_FUNC' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'MOAB_FC_FUNC_' since the value of 'MOAB_FC_FUNC_' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
    PCHECK;

    iMeshP_PartitionHandle prtn;
    iMeshP_createPartitionAll( imesh, MPI_COMM_WORLD, &prtn, &ierr );<--- Skipping configuration 'MOAB_FC_FUNC' since the value of 'MOAB_FC_FUNC' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'MOAB_FC_FUNC_' since the value of 'MOAB_FC_FUNC_' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
    PCHECK;

    PartMap map;

#ifdef MOAB_HAVE_HDF5
    if( rank == 0 )
    {
        ierr = create_mesh( FILENAME, size );
    }
    MPI_Bcast( &ierr, 1, MPI_INT, 0, MPI_COMM_WORLD );
    if( ierr )
    {
        if( rank == 0 )
        {
            std::cerr << "Failed to create input test file on root processor.  Aborting." << std::endl;
        }
        abort();
    }

    ierr = test_load( imesh, prtn, map, size );
    if( ierr )
    {
        if( rank == 0 )
        {
            std::cerr << "Failed to load input mesh." << std::endl
                      << "Cannot run further tests." << std::endl
                      << "ABORTING" << std::endl;
        }
        abort();
    }
#else
    // so we have MPI and no HDF5; in order to run the test we need to create the
    // model in memory, and then call sync to resolve shared ents, as if it was read
    ierr = create_mesh_in_memory( rank, size, imesh, prtn, map );
    MPI_Bcast( &ierr, 1, MPI_INT, 0, MPI_COMM_WORLD );
    if( ierr )
    {
        if( rank == 0 )
        {
            std::cerr << "Failed to create mesh.  Aborting." << std::endl;
        }
        abort();
    }

#endif
    int result = ( *func )( imesh, prtn, map );
    int is_err = is_any_proc_error( result );
    if( rank == 0 )
    {
        if( is_err )
            std::cout << func_name << " : FAILED!!" << std::endl;
        else
            std::cout << func_name << " : success" << std::endl;
    }

    iMesh_dtor( imesh, &ierr );CHKERR;<--- Skipping configuration 'MOAB_FC_FUNC' since the value of 'MOAB_FC_FUNC' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'MOAB_FC_FUNC_' since the value of 'MOAB_FC_FUNC_' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
    return is_err;
}

int main( int argc, char* argv[] )
{
    MPI_Init( &argc, &argv );
    int size, rank;
    MPI_Comm_rank( MPI_COMM_WORLD, &rank );
    MPI_Comm_size( MPI_COMM_WORLD, &size );

    if( argc > 2 && !strcmp( argv[1], "-p" ) )
    {
#if !defined( _MSC_VER ) && !defined( __MINGW32__ )
        std::cout << "Processor " << rank << " of " << size << " with PID " << getpid() << std::endl;
        std::cout.flush();
#endif
        // loop forever on requested processor, giving the user time
        // to attach a debugger.  Once the debugger in attached, user
        // can change 'pause'.  E.g. on gdb do "set var pause = 0"
        if( atoi( argv[2] ) == rank )
        {
            volatile int pause = 1;<--- Assignment 'pause=1', assigned value is 1
            while( pause )<--- Condition 'pause' is always true
                ;
        }
        MPI_Barrier( MPI_COMM_WORLD );
    }

    int num_errors = 0;
    num_errors += RUN_TEST( test_get_partitions );
    num_errors += RUN_TEST( test_get_parts );
    num_errors += RUN_TEST( test_get_by_type );
    num_errors += RUN_TEST( test_get_by_topo );
    num_errors += RUN_TEST( test_part_id_handle );
    num_errors += RUN_TEST( test_part_rank );
    num_errors += RUN_TEST( test_get_neighbors );
    num_errors += RUN_TEST( test_get_part_boundary );
    num_errors += RUN_TEST( test_part_boundary_iter );
    num_errors += RUN_TEST( test_get_adjacencies );
    num_errors += RUN_TEST( test_entity_iterator );
    num_errors += RUN_TEST( test_entity_owner );
    num_errors += RUN_TEST( test_entity_status );
    num_errors += RUN_TEST( test_entity_copy_parts );
    num_errors += RUN_TEST( test_entity_copies );
    num_errors += RUN_TEST( test_push_tag_data_iface );
    num_errors += RUN_TEST( test_push_tag_data_ghost );
    num_errors += RUN_TEST( test_create_ghost_ents );
    num_errors += RUN_TEST( test_exchange_ents );

    // wait until all procs are done before writing summary data
    std::cout.flush();
    MPI_Barrier( MPI_COMM_WORLD );

#ifdef MOAB_HAVE_HDF5
    // clean up output file
    if( rank == 0 ) remove( FILENAME );<--- First condition
#endif

    if( rank == 0 )<--- Second condition
    {
        if( !num_errors )
            std::cout << "All tests passed" << std::endl;
        else
            std::cout << num_errors << " TESTS FAILED!" << std::endl;
    }

    MPI_Finalize();
    return num_errors;
}

// Create a mesh
//
//
// Groups of four quads will be arranged into parts as follows:
// +------+------+------+------+------+-----
// |             |             |
// |             |             |
// +    Part 0   +    Part 2   +    Part 4
// |             |             |
// |             |             |
// +------+------+------+------+------+-----
// |             |             |
// |             |             |
// +    Part 1   +    Part 3   +    Part 5
// |             |             |
// |             |             |
// +------+------+------+------+------+-----
//
// Vertices will be enumerated as follows:
// 1------6-----11-----16-----21-----26-----
// |             |             |
// |             |             |
// 2      7     12     17     22     27
// |             |             |
// |             |             |
// 3------8-----13-----18-----23-----28-----
// |             |             |
// |             |             |
// 4      9     14     19     24     29
// |             |             |
// |             |             |
// 5-----10-----15-----20-----25-----30-----
//
// Element IDs will be [4*rank+1,4*rank+5]
template < int size >
struct EHARR
{
    iBase_EntityHandle h[size];
    iBase_EntityHandle& operator[]( int i )
    {
        return h[i];
    }
    operator iBase_EntityHandle*()
    {
        return h;
    }
};
int create_mesh( const char* filename, int num_parts )
{
    const char* tagname = "GLOBAL_ID";
    int ierr;

    iMesh_Instance imesh;
    iMesh_newMesh( 0, &imesh, &ierr, 0 );CHKERR;<--- Skipping configuration 'MOAB_FC_FUNC' since the value of 'MOAB_FC_FUNC' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'MOAB_FC_FUNC_' since the value of 'MOAB_FC_FUNC_' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.

    const int num_full_cols  = 2 * ( num_parts / 2 );
    const int need_half_cols = num_parts % 2;
    const int num_cols       = num_full_cols + 2 * need_half_cols;
    const int num_vtx        = 5 + 5 * num_cols - 4 * ( num_parts % 2 );
    std::vector< EHARR< 5 > > vertices( num_cols + 1 );
    std::vector< EHARR< 4 > > elements( num_cols );
    std::vector< int > vertex_ids( num_vtx );
    std::vector< iBase_EntityHandle > vertex_list( num_vtx );
    for( int i = 0; i < num_vtx; ++i )
        vertex_ids[i] = i + 1;

    // create vertices
    int vl_pos = 0;
    for( int i = 0; i <= num_cols; ++i )
    {
        double coords[15]       = { static_cast< double >( i ), 0, 0, static_cast< double >( i ), 1, 0,
                              static_cast< double >( i ), 2, 0, static_cast< double >( i ), 3, 0,
                              static_cast< double >( i ), 4, 0 };
        iBase_EntityHandle* ptr = vertices[i];
        const int n             = ( num_full_cols == num_cols || i <= num_full_cols ) ? 5 : 3;
        int junk1 = n, junk2 = n;
        iMesh_createVtxArr( imesh, n, iBase_INTERLEAVED, coords, 3 * n, &ptr, &junk1, &junk2, &ierr );CHKERR;<--- Skipping configuration 'MOAB_FC_FUNC' since the value of 'MOAB_FC_FUNC' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'MOAB_FC_FUNC_' since the value of 'MOAB_FC_FUNC_' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
        assert( ptr == vertices[i] );
        assert( junk1 == n );
        assert( junk2 == n );
        for( int j = 0; j < n; ++j )
            vertex_list[vl_pos++] = vertices[i][j];
    }

    // create elements
    for( int i = 0; i < num_cols; ++i )
    {
        iBase_EntityHandle conn[16];
        for( int j = 0; j < 4; ++j )
        {
            conn[4 * j]     = vertices[i][j];
            conn[4 * j + 1] = vertices[i][j + 1];
            conn[4 * j + 2] = vertices[i + 1][j + 1];
            conn[4 * j + 3] = vertices[i + 1][j];
        }
        iBase_EntityHandle* ptr = elements[i];
        const int n             = ( i < num_full_cols ) ? 4 : 2;
        int junk1 = n, junk2 = n, junk3 = n, junk4 = n;
        int stat[4];
        int* ptr2 = stat;
        iMesh_createEntArr( imesh, iMesh_QUADRILATERAL, conn, 4 * n, &ptr, &junk1, &junk2, &ptr2, &junk3, &junk4,<--- Skipping configuration 'MOAB_FC_FUNC' since the value of 'MOAB_FC_FUNC' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'MOAB_FC_FUNC_' since the value of 'MOAB_FC_FUNC_' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
                            &ierr );CHKERR;
        assert( ptr == elements[i] );
        assert( junk1 == n );
        assert( junk2 == n );
        assert( ptr2 == stat );
        assert( junk3 == n );
        assert( junk4 == n );
    }

    // create partition
    iMeshP_PartitionHandle partition;
    iMeshP_createPartitionAll( imesh, MPI_COMM_SELF, &partition, &ierr );CHKERR;<--- Skipping configuration 'MOAB_FC_FUNC' since the value of 'MOAB_FC_FUNC' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'MOAB_FC_FUNC_' since the value of 'MOAB_FC_FUNC_' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
    for( int i = 0; i < num_parts; ++i )
    {
        iMeshP_PartHandle part;
        iMeshP_createPart( imesh, partition, &part, &ierr );CHKERR;<--- Skipping configuration 'MOAB_FC_FUNC' since the value of 'MOAB_FC_FUNC' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'MOAB_FC_FUNC_' since the value of 'MOAB_FC_FUNC_' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
        iBase_EntityHandle quads[] = { elements[2 * ( i / 2 )][2 * ( i % 2 )],
                                       elements[2 * ( i / 2 ) + 1][2 * ( i % 2 )],
                                       elements[2 * ( i / 2 )][2 * ( i % 2 ) + 1],
                                       elements[2 * ( i / 2 ) + 1][2 * ( i % 2 ) + 1] };
        iMesh_addEntArrToSet( imesh, quads, 4, part, &ierr );CHKERR;<--- Skipping configuration 'MOAB_FC_FUNC' since the value of 'MOAB_FC_FUNC' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'MOAB_FC_FUNC_' since the value of 'MOAB_FC_FUNC_' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
    }

    // assign global ids to vertices
    iBase_TagHandle id_tag = 0;
    iMesh_getTagHandle( imesh, tagname, &id_tag, &ierr, strlen( tagname ) );<--- Skipping configuration 'MOAB_FC_FUNC' since the value of 'MOAB_FC_FUNC' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'MOAB_FC_FUNC_' since the value of 'MOAB_FC_FUNC_' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
    if( iBase_SUCCESS == ierr )
    {
        int tag_size, tag_type;
        iMesh_getTagSizeValues( imesh, id_tag, &tag_size, &ierr );CHKERR;<--- Skipping configuration 'MOAB_FC_FUNC' since the value of 'MOAB_FC_FUNC' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'MOAB_FC_FUNC_' since the value of 'MOAB_FC_FUNC_' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
        if( tag_size != 1 ) return iBase_TAG_ALREADY_EXISTS;
        iMesh_getTagType( imesh, id_tag, &tag_type, &ierr );CHKERR;<--- Skipping configuration 'MOAB_FC_FUNC' since the value of 'MOAB_FC_FUNC' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'MOAB_FC_FUNC_' since the value of 'MOAB_FC_FUNC_' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
        if( tag_type != iBase_INTEGER ) return iBase_TAG_ALREADY_EXISTS;
    }
    else
    {
        iMesh_createTag( imesh, tagname, 1, iBase_INTEGER, &id_tag, &ierr, strlen( tagname ) );CHKERR;<--- Skipping configuration 'MOAB_FC_FUNC' since the value of 'MOAB_FC_FUNC' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'MOAB_FC_FUNC_' since the value of 'MOAB_FC_FUNC_' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
    }
    iMesh_setIntArrData( imesh, &vertex_list[0], num_vtx, id_tag, &vertex_ids[0], num_vtx, &ierr );CHKERR;<--- Skipping configuration 'MOAB_FC_FUNC' since the value of 'MOAB_FC_FUNC' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'MOAB_FC_FUNC_' since the value of 'MOAB_FC_FUNC_' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.

    // write file
    iBase_EntitySetHandle root_set;
    iMesh_getRootSet( imesh, &root_set, &ierr );<--- Skipping configuration 'MOAB_FC_FUNC' since the value of 'MOAB_FC_FUNC' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'MOAB_FC_FUNC_' since the value of 'MOAB_FC_FUNC_' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
    iMeshP_saveAll( imesh, partition, root_set, filename, 0, &ierr, strlen( filename ), 0 );CHKERR;<--- Skipping configuration 'MOAB_FC_FUNC' since the value of 'MOAB_FC_FUNC' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'MOAB_FC_FUNC_' since the value of 'MOAB_FC_FUNC_' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.

    iMesh_dtor( imesh, &ierr );CHKERR;<--- Skipping configuration 'MOAB_FC_FUNC' since the value of 'MOAB_FC_FUNC' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'MOAB_FC_FUNC_' since the value of 'MOAB_FC_FUNC_' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.

    return 0;
}
int create_mesh_in_memory( int rank,
                           int num_parts,
                           iMesh_Instance imesh,
                           iMeshP_PartitionHandle& partition,
                           PartMap& map )
{
    const char* tagname = "GLOBAL_ID";
    int ierr;

    const int num_cols = 2;
    const int num_vtx  = 9;
    // we are on the top or botton row
    int bottom = rank % 2;  // 0  2
                            // 1  3
    std::vector< EHARR< 3 > > vertices( 3 );
    std::vector< EHARR< 2 > > elements( 2 );  // 4 elements per process
    std::vector< int > vertex_ids( num_vtx );
    std::vector< iBase_EntityHandle > vertex_list( num_vtx );
    int start = 1 + 2 * bottom + 10 * ( rank / 2 );

    for( int i = 0; i < 3; ++i )
        for( int j = 0; j < 3; ++j )
        {
            vertex_ids[i + 3 * j] = start + i + 5 * j;
        }

    // create vertices
    int vl_pos = 0;
    int startI = 2 * ( rank / 2 );  // so it will be 0, 0, 2, 2, ...)
    for( int i = 0; i <= 2; ++i )
    {
        double coords[9] = {
            static_cast< double >( i + startI ), 2. * bottom,     0,
            static_cast< double >( i + startI ), 1 + 2. * bottom, 0,
            static_cast< double >( i + startI ), 2 + 2. * bottom, 0,
        };
        iBase_EntityHandle* ptr = vertices[i];
        const int n             = 3;
        int junk1 = n, junk2 = n;
        iMesh_createVtxArr( imesh, n, iBase_INTERLEAVED, coords, 3 * n, &ptr, &junk1, &junk2, &ierr );CHKERR;<--- Skipping configuration 'MOAB_FC_FUNC' since the value of 'MOAB_FC_FUNC' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'MOAB_FC_FUNC_' since the value of 'MOAB_FC_FUNC_' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
        assert( ptr == vertices[i] );
        assert( junk1 == n );
        assert( junk2 == n );
        for( int j = 0; j < n; ++j )
            vertex_list[vl_pos++] = vertices[i][j];
    }

    // create elements
    for( int i = 0; i < num_cols; ++i )
    {
        iBase_EntityHandle conn[8];
        for( int j = 0; j < 2; ++j )
        {
            conn[4 * j]     = vertices[i][j];
            conn[4 * j + 1] = vertices[i][j + 1];
            conn[4 * j + 2] = vertices[i + 1][j + 1];
            conn[4 * j + 3] = vertices[i + 1][j];
        }
        iBase_EntityHandle* ptr = elements[i];
        const int n             = 2;
        int junk1 = n, junk2 = n, junk3 = n, junk4 = n;
        int stat[4];
        int* ptr2 = stat;
        iMesh_createEntArr( imesh, iMesh_QUADRILATERAL, conn, 4 * n, &ptr, &junk1, &junk2, &ptr2, &junk3, &junk4,<--- Skipping configuration 'MOAB_FC_FUNC' since the value of 'MOAB_FC_FUNC' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'MOAB_FC_FUNC_' since the value of 'MOAB_FC_FUNC_' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
                            &ierr );CHKERR;
        assert( ptr == elements[i] );
        assert( junk1 == n );
        assert( junk2 == n );
        assert( ptr2 == stat );
        assert( junk3 == n );
        assert( junk4 == n );
    }

    // create partition
    iMeshP_createPartitionAll( imesh, MPI_COMM_WORLD, &partition, &ierr );CHKERR;<--- Skipping configuration 'MOAB_FC_FUNC' since the value of 'MOAB_FC_FUNC' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'MOAB_FC_FUNC_' since the value of 'MOAB_FC_FUNC_' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.

    iMeshP_PartHandle part;
    iMeshP_createPart( imesh, partition, &part, &ierr );CHKERR;<--- Skipping configuration 'MOAB_FC_FUNC' since the value of 'MOAB_FC_FUNC' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'MOAB_FC_FUNC_' since the value of 'MOAB_FC_FUNC_' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
    iBase_EntityHandle quads[] = { elements[0][0], elements[0][1], elements[1][0], elements[1][1] };
    iMesh_addEntArrToSet( imesh, quads, 4, part, &ierr );CHKERR;<--- Skipping configuration 'MOAB_FC_FUNC' since the value of 'MOAB_FC_FUNC' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'MOAB_FC_FUNC_' since the value of 'MOAB_FC_FUNC_' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.

    // assign global ids to vertices
    iBase_TagHandle id_tag = 0;
    iMesh_getTagHandle( imesh, tagname, &id_tag, &ierr, strlen( tagname ) );<--- Skipping configuration 'MOAB_FC_FUNC' since the value of 'MOAB_FC_FUNC' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'MOAB_FC_FUNC_' since the value of 'MOAB_FC_FUNC_' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
    if( iBase_SUCCESS == ierr )
    {
        int tag_size, tag_type;
        iMesh_getTagSizeValues( imesh, id_tag, &tag_size, &ierr );CHKERR;<--- Skipping configuration 'MOAB_FC_FUNC' since the value of 'MOAB_FC_FUNC' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'MOAB_FC_FUNC_' since the value of 'MOAB_FC_FUNC_' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
        if( tag_size != 1 ) return iBase_TAG_ALREADY_EXISTS;
        iMesh_getTagType( imesh, id_tag, &tag_type, &ierr );CHKERR;<--- Skipping configuration 'MOAB_FC_FUNC' since the value of 'MOAB_FC_FUNC' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'MOAB_FC_FUNC_' since the value of 'MOAB_FC_FUNC_' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
        if( tag_type != iBase_INTEGER ) return iBase_TAG_ALREADY_EXISTS;
    }
    else
    {
        iMesh_createTag( imesh, tagname, 1, iBase_INTEGER, &id_tag, &ierr, strlen( tagname ) );CHKERR;<--- Skipping configuration 'MOAB_FC_FUNC' since the value of 'MOAB_FC_FUNC' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'MOAB_FC_FUNC_' since the value of 'MOAB_FC_FUNC_' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
    }
    iMesh_setIntArrData( imesh, &vertex_list[0], num_vtx, id_tag, &vertex_ids[0], num_vtx, &ierr );CHKERR;<--- Skipping configuration 'MOAB_FC_FUNC' since the value of 'MOAB_FC_FUNC' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'MOAB_FC_FUNC_' since the value of 'MOAB_FC_FUNC_' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.

    // some mesh sync
    iMeshP_syncPartitionAll( imesh, partition, &ierr );CHKERR;<--- Skipping configuration 'MOAB_FC_FUNC' since the value of 'MOAB_FC_FUNC' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'MOAB_FC_FUNC_' since the value of 'MOAB_FC_FUNC_' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
    iMeshP_syncMeshAll( imesh, partition, &ierr );CHKERR;<--- Skipping configuration 'MOAB_FC_FUNC' since the value of 'MOAB_FC_FUNC' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'MOAB_FC_FUNC_' since the value of 'MOAB_FC_FUNC_' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.

    ierr = map.build_map( imesh, partition, num_parts );CHKERR;
    return 0;
}
// generate unique for each vertex from coordinates.
// Assume integer coordinate values with x in [0,inf] and y in [0,4]
// as generated by create_mean(..).
int vertex_tag( iMesh_Instance imesh, iBase_EntityHandle vertex, int& tag )
{
    int ierr;
    double x, y, z;
    iMesh_getVtxCoord( imesh, vertex, &x, &y, &z, &ierr );CHKERR;<--- Skipping configuration 'MOAB_FC_FUNC' since the value of 'MOAB_FC_FUNC' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'MOAB_FC_FUNC_' since the value of 'MOAB_FC_FUNC_' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.

    int xc = (int)round( x );
    int yc = (int)round( y );
    tag    = 5 * xc + yc + 1;
    return ierr;
}

/**************************************************************************
                           Test  Implementations
 **************************************************************************/

int test_load( iMesh_Instance imesh, iMeshP_PartitionHandle prtn, PartMap& map, int proc_size )
{
    int ierr;

    iBase_EntitySetHandle root_set;
    iMesh_getRootSet( imesh, &root_set, &ierr );<--- Skipping configuration 'MOAB_FC_FUNC' since the value of 'MOAB_FC_FUNC' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'MOAB_FC_FUNC_' since the value of 'MOAB_FC_FUNC_' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
    const char* opt = "moab:PARTITION=PARALLEL_PARTITION";
    iMeshP_loadAll( imesh, prtn, root_set, FILENAME, opt, &ierr, strlen( FILENAME ), strlen( opt ) );<--- Skipping configuration 'MOAB_FC_FUNC' since the value of 'MOAB_FC_FUNC' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'MOAB_FC_FUNC_' since the value of 'MOAB_FC_FUNC_' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
    PCHECK;

    ierr = map.build_map( imesh, prtn, proc_size );CHKERR;
    return iBase_SUCCESS;
}

/**\brief Test partition query methods
 *
 * Test:
 * - iMeshP_getPartitionComm
 * - iMeshP_getNumPartitions
 * - iMeshP_getPartitions
 */
int test_get_partitions( iMesh_Instance imesh, iMeshP_PartitionHandle prtn, const PartMap& )
{
    int ierr;

    // test iMeshP_getPartitionCom
    MPI_Comm comm = MPI_COMM_SELF;
    iMeshP_getPartitionComm( imesh, prtn, &comm, &ierr );<--- Skipping configuration 'MOAB_FC_FUNC' since the value of 'MOAB_FC_FUNC' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'MOAB_FC_FUNC_' since the value of 'MOAB_FC_FUNC_' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
    PCHECK;
    ASSERT( comm == MPI_COMM_WORLD );

    // test iMeshP_getPartitions
    iMeshP_PartitionHandle* array = 0;
    int alloc = 0, size = -1;
    iMeshP_getPartitions( imesh, &array, &alloc, &size, &ierr );<--- Skipping configuration 'MOAB_FC_FUNC' since the value of 'MOAB_FC_FUNC' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'MOAB_FC_FUNC_' since the value of 'MOAB_FC_FUNC_' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
    PCHECK;
    ASSERT( array != 0 );
    ASSERT( alloc == size );
    ASSERT( size > 0 );
    int idx = std::find( array, array + size, prtn ) - array;
    free( array );
    ASSERT( idx < size );

    // test iMesP_getNumPartitions
    int size2 = -1;
    iMeshP_getNumPartitions( imesh, &size2, &ierr );<--- Skipping configuration 'MOAB_FC_FUNC' since the value of 'MOAB_FC_FUNC' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'MOAB_FC_FUNC_' since the value of 'MOAB_FC_FUNC_' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
    PCHECK;
    ASSERT( size2 == size );
    return 0;
}

/**\brief Test part quyery methods
 *
 * Test:
 * - iMeshP_getNumGlobalParts
 * - iMeshP_getNumLocalParts
 * - iMeshP_getLocalParts
 */
int test_get_parts( iMesh_Instance imesh, iMeshP_PartitionHandle prtn, const PartMap& map )
{
    int size, rank, ierr;
    MPI_Comm_rank( MPI_COMM_WORLD, &rank );
    MPI_Comm_size( MPI_COMM_WORLD, &size );

    int num_part_g;
    iMeshP_getNumGlobalParts( imesh, prtn, &num_part_g, &ierr );<--- Skipping configuration 'MOAB_FC_FUNC' since the value of 'MOAB_FC_FUNC' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'MOAB_FC_FUNC_' since the value of 'MOAB_FC_FUNC_' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
    PCHECK;
    ASSERT( num_part_g == map.num_parts() );

    int num_part_l;
    iMeshP_getNumLocalParts( imesh, prtn, &num_part_l, &ierr );<--- Skipping configuration 'MOAB_FC_FUNC' since the value of 'MOAB_FC_FUNC' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'MOAB_FC_FUNC_' since the value of 'MOAB_FC_FUNC_' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
    PCHECK;
    ASSERT( num_part_l == map.count_from_rank( rank ) );

    std::vector< iMeshP_PartHandle > parts( num_part_l );
    iMeshP_PartHandle* ptr = &parts[0];
    int junk1 = num_part_l, count = -1;
    iMeshP_getLocalParts( imesh, prtn, &ptr, &junk1, &count, &ierr );<--- Skipping configuration 'MOAB_FC_FUNC' since the value of 'MOAB_FC_FUNC' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'MOAB_FC_FUNC_' since the value of 'MOAB_FC_FUNC_' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
    PCHECK;
    assert( ptr == &parts[0] );
    assert( junk1 == num_part_l );
    ASSERT( count == num_part_l );

    return iBase_SUCCESS;
}

static int test_get_by_type_topo_all( iMesh_Instance imesh, iMeshP_PartitionHandle prtn, bool test_type, int num_parts )
{
    // calculate number of quads and vertices in entire mesh
    // from number of parts (see create_mesh(..) function.)
    const int expected_global_quad_count = 4 * num_parts;
    const int num_col                    = 2 * ( num_parts / 2 + num_parts % 2 );
    const int expected_global_vtx_count  = num_parts == 1 ? 9 : num_parts % 2 ? 1 + 5 * num_col : 5 + 5 * num_col;

    // test getNumOf*All for root set
    int ierr, count;
    iBase_EntitySetHandle root;
    iMesh_getRootSet( imesh, &root, &ierr );<--- Skipping configuration 'MOAB_FC_FUNC' since the value of 'MOAB_FC_FUNC' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'MOAB_FC_FUNC_' since the value of 'MOAB_FC_FUNC_' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
    if( test_type )
        iMeshP_getNumOfTypeAll( imesh, prtn, root, iBase_VERTEX, &count, &ierr );<--- Skipping configuration 'MOAB_FC_FUNC' since the value of 'MOAB_FC_FUNC' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'MOAB_FC_FUNC_' since the value of 'MOAB_FC_FUNC_' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
    else
        iMeshP_getNumOfTopoAll( imesh, prtn, root, iMesh_POINT, &count, &ierr );<--- Skipping configuration 'MOAB_FC_FUNC' since the value of 'MOAB_FC_FUNC' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'MOAB_FC_FUNC_' since the value of 'MOAB_FC_FUNC_' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
    PCHECK;
    ASSERT( count == expected_global_vtx_count );
    if( test_type )
        iMeshP_getNumOfTypeAll( imesh, prtn, root, iBase_FACE, &count, &ierr );<--- Skipping configuration 'MOAB_FC_FUNC' since the value of 'MOAB_FC_FUNC' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'MOAB_FC_FUNC_' since the value of 'MOAB_FC_FUNC_' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
    else
        iMeshP_getNumOfTopoAll( imesh, prtn, root, iMesh_QUADRILATERAL, &count, &ierr );<--- Skipping configuration 'MOAB_FC_FUNC' since the value of 'MOAB_FC_FUNC' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'MOAB_FC_FUNC_' since the value of 'MOAB_FC_FUNC_' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
    PCHECK;
    ASSERT( count == expected_global_quad_count );

    // create an entity set containing half of the quads
    std::vector< iBase_EntityHandle > all_quads, half_quads;
    ierr = get_entities( imesh, root, iBase_FACE, iMesh_QUADRILATERAL, all_quads );
    assert( 0 == all_quads.size() % 2 );
    half_quads.resize( all_quads.size() / 2 );
    for( size_t i = 0; i < all_quads.size() / 2; ++i )
        half_quads[i] = all_quads[2 * i];
    iBase_EntitySetHandle set;
    iMesh_createEntSet( imesh, 1, &set, &ierr );CHKERR;<--- Skipping configuration 'MOAB_FC_FUNC' since the value of 'MOAB_FC_FUNC' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'MOAB_FC_FUNC_' since the value of 'MOAB_FC_FUNC_' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
    iMesh_addEntArrToSet( imesh, &half_quads[0], half_quads.size(), set, &ierr );CHKERR;<--- Skipping configuration 'MOAB_FC_FUNC' since the value of 'MOAB_FC_FUNC' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'MOAB_FC_FUNC_' since the value of 'MOAB_FC_FUNC_' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.

    // test getNumOf*All with defined set
    if( test_type )
        iMeshP_getNumOfTypeAll( imesh, prtn, set, iBase_VERTEX, &count, &ierr );<--- Skipping configuration 'MOAB_FC_FUNC' since the value of 'MOAB_FC_FUNC' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'MOAB_FC_FUNC_' since the value of 'MOAB_FC_FUNC_' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
    else
        iMeshP_getNumOfTopoAll( imesh, prtn, set, iMesh_POINT, &count, &ierr );<--- Skipping configuration 'MOAB_FC_FUNC' since the value of 'MOAB_FC_FUNC' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'MOAB_FC_FUNC_' since the value of 'MOAB_FC_FUNC_' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
    PCHECK;
    ASSERT( count == 0 );
    if( test_type )
        iMeshP_getNumOfTypeAll( imesh, prtn, set, iBase_FACE, &count, &ierr );<--- Skipping configuration 'MOAB_FC_FUNC' since the value of 'MOAB_FC_FUNC' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'MOAB_FC_FUNC_' since the value of 'MOAB_FC_FUNC_' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
    else
        iMeshP_getNumOfTopoAll( imesh, prtn, set, iMesh_QUADRILATERAL, &count, &ierr );<--- Skipping configuration 'MOAB_FC_FUNC' since the value of 'MOAB_FC_FUNC' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'MOAB_FC_FUNC_' since the value of 'MOAB_FC_FUNC_' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
    PCHECK;
    ASSERT( count == expected_global_quad_count / 2 );

    return 0;
}

static int test_get_by_type_topo_local( iMesh_Instance imesh, iMeshP_PartitionHandle prtn, bool test_type )
{
    int ierr;
    iBase_EntitySetHandle root;
    iMesh_getRootSet( imesh, &root, &ierr );<--- Skipping configuration 'MOAB_FC_FUNC' since the value of 'MOAB_FC_FUNC' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'MOAB_FC_FUNC_' since the value of 'MOAB_FC_FUNC_' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.

    // select a single part
    std::vector< iMeshP_PartHandle > parts;
    ierr = get_local_parts( imesh, prtn, parts );CHKERR;
    iMeshP_PartHandle part = parts.front();

    // get the entities contained in the part
    std::vector< iBase_EntityHandle > part_quads, part_all;
    ierr = get_entities( imesh, part, iBase_FACE, iMesh_QUADRILATERAL, part_quads );CHKERR;
    ierr = get_entities( imesh, part, iBase_ALL_TYPES, iMesh_ALL_TOPOLOGIES, part_all );CHKERR;

    // compare local counts (using root set)

    int count;
    if( test_type )
        iMeshP_getNumOfType( imesh, prtn, part, root, iBase_FACE, &count, &ierr );<--- Skipping configuration 'MOAB_FC_FUNC' since the value of 'MOAB_FC_FUNC' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'MOAB_FC_FUNC_' since the value of 'MOAB_FC_FUNC_' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
    else
        iMeshP_getNumOfTopo( imesh, prtn, part, root, iMesh_QUADRILATERAL, &count, &ierr );CHKERR;<--- Skipping configuration 'MOAB_FC_FUNC' since the value of 'MOAB_FC_FUNC' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'MOAB_FC_FUNC_' since the value of 'MOAB_FC_FUNC_' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
    ASSERT( count == (int)part_quads.size() );

    if( test_type )
        iMeshP_getNumOfType( imesh, prtn, part, root, iBase_ALL_TYPES, &count, &ierr );<--- Skipping configuration 'MOAB_FC_FUNC' since the value of 'MOAB_FC_FUNC' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'MOAB_FC_FUNC_' since the value of 'MOAB_FC_FUNC_' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
    else
        iMeshP_getNumOfTopo( imesh, prtn, part, root, iMesh_ALL_TOPOLOGIES, &count, &ierr );CHKERR;<--- Skipping configuration 'MOAB_FC_FUNC' since the value of 'MOAB_FC_FUNC' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'MOAB_FC_FUNC_' since the value of 'MOAB_FC_FUNC_' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
    ASSERT( count == (int)part_all.size() );

    // compare local contents (using root set)

    iBase_EntityHandle* ptr = 0;
    int num_ent, junk1 = 0;
    iMeshP_getEntities( imesh, prtn, part, root, test_type ? iBase_FACE : iBase_ALL_TYPES,<--- Skipping configuration 'MOAB_FC_FUNC' since the value of 'MOAB_FC_FUNC' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'MOAB_FC_FUNC_' since the value of 'MOAB_FC_FUNC_' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
                        test_type ? iMesh_ALL_TOPOLOGIES : iMesh_QUADRILATERAL, &ptr, &junk1, &num_ent, &ierr );CHKERR;
    std::vector< iBase_EntityHandle > act_quads( ptr, ptr + num_ent );
    free( ptr );
    junk1 = num_ent = 0;
    ptr             = 0;
    iMeshP_getEntities( imesh, prtn, part, root, iBase_ALL_TYPES, iMesh_ALL_TOPOLOGIES, &ptr, &junk1, &num_ent, &ierr );CHKERR;<--- Skipping configuration 'MOAB_FC_FUNC' since the value of 'MOAB_FC_FUNC' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'MOAB_FC_FUNC_' since the value of 'MOAB_FC_FUNC_' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
    std::vector< iBase_EntityHandle > act_all( ptr, ptr + num_ent );
    free( ptr );
    std::sort( part_quads.begin(), part_quads.end() );
    std::sort( part_all.begin(), part_all.end() );
    std::sort( act_quads.begin(), act_quads.end() );
    std::sort( act_all.begin(), act_all.end() );
    ASSERT( part_quads == act_quads );
    ASSERT( part_all == act_all );

    // create an entity set containing half of the quads from the part
    std::vector< iBase_EntityHandle > half_quads( part_quads.size() / 2 );
    for( size_t i = 0; i < half_quads.size(); ++i )
        half_quads[i] = part_quads[2 * i];
    iBase_EntitySetHandle set;
    iMesh_createEntSet( imesh, 1, &set, &ierr );CHKERR;<--- Skipping configuration 'MOAB_FC_FUNC' since the value of 'MOAB_FC_FUNC' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'MOAB_FC_FUNC_' since the value of 'MOAB_FC_FUNC_' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
    iMesh_addEntArrToSet( imesh, &half_quads[0], half_quads.size(), set, &ierr );CHKERR;<--- Skipping configuration 'MOAB_FC_FUNC' since the value of 'MOAB_FC_FUNC' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'MOAB_FC_FUNC_' since the value of 'MOAB_FC_FUNC_' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.

    // check if there exists any quads not in the part that we
    // can add to the set
    std::vector< iBase_EntityHandle > all_quads, other_quads;
    ierr = get_entities( imesh, root, iBase_FACE, iMesh_QUADRILATERAL, all_quads );CHKERR;
    std::sort( all_quads.begin(), all_quads.end() );
    std::sort( part_quads.begin(), part_quads.end() );
    std::set_difference( all_quads.begin(), all_quads.end(), part_quads.begin(), part_quads.end(),
                         std::back_inserter( other_quads ) );
    iMesh_addEntArrToSet( imesh, &other_quads[0], other_quads.size(), set, &ierr );CHKERR;<--- Skipping configuration 'MOAB_FC_FUNC' since the value of 'MOAB_FC_FUNC' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'MOAB_FC_FUNC_' since the value of 'MOAB_FC_FUNC_' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.

    // compare local counts (using non-root set)

    if( test_type )
        iMeshP_getNumOfType( imesh, prtn, part, set, iBase_FACE, &count, &ierr );<--- Skipping configuration 'MOAB_FC_FUNC' since the value of 'MOAB_FC_FUNC' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'MOAB_FC_FUNC_' since the value of 'MOAB_FC_FUNC_' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
    else
        iMeshP_getNumOfTopo( imesh, prtn, part, set, iMesh_QUADRILATERAL, &count, &ierr );CHKERR;<--- Skipping configuration 'MOAB_FC_FUNC' since the value of 'MOAB_FC_FUNC' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'MOAB_FC_FUNC_' since the value of 'MOAB_FC_FUNC_' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
    ASSERT( count == (int)half_quads.size() );

    if( test_type )
        iMeshP_getNumOfType( imesh, prtn, part, set, iBase_VERTEX, &count, &ierr );<--- Skipping configuration 'MOAB_FC_FUNC' since the value of 'MOAB_FC_FUNC' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'MOAB_FC_FUNC_' since the value of 'MOAB_FC_FUNC_' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
    else
        iMeshP_getNumOfTopo( imesh, prtn, part, set, iMesh_POINT, &count, &ierr );CHKERR;<--- Skipping configuration 'MOAB_FC_FUNC' since the value of 'MOAB_FC_FUNC' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'MOAB_FC_FUNC_' since the value of 'MOAB_FC_FUNC_' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
    ASSERT( count == 0 );

    // compare local contents (using non-root set)

    junk1   = 0;
    num_ent = 0;
    ptr     = 0;
    iMeshP_getEntities( imesh, prtn, part, set, test_type ? iBase_FACE : iBase_ALL_TYPES,<--- Skipping configuration 'MOAB_FC_FUNC' since the value of 'MOAB_FC_FUNC' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'MOAB_FC_FUNC_' since the value of 'MOAB_FC_FUNC_' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
                        test_type ? iMesh_ALL_TOPOLOGIES : iMesh_QUADRILATERAL, &ptr, &junk1, &num_ent, &ierr );CHKERR;
    act_quads.resize( num_ent );
    std::copy( ptr, ptr + num_ent, act_quads.begin() );
    free( ptr );
    std::sort( half_quads.begin(), half_quads.end() );
    std::sort( act_quads.begin(), act_quads.end() );
    ASSERT( act_quads == half_quads );

    return iBase_SUCCESS;
}

/**\brief Test query by entity type
 *
 * Test:
 * - iMeshP_getNumOfTypeAll
 * - iMeshP_getNumOfType
 * - iMeshP_getEntities
 * -
 */
int test_get_by_type( iMesh_Instance imesh, iMeshP_PartitionHandle prtn, const PartMap& map )
{
    int ierr;
    ierr = test_get_by_type_topo_all( imesh, prtn, true, map.num_parts() );
    PCHECK;
    ierr = test_get_by_type_topo_local( imesh, prtn, true );
    PCHECK;
    return 0;
}

/**\brief Test query by entity topology
 *
 * Test:
 * - iMeshP_getNumOfTopoAll
 * - iMeshP_getNumOfTopo
 * - iMeshP_getEntities
 * -
 */
int test_get_by_topo( iMesh_Instance imesh, iMeshP_PartitionHandle prtn, const PartMap& map )
{
    int ierr;
    ierr = test_get_by_type_topo_all( imesh, prtn, false, map.num_parts() );
    PCHECK;
    ierr = test_get_by_type_topo_local( imesh, prtn, false );
    PCHECK;
    return 0;
}

/**\brief Test mapping from part id to part handle
 *
 * Test:
 * - iMeshP_getPartIdFromPartHandle
 * - iMeshP_getPartIdsFromPartHandlesArr
 * - iMeshP_getPartHandleFromPartId
 * - iMeshP_getPartHandlesFromPartsIdsArr
 */
int test_part_id_handle( iMesh_Instance imesh, iMeshP_PartitionHandle prtn, const PartMap& map )
{
    // get local part ids
    int rank, ierr;
    MPI_Comm_rank( MPI_COMM_WORLD, &rank );
    std::vector< iMeshP_Part > ids;
    map.part_id_from_rank( rank, ids );

    // check single-part functions and build list of part handles
    std::vector< iMeshP_PartHandle > handles( ids.size() );
    size_t i;
    for( i = 0; i < ids.size(); ++i )
    {
        iMeshP_getPartHandleFromPartId( imesh, prtn, ids[i], &handles[i], &ierr );CHKERR;<--- Skipping configuration 'MOAB_FC_FUNC' since the value of 'MOAB_FC_FUNC' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'MOAB_FC_FUNC_' since the value of 'MOAB_FC_FUNC_' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
        iMeshP_Part id;
        iMeshP_getPartIdFromPartHandle( imesh, prtn, handles[i], &id, &ierr );CHKERR;<--- Skipping configuration 'MOAB_FC_FUNC' since the value of 'MOAB_FC_FUNC' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'MOAB_FC_FUNC_' since the value of 'MOAB_FC_FUNC_' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
        if( id != ids[i] ) break;
    }
    ASSERT( i == ids.size() );

    // test iMeshP_getPartIdsFromPartHandlesArr
    std::vector< iMeshP_Part > ids2( ids.size() );
    int junk1 = ids.size(), junk2 = 0;
    iMeshP_Part* ptr = &ids2[0];
    iMeshP_getPartIdsFromPartHandlesArr( imesh, prtn, &handles[0], handles.size(), &ptr, &junk1, &junk2, &ierr );<--- Skipping configuration 'MOAB_FC_FUNC' since the value of 'MOAB_FC_FUNC' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'MOAB_FC_FUNC_' since the value of 'MOAB_FC_FUNC_' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
    PCHECK;
    ASSERT( ptr == &ids2[0] );
    ASSERT( junk2 == (int)ids2.size() );
    ASSERT( ids == ids2 );

    // test iMeshP_getPartHandlesFromPartsIdsArr
    std::vector< iMeshP_PartHandle > handles2( handles.size() );
    junk1                   = handles.size();
    junk2                   = 0;
    iMeshP_PartHandle* ptr2 = &handles2[0];
    iMeshP_getPartHandlesFromPartsIdsArr( imesh, prtn, &ids[0], ids.size(), &ptr2, &junk1, &junk2, &ierr );<--- Skipping configuration 'MOAB_FC_FUNC' since the value of 'MOAB_FC_FUNC' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'MOAB_FC_FUNC_' since the value of 'MOAB_FC_FUNC_' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
    PCHECK;
    ASSERT( ptr2 == &handles2[0] );
    ASSERT( junk2 == (int)handles2.size() );
    ASSERT( handles == handles2 );

    return 0;
}

/**\brief Test get part rank
 *
 * Tests:
 * - iMeshP_getRankOfPart
 * - iMeshP_getRankOfPartArr
 */
int test_part_rank( iMesh_Instance imesh, iMeshP_PartitionHandle prtn, const PartMap& map )
{
    int ierr = 0, rank;
    std::vector< iMeshP_Part > invalid, failed;
    MPI_Comm_rank( MPI_COMM_WORLD, &rank );

    // test iMeshP_getRankOfPart
    for( size_t i = 0; i < map.get_parts().size(); ++i )
    {
        int pr;
        iMeshP_getRankOfPart( imesh, prtn, map.get_parts()[i], &pr, &ierr );<--- Skipping configuration 'MOAB_FC_FUNC' since the value of 'MOAB_FC_FUNC' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'MOAB_FC_FUNC_' since the value of 'MOAB_FC_FUNC_' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
        if( iBase_SUCCESS != ierr )
            failed.push_back( map.get_parts()[i] );
        else if( pr != map.get_ranks()[i] )
            invalid.push_back( map.get_parts()[i] );
    }
    if( !failed.empty() )
    {
        std::cerr << "Processor " << rank << ": iMeshP_getRankOfPart failed for " << failed.size() << " parts."
                  << std::endl;
        ierr = iBase_FAILURE;
    }
    if( !invalid.empty() )
    {
        std::cerr << "Processor " << rank << ": iMeshP_getRankOfPart was incorrect for " << invalid.size() << " parts."
                  << std::endl;
        ierr = iBase_FAILURE;
    }
    PCHECK;

    // test iMeshP_getRankOfPartArr
    std::vector< int > ranks( map.get_parts().size() );
    int junk1 = ranks.size(), junk2, *ptr = &ranks[0];
    iMeshP_getRankOfPartArr( imesh, prtn, &map.get_parts()[0], map.get_parts().size(), &ptr, &junk1, &junk2, &ierr );<--- Skipping configuration 'MOAB_FC_FUNC' since the value of 'MOAB_FC_FUNC' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'MOAB_FC_FUNC_' since the value of 'MOAB_FC_FUNC_' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
    PCHECK;
    assert( ptr == &ranks[0] );
    assert( junk1 == (int)ranks.size() );
    ASSERT( junk2 == (int)ranks.size() );
    for( size_t i = 0; i < map.get_parts().size(); ++i )
    {
        if( ranks[i] != map.get_ranks()[i] ) invalid.push_back( map.get_parts()[i] );
    }
    if( !invalid.empty() )
    {
        std::cerr << "Processor " << rank << ": iMeshP_getRankOfPartArr was incorrect for " << invalid.size()
                  << " parts." << std::endl;
        ierr = iBase_FAILURE;
    }
    PCHECK;

    return 0;
}

// see create_mesh(..)
static void get_part_neighbors( int logical_part_id, int num_parts, int neighbors[5], int& num_neighbors )
{
    num_neighbors = 0;
    if( logical_part_id + 1 < num_parts ) neighbors[num_neighbors++] = logical_part_id + 1;
    if( logical_part_id + 2 < num_parts ) neighbors[num_neighbors++] = logical_part_id + 2;
    if( logical_part_id % 2 )
    {
        neighbors[num_neighbors++] = logical_part_id - 1;
        if( logical_part_id > 2 )
        {
            neighbors[num_neighbors++] = logical_part_id - 3;
            neighbors[num_neighbors++] = logical_part_id - 2;
        }
    }
    else
    {
        if( logical_part_id + 3 < num_parts ) neighbors[num_neighbors++] = logical_part_id + 3;
        if( logical_part_id > 1 )
        {
            neighbors[num_neighbors++] = logical_part_id - 1;
            neighbors[num_neighbors++] = logical_part_id - 2;
        }
    }
}

/**\brief Test querying of part neighbors
 *
 * Test:
 * - iMeshP_getNumPartNbors
 * - iMeshP_getNumPartNborsArr
 * - iMeshP_getPartNbors
 * - iMeshP_getPartNborsArr
 */
int test_get_neighbors( iMesh_Instance imesh, iMeshP_PartitionHandle prtn, const PartMap& map )
{
    int ierr, rank;
    MPI_Comm_rank( MPI_COMM_WORLD, &rank );

    std::vector< iMeshP_Part > local_parts;
    map.part_id_from_rank( rank, local_parts );

    // get handles for local parts
    std::vector< iMeshP_PartHandle > handles( local_parts.size() );
    iMeshP_PartHandle* ptr = &handles[0];
    int junk1 = handles.size(), junk2 = 0;
    iMeshP_getPartHandlesFromPartsIdsArr( imesh, prtn, &local_parts[0], local_parts.size(), &ptr, &junk1, &junk2,<--- Skipping configuration 'MOAB_FC_FUNC' since the value of 'MOAB_FC_FUNC' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'MOAB_FC_FUNC_' since the value of 'MOAB_FC_FUNC_' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
                                          &ierr );
    PCHECK;
    assert( ptr == &handles[0] );
    assert( junk2 == (int)handles.size() );

    // get logical ids for local parts
    std::vector< int > logical_ids;
    map.local_id_from_rank( rank, logical_ids );

    // get neighbors for each local part
    std::vector< std::vector< iMeshP_Part > > neighbors( logical_ids.size() );
    for( size_t i = 0; i < logical_ids.size(); ++i )
    {
        int logical_neighbors[5], num_neighbors;
        get_part_neighbors( logical_ids[i], map.num_parts(), logical_neighbors, num_neighbors );
        neighbors[i].resize( num_neighbors );
        for( int j = 0; j < num_neighbors; ++j )
            neighbors[i][j] = map.part_id_from_local_id( logical_neighbors[j] );
        std::sort( neighbors[i].begin(), neighbors[i].end() );
    }

    // test iMeshP_getNumPartNbors
    std::vector< iMeshP_Part > invalid, failed;
    for( size_t i = 0; i < local_parts.size(); ++i )
    {
        int count;
        iMeshP_getNumPartNbors( imesh, prtn, handles[i], iBase_VERTEX, &count, &ierr );<--- Skipping configuration 'MOAB_FC_FUNC' since the value of 'MOAB_FC_FUNC' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'MOAB_FC_FUNC_' since the value of 'MOAB_FC_FUNC_' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
        if( ierr )
            failed.push_back( local_parts[i] );
        else if( count != (int)neighbors[i].size() )
            invalid.push_back( local_parts[i] );
    }
    if( !failed.empty() )
    {
        std::cerr << "Processor " << rank << ": iMeshP_getNumPartNbors failed for " << failed.size() << " parts."
                  << std::endl;
        ierr = iBase_FAILURE;
        PCHECK;
    }
    if( !invalid.empty() )
    {
        std::cerr << "Processor " << rank << ": iMeshP_getNumPartNbors was incorrect for " << invalid.size()
                  << " parts." << std::endl;
        ierr = iBase_FAILURE;
        PCHECK;
    }

    // test iMeshP_getPartNbors
    ierr = 0;
    for( size_t i = 0; i < local_parts.size(); ++i )
    {
        int count, junk = 0, another_count;
        iMeshP_Part* list = 0;
        iMeshP_getPartNbors( imesh, prtn, handles[i], iBase_VERTEX, &another_count, &list, &junk, &count, &ierr );<--- Skipping configuration 'MOAB_FC_FUNC' since the value of 'MOAB_FC_FUNC' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'MOAB_FC_FUNC_' since the value of 'MOAB_FC_FUNC_' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
        assert( count == another_count );
        if( ierr )
            failed.push_back( local_parts[i] );
        else
        {
            std::sort( list, list + count );
            std::vector< iMeshP_Part > cpy( list, list + count );
            if( cpy != neighbors[i] ) invalid.push_back( local_parts[i] );
            free( list );
        }
    }
    if( !failed.empty() )
    {
        std::cerr << "Processor " << rank << ": iMeshP_getPartNbors failed for " << failed.size() << " parts."
                  << std::endl;
        ierr = iBase_FAILURE;
    }
    if( !invalid.empty() )
    {
        std::cerr << "Processor " << rank << ": iMeshP_getPartNbors was incorrect for " << invalid.size() << " parts."
                  << std::endl;
        ierr = iBase_FAILURE;
    }
    PCHECK;

    // test iMeshP_getNumPartNborsArr
    std::vector< int > count_vect( handles.size() );
    int* count_arr = &count_vect[0];
    junk1          = handles.size();
    iMeshP_getNumPartNborsArr( imesh, prtn, &handles[0], handles.size(), iBase_VERTEX, &count_arr, &junk1, &junk2,<--- Skipping configuration 'MOAB_FC_FUNC' since the value of 'MOAB_FC_FUNC' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'MOAB_FC_FUNC_' since the value of 'MOAB_FC_FUNC_' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
                               &ierr );
    PCHECK;
    assert( count_arr == &count_vect[0] );
    assert( junk2 == (int)handles.size() );
    for( size_t i = 0; i < local_parts.size(); ++i )
    {
        if( count_arr[i] != (int)neighbors[i].size() ) invalid.push_back( local_parts[i] );
    }
    if( !invalid.empty() )
    {
        std::cerr << "Processor " << rank << ": iMeshP_getNumPartNborsArr was incorrect for " << invalid.size()
                  << " parts." << std::endl;
        ierr = iBase_FAILURE;
    }
    PCHECK;

    // test iMeshP_getPartNborsArr
    iMeshP_Part* nbor_arr = 0;
    junk1 = handles.size(), junk2 = 0;
    int junk3 = 0, nbor_size;
    iMeshP_getPartNborsArr( imesh, prtn, &handles[0], handles.size(), iBase_VERTEX, &count_arr, &junk1, &junk2,<--- Skipping configuration 'MOAB_FC_FUNC' since the value of 'MOAB_FC_FUNC' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'MOAB_FC_FUNC_' since the value of 'MOAB_FC_FUNC_' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
                            &nbor_arr, &junk3, &nbor_size, &ierr );
    PCHECK;
    assert( count_arr == &count_vect[0] );
    assert( junk2 == (int)handles.size() );
    std::vector< iMeshP_Part > all_nbors( nbor_arr, nbor_arr + nbor_size );
    free( nbor_arr );
    std::vector< iMeshP_Part >::iterator j = all_nbors.begin();
    bool bad_length                        = false;
    for( size_t i = 0; i < local_parts.size(); ++i )
    {
        if( all_nbors.end() - j > count_arr[i] )
        {
            bad_length = true;
            break;
        }
        if( count_arr[i] != (int)neighbors[i].size() )
        {
            invalid.push_back( local_parts[i] );
        }
        else
        {
            std::vector< iMeshP_Part >::iterator e = j + count_arr[i];
            std::sort( j, e );
            if( !std::equal( j, e, neighbors[i].begin() ) ) invalid.push_back( local_parts[i] );
        }
    }
    if( bad_length )
    {
        std::cerr << "Processor " << rank << ": iMeshP_getPartNborsArr had inconsistent result array lengths."
                  << std::endl;
        ierr = iBase_FAILURE;
    }
    if( !invalid.empty() )
    {
        std::cerr << "Processor " << rank << ": iMeshP_getPartNborsArr was incorrect for " << invalid.size()
                  << " parts." << std::endl;
        ierr = iBase_FAILURE;
    }
    PCHECK;

    return 0;
}

// Determine the expected vertices on the interface between two parts.
// Returns no vertices for non-adjacient parts and fails if both parts
// are the same.
// See create_mesh(..) for the assumed mesh.
static int interface_verts( iMesh_Instance imesh,
                            iMeshP_PartitionHandle prtn,
                            iMeshP_PartHandle local_part,
                            iMeshP_Part other_part,
                            const PartMap& map,
                            std::vector< iBase_EntityHandle >& vtx_handles )
{
    int ierr, rank;
    MPI_Comm_rank( MPI_COMM_WORLD, &rank );

    iMeshP_Part local_id;
    iMeshP_getPartIdFromPartHandle( imesh, prtn, local_part, &local_id, &ierr );CHKERR;<--- Skipping configuration 'MOAB_FC_FUNC' since the value of 'MOAB_FC_FUNC' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'MOAB_FC_FUNC_' since the value of 'MOAB_FC_FUNC_' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.

    const int local_logical = map.local_id_from_part_id( local_id );
    const int other_logical = map.local_id_from_part_id( other_part );

    // get grid of local vertices

    iBase_EntityHandle verts[3][3];
    const double xbase = ( local_id / 2 ) * 2;
    const double ybase = ( local_id % 2 ) * 2;

    // get quads in partition
    iBase_EntityHandle quads[4], *ptr = quads;
    int junk1 = 4, junk2;
    iMesh_getEntities( imesh, local_part, iBase_FACE, iMesh_QUADRILATERAL, &ptr, &junk1, &junk2, &ierr );CHKERR;<--- Skipping configuration 'MOAB_FC_FUNC' since the value of 'MOAB_FC_FUNC' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'MOAB_FC_FUNC_' since the value of 'MOAB_FC_FUNC_' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
    assert( ptr == quads );
    assert( junk1 == 4 );
    assert( junk2 == 4 );

    // get vertices in quads
    iBase_EntityHandle conn[16];
    int offsets[5], *off_ptr = offsets, junk3 = 5, junk4;
    ptr   = conn;
    junk1 = 16;
    iMesh_getEntArrAdj( imesh, quads, 4, iBase_VERTEX, &ptr, &junk1, &junk2, &off_ptr, &junk3, &junk4, &ierr );CHKERR;<--- Skipping configuration 'MOAB_FC_FUNC' since the value of 'MOAB_FC_FUNC' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'MOAB_FC_FUNC_' since the value of 'MOAB_FC_FUNC_' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
    assert( ptr == conn );
    assert( junk1 == 16 );
    assert( junk2 == 16 );
    assert( off_ptr == offsets );
    assert( junk3 == 5 );
    assert( junk4 == 5 );

    // make unique vertex list
    std::sort( conn, conn + 16 );
    const int num_vtx = std::unique( conn, conn + 16 ) - conn;
    assert( 9 == num_vtx );

    // get vertex coords
    std::vector< double > coords( 27 );
    ierr = get_coords( imesh, conn, 9, &coords[0] );CHKERR;

    // use vertex coords to determine logical position
    for( int i = 0; i < num_vtx; ++i )
    {
        int x = (int)round( coords[3 * i] - xbase );
        int y = (int)round( coords[3 * i + 1] - ybase );
        if( x < 0 || x > 2 || y < 0 || y > 2 )
        {
            std::cerr << "Processor " << rank << ": Error at " __FILE__ ":" << __LINE__ << std::endl
                      << "  Invalid vertex coordinate: (" << coords[3 * i] << ", " << coords[3 * i + 1] << ", "
                      << coords[3 * i + 2] << ")" << std::endl
                      << "  For logical partition " << local_id << std::endl;
            return iBase_FAILURE;
        }
        verts[x][y] = conn[i];
    }

    if( local_logical % 2 )
    {
        switch( other_logical - local_logical )
        {
            case 0:
                return iBase_FAILURE;
            case 1:  // upper right
                vtx_handles.resize( 1 );
                vtx_handles[0] = verts[2][0];
                break;
            case 2:  // right
                vtx_handles.resize( 3 );
                std::copy( verts[2], verts[2] + 3, vtx_handles.begin() );
                break;
            case -1:  // above
                vtx_handles.resize( 3 );
                vtx_handles[0] = verts[0][0];
                vtx_handles[1] = verts[1][0];
                vtx_handles[2] = verts[2][0];
                break;
            case -2:  // left
                vtx_handles.resize( 3 );
                std::copy( verts[0], verts[0] + 3, vtx_handles.begin() );
                break;
            case -3:  // upper left
                vtx_handles.resize( 1 );
                vtx_handles[0] = verts[0][0];
                break;
            default:
                vtx_handles.clear();
                break;
        }
    }
    else
    {
        switch( other_logical - local_logical )
        {
            case 0:
                return iBase_FAILURE;
            case 1:  // below
                vtx_handles.resize( 3 );
                vtx_handles[0] = verts[0][2];
                vtx_handles[1] = verts[1][2];
                vtx_handles[2] = verts[2][2];
                break;
            case 2:  // right
                vtx_handles.resize( 3 );
                std::copy( verts[2], verts[2] + 3, vtx_handles.begin() );
                break;
            case 3:  // lower right
                vtx_handles.resize( 1 );
                vtx_handles[0] = verts[2][2];
                break;
            case -1:  // lower left
                vtx_handles.resize( 1 );
                vtx_handles[0] = verts[0][2];
                break;
            case -2:  // left
                vtx_handles.resize( 3 );
                std::copy( verts[0], verts[0] + 3, vtx_handles.begin() );
                break;
            default:
                vtx_handles.clear();
                break;
        }
    }

    return iBase_SUCCESS;
}

/**\brief Test querying of part boundary entities
 *
 * Test:
 * - iMeshP_getNumPartBdryEnts
 * - iMeshP_getPartBdryEnts
 */
int test_get_part_boundary( iMesh_Instance imesh, iMeshP_PartitionHandle prtn, const PartMap& map )
{
    int ierr, rank;
    MPI_Comm_rank( MPI_COMM_WORLD, &rank );

    // get local part handles and part ids, and global part id list
    std::vector< iMeshP_PartHandle > local_handles;
    std::vector< iMeshP_Part > local_ids;
    std::vector< iMeshP_Part > all_parts = map.get_parts();
    std::map< iMeshP_PartHandle, std::vector< iBase_EntityHandle > > part_bdry;
    ierr = get_local_parts( imesh, prtn, local_handles, &local_ids );CHKERR;

    // for each combination of local part with any other part,
    // check for valid function values.
    std::vector< std::pair< iMeshP_Part, iMeshP_Part > > num_failed, num_error, list_failed, list_error, error;
    for( size_t i = 0; i < local_handles.size(); ++i )
    {
        iMeshP_PartHandle local_handle = local_handles[i];
        iMeshP_Part local_id           = local_ids[i];
        for( std::vector< iMeshP_Part >::iterator j = all_parts.begin(); j != all_parts.end(); ++j )
        {
            iMeshP_Part other_id = *j;
            if( other_id == local_id ) continue;

            std::pair< iMeshP_Part, iMeshP_Part > part_pair;
            part_pair.first  = local_id;
            part_pair.second = other_id;

            // get expected values
            std::vector< iBase_EntityHandle > shared_verts;
            ierr = interface_verts( imesh, prtn, local_handle, other_id, map, shared_verts );
            if( ierr != iBase_SUCCESS )
            {
                error.push_back( part_pair );
                continue;
            }
            std::sort( shared_verts.begin(), shared_verts.end() );

            // test iMeshP_getNumPartBdryEnts
            int count;
            iMeshP_getNumPartBdryEnts( imesh, prtn, local_handle, iBase_VERTEX, iMesh_POINT, other_id, &count, &ierr );<--- Skipping configuration 'MOAB_FC_FUNC' since the value of 'MOAB_FC_FUNC' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'MOAB_FC_FUNC_' since the value of 'MOAB_FC_FUNC_' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
            if( iBase_SUCCESS != ierr )
                num_error.push_back( part_pair );
            else if( count != (int)shared_verts.size() )
                num_failed.push_back( part_pair );

            // test iMeshP_getPartBdryEnts
            iBase_EntityHandle* ptr = 0;
            int junk                = 0;
            iMeshP_getPartBdryEnts( imesh, prtn, local_handle, iBase_VERTEX, iMesh_POINT, other_id, &ptr, &junk, &count,<--- Skipping configuration 'MOAB_FC_FUNC' since the value of 'MOAB_FC_FUNC' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'MOAB_FC_FUNC_' since the value of 'MOAB_FC_FUNC_' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
                                    &ierr );
            if( iBase_SUCCESS != ierr )
                list_error.push_back( part_pair );
            else
            {
                std::copy( ptr, ptr + count, std::back_inserter( part_bdry[local_handles[i]] ) );
                std::sort( ptr, ptr + count );
                if( (int)shared_verts.size() != count || !std::equal( shared_verts.begin(), shared_verts.end(), ptr ) )
                    list_failed.push_back( part_pair );
                free( ptr );
            }
        }
    }

    if( !error.empty() )
    {
        std::cerr << "Processor " << rank << ": Error at " __FILE__ ":" << __LINE__ << std::endl
                  << "  Internal error for " << error.size() << " part pairs." << std::endl;
        ierr = iBase_FAILURE;
    }
    if( !num_error.empty() )
    {
        std::cerr << "Processor " << rank << ": Error at " __FILE__ ":" << __LINE__ << std::endl
                  << "  iMeshP_getNumPartBdryEnts return error for " << num_error.size() << " part pairs." << std::endl;
        ierr = iBase_FAILURE;
    }
    if( !list_error.empty() )
    {
        std::cerr << "Processor " << rank << ": Error at " __FILE__ ":" << __LINE__ << std::endl
                  << "  iMeshP_getPartBdryEnts return error for " << list_error.size() << " part pairs." << std::endl;
        ierr = iBase_FAILURE;
    }
    if( !num_failed.empty() )
    {
        std::cerr << "Processor " << rank << ": Error at " __FILE__ ":" << __LINE__ << std::endl
                  << "  iMeshP_getNumPartBdryEnts return incorrect results for " << num_failed.size() << " part pairs."
                  << std::endl;
        ierr = iBase_FAILURE;
    }
    if( !list_failed.empty() )
    {
        std::cerr << "Processor " << rank << ": Error at " __FILE__ ":" << __LINE__ << std::endl
                  << "  iMeshP_getPartBdryEnts return incorrect results for " << list_failed.size() << " part pairs."
                  << std::endl;
        ierr = iBase_FAILURE;
    }

    if( iBase_SUCCESS != ierr ) return ierr;

    // test with iMeshP_ALL_PARTS
    for( size_t i = 0; i < local_handles.size(); ++i )
    {
        std::vector< iBase_EntityHandle >& exp_bdry = part_bdry[local_handles[i]];
        std::sort( exp_bdry.begin(), exp_bdry.end() );
        exp_bdry.erase( std::unique( exp_bdry.begin(), exp_bdry.end() ), exp_bdry.end() );
        std::pair< iMeshP_Part, iMeshP_Part > part_pair;
        part_pair.first  = local_ids[i];
        part_pair.second = iMeshP_ALL_PARTS;

        int num = 0;
        iMeshP_getNumPartBdryEnts( imesh, prtn, local_handles[i], iBase_VERTEX, iMesh_POINT, iMeshP_ALL_PARTS, &num,<--- Skipping configuration 'MOAB_FC_FUNC' since the value of 'MOAB_FC_FUNC' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'MOAB_FC_FUNC_' since the value of 'MOAB_FC_FUNC_' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
                                   &ierr );
        if( ierr )
            num_error.push_back( part_pair );
        else if( num != (int)exp_bdry.size() )
            num_failed.push_back( part_pair );

        iBase_EntityHandle* bdry = 0;
        int junk = num = 0;
        iMeshP_getPartBdryEnts( imesh, prtn, local_handles[i], iBase_VERTEX, iMesh_POINT, iMeshP_ALL_PARTS, &bdry,<--- Skipping configuration 'MOAB_FC_FUNC' since the value of 'MOAB_FC_FUNC' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'MOAB_FC_FUNC_' since the value of 'MOAB_FC_FUNC_' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
                                &junk, &num, &ierr );
        if( ierr )
            list_error.push_back( part_pair );
        else
        {
            std::sort( bdry, bdry + num );
            if( num != (int)exp_bdry.size() || !std::equal( bdry, bdry + num, exp_bdry.begin() ) )
                list_failed.push_back( part_pair );
            free( bdry );
        }
    }
    if( !num_error.empty() )
    {
        std::cerr << "Processor " << rank << ": Error at " __FILE__ ":" << __LINE__ << std::endl
                  << "  iMeshP_getNumPartBdryEnts return error for " << num_error.size() << " part pairs." << std::endl;
        ierr = iBase_FAILURE;
    }
    if( !list_error.empty() )
    {
        std::cerr << "Processor " << rank << ": Error at " __FILE__ ":" << __LINE__ << std::endl
                  << "  iMeshP_getPartBdryEnts return error for " << list_error.size() << " part pairs." << std::endl;
        ierr = iBase_FAILURE;
    }
    if( !num_failed.empty() )
    {
        std::cerr << "Processor " << rank << ": Error at " __FILE__ ":" << __LINE__ << std::endl
                  << "  iMeshP_getNumPartBdryEnts return incorrect results for " << num_failed.size() << " part pairs."
                  << std::endl;
        ierr = iBase_FAILURE;
    }
    if( !list_failed.empty() )
    {
        std::cerr << "Processor " << rank << ": Error at " __FILE__ ":" << __LINE__ << std::endl
                  << "  iMeshP_getPartBdryEnts return incorrect results for " << list_failed.size() << " part pairs."
                  << std::endl;
        ierr = iBase_FAILURE;
    }

    return ierr;
}

/**\brief Test querying of part boundary entities
 *
 * Test:
 * - iMeshP_initPartBdryEntIter
 * - iMeshP_initPartBdryEntArrIter
 */
int test_part_boundary_iter( iMesh_Instance imesh, iMeshP_PartitionHandle prtn, const PartMap& map )
{
    int ierr, rank, has_data;
    MPI_Comm_rank( MPI_COMM_WORLD, &rank );

    // get local part handles and part ids, and global part id list
    std::vector< iMeshP_PartHandle > local_handles;
    std::vector< iMeshP_Part > local_ids;
    std::vector< iMeshP_Part > all_parts = map.get_parts();
    ierr                                 = get_local_parts( imesh, prtn, local_handles, &local_ids );CHKERR;

    std::vector< std::pair< iMeshP_Part, iMeshP_Part > > single_failed, single_error, single_step_error, array_failed,
        array_error, array_step_error;
    for( size_t i = 0; i < local_handles.size(); ++i )
    {
        iMeshP_PartHandle local_handle = local_handles[i];
        iMeshP_Part local_id           = local_ids[i];
        for( std::vector< iMeshP_Part >::iterator j = all_parts.begin(); j != all_parts.end(); ++j )
        {
            iMeshP_Part other_id = *j;
            if( other_id == local_id ) continue;

            std::pair< iMeshP_Part, iMeshP_Part > part_pair;
            part_pair.first  = local_id;
            part_pair.second = other_id;

            // get expected values
            std::vector< iBase_EntityHandle > shared_verts;
            ierr = interface_verts( imesh, prtn, local_handle, other_id, map, shared_verts );
            if( ierr != iBase_SUCCESS || 0 == shared_verts.size() ) continue;
            std::sort( shared_verts.begin(), shared_verts.end() );

            // test single entity iterator
            iBase_EntityIterator siter;
            iMeshP_initPartBdryEntIter( imesh, prtn, local_handle, iBase_VERTEX, iMesh_POINT, other_id, &siter, &ierr );<--- Skipping configuration 'MOAB_FC_FUNC' since the value of 'MOAB_FC_FUNC' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'MOAB_FC_FUNC_' since the value of 'MOAB_FC_FUNC_' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
            if( ierr != iBase_SUCCESS )
            {
                single_error.push_back( part_pair );
            }
            else
            {
                std::vector< iBase_EntityHandle > results;
                for( ;; )
                {
                    iBase_EntityHandle handle;
                    iMesh_getNextEntIter( imesh, siter, &handle, &has_data, &ierr );<--- Skipping configuration 'MOAB_FC_FUNC' since the value of 'MOAB_FC_FUNC' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'MOAB_FC_FUNC_' since the value of 'MOAB_FC_FUNC_' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
                    if( ierr != iBase_SUCCESS )
                    {
                        single_step_error.push_back( part_pair );
                        break;
                    }
                    if( !has_data ) break;
                    results.push_back( handle );
                }

                std::sort( results.begin(), results.end() );
                if( results.size() != shared_verts.size() ||
                    !std::equal( results.begin(), results.end(), shared_verts.begin() ) )
                    single_failed.push_back( part_pair );
            }
            iMesh_endEntIter( imesh, siter, &ierr );<--- Skipping configuration 'MOAB_FC_FUNC' since the value of 'MOAB_FC_FUNC' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'MOAB_FC_FUNC_' since the value of 'MOAB_FC_FUNC_' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.

            // test array iterator
            iBase_EntityArrIterator aiter;
            iMeshP_initPartBdryEntArrIter( imesh, prtn, local_handle, iBase_VERTEX, iMesh_POINT, shared_verts.size(),<--- Skipping configuration 'MOAB_FC_FUNC' since the value of 'MOAB_FC_FUNC' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'MOAB_FC_FUNC_' since the value of 'MOAB_FC_FUNC_' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
                                           other_id, &aiter, &ierr );
            if( ierr != iBase_SUCCESS )
            {
                array_error.push_back( part_pair );
                iMesh_endEntArrIter( imesh, aiter, &ierr );<--- Skipping configuration 'MOAB_FC_FUNC' since the value of 'MOAB_FC_FUNC' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'MOAB_FC_FUNC_' since the value of 'MOAB_FC_FUNC_' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
                continue;
            }
            iBase_EntityHandle results[5], *ptr = results;
            int junk = 5, count;
            iMesh_getNextEntArrIter( imesh, aiter, &ptr, &junk, &count, &has_data, &ierr );<--- Skipping configuration 'MOAB_FC_FUNC' since the value of 'MOAB_FC_FUNC' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'MOAB_FC_FUNC_' since the value of 'MOAB_FC_FUNC_' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
            if( ierr != iBase_SUCCESS || !has_data )
            {
                array_step_error.push_back( part_pair );
                iMesh_endEntArrIter( imesh, aiter, &ierr );<--- Skipping configuration 'MOAB_FC_FUNC' since the value of 'MOAB_FC_FUNC' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'MOAB_FC_FUNC_' since the value of 'MOAB_FC_FUNC_' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
                continue;
            }
            iMesh_endEntArrIter( imesh, aiter, &ierr );<--- Skipping configuration 'MOAB_FC_FUNC' since the value of 'MOAB_FC_FUNC' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'MOAB_FC_FUNC_' since the value of 'MOAB_FC_FUNC_' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
            assert( count <= 5 );
            assert( ptr == results );
            std::sort( ptr, ptr + count );
            if( count != (int)shared_verts.size() || !std::equal( shared_verts.begin(), shared_verts.end(), results ) )
                array_failed.push_back( part_pair );
        }
    }

    if( !single_error.empty() )
    {
        std::cerr << "Processor " << rank << ": Error at " __FILE__ ":" << __LINE__ << std::endl
                  << "  iMeshP_initPartBdryEntIter return error for " << single_error.size() << " part pairs."
                  << std::endl;
        ierr = iBase_FAILURE;
    }
    if( !single_step_error.empty() )
    {
        std::cerr << "Processor " << rank << ": Error at " __FILE__ ":" << __LINE__ << std::endl
                  << "  iMesh_getNextEntIter return error for " << single_step_error.size() << " part pairs."
                  << std::endl;
        ierr = iBase_FAILURE;
    }
    if( !single_failed.empty() )
    {
        std::cerr << "Processor " << rank << ": Error at " __FILE__ ":" << __LINE__ << std::endl
                  << "  iMeshP_initPartBdryEntIter iterator iterated over invalid entities for " << single_failed.size()
                  << " part pairs." << std::endl;
        ierr = iBase_FAILURE;
    }

    if( !array_error.empty() )
    {
        std::cerr << "Processor " << rank << ": Error at " __FILE__ ":" << __LINE__ << std::endl
                  << "  iMeshP_initPartBdryEntArrIter return error for " << array_error.size() << " part pairs."
                  << std::endl;
        ierr = iBase_FAILURE;
    }
    if( !array_step_error.empty() )
    {
        std::cerr << "Processor " << rank << ": Error at " __FILE__ ":" << __LINE__ << std::endl
                  << "  iMesh_getNextEntArrIter return error for " << array_step_error.size() << " part pairs."
                  << std::endl;
        ierr = iBase_FAILURE;
    }
    if( !array_failed.empty() )
    {
        std::cerr << "Processor " << rank << ": Error at " __FILE__ ":" << __LINE__ << std::endl
                  << "  iMeshP_initPartBdryEntArrIter iterator iterated over invalid entities for "
                  << array_failed.size() << " part pairs." << std::endl;
        ierr = iBase_FAILURE;
    }

    return ierr;
}

/**\brief Test adjacent entity query
 *
 * Test:
 * - iMeshP_getAdjEntities
 */
int test_get_adjacencies( iMesh_Instance /* imesh */, iMeshP_PartitionHandle /* prtn */, const PartMap& )
{
    return iBase_SUCCESS;
}

/**\brief Test entity iterators
 *
 * Test:
 * - iMeshP_initEntIter
 * - iMeshP_initEntArrIter
 */
int test_entity_iterator( iMesh_Instance /*imesh */, iMeshP_PartitionHandle /*prtn*/, const PartMap& )
{
    return iBase_SUCCESS;
}

/**\brief Test entity owner queries
 *
 * Test:
 * - iMeshP_getEntOwnerPart
 * - iMeshP_getEntOwnerPartArr
 * - iMeshP_isEntOwner
 * - iMeshP_isEntOwnerArr
 */
int test_entity_owner( iMesh_Instance imesh, iMeshP_PartitionHandle prtn, const PartMap& /* map */ )
{
    int ierr, rank, size;
    MPI_Comm_rank( MPI_COMM_WORLD, &rank );
    MPI_Comm_size( MPI_COMM_WORLD, &size );

    // get local part handles and part ids
    std::vector< iMeshP_PartHandle > local_handles;
    std::vector< iMeshP_Part > local_ids;
    ierr = get_local_parts( imesh, prtn, local_handles, &local_ids );
    PCHECK;

    // test iMeshP_getEntOwnerPart for quads in each part
    std::vector< iBase_EntityHandle > all_quads;
    std::vector< iMeshP_Part > quad_owners;
    int invalid_count = 0;
    for( size_t i = 0; i < local_handles.size(); ++i )
    {
        std::vector< iBase_EntityHandle > quads;
        ierr = get_entities( imesh, local_handles[0], iBase_FACE, iMesh_QUADRILATERAL, quads );
        if( ierr ) break;

        for( size_t j = 0; j < quads.size(); ++j )
        {
            all_quads.push_back( quads[j] );
            quad_owners.push_back( local_ids[i] );
            iMeshP_Part owner;
            iMeshP_getEntOwnerPart( imesh, prtn, quads[j], &owner, &ierr );<--- Skipping configuration 'MOAB_FC_FUNC' since the value of 'MOAB_FC_FUNC' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'MOAB_FC_FUNC_' since the value of 'MOAB_FC_FUNC_' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
            if( iBase_SUCCESS != ierr ) break;

            if( owner != local_ids[i] ) ++invalid_count;
        }
        if( iBase_SUCCESS != ierr ) break;
    }
    PCHECK;
    ASSERT( 0 == invalid_count );

    // test iMeshP_getEntOwnerPartArr for quads in each part
    invalid_count = 0;
    for( size_t i = 0; i < local_handles.size(); ++i )
    {
        std::vector< iBase_EntityHandle > quads;
        ierr = get_entities( imesh, local_handles[0], iBase_FACE, iMesh_QUADRILATERAL, quads );
        if( ierr ) break;

        std::vector< iMeshP_Part > owners( quads.size() ), expected( quads.size(), local_ids[i] );
        int junk         = owners.size(), count;
        iMeshP_Part* ptr = &owners[0];
        iMeshP_getEntOwnerPartArr( imesh, prtn, &quads[0], quads.size(), &ptr, &junk, &count, &ierr );<--- Skipping configuration 'MOAB_FC_FUNC' since the value of 'MOAB_FC_FUNC' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'MOAB_FC_FUNC_' since the value of 'MOAB_FC_FUNC_' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
        if( ierr ) break;
        assert( ptr == &owners[0] );
        assert( junk == (int)owners.size() );
        assert( count == (int)quads.size() );
        if( owners != expected ) ++invalid_count;
    }
    PCHECK;
    ASSERT( 0 == invalid_count );

    // get all vertices
    iBase_EntityHandle* vtx_arr = 0;
    int junk1                   = 0, num_vtx;
    int *junk2 = 0, junk3 = 0, junk4;
    iMesh_getEntArrAdj( imesh, &all_quads[0], all_quads.size(), iBase_VERTEX, &vtx_arr, &junk1, &num_vtx, &junk2,<--- Skipping configuration 'MOAB_FC_FUNC' since the value of 'MOAB_FC_FUNC' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'MOAB_FC_FUNC_' since the value of 'MOAB_FC_FUNC_' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
                        &junk3, &junk4, &ierr );
    PCHECK;
    free( junk2 );
    std::sort( vtx_arr, vtx_arr + num_vtx );
    num_vtx = std::unique( vtx_arr, vtx_arr + num_vtx ) - vtx_arr;
    std::vector< iBase_EntityHandle > all_verts( vtx_arr, vtx_arr + num_vtx );
    free( vtx_arr );

    // check consistency between iMeshP_getEntOwnerPart and iMeshP_getEntOwnerPartArr
    // for all vertices
    std::vector< iMeshP_Part > vert_owners( all_verts.size() );
    junk1              = vert_owners.size();
    iMeshP_Part* junk5 = &vert_owners[0];
    iMeshP_getEntOwnerPartArr( imesh, prtn, &all_verts[0], all_verts.size(), &junk5, &junk1, &junk3, &ierr );<--- Skipping configuration 'MOAB_FC_FUNC' since the value of 'MOAB_FC_FUNC' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'MOAB_FC_FUNC_' since the value of 'MOAB_FC_FUNC_' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
    PCHECK;
    assert( junk5 == &vert_owners[0] );
    assert( junk1 == (int)vert_owners.size() );
    assert( junk3 == (int)all_verts.size() );

    invalid_count = 0;
    for( size_t i = 0; i < all_verts.size(); ++i )
    {
        iMeshP_Part owner;
        iMeshP_getEntOwnerPart( imesh, prtn, all_verts[i], &owner, &ierr );<--- Skipping configuration 'MOAB_FC_FUNC' since the value of 'MOAB_FC_FUNC' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'MOAB_FC_FUNC_' since the value of 'MOAB_FC_FUNC_' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
        if( iBase_SUCCESS != ierr || owner != vert_owners[i] ) ++invalid_count;
    }
    ASSERT( 0 == invalid_count );

    // get lists for all entities
    std::vector< iBase_EntityHandle > all_entities( all_verts );
    std::copy( all_quads.begin(), all_quads.end(), std::back_inserter( all_entities ) );
    std::vector< iMeshP_Part > all_owners( vert_owners );
    std::copy( quad_owners.begin(), quad_owners.end(), std::back_inserter( all_owners ) );

    // check consistency of iMeshP_isEntOwner for all entities
    invalid_count = 0;
    ierr          = iBase_SUCCESS;
    for( size_t i = 0; i < local_handles.size(); ++i )
    {
        for( size_t j = 0; ierr == iBase_SUCCESS && j < all_entities.size(); ++j )
        {
            int is_owner;
            iMeshP_isEntOwner( imesh, prtn, local_handles[i], all_entities[j], &is_owner, &ierr );<--- Skipping configuration 'MOAB_FC_FUNC' since the value of 'MOAB_FC_FUNC' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'MOAB_FC_FUNC_' since the value of 'MOAB_FC_FUNC_' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
            if( ierr != iBase_SUCCESS ) break;
            if( !is_owner == ( local_ids[i] == all_owners[j] ) ) ++invalid_count;
        }
    }
    PCHECK;
    ASSERT( 0 == invalid_count );

    // check consistency of iMeshP_isEntOwnerArr for all entities
    for( size_t i = 0; i < local_handles.size(); ++i )
    {
        std::vector< int > is_owner_list( all_entities.size() );
        junk1      = is_owner_list.size();
        int* junk6 = &is_owner_list[0];
        iMeshP_isEntOwnerArr( imesh, prtn, local_handles[i], &all_entities[0], all_entities.size(), &junk6, &junk1,<--- Skipping configuration 'MOAB_FC_FUNC' since the value of 'MOAB_FC_FUNC' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'MOAB_FC_FUNC_' since the value of 'MOAB_FC_FUNC_' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
                              &junk3, &ierr );
        if( iBase_SUCCESS != ierr ) break;
        assert( junk6 == &is_owner_list[0] );
        assert( junk1 == (int)is_owner_list.size() );
        assert( junk3 == (int)all_entities.size() );
        invalid_count = 0;
        for( size_t j = 0; j < all_entities.size(); ++j )
        {
            if( !( is_owner_list[j] ) == ( local_ids[0] == all_owners[j] ) ) ++invalid_count;
        }
    }
    PCHECK;
    ASSERT( 0 == invalid_count );

    // check globally consistent owners for all vertices

    // first communicate total number of vertex entries to be sent to root proc
    int local_count = all_verts.size(), global_count = 0;
    ierr = MPI_Reduce( &local_count, &global_count, 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD );CHKERR;

    // for each vertex, store { (x << 2) | y, owning part id }
    std::vector< int > vtxdata( 2 * all_verts.size() );
    std::vector< double > coords( 3 * all_verts.size() );
    ierr = get_coords( imesh, &all_verts[0], all_verts.size(), &coords[0] );CHKERR;
    for( size_t i = 0; i < all_verts.size(); ++i )
    {
        int x              = (int)round( coords[3 * i] );
        int y              = (int)round( coords[3 * i + 1] );
        vtxdata[2 * i]     = ( x << 3 ) | y;
        vtxdata[2 * i + 1] = vert_owners[i];
    }

    // collect all data on root procesor
    std::vector< int > all_data( 2 * global_count );
    std::vector< int > displ( size ), counts( size );
    for( int i = 0; i < size; i++ )
    {
        counts[i] = vtxdata.size();
        displ[i]  = i * vtxdata.size();
    }

    // we could have used a simple gather, because all sequences are the same
    ierr = MPI_Gatherv( &vtxdata[0], vtxdata.size(), MPI_INT, &all_data[0], &counts[0], &displ[0], MPI_INT, 0,
                        MPI_COMM_WORLD );CHKERR;

    if( rank == 0 )
    {
        // map from vertex tag to indices into data
        std::multimap< int, int > data_map;
        for( int i = 0; i < global_count; ++i )
        {
            std::pair< int, int > p;
            p.first  = all_data[2 * i];
            p.second = i;
            data_map.insert( p );
        }

        // check consistent data for each vtx
        std::multimap< int, int >::const_iterator a, b;
        for( a = data_map.begin(); a != data_map.end(); a = b )
        {
            for( b = a; b != data_map.end() && a->first == b->first; ++b )
            {
                int idx1 = a->second;
                int idx2 = b->second;
                if( all_data[2 * idx1 + 1] == all_data[2 * idx2 + 1] ) continue;

                ierr = iBase_FAILURE;

                int proc1 = std::lower_bound( displ.begin(), displ.end(), 2 * idx1 ) - displ.begin();
                if( displ[proc1] != 2 * idx1 ) ++proc1;
                int proc2 = std::lower_bound( displ.begin(), displ.end(), 2 * idx2 ) - displ.begin();
                if( displ[proc2] != 2 * idx2 ) ++proc2;

                std::cerr << "Error at " __FILE__ ":" << __LINE__ << " : " << std::endl
                          << "  For vertex at (" << ( a->first >> 2 ) << ", " << ( a->first & 3 ) << ") :" << std::endl
                          << "  Processor " << proc1 << " has " << all_data[2 * idx1 + 1] << " as the owning part"
                          << std::endl
                          << "  Processor " << proc2 << " has " << all_data[2 * idx2 + 1] << " as the owning part"
                          << std::endl;
            }
        }
    }

    return ierr;
}

static int get_part_boundary_verts( iMesh_Instance imesh,
                                    iMeshP_PartitionHandle prtn,
                                    const PartMap& map,
                                    iMeshP_PartHandle part,
                                    std::vector< iBase_EntityHandle >& boundary )
{
    int ierr, logical_id;
    ierr = map.part_from_coords( imesh, part, logical_id );CHKERR;

    int neighbors[5], num_neighbors;
    get_part_neighbors( logical_id, map.get_parts().size(), neighbors, num_neighbors );

    for( int j = 0; j < num_neighbors; ++j )
    {
        std::vector< iBase_EntityHandle > iface;
        ierr = interface_verts( imesh, prtn, part, neighbors[j], map, iface );CHKERR;
        std::copy( iface.begin(), iface.end(), std::back_inserter( boundary ) );
    }

    std::sort( boundary.begin(), boundary.end() );
    boundary.erase( std::unique( boundary.begin(), boundary.end() ), boundary.end() );
    return iBase_SUCCESS;
}

/**\brief Test entity status
 *
 * Test:
 * - iMeshP_getEntStatus
 * - iMeshP_getEntStatusArr
 */
int test_entity_status( iMesh_Instance imesh, iMeshP_PartitionHandle prtn, const PartMap& map )
{
    int ierr, rank, size;
    MPI_Comm_rank( MPI_COMM_WORLD, &rank );
    MPI_Comm_size( MPI_COMM_WORLD, &size );

    // get local part handles
    std::vector< iMeshP_PartHandle > parts;
    ierr = get_local_parts( imesh, prtn, parts );
    PCHECK;

    // for each part
    int num_quad_ent_incorrect = 0, num_quad_ent_error = 0;
    int num_quad_arr_incorrect = 0, num_quad_arr_error = 0;
    int num_vert_ent_incorrect = 0, num_vert_ent_error = 0;
    int num_vert_arr_incorrect = 0, num_vert_arr_error = 0;
    for( size_t i = 0; i < parts.size(); ++i )
    {
        const iMeshP_PartHandle part = parts[i];

        // get quads and vertices
        std::vector< iBase_EntityHandle > quads, verts;
        ierr = get_part_quads_and_verts( imesh, part, quads, verts );
        if( ierr ) break;

        // check quad status (no ghosting yet)
        for( size_t j = 0; j < quads.size(); ++j )
        {
            int status;
            iMeshP_getEntStatus( imesh, prtn, part, quads[j], &status, &ierr );<--- Skipping configuration 'MOAB_FC_FUNC' since the value of 'MOAB_FC_FUNC' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'MOAB_FC_FUNC_' since the value of 'MOAB_FC_FUNC_' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
            if( ierr != iBase_SUCCESS )
            {
                ++num_quad_ent_error;
                ierr = iBase_SUCCESS;
                continue;
            }

            if( status != iMeshP_INTERNAL ) ++num_quad_ent_incorrect;
        }

        // check quad status using iMeshP_getEntStatusArr
        std::vector< int > stat_list( quads.size() );
        int* junk1 = &stat_list[0];
        int junk2  = stat_list.size(), count;
        iMeshP_getEntStatusArr( imesh, prtn, part, &quads[0], quads.size(), &junk1, &junk2, &count, &ierr );<--- Skipping configuration 'MOAB_FC_FUNC' since the value of 'MOAB_FC_FUNC' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'MOAB_FC_FUNC_' since the value of 'MOAB_FC_FUNC_' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
        if( ierr != iBase_SUCCESS )
        {
            ++num_quad_arr_error;
            ierr = iBase_SUCCESS;
            continue;
        }
        assert( junk1 == &stat_list[0] );
        assert( junk2 == (int)stat_list.size() );
        assert( count == (int)quads.size() );
        for( size_t j = 0; j < quads.size(); ++j )
            if( stat_list[j] != iMeshP_INTERNAL ) ++num_quad_arr_incorrect;

        // figure out which vertices are on the boundary
        std::vector< iBase_EntityHandle > boundary;
        ierr = get_part_boundary_verts( imesh, prtn, map, part, boundary );
        if( ierr ) break;
        std::sort( boundary.begin(), boundary.end() );

        // check vertex status (no ghosting yet)
        for( size_t j = 0; j < verts.size(); ++j )
        {
            int status;
            iMeshP_getEntStatus( imesh, prtn, part, verts[j], &status, &ierr );<--- Skipping configuration 'MOAB_FC_FUNC' since the value of 'MOAB_FC_FUNC' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'MOAB_FC_FUNC_' since the value of 'MOAB_FC_FUNC_' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
            if( ierr != iBase_SUCCESS )
            {
                ++num_vert_ent_error;
                ierr = iBase_SUCCESS;
                continue;
            }
            bool on_boundary = std::binary_search( boundary.begin(), boundary.end(), verts[j] );
            if( status != ( on_boundary ? iMeshP_BOUNDARY : iMeshP_INTERNAL ) ) ++num_vert_ent_incorrect;
        }

        // check vert status using iMeshP_getEntStatusArr
        stat_list.resize( verts.size() );
        junk1 = &stat_list[0];
        junk2 = stat_list.size();
        iMeshP_getEntStatusArr( imesh, prtn, part, &verts[0], verts.size(), &junk1, &junk2, &count, &ierr );<--- Skipping configuration 'MOAB_FC_FUNC' since the value of 'MOAB_FC_FUNC' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'MOAB_FC_FUNC_' since the value of 'MOAB_FC_FUNC_' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
        if( ierr != iBase_SUCCESS )
        {
            ++num_vert_arr_error;
            ierr = iBase_SUCCESS;
            continue;
        }
        assert( junk1 == &stat_list[0] );
        assert( junk2 == (int)stat_list.size() );
        assert( count == (int)verts.size() );
        for( size_t j = 0; j < verts.size(); ++j )
        {
            bool on_boundary = std::binary_search( boundary.begin(), boundary.end(), verts[j] );
            if( stat_list[j] != ( on_boundary ? iMeshP_BOUNDARY : iMeshP_INTERNAL ) ) ++num_vert_arr_incorrect;
        }
    }
    PCHECK;  // check if loop interrupted by any internal errors

    ASSERT( 0 == num_quad_ent_error );
    ASSERT( 0 == num_quad_arr_error );
    ASSERT( 0 == num_vert_ent_error );
    ASSERT( 0 == num_vert_arr_error );
    ASSERT( 0 == num_quad_ent_incorrect );
    ASSERT( 0 == num_quad_arr_incorrect );
    ASSERT( 0 == num_vert_ent_incorrect );
    ASSERT( 0 == num_vert_arr_incorrect );

    return iBase_SUCCESS;
}

/**\brief Test information about entity copies for interface entities
 *
 * Test:
 * - iMeshP_getNumCopies
 * - iMeshP_getCopyParts
 */
int test_entity_copy_parts( iMesh_Instance imesh, iMeshP_PartitionHandle prtn, const PartMap& map )
{
    int ierr, rank, size;
    MPI_Comm_rank( MPI_COMM_WORLD, &rank );
    MPI_Comm_size( MPI_COMM_WORLD, &size );

    // get local part handles
    std::vector< iMeshP_PartHandle > parts;
    ierr = get_local_parts( imesh, prtn, parts );
    PCHECK;
    ASSERT( !parts.empty() );

    // select a singe part to test
    const iMeshP_PartHandle part = parts[0];
    int logical_id;
    ierr = map.part_from_coords( imesh, part, logical_id );CHKERR;
    const iMeshP_Part part_id = map.part_id_from_local_id( logical_id );

    // get vertices in part
    std::vector< iBase_EntityHandle > quads, verts;
    ierr = get_part_quads_and_verts( imesh, part, quads, verts );
    PCHECK;

    // get neighbors
    int neighbors[5], num_neighbors;
    get_part_neighbors( logical_id, map.get_parts().size(), neighbors, num_neighbors );

    // build map of sharing data for each vertex
    std::map< iBase_EntityHandle, std::vector< iMeshP_Part > > vert_sharing;
    for( int j = 0; j < num_neighbors; ++j )
    {
        std::vector< iBase_EntityHandle > iface;
        ierr = interface_verts( imesh, prtn, part, neighbors[j], map, iface );CHKERR;
        for( size_t k = 0; k < iface.size(); ++k )
            vert_sharing[iface[k]].push_back( map.part_id_from_local_id( neighbors[j] ) );
    }

    // test getNumCopies for each vertex
    std::map< iBase_EntityHandle, std::vector< iMeshP_Part > >::iterator i;
    int num_failed = 0, num_incorrect = 0;
    for( i = vert_sharing.begin(); i != vert_sharing.end(); ++i )
    {
        int count;
        iBase_EntityHandle vtx = i->first;
        iMeshP_getNumCopies( imesh, prtn, vtx, &count, &ierr );<--- Skipping configuration 'MOAB_FC_FUNC' since the value of 'MOAB_FC_FUNC' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'MOAB_FC_FUNC_' since the value of 'MOAB_FC_FUNC_' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
        if( ierr )
            ++num_failed;
        else if( (unsigned)count != i->second.size() + 1 )  // add one for the part we queried from
            ++num_incorrect;
    }
    ASSERT( 0 == num_failed );
    ASSERT( 0 == num_incorrect );

    // get getCopyParts for each vertex
    num_failed = num_incorrect = 0;
    for( i = vert_sharing.begin(); i != vert_sharing.end(); ++i )
    {
        iMeshP_Part* list = 0;
        int junk          = 0, count;
        iMeshP_getCopyParts( imesh, prtn, i->first, &list, &junk, &count, &ierr );<--- Skipping configuration 'MOAB_FC_FUNC' since the value of 'MOAB_FC_FUNC' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'MOAB_FC_FUNC_' since the value of 'MOAB_FC_FUNC_' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
        if( iBase_SUCCESS != ierr )
        {
            ++num_failed;
            continue;
        }
        if( (unsigned)count != i->second.size() + 1 )
        {  // add one for the part we queried from
            ++num_incorrect;
            free( list );
            continue;
        }

        std::vector< iMeshP_Part > expected( i->second );
        expected.push_back( part_id );
        std::sort( list, list + count );
        std::sort( expected.begin(), expected.end() );
        bool eq = std::equal( list, list + count, expected.begin() );
        free( list );
        if( !eq ) ++num_incorrect;
    }
    ASSERT( 0 == num_failed );
    ASSERT( 0 == num_incorrect );

    return iBase_SUCCESS;
}

// store remote handle data for a vertex
struct VtxCopyData
{
    std::vector< iMeshP_Part > parts;
    std::vector< iBase_EntityHandle > handles;
};

/**\brief Test information about entity copies for interface entities
 *
 * Test:
 * - iMeshP_getCopies
 * - iMeshP_getCopyOnPart
 * - iMeshP_getOwnerCopy
 */
int test_entity_copies( iMesh_Instance imesh, iMeshP_PartitionHandle prtn, const PartMap& /* map */ )
{
    int ierr, rank, size;
    MPI_Comm_rank( MPI_COMM_WORLD, &rank );
    MPI_Comm_size( MPI_COMM_WORLD, &size );

    // generate a unique ID for each vertex using the coordinates.
    // see create_mesh(..): each vertex has integer coordinates (x,y,0)
    //                      with x in [0,inf] and y in [0,4]
    // then to an Allgatherv to exchange handles for each processor

    // cast everything to iBase_EntityHandle so we can pack it all in one communication
    MPI_Datatype tmp_type;
    if( sizeof( iBase_EntityHandle ) == sizeof( unsigned ) )
        tmp_type = MPI_UNSIGNED;
    else if( sizeof( iBase_EntityHandle ) == sizeof( unsigned long ) )
        tmp_type = MPI_UNSIGNED_LONG;
    else if( sizeof( iBase_EntityHandle ) == sizeof( unsigned long long ) )
        tmp_type = MPI_UNSIGNED_LONG_LONG;
    else
        return iBase_FAILURE;
    const MPI_Datatype type = tmp_type;  // make it const

    // get local part handles
    std::vector< iMeshP_PartHandle > parts;
    ierr = get_local_parts( imesh, prtn, parts );
    PCHECK;
    std::vector< iMeshP_Part > part_ids( parts.size() );
    iMeshP_Part* junk1 = &part_ids[0];
    int junk2          = part_ids.size(), junk3;
    iMeshP_getPartIdsFromPartHandlesArr( imesh, prtn, &parts[0], parts.size(), &junk1, &junk2, &junk3, &ierr );<--- Skipping configuration 'MOAB_FC_FUNC' since the value of 'MOAB_FC_FUNC' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'MOAB_FC_FUNC_' since the value of 'MOAB_FC_FUNC_' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
    PCHECK;
    assert( junk1 == &part_ids[0] );
    assert( junk2 == (int)part_ids.size() );
    assert( junk3 == (int)parts.size() );

    // build list of {vtx_id, part_id, handle} tuples to send
    // also build list of local vertex handles
    std::vector< iBase_EntityHandle > local_data, local_vertices;
    for( size_t i = 0; i < parts.size(); ++i )
    {
        // get vertices
        std::vector< iBase_EntityHandle > quads, verts;
        ierr = get_part_quads_and_verts( imesh, parts[i], quads, verts );
        if( ierr ) break;

        // add all vertices to local_data
        for( size_t j = 0; j < verts.size(); ++j )
        {
            int tag = 0;
            ierr    = vertex_tag( imesh, verts[j], tag );
            if( ierr ) break;
            long tmp_h = tag;
            local_data.push_back( (iBase_EntityHandle)tmp_h );
            tmp_h = part_ids[i];
            local_data.push_back( (iBase_EntityHandle)tmp_h );
            local_data.push_back( verts[j] );
        }
        if( ierr ) break;

        std::copy( verts.begin(), verts.end(), std::back_inserter( local_vertices ) );
    }

    // build list of local vertices
    std::sort( local_vertices.begin(), local_vertices.end() );
    local_vertices.erase( std::unique( local_vertices.begin(), local_vertices.end() ), local_vertices.end() );
    std::vector< int > local_vtx_tags( local_vertices.size() );CHKERR;
    for( size_t i = 0; i < local_vertices.size(); ++i )
    {
        ierr = vertex_tag( imesh, local_vertices[i], local_vtx_tags[i] );
        if( ierr ) break;
    }
    CHKERR;

    // communicate data
    std::vector< int > gcounts( size ), gdisp( size );
    int local_data_size = local_data.size();
    ierr                = MPI_Allgather( &local_data_size, 1, MPI_INT, &gcounts[0], 1, MPI_INT, MPI_COMM_WORLD );CHKERR;
    gdisp[0] = 0;
    for( int i = 1; i < size; ++i )
        gdisp[i] = gdisp[i - 1] + gcounts[i - 1];
    std::vector< iBase_EntityHandle > global_data( gdisp[size - 1] + gcounts[size - 1] );
    ierr = MPI_Allgatherv( &local_data[0], local_data_size, type, &global_data[0], &gcounts[0], &gdisp[0], type,
                           MPI_COMM_WORLD );CHKERR;

    // arrange global data in a more useful way
    std::map< int, VtxCopyData > vtx_sharing;
    assert( global_data.size() % 3 == 0 );
    for( size_t i = 0; i < global_data.size(); i += 3 )
    {
        int tag                   = (int)(size_t)global_data[i];
        iMeshP_Part part          = (iMeshP_Part)(size_t)global_data[i + 1];
        iBase_EntityHandle handle = global_data[i + 2];
        vtx_sharing[tag].parts.push_back( part );
        vtx_sharing[tag].handles.push_back( handle );
    }

    // test iMeshP_getCopies for each local vertex
    int num_error = 0, num_incorrect = 0, junk4;
    for( size_t i = 0; i < local_vertices.size(); ++i )
    {
        int num_copies = -1;
        // iMeshP_Part* part_ids = 0;
        iMeshP_Part* ptr_part_ids  = 0;  // Use ptr_part_ids to avoid shadowing std::vector<iMeshP_Part> part_ids
        iBase_EntityHandle* copies = 0;
        junk2 = junk3 = junk4 = 0;
        iMeshP_getCopies( imesh, prtn, local_vertices[i], &ptr_part_ids, &junk2, &num_copies, &copies, &junk3, &junk4,<--- Skipping configuration 'MOAB_FC_FUNC' since the value of 'MOAB_FC_FUNC' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'MOAB_FC_FUNC_' since the value of 'MOAB_FC_FUNC_' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
                          &ierr );
        if( iBase_SUCCESS != ierr )
        {
            ++num_error;
            continue;
        }
        assert( junk4 == num_copies );

        VtxCopyData& expected = vtx_sharing[local_vtx_tags[i]];
        if( num_copies != (int)expected.parts.size() )
            ++num_incorrect;
        else
            for( size_t j = 0; j < expected.parts.size(); ++j )
            {
                int idx = std::find( ptr_part_ids, ptr_part_ids + num_copies, expected.parts[j] ) - ptr_part_ids;
                if( idx == num_copies || copies[idx] != expected.handles[j] )
                {
                    ++num_incorrect;
                    break;
                }
            }
        free( ptr_part_ids );
        free( copies );
    }
    ASSERT( 0 == num_error );
    ASSERT( 0 == num_incorrect );

    // test iMeshP_getCopyOnPart for each local vertex
    num_error = num_incorrect = 0;
    for( size_t i = 0; i < local_vertices.size(); ++i )
    {
        VtxCopyData& expected = vtx_sharing[local_vtx_tags[i]];
        for( size_t j = 0; j < expected.parts.size(); ++j )
        {
            iBase_EntityHandle copy;
            iMeshP_getCopyOnPart( imesh, prtn, local_vertices[i], expected.parts[j], &copy, &ierr );<--- Skipping configuration 'MOAB_FC_FUNC' since the value of 'MOAB_FC_FUNC' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'MOAB_FC_FUNC_' since the value of 'MOAB_FC_FUNC_' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
            if( iBase_SUCCESS != ierr )
                ++num_error;
            else if( expected.handles[j] != copy )
                ++num_incorrect;
        }
    }
    ASSERT( 0 == num_error );
    ASSERT( 0 == num_incorrect );

    // test iMeshP_getOwnerCopy for each local vertex
    num_error = num_incorrect = 0;
    for( size_t i = 0; i < local_vertices.size(); ++i )
    {
        VtxCopyData& expected = vtx_sharing[local_vtx_tags[i]];
        iMeshP_Part owner_id  = 0;
        iMeshP_getEntOwnerPart( imesh, prtn, local_vertices[i], &owner_id, &ierr );<--- Skipping configuration 'MOAB_FC_FUNC' since the value of 'MOAB_FC_FUNC' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'MOAB_FC_FUNC_' since the value of 'MOAB_FC_FUNC_' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
        if( iBase_SUCCESS != ierr ) continue;  // not testing getEntOwnerPart here

        size_t idx = std::find( expected.parts.begin(), expected.parts.end(), owner_id ) - expected.parts.begin();
        if( idx == expected.parts.size() ) continue;  // not testing getEntOwnerPart here

        iMeshP_Part owner_id_2  = 0;
        iBase_EntityHandle copy = 0;
        iMeshP_getOwnerCopy( imesh, prtn, local_vertices[i], &owner_id_2, &copy, &ierr );<--- Skipping configuration 'MOAB_FC_FUNC' since the value of 'MOAB_FC_FUNC' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'MOAB_FC_FUNC_' since the value of 'MOAB_FC_FUNC_' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
        if( iBase_SUCCESS != ierr )
            ++num_error;
        else if( owner_id_2 != owner_id && copy != expected.handles[idx] )
            ++num_incorrect;
    }
    ASSERT( 0 == num_error );
    ASSERT( 0 == num_incorrect );

    return iBase_SUCCESS;
}

int get_num_adj_quads( iMesh_Instance imesh, iBase_EntityHandle vtx, int& num )
{
    iBase_EntityHandle* list = 0;
    int ierr, junk = 0;
    iMesh_getEntAdj( imesh, vtx, iBase_FACE, &list, &junk, &num, &ierr );<--- Skipping configuration 'MOAB_FC_FUNC' since the value of 'MOAB_FC_FUNC' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'MOAB_FC_FUNC_' since the value of 'MOAB_FC_FUNC_' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
    if( iBase_SUCCESS == ierr ) free( list );
    return ierr;
}

int get_adj( iMesh_Instance imesh, iBase_EntityHandle ent, int type, std::vector< iBase_EntityHandle >& adj )
{
    iBase_EntityHandle* list = 0;
    int ierr, num, junk = 0;
    iMesh_getEntAdj( imesh, ent, type, &list, &junk, &num, &ierr );<--- Skipping configuration 'MOAB_FC_FUNC' since the value of 'MOAB_FC_FUNC' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'MOAB_FC_FUNC_' since the value of 'MOAB_FC_FUNC_' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
    if( iBase_SUCCESS == ierr )
    {
        std::copy( list, list + num, std::back_inserter( adj ) );
        free( list );
    }
    return ierr;
}

// assume regular quad mesh
int get_boundary_vertices( iMesh_Instance imesh, std::vector< iBase_EntityHandle >& bdry )
{
    int ierr, n;
    iBase_EntitySetHandle root;
    iMesh_getRootSet( imesh, &root, &ierr );CHKERR;<--- Skipping configuration 'MOAB_FC_FUNC' since the value of 'MOAB_FC_FUNC' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'MOAB_FC_FUNC_' since the value of 'MOAB_FC_FUNC_' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
    std::vector< iBase_EntityHandle > all_verts;
    ierr = get_entities( imesh, root, iBase_VERTEX, iMesh_POINT, all_verts );CHKERR;
    bdry.clear();
    for( size_t i = 0; i < all_verts.size(); ++i )
    {
        ierr = get_num_adj_quads( imesh, all_verts[i], n );CHKERR;
        if( n != 4 ) bdry.push_back( all_verts[i] );
    }
    return iBase_SUCCESS;
}

int check_one_layer( iMesh_Instance imesh,
                     iBase_EntityHandle vtx,
                     const std::vector< iBase_EntityHandle >& sorted_vertices )
{
    int ierr;
    if( std::binary_search( sorted_vertices.begin(), sorted_vertices.end(), vtx ) ) return iBase_SUCCESS;
    std::vector< iBase_EntityHandle > quads, verts;
    ierr = get_adj( imesh, vtx, iBase_FACE, quads );CHKERR;
    for( size_t i = 0; i < quads.size(); ++i )
    {
        verts.clear();
        ierr = get_adj( imesh, quads[i], iBase_VERTEX, verts );CHKERR;
        for( size_t j = 0; j < verts.size(); ++j )
        {
            if( std::binary_search( sorted_vertices.begin(), sorted_vertices.end(), verts[j] ) ) return iBase_SUCCESS;
        }
    }

    return iBase_FAILURE;
}

// get number of adjacent quads to each vertex, both on the local
// processor and in the entire mesh
int get_num_adj_all( iMesh_Instance imesh,
                     const std::vector< iBase_EntityHandle >& verts,
                     std::vector< int >& num_local_adj,
                     std::vector< int >& num_all_adj )
{
    int ierr, size;
    MPI_Comm_size( MPI_COMM_WORLD, &size );

    std::vector< int > vtx_tags( verts.size() );
    num_local_adj.resize( verts.size() );
    for( size_t i = 0; i < verts.size(); ++i )
    {
        ierr = get_num_adj_quads( imesh, verts[i], num_local_adj[i] );CHKERR;
        ierr = vertex_tag( imesh, verts[i], vtx_tags[i] );CHKERR;
    }

    std::vector< int > counts( size ), displ( size );
    int num_vtx = verts.size();
    ierr        = MPI_Allgather( &num_vtx, 1, MPI_INT, &counts[0], 1, MPI_INT, MPI_COMM_WORLD );CHKERR;
    displ[0] = 0;
    for( int i = 1; i < size; ++i )
        displ[i] = displ[i - 1] + counts[i - 1];
    int total = displ[size - 1] + counts[size - 1];
    std::vector< int > all_tags( total ), all_adj_counts( total );
    ierr = MPI_Allgatherv( &vtx_tags[0], vtx_tags.size(), MPI_INT, &all_tags[0], &counts[0], &displ[0], MPI_INT,
                           MPI_COMM_WORLD );CHKERR;
    ierr = MPI_Allgatherv( &num_local_adj[0], num_local_adj.size(), MPI_INT, &all_adj_counts[0], &counts[0], &displ[0],
                           MPI_INT, MPI_COMM_WORLD );CHKERR;

    num_all_adj.clear();
    num_all_adj.resize( total, 0 );
    for( int i = 0; i < total; ++i )
    {
        std::vector< int >::iterator it = std::find( vtx_tags.begin(), vtx_tags.end(), all_tags[i] );
        if( it == vtx_tags.end() ) continue;
        int idx = it - vtx_tags.begin();
        num_all_adj[idx] += all_adj_counts[i];
    }

    return iBase_SUCCESS;
}

/**\brief Test creation of ghost entities
 *
 * Test:
 * - iMeshP_createGhostEntsAll
 */
int test_create_ghost_ents( iMesh_Instance imesh, iMeshP_PartitionHandle prtn, const PartMap& /* map */ )
{
    int ierr;

    // get boundary vertices
    std::vector< iBase_EntityHandle > bdry;
    ierr = get_boundary_vertices( imesh, bdry );
    PCHECK;
    // get counts of adjacent entities
    std::vector< int > num_local_adj, num_global_adj;
    ierr = get_num_adj_all( imesh, bdry, num_local_adj, num_global_adj );
    PCHECK;
    // create one layer of ghost entities
    iMeshP_createGhostEntsAll( imesh, prtn, iBase_FACE, iBase_VERTEX, 1, 0, &ierr );<--- Skipping configuration 'MOAB_FC_FUNC' since the value of 'MOAB_FC_FUNC' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'MOAB_FC_FUNC_' since the value of 'MOAB_FC_FUNC_' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
    PCHECK;
    // check that each vertex has the correct number of adjacent entities
    int num_incorrect = 0;
    for( size_t i = 0; i < bdry.size(); ++i )
    {
        int n;
        ierr = get_num_adj_quads( imesh, bdry[i], n );
        if( iBase_SUCCESS != ierr || num_global_adj[i] != n ) ++num_incorrect;
    }
    ASSERT( 0 == num_incorrect );
    // get new the new boundary
    std::vector< iBase_EntityHandle > new_bdry;
    ierr = get_boundary_vertices( imesh, new_bdry );
    PCHECK;
    // check that each vertex on the new boundary is separated by
    // at most one layer from the old boundary
    std::sort( bdry.begin(), bdry.end() );
    num_incorrect = 0;
    for( size_t i = 0; i < new_bdry.size(); ++i )
    {
        ierr = check_one_layer( imesh, new_bdry[i], bdry );
        if( ierr ) ++num_incorrect;
    }
    ASSERT( 0 == num_incorrect );
    // make another layer of ghost entiites
    bdry.swap( new_bdry );
    new_bdry.clear();
    ierr = get_num_adj_all( imesh, bdry, num_local_adj, num_global_adj );
    PCHECK;
    iMeshP_createGhostEntsAll( imesh, prtn, iBase_FACE, iBase_VERTEX, 2, 0, &ierr );<--- Skipping configuration 'MOAB_FC_FUNC' since the value of 'MOAB_FC_FUNC' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'MOAB_FC_FUNC_' since the value of 'MOAB_FC_FUNC_' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
    PCHECK;
    // check that each vertex has the correct number of adjacent entities
    num_incorrect = 0;
    for( size_t i = 0; i < bdry.size(); ++i )
    {
        int n;
        ierr = get_num_adj_quads( imesh, bdry[i], n );
        if( iBase_SUCCESS != ierr || num_global_adj[i] != n ) ++num_incorrect;
    }
    // check that each vertex on the new boundary is separated by
    // at most one layer from the old boundary
    std::sort( bdry.begin(), bdry.end() );
    num_incorrect = 0;
    for( size_t i = 0; i < new_bdry.size(); ++i )
    {
        ierr = check_one_layer( imesh, new_bdry[i], bdry );
        if( ierr ) ++num_incorrect;
    }
    ASSERT( 0 == num_incorrect );

    return iBase_SUCCESS;
}

/**\brief Test exchange entities
 *
 * Test:
 * - iMeshP_exchEntArrToPartsAll
 */
int test_exchange_ents( iMesh_Instance imesh, iMeshP_PartitionHandle prtn, const PartMap& map )
{
    int ierr, rank, size;
    int num_err = 0;
    iMeshP_RequestHandle request;
    MPI_Comm_rank( MPI_COMM_WORLD, &rank );
    MPI_Comm_size( MPI_COMM_WORLD, &size );

    std::vector< iBase_EntityHandle > all_elems;
    std::vector< iMeshP_Part > all_ids;
    std::vector< iBase_EntityHandle > quads;

    // get local part handles and part ids
    std::vector< iMeshP_PartHandle > local_handles;
    std::vector< iMeshP_Part > local_ids;
    ierr = get_local_parts( imesh, prtn, local_handles, &local_ids );
    PCHECK;

    // get loacal quads before exchange
    quads.clear();
    ierr = get_entities( imesh, local_handles[0], iBase_FACE, iMesh_QUADRILATERAL, quads );CHKERR;
    int n_quads = quads.size();

    // send all elements in local processor to all other processors
    for( size_t i = 0; i < map.get_parts().size(); ++i )
    {
        if( map.get_parts()[i] == (unsigned int)rank ) continue;  // skip own rank

        for( int j = 0; j < n_quads; j++ )
        {
            all_elems.push_back( quads[j] );
            all_ids.push_back( map.get_parts()[i] );
        }
    }

    // exchange entities
    iMeshP_exchEntArrToPartsAll( imesh, prtn, &all_elems[0], all_elems.size(), &all_ids[0], 0, 0, &request, &ierr );<--- Skipping configuration 'MOAB_FC_FUNC' since the value of 'MOAB_FC_FUNC' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'MOAB_FC_FUNC_' since the value of 'MOAB_FC_FUNC_' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
    if( iBase_SUCCESS != ierr ) ++num_err;

    // get local quads after exchange
    quads.clear();
    ierr = get_entities( imesh, local_handles[0], iBase_FACE, iMesh_QUADRILATERAL, quads );CHKERR;

    // # of elements should be # of quads * # of processors
    ASSERT( quads.size() == (unsigned int)n_quads * size );

    ASSERT( 0 == num_err );

    return iBase_SUCCESS;
}

/**\brief Test commuinication of tag data
 *
 * Test:
 * - iMeshP_pushTags
 * - iMeshP_pushTagsEnt
 */
int test_push_tag_data_common( iMesh_Instance imesh, iMeshP_PartitionHandle prtn, int num_ghost_layers )
{
    const char* src_name = "test_src";
    const char* dst_name = "test_dst";
    int ierr, rank;
    MPI_Comm_rank( MPI_COMM_WORLD, &rank );

    if( num_ghost_layers )
    {
        iMeshP_createGhostEntsAll( imesh, prtn, iBase_FACE, iBase_VERTEX, num_ghost_layers, 0, &ierr );<--- Skipping configuration 'MOAB_FC_FUNC' since the value of 'MOAB_FC_FUNC' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'MOAB_FC_FUNC_' since the value of 'MOAB_FC_FUNC_' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
        PCHECK;
    }

    iBase_TagHandle src_tag, dst_tag;
    iMesh_createTag( imesh, src_name, 1, iBase_INTEGER, &src_tag, &ierr, strlen( src_name ) );CHKERR;<--- Skipping configuration 'MOAB_FC_FUNC' since the value of 'MOAB_FC_FUNC' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'MOAB_FC_FUNC_' since the value of 'MOAB_FC_FUNC_' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
    iMesh_createTag( imesh, dst_name, 1, iBase_INTEGER, &dst_tag, &ierr, strlen( dst_name ) );CHKERR;<--- Skipping configuration 'MOAB_FC_FUNC' since the value of 'MOAB_FC_FUNC' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'MOAB_FC_FUNC_' since the value of 'MOAB_FC_FUNC_' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.

    iBase_EntitySetHandle root;
    iMesh_getRootSet( imesh, &root, &ierr );CHKERR;<--- Skipping configuration 'MOAB_FC_FUNC' since the value of 'MOAB_FC_FUNC' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'MOAB_FC_FUNC_' since the value of 'MOAB_FC_FUNC_' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.

    std::vector< iBase_EntityHandle > verts;
    ierr = get_entities( imesh, root, iBase_VERTEX, iMesh_POINT, verts );CHKERR;

    // test iMeshP_pushTags
    // each processor writes its rank on all vertices
    // after push, each vertex should be tagged with the rank of its owner

    std::vector< int > tag_vals( verts.size(), rank );
    iMesh_setIntArrData( imesh, &verts[0], verts.size(), src_tag, &tag_vals[0], tag_vals.size(), &ierr );CHKERR;<--- Skipping configuration 'MOAB_FC_FUNC' since the value of 'MOAB_FC_FUNC' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'MOAB_FC_FUNC_' since the value of 'MOAB_FC_FUNC_' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.

    iMeshP_pushTags( imesh, prtn, src_tag, dst_tag, iBase_VERTEX, iMesh_POINT, &ierr );<--- Skipping configuration 'MOAB_FC_FUNC' since the value of 'MOAB_FC_FUNC' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'MOAB_FC_FUNC_' since the value of 'MOAB_FC_FUNC_' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
    PCHECK;

    tag_vals.clear();
    tag_vals.resize( verts.size(), -1 );
    iBase_TagHandle id_tag;
    iMesh_getTagHandle( imesh, "GLOBAL_ID", &id_tag, &ierr, strlen( "GLOBAL_ID" ) );<--- Skipping configuration 'MOAB_FC_FUNC' since the value of 'MOAB_FC_FUNC' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'MOAB_FC_FUNC_' since the value of 'MOAB_FC_FUNC_' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
    std::vector< int > ids( verts.size() );
    int *junk1 = &ids[0], junk2 = ids.size(), junk3;
    iMesh_getIntArrData( imesh, &verts[0], verts.size(), id_tag, &junk1, &junk2, &junk3, &ierr );<--- Skipping configuration 'MOAB_FC_FUNC' since the value of 'MOAB_FC_FUNC' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'MOAB_FC_FUNC_' since the value of 'MOAB_FC_FUNC_' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
    PCHECK;
    int errcount = 0;
    for( size_t i = 0; i < verts.size(); ++i )
    {
        iMesh_getIntData( imesh, verts[i], dst_tag, &tag_vals[i], &ierr );<--- Skipping configuration 'MOAB_FC_FUNC' since the value of 'MOAB_FC_FUNC' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'MOAB_FC_FUNC_' since the value of 'MOAB_FC_FUNC_' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
        if( ierr != iBase_SUCCESS )
        {
            std::cerr << "Rank " << rank << " : getIntData failed for vertex " << ids[i] << std::endl;
            std::cerr.flush();
            ++errcount;
        }
    }
    ASSERT( 0 == errcount );

    //  int *junk1 = &tag_vals[0], junk2 = tag_vals.size(), junk3;
    //  iMesh_getIntArrData( imesh, &verts[0], verts.size(), dst_tag, &junk1, &junk2, &junk3, &ierr
    //  ); PCHECK; assert( junk1 == &tag_vals[0] ); assert( junk2 == (int)tag_vals.size() ); assert(
    //  junk3 == (int)verts.size() );

    std::vector< int > expected( verts.size() );
    std::vector< iMeshP_Part > parts( verts.size() );
    iMeshP_Part* junk4 = &parts[0];
    junk2              = parts.size();
    iMeshP_getEntOwnerPartArr( imesh, prtn, &verts[0], verts.size(), &junk4, &junk2, &junk3, &ierr );<--- Skipping configuration 'MOAB_FC_FUNC' since the value of 'MOAB_FC_FUNC' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'MOAB_FC_FUNC_' since the value of 'MOAB_FC_FUNC_' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
    PCHECK;
    assert( junk4 == &parts[0] );
    assert( junk2 == (int)parts.size() );
    assert( junk3 == (int)verts.size() );
    junk1 = &expected[0];
    junk2 = expected.size();
    iMeshP_getRankOfPartArr( imesh, prtn, &parts[0], parts.size(), &junk1, &junk2, &junk3, &ierr );<--- Skipping configuration 'MOAB_FC_FUNC' since the value of 'MOAB_FC_FUNC' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'MOAB_FC_FUNC_' since the value of 'MOAB_FC_FUNC_' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
    PCHECK;
    assert( junk1 == &expected[0] );
    assert( junk2 == (int)expected.size() );
    assert( junk3 == (int)parts.size() );

    ASSERT( tag_vals == expected );

    // test iMeshP_pushTagsEnt
    // write -1 on all vertices
    // For each vertex owned by this processor and shared with more than
    // two others, write the rank of the owning processor.

    tag_vals.clear();
    tag_vals.resize( verts.size(), -1 );
    iMesh_setIntArrData( imesh, &verts[0], verts.size(), src_tag, &tag_vals[0], tag_vals.size(), &ierr );<--- Skipping configuration 'MOAB_FC_FUNC' since the value of 'MOAB_FC_FUNC' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'MOAB_FC_FUNC_' since the value of 'MOAB_FC_FUNC_' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
    PCHECK;
    tag_vals.resize( verts.size(), -1 );
    iMesh_setIntArrData( imesh, &verts[0], verts.size(), dst_tag, &tag_vals[0], tag_vals.size(), &ierr );<--- Skipping configuration 'MOAB_FC_FUNC' since the value of 'MOAB_FC_FUNC' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'MOAB_FC_FUNC_' since the value of 'MOAB_FC_FUNC_' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
    PCHECK;

    std::vector< iBase_EntityHandle > some;
    for( size_t i = 0; i < verts.size(); ++i )
    {
        int num;
        iMeshP_getNumCopies( imesh, prtn, verts[i], &num, &ierr );<--- Skipping configuration 'MOAB_FC_FUNC' since the value of 'MOAB_FC_FUNC' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'MOAB_FC_FUNC_' since the value of 'MOAB_FC_FUNC_' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
        if( iBase_SUCCESS != ierr ) break;
        if( num > 2 )
            some.push_back( verts[i] );
        else
            expected[i] = -1;
    }

    tag_vals.clear();
    tag_vals.resize( some.size(), rank );
    iMesh_setIntArrData( imesh, &some[0], some.size(), src_tag, &tag_vals[0], tag_vals.size(), &ierr );<--- Skipping configuration 'MOAB_FC_FUNC' since the value of 'MOAB_FC_FUNC' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'MOAB_FC_FUNC_' since the value of 'MOAB_FC_FUNC_' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
    PCHECK;

    iMeshP_pushTagsEnt( imesh, prtn, src_tag, dst_tag, &some[0], some.size(), &ierr );<--- Skipping configuration 'MOAB_FC_FUNC' since the value of 'MOAB_FC_FUNC' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'MOAB_FC_FUNC_' since the value of 'MOAB_FC_FUNC_' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
    PCHECK;

    tag_vals.clear();
    tag_vals.resize( verts.size(), -1 );
    junk1 = &tag_vals[0];
    junk2 = tag_vals.size();
    iMesh_getIntArrData( imesh, &verts[0], verts.size(), dst_tag, &junk1, &junk2, &junk3, &ierr );CHKERR;<--- Skipping configuration 'MOAB_FC_FUNC' since the value of 'MOAB_FC_FUNC' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'MOAB_FC_FUNC_' since the value of 'MOAB_FC_FUNC_' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
    assert( junk1 == &tag_vals[0] );
    assert( junk2 == (int)tag_vals.size() );
    assert( junk3 == (int)verts.size() );

    ASSERT( tag_vals == expected );
    return iBase_SUCCESS;
}

/**\brief Test commuinication of tag data
 *
 * Test:
 * - iMeshP_pushTags
 * - iMeshP_pushTagsEnt
 */
int test_push_tag_data_iface( iMesh_Instance imesh, iMeshP_PartitionHandle prtn, const PartMap& )
{
    return test_push_tag_data_common( imesh, prtn, 0 );
}

/**\brief Test commuinication of tag data
 *
 * Test:
 * - iMeshP_pushTags
 * - iMeshP_pushTagsEnt
 */
int test_push_tag_data_ghost( iMesh_Instance imesh, iMeshP_PartitionHandle prtn, const PartMap& )
{
    return test_push_tag_data_common( imesh, prtn, 1 );
}

/**************************************************************************
                          PartMap class
 **************************************************************************/

int PartMap::build_map( iMesh_Instance imesh, iMeshP_PartitionHandle prtn, int num_expected_parts )
{
    int ierr, rank, size;
    MPI_Comm_rank( MPI_COMM_WORLD, &rank );
    MPI_Comm_size( MPI_COMM_WORLD, &size );

    // get local parts
    std::vector< iMeshP_PartHandle > local_parts;
    std::vector< iMeshP_Part > imesh_ids;
    ierr = get_local_parts( imesh, prtn, local_parts, &imesh_ids );CHKERR;

    // get logical ids for local parts
    std::vector< int > local_ids( local_parts.size() );
    for( size_t i = 0; i < local_parts.size(); ++i )
    {
        ierr = part_from_coords( imesh, local_parts[i], local_ids[i] );CHKERR;
    }

    // get total number of parts
    int num_global = 0, num_local = local_parts.size();
    ierr = MPI_Allreduce( &num_local, &num_global, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD );CHKERR;
    if( num_global != num_expected_parts )
    {
        std::cerr << "Invalid/unexpected global part count at " __FILE__ ":" << __LINE__ << " (proc " << rank
                  << "): " << std::endl
                  << "  Expected: " << num_expected_parts << std::endl
                  << "  Actual:   " << num_global << std::endl;
        return 1;
    }

    // get counts and displacements for Allgatherv calls
    std::vector< int > dspls( size ), counts( size );
    ierr = MPI_Allgather( &num_local, 1, MPI_INT, &counts[0], 1, MPI_INT, MPI_COMM_WORLD );CHKERR;
    dspls[0] = 0;
    for( int i = 1; i < size; ++i )
        dspls[i] = dspls[i - 1] + counts[i - 1];

    // gather iMeshP_Part list from each processor
    std::vector< unsigned > global_part_ids( num_expected_parts );
    assert( sizeof( iMeshP_Part ) == sizeof( int ) );
    ierr = MPI_Allgatherv( &imesh_ids[0], num_local, MPI_UNSIGNED, &global_part_ids[0], &counts[0], &dspls[0],
                           MPI_UNSIGNED, MPI_COMM_WORLD );CHKERR;

    // gather local ids from each processor
    std::vector< int > global_id_list( num_expected_parts );
    ierr = MPI_Allgatherv( &local_ids[0], num_local, MPI_INT, &global_id_list[0], &counts[0], &dspls[0], MPI_INT,
                           MPI_COMM_WORLD );CHKERR;

    // build owner list
    std::vector< int > global_owners( num_expected_parts );
    for( int i = 0; i < size; ++i )
        for( int j = 0; j < counts[i]; ++j )
            global_owners[dspls[i] + j] = i;

    // populate member lists
    sortedPartList = global_part_ids;
    std::sort( sortedPartList.begin(), sortedPartList.end() );
    partLocalIds.resize( num_expected_parts );
    partRanks.resize( num_expected_parts );
    for( int i = 0; i < num_expected_parts; ++i )
    {
        int idx = std::lower_bound( sortedPartList.begin(), sortedPartList.end(), global_part_ids[i] ) -
                  sortedPartList.begin();
        partLocalIds[idx] = global_id_list[i];
        partRanks[idx]    = global_owners[i];
    }

    // do some consistency checking
    if( std::unique( sortedPartList.begin(), sortedPartList.end() ) != sortedPartList.end() )
    {
        if( rank == 0 )
        {
            std::cerr << "ERROR: Duplicate iMeshP_Part values detected at " __FILE__ ":" << __LINE__ << std::endl;
        }
        return 1;
    }

    // build revesre local id map and check for duplicates
    localIdReverseMap.clear();
    localIdReverseMap.resize( num_expected_parts, -1 );
    for( int i = 0; i < num_expected_parts; ++i )
    {
        int idx = partLocalIds[i];
        if( localIdReverseMap[idx] != -1 )
        {
            if( rank == 0 )
            {
                std::cerr << "ERROR: Part mesh has been duplicated in multiple parts." << std::endl
                          << "  Detected at " __FILE__ ":" << __LINE__ << std::endl
                          << "  See PartMap::part_from_coords" << std::endl;
            }
            return 1;
        }
        if( idx >= num_expected_parts )
        {
            if( rank == 0 )
            {
                std::cerr << "ERROR: Part mesh invalid/incorrect mesh." << std::endl
                          << "  Detected at " __FILE__ ":" << __LINE__ << std::endl
                          << "  See PartMap::part_from_coords" << std::endl;
            }
            return 1;
        }

        localIdReverseMap[idx] = i;
    }

    return 0;
}

void PartMap::part_id_from_rank( int rank, std::vector< iMeshP_Part >& parts ) const
{
    for( size_t i = 0; i < sortedPartList.size(); ++i )
        if( partRanks[i] == rank ) parts.push_back( sortedPartList[i] );
}

void PartMap::local_id_from_rank( int rank, std::vector< int >& ids ) const
{
    for( size_t i = 0; i < sortedPartList.size(); ++i )
        if( partRanks[i] == rank ) ids.push_back( partLocalIds[i] );
}

int PartMap::part_from_coords( iMesh_Instance imesh, iMeshP_PartHandle part, int& id )
{
    int ierr, rank;
    MPI_Comm_rank( MPI_COMM_WORLD, &rank );

    // get elements
    const int num_elem = 4;
    iBase_EntityHandle array[num_elem];
    iBase_EntityHandle* ptr = array;
    int junk1 = num_elem, n = -1;
    iMesh_getEntities( imesh, part, iBase_FACE, iMesh_QUADRILATERAL, &ptr, &junk1, &n, &ierr );CHKERR;<--- Skipping configuration 'MOAB_FC_FUNC' since the value of 'MOAB_FC_FUNC' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'MOAB_FC_FUNC_' since the value of 'MOAB_FC_FUNC_' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
    assert( ptr == array );
    assert( junk1 == num_elem );
    if( n != num_elem )
    {
        std::cerr << "Internal error at " __FILE__ ":" << __LINE__ << " (proc " << rank
                  << "): Expected all parts to have " << num_elem << " elements.  Found one with " << n << std::endl;
        return 1;
    }

    // get vertices
    iBase_EntityHandle adj_array[4 * num_elem];
    int junk2, junk3, offset_array[5];
    ptr       = adj_array;
    junk1     = sizeof( adj_array ) / sizeof( adj_array[0] );
    junk2     = sizeof( offset_array ) / sizeof( offset_array[0] );
    int* ptr2 = offset_array;
    iMesh_getEntArrAdj( imesh, array, num_elem, iBase_VERTEX, &ptr, &junk1, &n, &ptr2, &junk2, &junk3, &ierr );CHKERR;<--- Skipping configuration 'MOAB_FC_FUNC' since the value of 'MOAB_FC_FUNC' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'MOAB_FC_FUNC_' since the value of 'MOAB_FC_FUNC_' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
    assert( ptr == adj_array );
    assert( ptr2 == offset_array );
    assert( junk1 == sizeof( adj_array ) / sizeof( adj_array[0] ) );
    assert( junk2 == sizeof( offset_array ) / sizeof( offset_array[0] ) );
    assert( n == 4 * num_elem );
    assert( offset_array[0] == 0 );
    for( int i = 1; i < junk3; ++i )
        assert( offset_array[i] - offset_array[i - 1] == 4 );

    // find center vertex
    iBase_EntityHandle vtx;
    bool all_match;
    for( int i = 0; i < 4; ++i )
    {
        vtx       = adj_array[i];
        all_match = true;
        for( int j = 1; j < 4; ++j )
        {
            iBase_EntityHandle* mvtx = adj_array + 4 * j;
            int k;
            for( k = 0; k < 4; ++k )
                if( mvtx[k] == vtx ) break;
            if( k == 4 ) all_match = false;
        }
        if( all_match ) break;
    }
    assert( all_match );

    // get center vertex coordinates
    double x, y, z;
    iMesh_getVtxCoord( imesh, vtx, &x, &y, &z, &ierr );CHKERR;<--- Skipping configuration 'MOAB_FC_FUNC' since the value of 'MOAB_FC_FUNC' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'MOAB_FC_FUNC_' since the value of 'MOAB_FC_FUNC_' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
    assert( 0.0 == z );
    const int xi = ( (int)round( x ) - 1 ) / 2;
    const int yi = ( (int)round( y ) - 1 ) / 2;
    assert( xi >= 0 );
    assert( yi >= 0 );
    assert( fabs( x - 2 * xi - 1 ) < 1e-12 );
    assert( fabs( y - 2 * yi - 1 ) < 1e-12 );

    id = 2 * xi + yi;
    return 0;
}