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
|
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
/*
* Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
* University Research and Technology
* Corporation. All rights reserved.
* Copyright (c) 2004-2023 The University of Tennessee and The University
* of Tennessee Research Foundation. All rights
* reserved.
* Copyright (c) 2004-2022 High Performance Computing Center Stuttgart,
* University of Stuttgart. All rights reserved.
* Copyright (c) 2004-2005 The Regents of the University of California.
* All rights reserved.
* Copyright (c) 2007-2011 University of Houston. All rights reserved.
* Copyright (c) 2007-2018 Cisco Systems, Inc. All rights reserved
* Copyright (c) 2009 Sun Microsystems, Inc. All rights reserved.
* Copyright (c) 2011-2013 Inria. All rights reserved.
* Copyright (c) 2011-2013 Universite Bordeaux 1
* Copyright (c) 2012 Oak Ridge National Labs. All rights reserved.
* Copyright (c) 2012-2016 Los Alamos National Security, LLC.
* All rights reserved.
* Copyright (c) 2014-2017 Research Organization for Information Science
* and Technology (RIST). All rights reserved.
* Copyright (c) 2014-2020 Intel, Inc. All rights reserved.
* Copyright (c) 2015 Mellanox Technologies. All rights reserved.
* Copyright (c) 2017-2022 IBM Corporation. All rights reserved.
* Copyright (c) 2021 Nanook Consulting. All rights reserved.
* Copyright (c) 2018-2024 Triad National Security, LLC. All rights
* reserved.
* Copyright (c) 2023 Advanced Micro Devices, Inc. All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*/
#include "ompi_config.h"
#include <string.h>
#include <stdio.h>
#include "ompi/constants.h"
#include "opal/mca/hwloc/base/base.h"
#include "opal/mca/pmix/pmix-internal.h"
#include "opal/util/string_copy.h"
#include "ompi/proc/proc.h"
#include "opal/mca/threads/mutex.h"
#include "opal/util/bit_ops.h"
#include "opal/util/output.h"
#include "opal/util/show_help.h"
#include "ompi/mca/topo/topo.h"
#include "ompi/mca/topo/base/base.h"
#include "ompi/dpm/dpm.h"
#include "ompi/attribute/attribute.h"
#include "ompi/communicator/communicator.h"
#include "ompi/mca/pml/pml.h"
#include "ompi/request/request.h"
#include "ompi/runtime/params.h"
struct ompi_comm_split_type_hw_guided_t {
const char *info_value;
int split_type;
};
typedef struct ompi_comm_split_type_hw_guided_t ompi_comm_split_type_hw_guided_t;
/*
* The ompi_comm_split_unguided function uses this array to determine the next
* topology to test for a MPI_COMM_TYPE_HW_UNGUIDED communicator split. Therefore,
* the order in this array must be from largest topology class to smallest.
*/
static const ompi_comm_split_type_hw_guided_t ompi_comm_split_type_hw_guided_support[] = {
{.info_value = "cluster", .split_type = OMPI_COMM_TYPE_CLUSTER},
{.info_value = "cu", .split_type = OMPI_COMM_TYPE_CU},
{.info_value = "host", .split_type = OMPI_COMM_TYPE_HOST},
{.info_value = "mpi_shared_memory", .split_type = MPI_COMM_TYPE_SHARED},
{.info_value = "board", .split_type = OMPI_COMM_TYPE_BOARD},
{.info_value = "numanode", .split_type = OMPI_COMM_TYPE_NUMA},
{.info_value = "socket", .split_type = OMPI_COMM_TYPE_SOCKET},
{.info_value = "l3cache", .split_type = OMPI_COMM_TYPE_L3CACHE},
{.info_value = "l2cache", .split_type = OMPI_COMM_TYPE_L2CACHE},
{.info_value = "l1cache", .split_type = OMPI_COMM_TYPE_L1CACHE},
{.info_value = "core", .split_type = OMPI_COMM_TYPE_CORE},
{.info_value = "hwthread", .split_type = OMPI_COMM_TYPE_HWTHREAD},
{.info_value = NULL},
};
static const char * ompi_comm_split_type_to_str(int split_type) {
for (int i = 0; NULL != ompi_comm_split_type_hw_guided_support[i].info_value; ++i) {
if (split_type == ompi_comm_split_type_hw_guided_support[i].split_type) {
return ompi_comm_split_type_hw_guided_support[i].info_value;
}
}
if (MPI_COMM_TYPE_HW_GUIDED == split_type) {
return "MPI_COMM_TYPE_HW_GUIDED";
}
else if (MPI_COMM_TYPE_HW_UNGUIDED == split_type) {
return "MPI_COMM_TYPE_HW_UNGUIDED";
}
return "Unknown";
}
/*
** sort-function for MPI_Comm_split
*/
static int rankkeycompare(const void *, const void *);
/**
* to fill the rest of the stuff for the communicator
*/
static int ompi_comm_fill_rest (ompi_communicator_t *comm,
int num_procs,
ompi_proc_t **proc_pointers,
int my_rank,
ompi_errhandler_t *errh );
/*
** typedef for the allgather_intra required in comm_split.
** the reason for introducing this abstraction is, that
** for Comm_split for inter-coms, we do not have this
** functions, so we need to emulate it.
*/
typedef int ompi_comm_allgatherfct (void* inbuf, int incount, MPI_Datatype intype,
void* outbuf, int outcount, MPI_Datatype outtype,
ompi_communicator_t *comm,
mca_coll_base_module_t *data);
static int ompi_comm_allgather_emulate_intra (void* inbuf, int incount, MPI_Datatype intype,
void* outbuf, int outcount,
MPI_Datatype outtype,
ompi_communicator_t *comm,
mca_coll_base_module_t *data);
static int ompi_comm_copy_topo (ompi_communicator_t *oldcomm,
ompi_communicator_t *newcomm);
/* idup with local group and info. the local group support is provided to support ompi_comm_set_nb */
static int ompi_comm_idup_internal (ompi_communicator_t *comm, ompi_group_t *group, ompi_group_t *remote_group,
opal_info_t *info, ompi_communicator_t **newcomm, ompi_request_t **req);
static int ompi_comm_get_rprocs (ompi_communicator_t *local_comm, ompi_communicator_t *bridge_comm,
int local_leader, int remote_leader, int tag, int rsize,
ompi_proc_t ***rprocs);
/**********************************************************************/
/**********************************************************************/
/**********************************************************************/
/*
* This is the function setting all elements of a communicator.
* All other routines are just used to determine these elements.
*/
int ompi_comm_set ( ompi_communicator_t **ncomm,
ompi_communicator_t *oldcomm,
int local_size,
int *local_ranks,
int remote_size,
int *remote_ranks,
opal_hash_table_t *attr,
ompi_errhandler_t *errh,
ompi_group_t *local_group,
ompi_group_t *remote_group,
uint32_t flags)
{
ompi_request_t *req;
int rc;
rc = ompi_comm_set_nb (ncomm, oldcomm, local_size, local_ranks, remote_size, remote_ranks,
attr, errh, local_group, remote_group, flags, &req);
if (OMPI_SUCCESS != rc) {
return rc;
}
if (NULL != req) {
rc = ompi_request_wait( &req, MPI_STATUS_IGNORE);
}
return rc;
}
static int ompi_comm_set_simple (ompi_communicator_t **ncomm, ompi_errhandler_t *errhandler,
ompi_group_t *local_group)
{
return ompi_comm_set (ncomm, NULL, local_group->grp_proc_count, NULL, 0, NULL, NULL, errhandler,
local_group, NULL, 0);
}
/*
* if remote_group == &ompi_mpi_group_null, then the new communicator
* is forced to be an inter communicator.
*/
int ompi_comm_set_nb (ompi_communicator_t **ncomm, ompi_communicator_t *oldcomm, int local_size,
int *local_ranks, int remote_size, int *remote_ranks, opal_hash_table_t *attr,
ompi_errhandler_t *errh, ompi_group_t *local_group, ompi_group_t *remote_group,
uint32_t flags, ompi_request_t **req)
{
bool copy_topocomponent = !!(flags & OMPI_COMM_SET_FLAG_COPY_TOPOLOGY);
bool dup_comm = !(flags & OMPI_COMM_SET_FLAG_LOCAL_COMM_NODUP);
ompi_communicator_t *newcomm = NULL;
int ret;
if (NULL != local_group) {
local_size = ompi_group_size (local_group);
}
if ( (NULL != remote_group) && (&ompi_mpi_group_null.group != remote_group) ) {
remote_size = ompi_group_size (remote_group);
}
*req = NULL;
/* ompi_comm_allocate */
newcomm = OBJ_NEW(ompi_communicator_t);
if (NULL == newcomm) {
return OMPI_ERR_OUT_OF_RESOURCE;
}
newcomm->c_name = (char*) malloc (OPAL_MAX_OBJECT_NAME);
if (NULL == newcomm->c_name) {
return OMPI_ERR_OUT_OF_RESOURCE;
}
newcomm->c_name[0] = '\0';
newcomm->super.s_info = NULL;
/* fill in the inscribing hyper-cube dimensions */
newcomm->c_cube_dim = opal_cube_dim(local_size);
if (NULL == local_group) {
/* determine how the list of local_rank can be stored most
efficiently */
ret = ompi_group_incl(oldcomm->c_local_group, local_size,
local_ranks, &newcomm->c_local_group);
if (OPAL_UNLIKELY(OMPI_SUCCESS != ret)) {
return ret;
}
} else {
newcomm->c_local_group = local_group;
OBJ_RETAIN(newcomm->c_local_group);
}
newcomm->c_my_rank = newcomm->c_local_group->grp_my_rank;
newcomm->c_assertions = 0;
/* Set remote group and duplicate the local comm, if applicable */
if ((NULL == remote_group) && (NULL != remote_ranks)) {
/* determine how the list of local_rank can be stored most
efficiently */
ret = ompi_group_incl(oldcomm->c_remote_group, remote_size,
remote_ranks, &newcomm->c_remote_group);
if (OPAL_UNLIKELY(OMPI_SUCCESS != ret)) {
return ret;
}
remote_group = newcomm->c_remote_group;
}
if ( NULL != remote_group ) {
ompi_communicator_t *old_localcomm;
if (&ompi_mpi_group_null.group == remote_group) {
ret = ompi_group_incl(oldcomm->c_remote_group, remote_size,
remote_ranks, &newcomm->c_remote_group);
if (OPAL_UNLIKELY(OMPI_SUCCESS != ret)) {
return ret;
}
} else {
newcomm->c_remote_group = remote_group;
OBJ_RETAIN(newcomm->c_remote_group);
}
newcomm->c_flags |= OMPI_COMM_INTER;
if (dup_comm) {
old_localcomm = OMPI_COMM_IS_INTRA(oldcomm) ? oldcomm : oldcomm->c_local_comm;
/* NTH: use internal idup function that takes a local group argument */
ompi_comm_idup_internal (old_localcomm, newcomm->c_local_group, NULL, NULL,
&newcomm->c_local_comm, req);
} else {
/* take ownership of the old communicator (it must be an intracommunicator) */
assert (OMPI_COMM_IS_INTRA(oldcomm));
newcomm->c_local_comm = oldcomm;
}
} else {
newcomm->c_remote_group = newcomm->c_local_group;
OBJ_RETAIN(newcomm->c_remote_group);
}
/* Check how many different jobids are represented in this communicator.
Necessary for the disconnect of dynamic communicators. */
if ( 0 < local_size && (OMPI_COMM_IS_INTRA(newcomm) || 0 <remote_size) ) {
ompi_dpm_mark_dyncomm (newcomm);
}
/* Set error handler */
newcomm->error_handler = errh;
OBJ_RETAIN ( newcomm->error_handler );
/* Set Topology, if required and if available */
if (NULL != oldcomm && copy_topocomponent && (NULL != oldcomm->c_topo) ) {
/**
* The MPI standard is pretty clear on this, the topology information
* behave as info keys, and is copied only on MPI_Comm_dup.
*/
if (OMPI_SUCCESS != (ret = ompi_comm_copy_topo(oldcomm, newcomm))) {
ompi_comm_free(&newcomm);
return ret;
}
}
/* Copy attributes and call according copy functions, if required */
if (NULL != oldcomm && NULL != oldcomm->c_keyhash) {
if (NULL != attr) {
ompi_attr_hash_init(&newcomm->c_keyhash);
if (OMPI_SUCCESS != (ret = ompi_attr_copy_all (COMM_ATTR, oldcomm,
newcomm, attr,
newcomm->c_keyhash))) {
ompi_comm_free(&newcomm);
return ret;
}
}
}
if (NULL != oldcomm) {
newcomm->instance = oldcomm->instance;
}
*ncomm = newcomm;
return (OMPI_SUCCESS);
}
/**********************************************************************/
/**********************************************************************/
/**********************************************************************/
/*
** Counterpart to MPI_Comm_group. To be used within OMPI functions.
*/
int ompi_comm_group ( ompi_communicator_t* comm, ompi_group_t **group )
{
/* increment reference counters for the group */
OBJ_RETAIN(comm->c_local_group);
*group = comm->c_local_group;
return OMPI_SUCCESS;
}
/**********************************************************************/
/**********************************************************************/
/**********************************************************************/
/*
** Counterpart to MPI_Comm_create. To be used within OMPI.
*/
int ompi_comm_create_w_info (ompi_communicator_t *comm, ompi_group_t *group, opal_info_t *info,
ompi_communicator_t **newcomm)
{
ompi_communicator_t *newcomp = NULL;
int rsize;
int mode,i,j;
int *allranks=NULL;
int *rranks=NULL;
int rc = OMPI_SUCCESS;
ompi_group_t *remote_group = NULL;
/* silence clang warning. newcomm should never be NULL */
if (OPAL_UNLIKELY(NULL == newcomm)) {
return OMPI_ERR_BAD_PARAM;
}
if ( OMPI_COMM_IS_INTER(comm) ) {
int tsize;
remote_group = &ompi_mpi_group_null.group;
tsize = ompi_comm_remote_size(comm);
allranks = (int *) malloc ( tsize * sizeof(int));
if ( NULL == allranks ) {
rc = OMPI_ERR_OUT_OF_RESOURCE;
goto exit;
}
rc = comm->c_coll->coll_allgather ( &(group->grp_my_rank),
1, MPI_INT, allranks,
1, MPI_INT, comm,
comm->c_coll->coll_allgather_module);
if ( OMPI_SUCCESS != rc ) {
goto exit;
}
/* Count number of procs in future remote group */
for (rsize=0, i = 0; i < tsize; i++) {
if ( MPI_UNDEFINED != allranks[i] ) {
rsize++;
}
}
/* If any of those groups is empty, we have to return
MPI_COMM_NULL */
if ( 0 == rsize || 0 == group->grp_proc_count ) {
newcomp = MPI_COMM_NULL;
rc = OMPI_SUCCESS;
goto exit;
}
/* Set proc-pointers for remote group */
rranks = (int *) malloc ( rsize * sizeof(int));
if ( NULL == rranks ) {
rc = OMPI_ERR_OUT_OF_RESOURCE;
goto exit;
}
for ( j = 0, i = 0; i < tsize; i++ ) {
if ( MPI_UNDEFINED != allranks[i] ) {
rranks[j] = i;
j++;
}
}
mode = OMPI_COMM_CID_INTER;
} else {
rsize = 0;
rranks = NULL;
mode = OMPI_COMM_CID_INTRA;
}
rc = ompi_comm_set ( &newcomp, /* new comm */
comm, /* old comm */
0, /* local array size */
NULL, /* local_ranks */
rsize, /* remote_size */
rranks, /* remote_ranks */
NULL, /* attrs */
comm->error_handler, /* error handler */
group, /* local group */
remote_group, /* remote group */
0); /* flags */
if ( OMPI_SUCCESS != rc ) {
goto exit;
}
/* Determine context id. It is identical to f_2_c_handle */
rc = ompi_comm_nextcid (newcomp, comm, NULL, NULL, NULL, false, mode);
if ( OMPI_SUCCESS != rc ) {
goto exit;
}
/* Copy info if there is one. */
newcomp->super.s_info = OBJ_NEW(opal_info_t);
if (info) {
opal_info_dup(info, &(newcomp->super.s_info));
}
/* Set name for debugging purposes */
snprintf(newcomp->c_name, MPI_MAX_OBJECT_NAME, "MPI COMMUNICATOR %s CREATE FROM %s",
ompi_comm_print_cid (newcomp), ompi_comm_print_cid (comm));
/* Activate the communicator and init coll-component */
rc = ompi_comm_activate (&newcomp, comm, NULL, NULL, NULL, false, mode);
if ( OMPI_SUCCESS != rc ) {
goto exit;
}
/* Check whether we are part of the new comm.
If not, we have to free the structure again.
However, we could not avoid the comm_nextcid step, since
all processes of the original comm have to participate in
that function call. Additionally, all errhandler stuff etc.
has to be set to make ompi_comm_free happy */
if ( MPI_UNDEFINED == newcomp->c_local_group->grp_my_rank ) {
ompi_comm_free ( &newcomp );
}
exit:
if ( NULL != allranks ) {
free ( allranks );
}
if ( NULL != rranks ) {
free ( rranks );
}
*newcomm = newcomp;
return ( rc );
}
int ompi_comm_create ( ompi_communicator_t *comm, ompi_group_t *group,
ompi_communicator_t **newcomm )
{
return ompi_comm_create_w_info (comm, group, NULL, newcomm);
}
/**********************************************************************/
/**********************************************************************/
/**********************************************************************/
int ompi_comm_split_with_info( ompi_communicator_t* comm, int color, int key,
opal_info_t *info,
ompi_communicator_t **newcomm, bool pass_on_topo )
{
int myinfo[2];
int size, my_size;
int my_rsize=0;
int mode;
int rsize;
int i, loc;
int inter;
int *results=NULL, *sorted=NULL;
int *rresults=NULL, *rsorted=NULL;
int rc=OMPI_SUCCESS;
ompi_communicator_t *newcomp = NULL;
int *lranks=NULL, *rranks=NULL;
ompi_group_t * local_group=NULL, *remote_group=NULL;
ompi_comm_allgatherfct *allgatherfct=NULL;
/* Step 1: determine all the information for the local group */
/* --------------------------------------------------------- */
/* sort according to color and rank. Gather information from everyone */
myinfo[0] = color;
myinfo[1] = key;
size = ompi_comm_size ( comm );
inter = OMPI_COMM_IS_INTER(comm);
if ( inter ) {
allgatherfct = (ompi_comm_allgatherfct *)ompi_comm_allgather_emulate_intra;
} else {
allgatherfct = (ompi_comm_allgatherfct *)comm->c_coll->coll_allgather;
}
results = (int*) malloc ( 2 * size * sizeof(int));
if ( NULL == results ) {
return OMPI_ERR_OUT_OF_RESOURCE;
}
rc = allgatherfct( myinfo, 2, MPI_INT, results, 2, MPI_INT, comm, comm->c_coll->coll_allgather_module );
if ( OMPI_SUCCESS != rc ) {
goto exit;
}
/* how many have the same color like me */
for ( my_size = 0, i=0; i < size; i++) {
if ( results[(2*i)+0] == color) {
my_size++;
}
}
/* silence clang warning. my_size should never be 0 here */
if (OPAL_UNLIKELY(0 == my_size)) {
rc = OMPI_ERR_BAD_PARAM;
goto exit;
}
sorted = (int *) calloc (my_size * 2, sizeof (int));
if ( NULL == sorted) {
rc = OMPI_ERR_OUT_OF_RESOURCE;
goto exit;
}
/* ok we can now fill this info */
for( loc = 0, i = 0; i < size; i++ ) {
if ( results[(2*i)+0] == color) {
sorted[(2*loc)+0] = i; /* copy org rank */
sorted[(2*loc)+1] = results[(2*i)+1]; /* copy key */
loc++;
}
}
/* the new array needs to be sorted so that it is in 'key' order */
/* if two keys are equal then it is sorted in original rank order! */
if(my_size>1){
qsort ((int*)sorted, my_size, sizeof(int)*2, rankkeycompare);
}
/* put group elements in a list */
lranks = (int *) malloc ( my_size * sizeof(int));
if ( NULL == lranks ) {
rc = OMPI_ERR_OUT_OF_RESOURCE;
goto exit;
}
for (i = 0; i < my_size; i++) {
lranks[i] = sorted[i*2];
}
/* Step 2: determine all the information for the remote group */
/* --------------------------------------------------------- */
if ( inter ) {
remote_group = &ompi_mpi_group_null.group;
rsize = comm->c_remote_group->grp_proc_count;
rresults = (int *) malloc ( rsize * 2 * sizeof(int));
if ( NULL == rresults ) {
rc = OMPI_ERR_OUT_OF_RESOURCE;
goto exit;
}
/* this is an allgather on an inter-communicator */
rc = comm->c_coll->coll_allgather( myinfo, 2, MPI_INT, rresults, 2,
MPI_INT, comm,
comm->c_coll->coll_allgather_module);
if ( OMPI_SUCCESS != rc ) {
goto exit;
}
/* how many have the same color like me */
for ( my_rsize = 0, i=0; i < rsize; i++) {
if ( rresults[(2*i)+0] == color) {
my_rsize++;
}
}
if (my_rsize > 0) {
rsorted = (int *) calloc (my_rsize * 2, sizeof (int));
if ( NULL == rsorted) {
rc = OMPI_ERR_OUT_OF_RESOURCE;
goto exit;
}
/* ok we can now fill this info */
for( loc = 0, i = 0; i < rsize; i++ ) {
if ( rresults[(2*i)+0] == color) {
rsorted[(2*loc)+0] = i; /* org rank */
rsorted[(2*loc)+1] = rresults[(2*i)+1]; /* key */
loc++;
}
}
/* the new array needs to be sorted so that it is in 'key' order */
/* if two keys are equal then it is sorted in original rank order! */
if (my_rsize > 1) {
qsort ((int*)rsorted, my_rsize, sizeof(int)*2, rankkeycompare);
}
/* put group elements in a list */
rranks = (int *) malloc ( my_rsize * sizeof(int));
if ( NULL == rranks) {
rc = OMPI_ERR_OUT_OF_RESOURCE;
goto exit;
}
for (i = 0; i < my_rsize; i++) {
rranks[i] = rsorted[i*2];
}
}
rc = ompi_group_incl(comm->c_local_group, my_size, lranks, &local_group);
if (OMPI_SUCCESS != rc) {
goto exit;
}
mode = OMPI_COMM_CID_INTER;
} else {
rranks = NULL;
mode = OMPI_COMM_CID_INTRA;
}
/* Step 3: set up the communicator */
/* --------------------------------------------------------- */
/* Create the communicator finally */
rc = ompi_comm_set ( &newcomp, /* new comm */
comm, /* old comm */
my_size, /* local_size */
lranks, /* local_ranks */
my_rsize, /* remote_size */
rranks, /* remote_ranks */
NULL, /* attrs */
comm->error_handler,/* error handler */
local_group, /* local group */
remote_group, /* remote group */
pass_on_topo ? OMPI_COMM_SET_FLAG_COPY_TOPOLOGY : 0); /* flags */
if ( OMPI_SUCCESS != rc ) {
goto exit;
}
if ( inter ) {
OBJ_RELEASE(local_group);
if (NULL != newcomp->c_local_comm) {
snprintf(newcomp->c_local_comm->c_name, MPI_MAX_OBJECT_NAME,
"MPI COMM %s SPLIT FROM %s", ompi_comm_print_cid (newcomp),
ompi_comm_print_cid (comm));
}
}
/* set the rank to MPI_UNDEFINED. This prevents this process from interfering
* in ompi_comm_nextcid() and the collective module selection in ompi_comm_activate()
* for a communicator that will be freed anyway.
*/
if ( MPI_UNDEFINED == color || (inter && my_rsize==0)) {
newcomp->c_local_group->grp_my_rank = MPI_UNDEFINED;
}
/* Determine context id. It is identical to f_2_c_handle */
rc = ompi_comm_nextcid (newcomp, comm, NULL, NULL, NULL, false, mode);
if ( OMPI_SUCCESS != rc ) {
goto exit;
}
/* Set name for debugging purposes */
snprintf(newcomp->c_name, MPI_MAX_OBJECT_NAME, "MPI COMM %s SPLIT FROM %s",
ompi_comm_print_cid (newcomp), ompi_comm_print_cid (comm));
/* Copy info if there is one */
if (info) {
newcomp->super.s_info = OBJ_NEW(opal_info_t);
opal_info_dup(info, &(newcomp->super.s_info));
}
/* Activate the communicator and init coll-component */
rc = ompi_comm_activate (&newcomp, comm, NULL, NULL, NULL, false, mode);
exit:
free ( results );
free ( sorted );
free ( rresults );
free ( rsorted );
free ( lranks );
free ( rranks );
/* Step 4: if we are not part of the comm, free the struct */
/* --------------------------------------------------------- */
if (inter && my_rsize == 0) {
color = MPI_UNDEFINED;
}
if ( NULL != newcomp && MPI_UNDEFINED == color ) {
ompi_comm_free ( &newcomp );
}
*newcomm = newcomp;
return rc;
}
/*
** Counterpart to MPI_Comm_split. To be used within OMPI (e.g. MPI_Cart_sub).
*/
int ompi_comm_split( ompi_communicator_t* comm, int color, int key,
ompi_communicator_t **newcomm, bool pass_on_topo )
{
return ompi_comm_split_with_info(comm, color, key, NULL, newcomm, pass_on_topo);
}
/**********************************************************************/
/**********************************************************************/
/**********************************************************************/
/*
* Produces an array of ranks that will be part of the local/remote group in the
* new communicator. The results array will be modified by this call.
*/
static int ompi_comm_split_type_get_part (ompi_group_t *group, const int split_type, int **ranks_out, int *rank_size) {
int size = ompi_group_size (group);
int my_size = 0;
int *ranks;
int ret;
ranks = malloc (size * sizeof (int));
if (OPAL_UNLIKELY(NULL == ranks)) {
return OMPI_ERR_OUT_OF_RESOURCE;
}
for (int i = 0 ; i < size ; ++i) {
ompi_proc_t *proc = ompi_group_get_proc_ptr_raw (group, i);
uint16_t locality, *u16ptr;
int include = false;
if (ompi_proc_is_sentinel (proc)) {
opal_process_name_t proc_name = ompi_proc_sentinel_to_name ((uintptr_t) proc);
if (split_type <= OMPI_COMM_TYPE_HOST) {
/* local ranks should never be represented by sentinel procs. ideally we
* should be able to use OPAL_MODEX_RECV_VALUE_OPTIONAL but it does have
* some overhead. update this to use the optional recv if that is ever fixed. */
continue;
}
u16ptr = &locality;
OPAL_MODEX_RECV_VALUE_OPTIONAL(ret, PMIX_LOCALITY, &proc_name, &u16ptr, PMIX_UINT16);
if (OPAL_SUCCESS != ret) {
continue;
}
} else {
locality = proc->super.proc_flags;
}
switch (split_type) {
case OMPI_COMM_TYPE_HWTHREAD:
include = OPAL_PROC_ON_LOCAL_HWTHREAD(locality);
break;
case OMPI_COMM_TYPE_CORE:
include = OPAL_PROC_ON_LOCAL_CORE(locality);
break;
case OMPI_COMM_TYPE_L1CACHE:
include = OPAL_PROC_ON_LOCAL_L1CACHE(locality);
break;
case OMPI_COMM_TYPE_L2CACHE:
include = OPAL_PROC_ON_LOCAL_L2CACHE(locality);
break;
case OMPI_COMM_TYPE_L3CACHE:
include = OPAL_PROC_ON_LOCAL_L3CACHE(locality);
break;
case OMPI_COMM_TYPE_SOCKET:
include = OPAL_PROC_ON_LOCAL_SOCKET(locality);
break;
case OMPI_COMM_TYPE_NUMA:
include = OPAL_PROC_ON_LOCAL_NUMA(locality);
break;
case MPI_COMM_TYPE_SHARED:
include = OPAL_PROC_ON_LOCAL_NODE(locality);
break;
case OMPI_COMM_TYPE_BOARD:
include = OPAL_PROC_ON_LOCAL_BOARD(locality);
break;
case OMPI_COMM_TYPE_HOST:
include = OPAL_PROC_ON_LOCAL_HOST(locality);
break;
case OMPI_COMM_TYPE_CU:
include = OPAL_PROC_ON_LOCAL_CU(locality);
break;
case OMPI_COMM_TYPE_CLUSTER:
include = OPAL_PROC_ON_LOCAL_CLUSTER(locality);
break;
case MPI_COMM_TYPE_HW_GUIDED:
case MPI_COMM_TYPE_HW_UNGUIDED:
/*
* MPI_COMM_TYPE_HW_(UN)GUIDED handled in calling function.
* We should not get here as the split type will be changed
* at a higher level.
*/
opal_show_help("help-comm.txt",
"unexpected-split-type",
true,
ompi_comm_split_type_to_str(split_type),
split_type);
free (ranks);
return OMPI_ERR_BAD_PARAM;
}
if (include) {
ranks[my_size++] = i;
}
}
*rank_size = my_size;
/* silence a clang warning about a 0-byte malloc. my_size will never be 0 here */
if (OPAL_UNLIKELY(0 == my_size)) {
free (ranks);
return OMPI_SUCCESS;
}
/* shrink the rank array */
int *tmp = realloc (ranks, my_size * sizeof (int));
if (OPAL_LIKELY(NULL != tmp)) {
ranks = tmp;
}
*ranks_out = ranks;
return OMPI_SUCCESS;
}
static int ompi_comm_split_verify (ompi_communicator_t *comm, int split_type, int key, bool *need_split)
{
int rank = ompi_comm_rank (comm);
int size = ompi_comm_size (comm);
int *results;
int rc;
if (*need_split) {
return OMPI_SUCCESS;
}
results = malloc (2 * sizeof (int) * size);
if (OPAL_UNLIKELY(NULL == results)) {
return OMPI_ERR_OUT_OF_RESOURCE;
}
*need_split = false;
results[rank * 2] = split_type;
results[rank * 2 + 1] = key;
rc = comm->c_coll->coll_allgather (MPI_IN_PLACE, 2, MPI_INT, results, 2, MPI_INT, comm,
comm->c_coll->coll_allgather_module);
if (OMPI_SUCCESS != rc) {
free (results);
return rc;
}
for (int i = 0 ; i < size ; ++i) {
if (MPI_UNDEFINED == results[i * 2] || (i >= 1 && results[i * 2 + 1] < results[i * 2 - 1])) {
*need_split = true;
break;
}
}
free (results);
return OMPI_SUCCESS;
}
/**
* ompi_comm_split_type_core: Perform common processing for a MPI_Comm_type_split
* function call.
*
* comm(in) i : input communicator
* global_split_type(in) : Split type defined by all ranks in the communicator
* local_split_type(in) : Split type defined by this rank in the communicator
* (might be MPI_UNDEFINED)
* key(in) : original key from the user
* need_split : If a split is needed to separate ranks supplying
* MPI_UNDEFINED from others
* no_reorder(in) : Did all of the ranks specify the same key (optimization)
* no_undefined(in) : None of the ranks specified MPI_UNDEFINED (optimization)
* info(out) : info guiding the split operation
* newcomm(out) : Pointer to the newly created communicator, or pointer to MPI_COMM_NULL
* if no communicator created.
*/
static int ompi_comm_split_type_core(ompi_communicator_t *comm,
int global_split_type, int local_split_type,
int key, bool need_split, bool no_reorder,
bool no_undefined, opal_info_t *info,
ompi_communicator_t **newcomm)
{
int *lranks = NULL, *rranks = NULL;
ompi_communicator_t *newcomp = MPI_COMM_NULL;
int my_size, my_rsize = 0, mode;
int rc;
int inter = OMPI_COMM_IS_INTER(comm);
/* Perform the rest of the processing for a communicator split.
*
* Step 1: Build potential communicator groups. If any ranks will not be part of
* the ultimate communicator we will drop them later. This saves doing an extra
* allgather on the whole communicator. By using ompi_comm_split() later only
* if needed we 1) optimized the common case (no MPI_UNDEFINED and no reorder),
* and 2) limit the allgather to a smaller set of peers in the uncommon case. */
/* --------------------------------------------------------- */
/* allowed splitting types:
CLUSTER
CU
HOST
BOARD
NODE
NUMA
SOCKET
L3CACHE
L2CACHE
L1CACHE
CORE
HWTHREAD
Even though HWTHREAD/CORE etc. is overkill they are here for consistency.
They will most likely return a communicator which is equal to MPI_COMM_SELF
Unless oversubscribing.
*/
/* how many ranks are potentially participating and on my node? */
rc = ompi_comm_split_type_get_part (comm->c_local_group, global_split_type, &lranks, &my_size);
if (OPAL_UNLIKELY(OMPI_SUCCESS != rc)) {
return rc;
}
/* Step 2: determine all the information for the remote group */
/* --------------------------------------------------------- */
if (inter) {
rc = ompi_comm_split_type_get_part (comm->c_remote_group, global_split_type, &rranks, &my_rsize);
if (OPAL_UNLIKELY(OMPI_SUCCESS != rc)) {
free (lranks);
return rc;
}
}
/* set the CID allgather mode to the appropriate one for the communicator */
mode = inter ? OMPI_COMM_CID_INTER : OMPI_COMM_CID_INTRA;
/* Step 3: set up the communicator */
/* --------------------------------------------------------- */
/* Create the communicator finally */
rc = ompi_comm_set (&newcomp, comm, my_size, lranks, my_rsize,
rranks, NULL, comm->error_handler, NULL, NULL, 0);
if (OPAL_UNLIKELY(OMPI_SUCCESS != rc)) {
goto exit;
}
/* Determine context id. It is identical to f_2_c_handle */
rc = ompi_comm_nextcid (newcomp, comm, NULL, NULL, NULL, false, mode);
if (OPAL_UNLIKELY(OMPI_SUCCESS != rc)) {
goto exit;
}
ompi_comm_assert_subscribe (newcomp, OMPI_COMM_ASSERT_LAZY_BARRIER);
ompi_comm_assert_subscribe (newcomp, OMPI_COMM_ASSERT_ACTIVE_POLL);
if (info) {
opal_infosubscribe_change_info(&newcomp->super, info);
}
/* Activate the communicator and init coll-component */
rc = ompi_comm_activate (&newcomp, comm, NULL, NULL, NULL, false, mode);
if (OPAL_UNLIKELY(OMPI_SUCCESS != rc)) {
goto exit;
}
/* Step 4: Check if we need to remove or reorder ranks in the communicator */
if (!(no_reorder && no_undefined)) {
rc = ompi_comm_split_verify (newcomp, local_split_type, key, &need_split);
if (inter) {
/* verify that no local ranks need to be removed or reordered */
rc = ompi_comm_split_verify (newcomp->c_local_comm, local_split_type, key,
&need_split);
}
}
if (!need_split) {
/* common case. no reordering and no MPI_UNDEFINED */
*newcomm = newcomp;
/* Set name for debugging purposes */
snprintf(newcomp->c_name, MPI_MAX_OBJECT_NAME, "MPI COMM %s SPLIT_TYPE FROM %s",
ompi_comm_print_cid (newcomp), ompi_comm_print_cid (comm));
goto exit;
}
/* TODO: there probably is better way to handle this case without throwing away the
* intermediate communicator. */
rc = ompi_comm_split (newcomp, local_split_type, key, newcomm, false);
/* get rid of the intermediate communicator */
ompi_comm_free (&newcomp);
exit:
if (OPAL_UNLIKELY(OMPI_SUCCESS != rc && MPI_COMM_NULL != newcomp)) {
ompi_comm_free (&newcomp);
*newcomm = MPI_COMM_NULL;
}
free (lranks);
free (rranks);
return rc;
}
/**
* ompi_comm_split_unguided: Process an MPI_Comm_split_type function call where the
* split is performed at the next lower topology level where
* the new communicator would contain fewer ranks than the
* input communicator.
*
* comm(in) : Input communicator
* split_type(in) : Communicator split type for this task, may be MPI_UNDEFINED
* key(in) : Original key from the user
* need_split(in) : If a split is needed to separate ranks supplying MPI_UNDEFINED
* from others
* no_reorder(in) : Did all of the ranks specify the same key (optimization)
* no_undefined(in) : None of the ranks specified MPI_UNDEFINED (optimization)
* info(out) : Info object to update with selected topology class
* newcomm(out) : Pointer to newly created communicator, or pointer to
* MPI_COMM_NULL if no communicator generated.
*/
static int ompi_comm_split_unguided(ompi_communicator_t *comm, int split_type, int key,
bool need_split, bool no_reorder,
bool no_undefined, struct opal_info_t *info,
ompi_communicator_t** newcomm)
{
int i, rc;
struct opal_info_t *split_info = NULL;
int new_size, original_size;
ompi_communicator_t *unguided_comm = NULL;
if (1 == ompi_comm_size(comm)) {
/* Communicator cannot be split any smaller */
*newcomm = MPI_COMM_NULL;
return OMPI_SUCCESS;
}
/*
* Split out the MPI_UNDEFINED
*/
rc = ompi_comm_split(comm,
MPI_UNDEFINED == split_type ? MPI_UNDEFINED : 0,
key,
&unguided_comm, false);
if (OMPI_SUCCESS != rc) {
*newcomm = MPI_COMM_NULL;
return rc;
}
if (MPI_UNDEFINED == split_type) {
ompi_comm_free(&unguided_comm);
*newcomm = MPI_COMM_NULL;
return OMPI_SUCCESS;
}
/*
* Attempt to split the communicator based on topology class by iteratively
* calling ompi_comm_split_type specifying the split type as
* MPI_COMM_TYPE_HW_GUIDED using the next lower topology class until a
* split results in a smaller size communicator than the input communicator.
* The search starts with OMPI_COMM_TYPE_CU since that is the highest possible
* topology class where the communicator size can be smaller than MPI_COMM_WORLD.
*/
original_size = ompi_comm_size(unguided_comm);
split_info = OBJ_NEW(opal_info_t);
i = 1;
while (NULL != ompi_comm_split_type_hw_guided_support[i].info_value) {
/* MPI_COMM_TYPE_HW_GUIDED splits require mpi_hw_resource_type to be set */
opal_info_set(split_info, "mpi_hw_resource_type",
ompi_comm_split_type_hw_guided_support[i].info_value);
rc = ompi_comm_split_type_core(unguided_comm,
ompi_comm_split_type_hw_guided_support[i].split_type,
ompi_comm_split_type_hw_guided_support[i].split_type,
key, need_split, no_reorder, no_undefined,
split_info, newcomm);
if (OMPI_SUCCESS != rc) {
break;
}
// Everyone else will get a new communicator.
// Check the size to see if we need to iterate again.
new_size = ompi_comm_size(*newcomm);
if (new_size < original_size) {
/* If a valid info object was passed, set the selected topology */
if (NULL != info) {
opal_info_set(info, "mpi_hw_resource_type",
ompi_comm_split_type_hw_guided_support[i].info_value);
}
ompi_comm_free(&unguided_comm);
OBJ_RELEASE(split_info);
return OMPI_SUCCESS;
}
// Free the new communicator, and prepare for the next iteration.
ompi_comm_free(newcomm);
i = i + 1;
}
ompi_comm_free(&unguided_comm);
OBJ_RELEASE(split_info);
*newcomm = MPI_COMM_NULL;
return rc;
}
/*
* ompi_comm_split_type: Performs a communicator split. This function performs initial
* processing to set up a MPI_COMM_TYPE_HW_GUIDED split and
* validation of input parameters.
* comm(in) : Input communicator
* split_type(in) : Split type to be performed by this rank, may be MPI_UNDEFINED
* key(in) : Original key from the user
* info(in/out) : Info guiding the split operation
* newcomm(out) : Pointer to the newly created communicator, or pointer to MPI_COMM_NULL
* if no communicator created.
*/
int ompi_comm_split_type (ompi_communicator_t *comm, int split_type, int key,
opal_info_t *info, ompi_communicator_t **newcomm)
{
bool need_split = false, no_reorder = false, no_undefined = false;
int inter;
int global_split_type, global_orig_split_type, ok[2], tmp[6];
int rc;
int orig_split_type = split_type;
int flag;
opal_cstring_t *value = NULL;
/* silence clang warning. newcomm should never be NULL */
if (OPAL_UNLIKELY(NULL == newcomm)) {
return OMPI_ERR_BAD_PARAM;
}
inter = OMPI_COMM_IS_INTER(comm);
/* Step 0: Convert MPI_COMM_TYPE_HW_GUIDED to the internal type */
if (MPI_COMM_TYPE_HW_GUIDED == split_type) {
opal_info_get(info, "mpi_hw_resource_type", &value, &flag);
/* If key is not in the 'info', then return MPI_COMM_NULL.
* This is caught at the MPI interface level, but it doesn't hurt to
* check it again.
*/
if (!flag) {
*newcomm = MPI_COMM_NULL;
return OMPI_SUCCESS;
}
/* Verify the value associated with the "mpi_hw_resource_type" key
* - is supported, and
* - is the same value at all ranks
*
* If not supported, then return MPI_COMM_NULL.
* If not the same at all ranks, throw an error.
*/
flag = 0;
for (int i = 0; NULL != ompi_comm_split_type_hw_guided_support[i].info_value; ++i) {
if (0 == strncasecmp(value->string,
ompi_comm_split_type_hw_guided_support[i].info_value,
strlen(ompi_comm_split_type_hw_guided_support[i].info_value))) {
split_type = ompi_comm_split_type_hw_guided_support[i].split_type;
flag = 1;
break;
}
}
/* If not supported, then return MPI_COMM_NULL. */
if (0 == flag) {
*newcomm = MPI_COMM_NULL;
return OMPI_SUCCESS;
}
}
/* Step 1: verify all ranks have supplied the same value for split type. All split types
* must be the same or MPI_UNDEFINED (which is negative). */
tmp[0] = orig_split_type;
tmp[1] = -orig_split_type;
tmp[2] = key;
tmp[3] = -key;
/* For MPI_COMM_TYPE_HW_GUIDED, verify all ranks have supplied the same
* split_type (represented by orig_split_type) and info 'value' (represented by split_type).
*
* For split_type != MPI_COMM_TYPE_HW_GUIDED then orig_split_type == split_type.
*/
tmp[4] = split_type;
tmp[5] = -split_type;
rc = comm->c_coll->coll_allreduce (MPI_IN_PLACE, &tmp, 6, MPI_INT, MPI_MAX, comm,
comm->c_coll->coll_allreduce_module);
if (OPAL_UNLIKELY(OMPI_SUCCESS != rc)) {
return rc;
}
global_orig_split_type = tmp[0];
global_split_type = tmp[4];
if (tmp[0] != -tmp[1] || tmp[4] != -tmp[5] || inter) {
/* at least one rank supplied a different split type check if our split_type is ok */
ok[0] = (MPI_UNDEFINED == orig_split_type) || global_orig_split_type == orig_split_type;
ok[1] = (MPI_UNDEFINED == orig_split_type) || global_split_type == split_type;
rc = comm->c_coll->coll_allreduce (MPI_IN_PLACE, &ok, 2, MPI_INT, MPI_MIN, comm,
comm->c_coll->coll_allreduce_module);
if (OPAL_UNLIKELY(OMPI_SUCCESS != rc)) {
return rc;
}
if (inter) {
/* need an extra allreduce to ensure that all ranks have the same result */
rc = comm->c_coll->coll_allreduce (MPI_IN_PLACE, &ok, 2, MPI_INT, MPI_MIN, comm,
comm->c_coll->coll_allreduce_module);
if (OPAL_UNLIKELY(OMPI_SUCCESS != rc)) {
return rc;
}
}
if (OPAL_UNLIKELY(!ok[0] || !ok[1])) {
if (0 == ompi_comm_rank(comm)) {
opal_info_get(info, "mpi_hw_resource_type", &value, &flag);
if (!flag) {
value = NULL;
}
opal_show_help("help-comm.txt",
"mismatched-split_type-values",
true,
ompi_comm_split_type_to_str(orig_split_type),
orig_split_type,
NULL == value ? "" : value->string);
}
return OMPI_ERR_BAD_PARAM;
}
need_split = tmp[0] == -tmp[1];
} else {
/* intracommunicator and all ranks specified the same split type */
no_undefined = true;
/* check if all ranks specified the same key */
no_reorder = tmp[2] == -tmp[3];
}
if (MPI_UNDEFINED == global_orig_split_type) {
/* short-circut. every rank provided MPI_UNDEFINED */
*newcomm = MPI_COMM_NULL;
return OMPI_SUCCESS;
}
if (MPI_COMM_TYPE_HW_UNGUIDED == global_orig_split_type) {
/* Handle MPI_COMM_TYPE_HW_UNGUIDED communicator split. */
return ompi_comm_split_unguided( comm, split_type,
key, need_split, no_reorder,
no_undefined, info, newcomm );
} else {
return ompi_comm_split_type_core( comm, global_split_type, split_type,
key, need_split, no_reorder,
no_undefined, info, newcomm);
}
}
/**********************************************************************/
/**********************************************************************/
/**********************************************************************/
int ompi_comm_dup ( ompi_communicator_t * comm, ompi_communicator_t **newcomm )
{
return ompi_comm_dup_with_info (comm, NULL, newcomm);
}
/**********************************************************************/
/**********************************************************************/
/**********************************************************************/
int ompi_comm_dup_with_info ( ompi_communicator_t * comm, opal_info_t *info, ompi_communicator_t **newcomm )
{
ompi_communicator_t *newcomp = NULL;
ompi_group_t *remote_group = NULL;
int mode = OMPI_COMM_CID_INTRA, rc = OMPI_SUCCESS;
if ( OMPI_COMM_IS_INTER ( comm ) ){
mode = OMPI_COMM_CID_INTER;
remote_group = comm->c_remote_group;
}
*newcomm = MPI_COMM_NULL;
rc = ompi_comm_set ( &newcomp, /* new comm */
comm, /* old comm */
0, /* local array size */
NULL, /* local_procs*/
0, /* remote array size */
NULL, /* remote_procs */
comm->c_keyhash, /* attrs */
comm->error_handler, /* error handler */
comm->c_local_group, /* local group */
remote_group, /* remote group */
OMPI_COMM_SET_FLAG_COPY_TOPOLOGY); /* flags */
if ( OMPI_SUCCESS != rc) {
return rc;
}
/* Determine context id. It is identical to f_2_c_handle */
rc = ompi_comm_nextcid (newcomp, comm, NULL, NULL, NULL, false, mode);
if ( OMPI_SUCCESS != rc ) {
OBJ_RELEASE(newcomp);
return rc;
}
/* Set name for debugging purposes */
snprintf(newcomp->c_name, MPI_MAX_OBJECT_NAME, "MPI COMM %s DUP FROM %s",
ompi_comm_print_cid (newcomp), ompi_comm_print_cid (comm));
// Copy info if there is one.
ompi_comm_assert_subscribe (newcomp, OMPI_COMM_ASSERT_LAZY_BARRIER);
ompi_comm_assert_subscribe (newcomp, OMPI_COMM_ASSERT_ACTIVE_POLL);
if (info) {
opal_infosubscribe_change_info(&newcomp->super, info);
}
/* activate communicator and init coll-module */
rc = ompi_comm_activate (&newcomp, comm, NULL, NULL, NULL, false, mode);
if ( OMPI_SUCCESS != rc ) {
OBJ_RELEASE(newcomp);
return rc;
}
*newcomm = newcomp;
return MPI_SUCCESS;
}
struct ompi_comm_idup_with_info_context_t {
opal_object_t super;
ompi_communicator_t *comm;
ompi_communicator_t *newcomp;
};
typedef struct ompi_comm_idup_with_info_context_t ompi_comm_idup_with_info_context_t;
OBJ_CLASS_INSTANCE(ompi_comm_idup_with_info_context_t, opal_object_t, NULL, NULL);
static int ompi_comm_idup_with_info_activate (ompi_comm_request_t *request);
static int ompi_comm_idup_with_info_finish (ompi_comm_request_t *request);
static int ompi_comm_idup_getcid (ompi_comm_request_t *request);
int ompi_comm_idup (ompi_communicator_t *comm, ompi_communicator_t **newcomm, ompi_request_t **req)
{
return ompi_comm_idup_with_info (comm, NULL, newcomm, req);
}
int ompi_comm_idup_with_info (ompi_communicator_t *comm, opal_info_t *info, ompi_communicator_t **newcomm, ompi_request_t **req)
{
return ompi_comm_idup_internal (comm, comm->c_local_group, comm->c_remote_group, info, newcomm, req);
}
/* NTH: we need a way to idup with a smaller local group so this function takes a local group */
static int ompi_comm_idup_internal (ompi_communicator_t *comm, ompi_group_t *group, ompi_group_t *remote_group,
opal_info_t *info, ompi_communicator_t **newcomm, ompi_request_t **req)
{
ompi_comm_idup_with_info_context_t *context;
ompi_comm_request_t *request;
ompi_request_t *subreq[1];
int rc;
*newcomm = MPI_COMM_NULL;
if (!OMPI_COMM_IS_INTER (comm)){
remote_group = NULL;
}
request = ompi_comm_request_get ();
if (NULL == request) {
return OMPI_ERR_OUT_OF_RESOURCE;
}
context = OBJ_NEW(ompi_comm_idup_with_info_context_t);
if (NULL == context) {
ompi_comm_request_return (request);
return OMPI_ERR_OUT_OF_RESOURCE;
}
context->comm = comm;
request->context = &context->super;
request->super.req_mpi_object.comm = comm;
rc = ompi_comm_set_nb (&context->newcomp, /* new comm */
comm, /* old comm */
0, /* local array size */
NULL, /* local_procs */
0, /* remote array size */
NULL, /* remote_procs */
comm->c_keyhash, /* attrs */
comm->error_handler, /* error handler */
group, /* local group */
remote_group, /* remote group */
OMPI_COMM_SET_FLAG_COPY_TOPOLOGY, /* flags */
subreq); /* new subrequest */
if (OMPI_SUCCESS != rc) {
ompi_comm_request_return (request);
return rc;
}
// Copy info if there is one.
{
ompi_communicator_t *newcomp = context->newcomp;
newcomp->super.s_info = OBJ_NEW(opal_info_t);
if (info) {
opal_info_dup(info, &(newcomp->super.s_info));
}
}
ompi_comm_request_schedule_append (request, ompi_comm_idup_getcid, subreq, subreq[0] ? 1 : 0);
/* assign the newcomm now */
*newcomm = context->newcomp;
/* kick off the request */
ompi_comm_request_start (request);
*req = &request->super;
return OMPI_SUCCESS;
}
static int ompi_comm_idup_getcid (ompi_comm_request_t *request)
{
ompi_comm_idup_with_info_context_t *context =
(ompi_comm_idup_with_info_context_t *) request->context;
ompi_request_t *subreq[1];
int rc, mode;
if (OMPI_COMM_IS_INTER(context->comm)){
mode = OMPI_COMM_CID_INTER;
} else {
mode = OMPI_COMM_CID_INTRA;
}
/* Determine context id. It is identical to f_2_c_handle */
rc = ompi_comm_nextcid_nb (context->newcomp, context->comm, NULL, NULL,
NULL, false, mode, subreq);
if (OMPI_SUCCESS != rc) {
ompi_comm_request_return (request);
OBJ_RELEASE(context->newcomp);
return rc;
}
ompi_comm_request_schedule_append (request, ompi_comm_idup_with_info_activate, subreq, 1);
return OMPI_SUCCESS;
}
static int ompi_comm_idup_with_info_activate (ompi_comm_request_t *request)
{
ompi_comm_idup_with_info_context_t *context =
(ompi_comm_idup_with_info_context_t *) request->context;
ompi_request_t *subreq[1];
int rc, mode;
if (OMPI_COMM_IS_INTER(context->comm)){
mode = OMPI_COMM_CID_INTER;
} else {
mode = OMPI_COMM_CID_INTRA;
}
/* Set name for debugging purposes */
snprintf(context->newcomp->c_name, MPI_MAX_OBJECT_NAME, "MPI COMM %s DUP FROM %s",
ompi_comm_print_cid (context->newcomp), ompi_comm_print_cid (context->comm));
/* activate communicator and init coll-module */
rc = ompi_comm_activate_nb (&context->newcomp, context->comm, NULL, NULL, NULL, false, mode, subreq);
if ( OMPI_SUCCESS != rc ) {
OBJ_RELEASE(context->newcomp);
return rc;
}
ompi_comm_request_schedule_append (request, ompi_comm_idup_with_info_finish, subreq, 1);
return OMPI_SUCCESS;
}
static int ompi_comm_idup_with_info_finish (ompi_comm_request_t *request)
{
ompi_comm_idup_with_info_context_t *context =
(ompi_comm_idup_with_info_context_t *) request->context;
/* done */
return MPI_SUCCESS;
}
/**********************************************************************/
/**********************************************************************/
/**********************************************************************/
int ompi_comm_create_group (ompi_communicator_t *comm, ompi_group_t *group, int tag, ompi_communicator_t **newcomm)
{
ompi_communicator_t *newcomp = NULL;
int mode = OMPI_COMM_CID_GROUP, rc = OMPI_SUCCESS;
*newcomm = MPI_COMM_NULL;
rc = ompi_comm_set ( &newcomp, /* new comm */
comm, /* old comm */
group->grp_proc_count, /* local_size */
NULL, /* local_procs*/
0, /* remote_size */
NULL, /* remote_procs */
comm->c_keyhash, /* attrs */
comm->error_handler, /* error handler */
group, /* local group */
NULL, /* remote group */
OMPI_COMM_SET_FLAG_COPY_TOPOLOGY); /* flags */
if ( OMPI_SUCCESS != rc) {
return rc;
}
/* Determine context id. It is identical to f_2_c_handle */
rc = ompi_comm_nextcid (newcomp, comm, NULL, &tag, NULL, false, mode);
if ( OMPI_SUCCESS != rc ) {
OBJ_RELEASE(newcomp);
return rc;
}
/* Set name for debugging purposes */
snprintf(newcomp->c_name, MPI_MAX_OBJECT_NAME, "MPI COMM %s GROUP FROM %s",
ompi_comm_print_cid (newcomp), ompi_comm_print_cid (comm));
/* activate communicator and init coll-module */
rc = ompi_comm_activate (&newcomp, comm, NULL, &tag, NULL, false, mode);
if ( OMPI_SUCCESS != rc ) {
OBJ_RELEASE(newcomp);
return rc;
}
*newcomm = newcomp;
return MPI_SUCCESS;
}
int ompi_comm_create_from_group (ompi_group_t *group, const char *tag, opal_info_t *info,
ompi_errhandler_t *errhandler, ompi_communicator_t **newcomm)
{
ompi_communicator_t *newcomp = NULL;
int rc;
*newcomm = MPI_COMM_NULL;
rc = ompi_comm_set_simple (&newcomp, errhandler, group);
if (OPAL_UNLIKELY(OMPI_SUCCESS != rc)) {
return rc;
}
/* Determine context id. It is identical to f_2_c_handle */
rc = ompi_comm_nextcid (newcomp, NULL, NULL, (void *) tag, NULL, false,
OMPI_COMM_CID_GROUP_NEW);
if ( OMPI_SUCCESS != rc ) {
return rc;
}
/* Set name for debugging purposes */
snprintf(newcomp->c_name, MPI_MAX_OBJECT_NAME, "MPI COMM %s FROM GROUP",
ompi_comm_print_cid (newcomp));
newcomp->super.s_info = OBJ_NEW(opal_info_t);
if (NULL == newcomp->super.s_info) {
return OMPI_ERR_OUT_OF_RESOURCE;
}
/* activate communicator and init coll-module. use the group allreduce implementation as
* no collective module has yet been selected. the tag does not matter as any tag will
* be unique on the new communicator. */
rc = ompi_comm_activate (&newcomp, newcomp, NULL, &(int) {0xfeed}, NULL,
false, OMPI_COMM_CID_GROUP);
if ( OMPI_SUCCESS != rc ) {
return rc;
}
newcomp->instance = group->grp_instance;
/*
* setup predefined keyvals - see MPI Standard for predefined keyvals cached on
* communicators created via MPI_Comm_create_from_group or MPI_Intercomm_create_from_groups
*/
ompi_attr_hash_init(&newcomp->c_keyhash);
ompi_attr_set_int(COMM_ATTR,
newcomp,
&newcomp->c_keyhash,
MPI_TAG_UB, mca_pml.pml_max_tag,
true);
*newcomm = newcomp;
return MPI_SUCCESS;
}
int ompi_intercomm_create (ompi_communicator_t *local_comm, int local_leader, ompi_communicator_t *bridge_comm,
int remote_leader, int tag, ompi_communicator_t **newintercomm)
{
int local_size = 0, local_rank = 0, lleader = 0, rleader = 0, rc, rsize = 0;
struct ompi_proc_t **rprocs;
ompi_communicator_t *newcomp;
ompi_group_t *new_group_pointer;
*newintercomm = MPI_COMM_NULL;
local_size = ompi_comm_size ( local_comm );
local_rank = ompi_comm_rank ( local_comm );
lleader = local_leader;
rleader = remote_leader;
if ( MPI_PARAM_CHECK ) {
if ( (0 > local_leader) || (local_leader >= local_size) ) {
return OMPI_ERR_BAD_PARAM;
}
/* remember that the remote_leader and bridge_comm arguments
just have to be valid at the local_leader */
if ( local_rank == local_leader ) {
if (ompi_comm_invalid (bridge_comm) || (bridge_comm->c_flags & OMPI_COMM_INTER)) {
return MPI_ERR_COMM;
}
if ((remote_leader < 0) || (remote_leader >= ompi_comm_size(bridge_comm))) {
return OMPI_ERR_BAD_PARAM;
}
} /* if ( local_rank == local_leader ) */
}
if (local_rank == local_leader) {
MPI_Request req;
/* local leader exchange group sizes lists */
rc = MCA_PML_CALL(irecv (&rsize, 1, MPI_INT, rleader, tag, bridge_comm, &req));
if ( rc != MPI_SUCCESS ) {
return rc;
}
rc = MCA_PML_CALL(send (&local_size, 1, MPI_INT, rleader, tag,
MCA_PML_BASE_SEND_STANDARD, bridge_comm));
if ( rc != MPI_SUCCESS ) {
return rc;
}
rc = ompi_request_wait (&req, MPI_STATUS_IGNORE);
if ( rc != MPI_SUCCESS ) {
return rc;
}
}
/* bcast size and list of remote processes to all processes in local_comm */
rc = local_comm->c_coll->coll_bcast (&rsize, 1, MPI_INT, lleader, local_comm,
local_comm->c_coll->coll_bcast_module);
if (OPAL_UNLIKELY(OMPI_SUCCESS != rc)) {
return rc;
}
rc = ompi_comm_get_rprocs (local_comm, bridge_comm, lleader, remote_leader, tag, rsize, &rprocs);
if (OPAL_UNLIKELY(OMPI_SUCCESS != rc)) {
return rc;
}
/* put group elements in the list */
new_group_pointer = ompi_group_allocate_plist_w_procs (local_comm->c_local_group, rprocs, rsize);
if (OPAL_UNLIKELY(NULL == new_group_pointer)) {
free (rprocs);
return MPI_ERR_GROUP;
}
if (MPI_PARAM_CHECK) {
bool overlap = ompi_group_overlap (local_comm->c_local_group, new_group_pointer);
if (overlap && MPI_THREAD_MULTIPLE != ompi_mpi_thread_provided) {
ompi_group_free (&new_group_pointer);
return OMPI_ERR_BAD_PARAM;
}
}
rc = ompi_comm_set (&newcomp, /* new comm */
local_comm, /* old comm */
local_comm->c_local_group->grp_proc_count, /* local_size */
NULL, /* local_procs*/
rsize, /* remote_size */
NULL, /* remote_procs */
NULL, /* attrs */
local_comm->error_handler, /* error handler*/
local_comm->c_local_group, /* local group */
new_group_pointer, /* remote group */
0); /* flags */
if (OPAL_UNLIKELY(OMPI_SUCCESS != rc)) {
ompi_group_free (&new_group_pointer);
return rc;
}
/* Determine context id. It is identical to f_2_c_handle */
rc = ompi_comm_nextcid (newcomp, local_comm, bridge_comm, &lleader,
&rleader, false, OMPI_COMM_CID_INTRA_BRIDGE);
if (OPAL_UNLIKELY(OMPI_SUCCESS != rc)) {
ompi_comm_free (&newcomp);
return rc;
}
/* activate comm and init coll-module */
rc = ompi_comm_activate (&newcomp, local_comm, bridge_comm, &lleader, &rleader,
false, OMPI_COMM_CID_INTRA_BRIDGE);
if ( MPI_SUCCESS != rc ) {
ompi_comm_free (&newcomp);
return rc;
}
*newintercomm = newcomp;
return OMPI_SUCCESS;
}
int ompi_intercomm_create_from_groups (ompi_group_t *local_group, int local_leader,
ompi_group_t *remote_group, int remote_leader, const char *tag,
opal_info_t *info, ompi_errhandler_t *errhandler,
ompi_communicator_t **newintercomm)
{
ompi_communicator_t *newcomp = NULL, *local_comm, *leader_comm = MPI_COMM_NULL;
ompi_comm_extended_cid_block_t new_block = {0};
bool i_am_leader = local_leader == local_group->grp_my_rank;
ompi_proc_t **rprocs;
uint64_t data[4];
int leader_comm_remote_leader;
char *sub_tag = NULL;
size_t rsize;
int rc;
*newintercomm = MPI_COMM_NULL;
/* create a local communicator first. create a unique tag for this communicator */
opal_asprintf (&sub_tag, "%s-OMPIi-%s", tag, OPAL_NAME_PRINT(ompi_group_get_proc_name (local_group, local_leader)));
if (OPAL_UNLIKELY(NULL == sub_tag)) {
return OMPI_ERR_OUT_OF_RESOURCE;
}
rc = ompi_comm_create_from_group (local_group, sub_tag, info, errhandler, &local_comm);
free (sub_tag);
sub_tag = NULL;
if (OPAL_UNLIKELY(OMPI_SUCCESS != rc)) {
return rc;
}
if (i_am_leader) {
/* create a bridge communicator for the leaders (so we can use the existing collectives
* for activation). there are probably more efficient ways to do this but for intercommunicator
* creation is not considered a performance critical operation. */
ompi_proc_t **leader_procs, *my_proc;
ompi_group_t *leader_group;
leader_procs = calloc (2, sizeof (*leader_procs));
my_proc = leader_procs[0] = ompi_group_get_proc_ptr (local_group, local_leader, true);
leader_procs[1] = ompi_group_get_proc_ptr (remote_group, remote_leader, true);
if (leader_procs[0] != leader_procs[1]) {
/* NTH: they are definitely different (can the ever be the same) */
if (leader_procs[0]->super.proc_name.jobid > leader_procs[1]->super.proc_name.jobid ||
(leader_procs[0]->super.proc_name.jobid == leader_procs[1]->super.proc_name.jobid &&
leader_procs[0]->super.proc_name.vpid > leader_procs[1]->super.proc_name.vpid)) {
ompi_proc_t *tmp = leader_procs[0];
leader_procs[0] = leader_procs[1];
leader_procs[1] = tmp;
}
leader_group = ompi_group_allocate_plist_w_procs (NULL, leader_procs, 2);
ompi_set_group_rank (leader_group, my_proc);
if (OPAL_UNLIKELY(NULL == leader_group)) {
free(leader_procs);
ompi_comm_free (&local_comm);
return OMPI_ERR_OUT_OF_RESOURCE;
}
/* create a unique tag for allocating the leader communicator. we can eliminate this step
* if we take a CID from the newly allocated block belonging to local_comm. this is
* a note to make this change at a later time. */
opal_asprintf (&sub_tag, "%s-OMPIi-LC-%s", tag, OPAL_NAME_PRINT(ompi_group_get_proc_name (leader_group, 0)));
if (OPAL_UNLIKELY(NULL == sub_tag)) {
free(leader_procs);
ompi_comm_free (&local_comm);
OBJ_RELEASE(leader_group);
return OMPI_ERR_OUT_OF_RESOURCE;
}
/* remote leader is whichever rank I am not */
leader_comm_remote_leader = !(leader_group->grp_my_rank);
rc = ompi_comm_create_from_group (leader_group, sub_tag, info, errhandler, &leader_comm);
OBJ_RELEASE(leader_group);
free (sub_tag);
sub_tag = NULL;
if (OPAL_UNLIKELY(OMPI_SUCCESS != rc)) {
free(leader_procs);
ompi_comm_free (&local_comm);
return rc;
}
/* grab a CID for the intercomm while we are at it */
ompi_comm_extended_cid_block_new (&leader_comm->c_contextidb, &new_block, false);
data[0] = remote_group->grp_proc_count;
/* store the relevant new_block data */
data[1] = new_block.block_cid.cid_base;
data[2] = new_block.block_cid.cid_sub.u64;
data[3] = new_block.block_level;
} else {
free (leader_procs);
}
}
/* bcast size and list of remote processes to all processes in local_comm */
rc = local_comm->c_coll->coll_bcast (data, 4, MPI_UINT64_T, local_leader, local_comm,
local_comm->c_coll->coll_bcast_module);
rsize = data[0];
if (OPAL_UNLIKELY(OPAL_SUCCESS != rc)) {
ompi_comm_free (&local_comm);
return rc;
}
/* using 0 for the tag because we control both local_comm and leader_comm */
rc = ompi_comm_get_rprocs (local_comm, leader_comm, local_leader, leader_comm_remote_leader, 0, rsize, &rprocs);
if (OPAL_UNLIKELY(OMPI_SUCCESS != rc)) {
ompi_comm_free (&local_comm);
return rc;
}
if (!i_am_leader) {
/* create a new group containing the remote processes for non-leader ranks */
remote_group = ompi_group_allocate_plist_w_procs (local_group, rprocs, rsize);
if (OPAL_UNLIKELY(NULL == remote_group)) {
free (rprocs);
ompi_comm_free (&local_comm);
return OMPI_ERR_OUT_OF_RESOURCE;
}
} else {
OBJ_RETAIN(remote_group);
}
rc = ompi_comm_set (&newcomp, local_comm, local_group->grp_proc_count, NULL, remote_group->grp_proc_count,
NULL, NULL, errhandler, local_group, remote_group, OMPI_COMM_SET_FLAG_LOCAL_COMM_NODUP);
OBJ_RELEASE(remote_group);
if (OPAL_UNLIKELY(OMPI_SUCCESS != rc)) {
ompi_comm_free (&local_comm);
return rc;
}
/*
* append the pmix CONTEXT_ID obtained when creating the leader comm as discriminator
*/
opal_asprintf (&sub_tag, "%s-%ld", tag, data[1]);
if (OPAL_UNLIKELY(NULL == sub_tag)) {
return OMPI_ERR_OUT_OF_RESOURCE;
}
rc = ompi_comm_nextcid (newcomp, NULL, NULL, (void *) sub_tag, NULL, false, OMPI_COMM_CID_GROUP_NEW);
free (sub_tag);
if ( OMPI_SUCCESS != rc ) {
OBJ_RELEASE(newcomp);
return rc;
}
/* Set name for debugging purposes */
snprintf(newcomp->c_name, MPI_MAX_OBJECT_NAME, "MPI INTERCOMM %s FROM GROUP", ompi_comm_print_cid (newcomp));
// Copy info if there is one.
newcomp->super.s_info = OBJ_NEW(opal_info_t);
if (info) {
opal_info_dup(info, &(newcomp->super.s_info));
}
/* activate communicator and init coll-module */
rc = ompi_comm_activate (&newcomp, local_comm, leader_comm, &local_leader, &leader_comm_remote_leader,
false, OMPI_COMM_CID_INTRA_BRIDGE);
if (MPI_COMM_NULL != leader_comm) {
ompi_comm_free (&leader_comm);
}
if (OPAL_UNLIKELY(OMPI_SUCCESS != rc)) {
ompi_comm_free (&newcomp);
return rc;
}
*newintercomm = newcomp;
return MPI_SUCCESS;
}
/**********************************************************************/
/**********************************************************************/
/**********************************************************************/
int ompi_comm_compare(ompi_communicator_t *comm1, ompi_communicator_t *comm2, int *result) {
/* local variables */
ompi_communicator_t *comp1, *comp2;
int size1, size2, rsize1, rsize2;
int lresult, rresult=MPI_CONGRUENT;
int cmp_result;
if (comm1->instance != comm2->instance) {
return OMPI_ERR_BAD_PARAM;
}
comp1 = (ompi_communicator_t *) comm1;
comp2 = (ompi_communicator_t *) comm2;
if (ompi_comm_compare_cids(comp1,comp2)) {
*result = MPI_IDENT;
return MPI_SUCCESS;
}
if ( MPI_COMM_NULL == comm1 || MPI_COMM_NULL == comm2 ) {
*result = MPI_UNEQUAL;
return MPI_SUCCESS;
}
/* compare sizes of local and remote groups */
size1 = ompi_comm_size (comp1);
size2 = ompi_comm_size (comp2);
rsize1 = ompi_comm_remote_size (comp1);
rsize2 = ompi_comm_remote_size (comp2);
if ( size1 != size2 || rsize1 != rsize2 ) {
*result = MPI_UNEQUAL;
return MPI_SUCCESS;
}
/* Compare local groups */
ompi_group_compare((ompi_group_t *)comp1->c_local_group,
(ompi_group_t *)comp2->c_local_group,
&cmp_result);
/* MPI_IDENT resulting from the group comparison is
* MPI_CONGRUENT for communicators.
* All others results are the same.
*/
if( MPI_IDENT == cmp_result ) {
lresult = MPI_CONGRUENT;
} else {
lresult = cmp_result;
}
if ( rsize1 > 0 ) {
/* Compare remote groups for inter-communicators */
ompi_group_compare((ompi_group_t *)comp1->c_remote_group,
(ompi_group_t *)comp2->c_remote_group,
&cmp_result);
/* MPI_IDENT resulting from the group comparison is
* MPI_CONGRUENT for communicators.
* All others results are the same.
*/
if( MPI_IDENT == cmp_result ) {
rresult = MPI_CONGRUENT;
} else {
rresult = cmp_result;
}
}
/* determine final results */
if ( MPI_CONGRUENT == rresult ) {
*result = lresult;
}
else if ( MPI_SIMILAR == rresult ) {
if ( MPI_SIMILAR == lresult || MPI_CONGRUENT == lresult ) {
*result = MPI_SIMILAR;
}
else {
*result = MPI_UNEQUAL;
}
}
else if ( MPI_UNEQUAL == rresult ) {
*result = MPI_UNEQUAL;
}
return OMPI_SUCCESS;
}
/**********************************************************************/
/**********************************************************************/
/**********************************************************************/
int ompi_comm_set_name (ompi_communicator_t *comm, const char *name )
{
OPAL_THREAD_LOCK(&(comm->c_lock));
opal_string_copy(comm->c_name, name, MPI_MAX_OBJECT_NAME);
comm->c_flags |= OMPI_COMM_NAMEISSET;
OPAL_THREAD_UNLOCK(&(comm->c_lock));
return OMPI_SUCCESS;
}
/**********************************************************************/
/**********************************************************************/
/**********************************************************************/
/*
* Implementation of MPI_Allgather for the local_group in an inter-comm.
* The algorithm consists of two steps:
* 1. an inter-gather to rank 0 in remote group
* 2. an inter-bcast from rank 0 in remote_group.
*/
static int ompi_comm_allgather_emulate_intra( void *inbuf, int incount,
MPI_Datatype intype, void* outbuf,
int outcount, MPI_Datatype outtype,
ompi_communicator_t *comm,
mca_coll_base_module_t *data)
{
int rank, size, rsize, i, rc;
int *tmpbuf=NULL;
MPI_Request *req=NULL, sendreq;
rsize = ompi_comm_remote_size(comm);
size = ompi_comm_size(comm);
rank = ompi_comm_rank(comm);
/* silence clang warning about 0-byte malloc. neither of these values can
* be 0 here */
if (OPAL_UNLIKELY(0 == rsize || 0 == outcount)) {
return OMPI_ERR_BAD_PARAM;
}
/* Step 1: the gather-step */
if ( 0 == rank ) {
tmpbuf = (int *) malloc (rsize*outcount*sizeof(int));
if ( NULL == tmpbuf ) {
return (OMPI_ERR_OUT_OF_RESOURCE);
}
req = (MPI_Request *)malloc (rsize*outcount*sizeof(MPI_Request));
if ( NULL == req ) {
free ( tmpbuf );
return (OMPI_ERR_OUT_OF_RESOURCE);
}
for ( i=0; i<rsize; i++) {
rc = MCA_PML_CALL(irecv( &tmpbuf[outcount*i], outcount, outtype, i,
OMPI_COMM_ALLGATHER_TAG, comm, &req[i] ));
if ( OMPI_SUCCESS != rc ) {
goto exit;
}
}
}
rc = MCA_PML_CALL(isend( inbuf, incount, intype, 0, OMPI_COMM_ALLGATHER_TAG,
MCA_PML_BASE_SEND_STANDARD, comm, &sendreq ));
if ( OMPI_SUCCESS != rc ) {
goto exit;
}
if ( 0 == rank ) {
rc = ompi_request_wait_all( rsize, req, MPI_STATUSES_IGNORE);
if ( OMPI_SUCCESS != rc ) {
goto exit;
}
}
rc = ompi_request_wait( &sendreq, MPI_STATUS_IGNORE);
if ( OMPI_SUCCESS != rc ) {
goto exit;
}
/* Step 2: the inter-bcast step */
rc = MCA_PML_CALL(irecv (outbuf, size*outcount, outtype, 0,
OMPI_COMM_ALLGATHER_TAG, comm, &sendreq));
if ( OMPI_SUCCESS != rc ) {
goto exit;
}
if ( 0 == rank ) {
for ( i=0; i < rsize; i++ ){
rc = MCA_PML_CALL(send (tmpbuf, rsize*outcount, outtype, i,
OMPI_COMM_ALLGATHER_TAG,
MCA_PML_BASE_SEND_STANDARD, comm));
if ( OMPI_SUCCESS != rc ) {
goto exit;
}
}
}
rc = ompi_request_wait( &sendreq, MPI_STATUS_IGNORE );
exit:
if ( NULL != req ) {
free ( req );
}
if ( NULL != tmpbuf ) {
free ( tmpbuf );
}
return (rc);
}
/**********************************************************************/
/**********************************************************************/
/**********************************************************************/
/*
** Counterpart to MPI_Comm_free. To be used within OMPI.
** The freeing of all attached objects (groups, errhandlers
** etc. ) has moved to the destructor.
*/
int ompi_comm_free( ompi_communicator_t **comm )
{
int ret;
int cid = (*comm)->c_index;
int is_extra_retain = OMPI_COMM_IS_EXTRA_RETAIN(*comm);
/* Release attributes. We do this now instead of during the
communicator destructor for 2 reasons:
1. The destructor will only NOT be called immediately during
ompi_comm_free() if the reference count is still greater
than zero at that point, meaning that there are ongoing
communications. However, pending communications will never
need attributes, so it's safe to release them directly here.
2. Releasing attributes in ompi_comm_free() enables us to check
the return status of the attribute delete functions. At
least one interpretation of the MPI standard (i.e., the one
of the Intel test suite) is that if any of the attribute
deletion functions fail, then MPI_COMM_FREE /
MPI_COMM_DISCONNECT should also fail. We can't do that if
we delay releasing the attributes -- we need to release the
attributes right away so that we can report the error right
away. */
if (NULL != (*comm)->c_keyhash) {
ret = ompi_attr_delete_all(COMM_ATTR, *comm, (*comm)->c_keyhash);
if (OMPI_SUCCESS != ret) {
return ret;
}
OBJ_RELEASE((*comm)->c_keyhash);
}
if ( OMPI_COMM_IS_INTER(*comm) ) {
if ( ! OMPI_COMM_IS_INTRINSIC((*comm)->c_local_comm)) {
ompi_comm_free (&(*comm)->c_local_comm);
}
}
/* Special case: if we are freeing the parent handle, then we need
to set our internal handle to the parent to be equal to
COMM_NULL. This is according to MPI-2:88-89. */
if (*comm == ompi_mpi_comm_parent && comm != &ompi_mpi_comm_parent) {
ompi_mpi_comm_parent = &ompi_mpi_comm_null.comm;
}
if (NULL != ((*comm)->super.s_info)) {
OBJ_RELEASE((*comm)->super.s_info);
}
/* Release the communicator */
if ( OMPI_COMM_IS_DYNAMIC (*comm) ) {
ompi_comm_num_dyncomm --;
}
OBJ_RELEASE( (*comm) );
if ( is_extra_retain) {
/* This communicator has been marked as an "extra retain"
* communicator. This can happen if a communicator creates
* 'dependent' subcommunicators (e.g. for inter
* communicators or when using hierarch collective
* module *and* the cid of the dependent communicator
* turned out to be lower than of the parent one.
* In that case, the reference counter has been increased
* by one more, in order to handle the scenario,
* that the user did not free the communicator.
* Note, that if we enter this routine, we can
* decrease the counter by one more therefore. However,
* in ompi_comm_finalize, we only used OBJ_RELEASE instead
* of ompi_comm_free(), and the increased reference counter
* makes sure that the pointer to the dependent communicator
* still contains a valid object.
*/
ompi_communicator_t *tmpcomm = ompi_comm_lookup(cid);
if ( NULL != tmpcomm ){
ompi_comm_free(&tmpcomm);
}
}
*comm = MPI_COMM_NULL;
return OMPI_SUCCESS;
}
/**********************************************************************/
/**********************************************************************/
/**********************************************************************/
/**
* This is a short-hand routine used in intercomm_create.
* The routine makes sure, that all processes have afterwards
* a list of ompi_proc_t pointers for the remote group.
*/
int ompi_comm_get_rprocs (ompi_communicator_t *local_comm, ompi_communicator_t *bridge_comm,
int local_leader, int remote_leader, int tag, int rsize, ompi_proc_t ***prprocs)
{
MPI_Request req;
int rc = OMPI_SUCCESS;
int local_rank, local_size;
ompi_proc_t **rprocs=NULL;
size_t size_len;
int int_len=0, rlen;
pmix_data_buffer_t *sbuf=NULL, *rbuf=NULL;
char *sendbuf=NULL;
char *recvbuf;
ompi_proc_t **proc_list = NULL;
int i;
local_rank = ompi_comm_rank (local_comm);
local_size = ompi_comm_size (local_comm);
if (local_rank == local_leader) {
PMIX_DATA_BUFFER_CREATE(sbuf);
if (NULL == sbuf) {
rc = OMPI_ERR_OUT_OF_RESOURCE;
goto err_exit;
}
if(OMPI_GROUP_IS_DENSE(local_comm->c_local_group)) {
rc = ompi_proc_pack(local_comm->c_local_group->grp_proc_pointers,
local_size, sbuf);
}
/* get the proc list for the sparse implementations */
else {
proc_list = (ompi_proc_t **) calloc (local_comm->c_local_group->grp_proc_count,
sizeof (ompi_proc_t *));
for(i=0 ; i<local_comm->c_local_group->grp_proc_count ; i++)
proc_list[i] = ompi_group_peer_lookup(local_comm->c_local_group,i);
rc = ompi_proc_pack (proc_list, local_size, sbuf);
}
if ( OMPI_SUCCESS != rc ) {
goto err_exit;
}
PMIX_DATA_BUFFER_UNLOAD(sbuf, sendbuf, size_len);
if (NULL == sendbuf) {
rc = OMPI_ERR_UNPACK_FAILURE;
goto err_exit;
}
/* send the remote_leader the length of the buffer */
rc = MCA_PML_CALL(irecv (&rlen, 1, MPI_INT, remote_leader, tag,
bridge_comm, &req ));
if ( OMPI_SUCCESS != rc ) {
goto err_exit;
}
int_len = (int)size_len;
rc = MCA_PML_CALL(send (&int_len, 1, MPI_INT, remote_leader, tag,
MCA_PML_BASE_SEND_STANDARD, bridge_comm ));
if ( OMPI_SUCCESS != rc ) {
rlen = 0; /* complete the recv and then the collectives */
}
rc = ompi_request_wait( &req, MPI_STATUS_IGNORE );
if ( OMPI_SUCCESS != rc ) {
rlen = 0; /* participate in the collective and then done */
}
}
/* broadcast buffer length to all processes in local_comm */
rc = local_comm->c_coll->coll_bcast( &rlen, 1, MPI_INT,
local_leader, local_comm,
local_comm->c_coll->coll_bcast_module );
if ( OMPI_SUCCESS != rc ) {
#if OPAL_ENABLE_FT_MPI
if ( local_rank != local_leader ) {
goto err_exit;
}
/* the leaders must go on in order to avoid deadlocks */
#else
goto err_exit;
#endif /* OPAL_ENABLE_FT_MPI */
}
/* Allocate temporary buffer */
recvbuf = (char *)malloc(rlen);
if ( NULL == recvbuf ) {
rc = OMPI_ERR_OUT_OF_RESOURCE;
goto err_exit;
}
if ( local_rank == local_leader ) {
/* local leader exchange name lists */
rc = MCA_PML_CALL(irecv (recvbuf, rlen, MPI_BYTE, remote_leader, tag,
bridge_comm, &req ));
if ( OMPI_SUCCESS != rc ) {
goto err_exit;
}
rc = MCA_PML_CALL(send(sendbuf, int_len, MPI_BYTE, remote_leader, tag,
MCA_PML_BASE_SEND_STANDARD, bridge_comm ));
#if OPAL_ENABLE_FT_MPI
/* let it flow even if there are errors */
if ( OMPI_SUCCESS != rc && MPI_ERR_PROC_FAILED != rc && MPI_ERR_REVOKED != rc ) {
#else
if ( OMPI_SUCCESS != rc ) {
#endif
goto err_exit;
}
rc = ompi_request_wait( &req, MPI_STATUS_IGNORE );
#if OPAL_ENABLE_FT_MPI
/* let it flow even if there are errors */
if ( OMPI_SUCCESS != rc && MPI_ERR_PROC_FAILED != rc && MPI_ERR_REVOKED != rc ) {
#else
if ( OMPI_SUCCESS != rc ) {
#endif
goto err_exit;
}
PMIX_DATA_BUFFER_RELEASE(sbuf);
}
/* broadcast name list to all processes in local_comm */
rc = local_comm->c_coll->coll_bcast( recvbuf, rlen, MPI_BYTE,
local_leader, local_comm,
local_comm->c_coll->coll_bcast_module);
if ( OMPI_SUCCESS != rc ) {
goto err_exit;
}
PMIX_DATA_BUFFER_CREATE(rbuf);
if (NULL == rbuf) {
rc = OMPI_ERR_OUT_OF_RESOURCE;
goto err_exit;
}
PMIX_DATA_BUFFER_LOAD(rbuf, recvbuf, rlen);
/* decode the names into a proc-list -- will never add a new proc
as the result of this operation, so no need to get the newprocs
list or call PML add_procs(). */
rc = ompi_proc_unpack(rbuf, rsize, &rprocs, NULL, NULL);
PMIX_DATA_BUFFER_RELEASE(rbuf);
if (OMPI_SUCCESS != rc) {
goto err_exit;
}
/* set the locality of the remote procs */
for (i=0; i < rsize; i++) {
/* get the locality information - all RTEs are required
* to provide this information at startup */
uint16_t *u16ptr, u16;
u16ptr = &u16;
OPAL_MODEX_RECV_VALUE_OPTIONAL(rc, PMIX_LOCALITY, &rprocs[i]->super.proc_name, &u16ptr, PMIX_UINT16);
if (OPAL_SUCCESS == rc) {
rprocs[i]->super.proc_flags = u16;
} else {
rprocs[i]->super.proc_flags = OPAL_PROC_NON_LOCAL;
}
}
/* And now add the information into the database */
if (OMPI_SUCCESS != (rc = MCA_PML_CALL(add_procs(rprocs, rsize)))) {
goto err_exit;
}
err_exit:
/* rprocs isn't freed unless we have an error,
since it is used in the communicator */
if ( OMPI_SUCCESS != rc ) {
OMPI_ERROR_LOG(rc);
opal_output(0, "%d: Error in ompi_comm_get_rprocs\n", local_rank);
if ( NULL != rprocs ) {
free ( rprocs );
rprocs=NULL;
}
}
/* make sure the buffers have been released */
if (NULL != sbuf) {
PMIX_DATA_BUFFER_RELEASE(sbuf);
}
if (NULL != rbuf) {
PMIX_DATA_BUFFER_RELEASE(rbuf);
}
if ( NULL != proc_list ) {
free ( proc_list );
}
if (NULL != sendbuf) {
free ( sendbuf );
}
*prprocs = rprocs;
return rc;
}
/**********************************************************************/
/**********************************************************************/
/**********************************************************************/
int ompi_comm_determine_first ( ompi_communicator_t *intercomm, int high )
{
int flag, rhigh;
int rank, rsize;
int *rcounts;
int *rdisps;
int scount=0;
int rc;
rank = ompi_comm_rank (intercomm);
rsize= ompi_comm_remote_size (intercomm);
/* silence clang warnings. rsize can not be 0 here */
if (OPAL_UNLIKELY(0 == rsize)) {
return OMPI_ERR_BAD_PARAM;
}
rdisps = (int *) calloc ( rsize, sizeof(int));
if ( NULL == rdisps ){
return OMPI_ERR_OUT_OF_RESOURCE;
}
rcounts = (int *) calloc ( rsize, sizeof(int));
if ( NULL == rcounts ){
free (rdisps);
return OMPI_ERR_OUT_OF_RESOURCE;
}
rcounts[0] = 1;
if ( 0 == rank ) {
scount = 1;
}
rc = intercomm->c_coll->coll_allgatherv(&high, scount, MPI_INT,
&rhigh, rcounts, rdisps,
MPI_INT, intercomm,
intercomm->c_coll->coll_allgatherv_module);
if ( NULL != rdisps ) {
free ( rdisps );
}
if ( NULL != rcounts ) {
free ( rcounts );
}
if ( rc != OMPI_SUCCESS ) {
return rc;
}
/* This is the logic for determining who is first, who is second */
if ( high && !rhigh ) {
flag = false;
}
else if ( !high && rhigh ) {
flag = true;
}
else {
flag = ompi_comm_determine_first_auto(intercomm);
}
return flag;
}
int ompi_comm_determine_first_auto ( ompi_communicator_t* intercomm )
{
ompi_proc_t *ourproc, *theirproc;
ompi_rte_cmp_bitmask_t mask;
int rc;
ourproc = ompi_group_peer_lookup(intercomm->c_local_group,0);
theirproc = ompi_group_peer_lookup(intercomm->c_remote_group,0);
mask = OMPI_RTE_CMP_JOBID | OMPI_RTE_CMP_VPID;
rc = ompi_rte_compare_name_fields(mask, (const ompi_process_name_t*)&(ourproc->super.proc_name),
(const ompi_process_name_t*)&(theirproc->super.proc_name));
return (rc > 0);
}
/********************************************************************************/
/********************************************************************************/
/********************************************************************************/
int ompi_comm_dump ( ompi_communicator_t *comm )
{
opal_output(0, "Dumping information for comm_cid %s\n", ompi_comm_print_cid (comm));
opal_output(0," f2c index:%d cube_dim: %d\n", comm->c_f_to_c_index,
comm->c_cube_dim);
opal_output(0," Local group: size = %d my_rank = %d\n",
comm->c_local_group->grp_proc_count,
comm->c_local_group->grp_my_rank );
opal_output(0," Communicator is:");
/* Display flags */
if ( OMPI_COMM_IS_INTER(comm) )
opal_output(0," inter-comm,");
if ( OMPI_COMM_IS_CART(comm))
opal_output(0," topo-cart");
else if ( OMPI_COMM_IS_GRAPH(comm))
opal_output(0," topo-graph");
else if ( OMPI_COMM_IS_DIST_GRAPH(comm))
opal_output(0," topo-dist-graph");
opal_output(0,"\n");
if (OMPI_COMM_IS_INTER(comm)) {
opal_output(0," Remote group size:%d\n", comm->c_remote_group->grp_proc_count);
}
return OMPI_SUCCESS;
}
/********************************************************************************/
/********************************************************************************/
/********************************************************************************/
/* static functions */
/*
** rankkeygidcompare() compares a tuple of (rank,key,gid) producing
** sorted lists that match the rules needed for a MPI_Comm_split
*/
static int rankkeycompare (const void *p, const void *q)
{
int *a, *b;
/* ranks at [0] key at [1] */
/* i.e. we cast and just compare the keys and then the original ranks.. */
a = (int*)p;
b = (int*)q;
/* simple tests are those where the keys are different */
if (a[1] < b[1]) {
return (-1);
}
if (a[1] > b[1]) {
return (1);
}
/* ok, if the keys are the same then we check the original ranks */
if (a[1] == b[1]) {
if (a[0] < b[0]) {
return (-1);
}
if (a[0] == b[0]) {
return (0);
}
if (a[0] > b[0]) {
return (1);
}
}
return ( 0 );
}
/***********************************************************************
* Counterpart of MPI_Cart/Graph_create. This will be called from the
* top level MPI. The condition for INTER communicator is already
* checked by the time this has been invoked. This function should do
* somewhat the same things which ompi_comm_create does. It will
* however select a component for topology and then call the
* cart_create on that component so that it can re-arrange the proc
* structure as required (if the reorder flag is true). It will then
* use this proc structure to create the communicator using
* ompi_comm_set.
*/
/**
* Take an almost complete communicator and reserve the CID as well
* as activate it (initialize the collective and the topologies).
*/
int ompi_comm_enable(ompi_communicator_t *old_comm,
ompi_communicator_t *new_comm,
int new_rank,
int num_procs,
ompi_proc_t** topo_procs)
{
int ret = OMPI_SUCCESS;
/* set the rank information before calling nextcid */
new_comm->c_local_group->grp_my_rank = new_rank;
new_comm->c_my_rank = new_rank;
/* Determine context id. It is identical to f_2_c_handle */
ret = ompi_comm_nextcid (new_comm, old_comm, NULL, NULL, NULL, false,
OMPI_COMM_CID_INTRA);
if (OMPI_SUCCESS != ret) {
/* something wrong happened while setting the communicator */
goto complete_and_return;
}
/* Now, the topology module has been selected and the group
* which has the topology information has been created. All we
* need to do now is to fill the rest of the information into the
* communicator. The following steps are not just similar to
* ompi_comm_set, but are actually the same */
ret = ompi_comm_fill_rest(new_comm, /* the communicator */
num_procs, /* local size */
topo_procs, /* process structure */
new_rank, /* rank of the process */
old_comm->error_handler); /* error handler */
if (OMPI_SUCCESS != ret) {
/* something wrong happened while setting the communicator */
goto complete_and_return;
}
ret = ompi_comm_activate (&new_comm, old_comm, NULL, NULL, NULL, false,
OMPI_COMM_CID_INTRA);
if (OMPI_SUCCESS != ret) {
/* something wrong happened while setting the communicator */
goto complete_and_return;
}
complete_and_return:
return ret;
}
static int ompi_comm_fill_rest(ompi_communicator_t *comm,
int num_procs,
ompi_proc_t **proc_pointers,
int my_rank,
ompi_errhandler_t *errh)
{
ompi_group_t *new_group;
new_group = ompi_group_allocate_plist_w_procs(comm->c_local_group, proc_pointers, num_procs);
/* properly decrement the ref counts on the groups.
We are doing this because this function is sort of a redo
of what is done in comm.c. No need to decrement the ref
count on the proc pointers
This is just a quick fix, and will be looking for a
better solution */
if (comm->c_local_group) {
OBJ_RELEASE( comm->c_local_group );
}
if (comm->c_remote_group) {
OBJ_RELEASE( comm->c_remote_group );
}
/* allocate a group structure for the new communicator */
comm->c_local_group = new_group;
/* set the remote group to be the same as local group */
comm->c_remote_group = comm->c_local_group;
OBJ_RETAIN( comm->c_remote_group );
/* set the rank information */
comm->c_local_group->grp_my_rank = my_rank;
comm->c_my_rank = my_rank;
if( MPI_UNDEFINED != my_rank ) {
/* verify whether to set the flag, that this comm
contains process from more than one jobid. */
ompi_dpm_mark_dyncomm (comm);
}
/* set the error handler */
comm->error_handler = errh;
OBJ_RETAIN (comm->error_handler);
/* set name for debugging purposes */
/* there is no cid at this stage ... make this right and make edgars
* code call this function and remove dupli cde
*/
snprintf (comm->c_name, MPI_MAX_OBJECT_NAME, "MPI_COMMUNICATOR %s",
ompi_comm_print_cid (comm));
/* determine the cube dimensions */
comm->c_cube_dim = opal_cube_dim(comm->c_local_group->grp_proc_count);
return OMPI_SUCCESS;
}
static int ompi_comm_copy_topo(ompi_communicator_t *oldcomm,
ompi_communicator_t *newcomm)
{
if( NULL == oldcomm->c_topo )
return OMPI_ERR_NOT_FOUND;
newcomm->c_topo = oldcomm->c_topo;
OBJ_RETAIN(newcomm->c_topo);
newcomm->c_flags |= newcomm->c_topo->type;
return OMPI_SUCCESS;
}
char *ompi_comm_print_cid (const ompi_communicator_t *comm)
{
#if OPAL_HAVE_THREAD_LOCAL
static opal_thread_local char cid_buffer[2][20];
static opal_thread_local int cid_buffer_index = 0;
#else
/* no thread local == you get what you get. upgrade your compiler */
static char cid_buffer[2][20];
static int cid_buffer_index = 0;
#endif
int bindex = cid_buffer_index;
if (mca_pml_base_supports_extended_cid () && !OMPI_COMM_IS_GLOBAL_INDEX(comm)) {
snprintf (cid_buffer[bindex], sizeof (cid_buffer[0]), "0x%" PRIx64 "%08" PRIx64,
comm->c_contextid.cid_base,
comm->c_contextid.cid_sub.u64);
} else {
snprintf (cid_buffer[bindex], sizeof (cid_buffer[0]), "%d", comm->c_index);
}
cid_buffer_index = cid_buffer_index ? 0 : 1;
return cid_buffer[bindex];
}
|