/usr/include/trilinos/Tpetra_CrsGraph_decl.hpp is in libtrilinos-tpetra-dev 12.4.2-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 | // @HEADER
// ***********************************************************************
//
// Tpetra: Templated Linear Algebra Services Package
// Copyright (2008) Sandia Corporation
//
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
// the U.S. Government retains certain rights in this software.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// 3. Neither the name of the Corporation nor the names of the
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Questions? Contact Michael A. Heroux (maherou@sandia.gov)
//
// ************************************************************************
// @HEADER
#ifndef TPETRA_CRSGRAPH_DECL_HPP
#define TPETRA_CRSGRAPH_DECL_HPP
/// \file Tpetra_CrsGraph_decl.hpp
/// \brief Declaration of the Tpetra::CrsGraph class
///
/// If you want to use Tpetra::CrsGraph, include "Tpetra_CrsGraph.hpp"
/// (a file which CMake generates and installs for you). If you only
/// want the declaration of Tpetra::CrsGraph, include this file
/// (Tpetra_CrsGraph_decl.hpp).
#include "Tpetra_ConfigDefs.hpp"
#include "Tpetra_RowGraph.hpp"
#include "Tpetra_DistObject.hpp"
#include "Tpetra_Exceptions.hpp"
#include "KokkosCompat_ClassicNodeAPI_Wrapper.hpp"
#include "Kokkos_DualView.hpp"
#include "Kokkos_StaticCrsGraph.hpp"
#include "Teuchos_Describable.hpp"
#include "Teuchos_ParameterListAcceptorDefaultBase.hpp"
namespace Tpetra {
#ifndef DOXYGEN_SHOULD_SKIP_THIS
//
// Dear users: These are just forward declarations. Please skip
// over them and go down to the CrsMatrix class declaration. Thank
// you.
//
template <class LO, class GO, class N, const bool isClassic>
class CrsGraph;
// forward declaration (needed for "friend" inside CrsGraph)
template <class S, class LO, class GO, class N, const bool isClassic>
class CrsMatrix;
namespace Experimental {
// forward declaration (needed for "friend" inside CrsGraph)
template<class S, class LO, class GO, class N>
class BlockCrsMatrix;
} // namespace Experimental
namespace Details {
// Forward declaration of an implementation detail of CrsGraph::clone.
template<class OutputCrsGraphType, class InputCrsGraphType>
class CrsGraphCopier {
public:
static Teuchos::RCP<OutputCrsGraphType>
clone (const InputCrsGraphType& graphIn,
const Teuchos::RCP<typename OutputCrsGraphType::node_type> nodeOut,
const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
};
} // namespace Details
#endif // DOXYGEN_SHOULD_SKIP_THIS
/// \struct RowInfo
/// \brief Allocation information for a locally owned row in a
/// CrsGraph or CrsMatrix
///
/// A RowInfo instance identifies a locally owned row uniquely by
/// its local index, and contains other information useful for
/// inserting entries into the row. It is the return value of
/// CrsGraph's getRowInfo() or updateAllocAndValues() methods.
struct RowInfo {
size_t localRow;
size_t allocSize;
size_t numEntries;
size_t offset1D;
};
enum ELocalGlobal {
LocalIndices,
GlobalIndices
};
namespace Details {
/// \brief Status of the graph's or matrix's storage, when not in
/// a fill-complete state.
///
/// When a CrsGraph or CrsMatrix is <i>not</i> fill complete, its
/// data live in one of three storage formats:
///
/// <ol>
/// <li> "2-D storage": The graph stores column indices as "array
/// of arrays," and the matrix stores values as "array of
/// arrays." The graph <i>must</i> have k_numRowEntries_
/// allocated. This only ever exists if the graph was created
/// with DynamicProfile. A matrix with 2-D storage must own its
/// graph, and the graph must have 2-D storage. </li>
///
/// <li> "Unpacked 1-D storage": The graph uses a row offsets
/// array, and stores column indices in a single array. The
/// matrix also stores values in a single array. "Unpacked"
/// means that there may be extra space in each row: that is,
/// the row offsets array only says how much space there is in
/// each row. The graph must use k_numRowEntries_ to find out
/// how many entries there actually are in the row. A matrix
/// with unpacked 1-D storage must own its graph, and the graph
/// must have unpacked 1-D storage. </li>
///
/// <li> "Packed 1-D storage": The matrix may or may not own the
/// graph. "Packed" means that there is no extra space in each
/// row. Thus, the k_numRowEntries_ array is not necessary and
/// may have been deallocated. If the matrix was created with a
/// constant ("static") graph, this must be true. </li>
/// </ol>
///
/// With respect to the Kokkos refactor version of Tpetra, "2-D
/// storage" should be considered a legacy option.
///
/// The phrase "When not in a fill-complete state" is important.
/// When the graph is fill complete, it <i>always</i> uses 1-D
/// "packed" storage. However, if storage is "not optimized," we
/// retain the 1-D unpacked or 2-D format, and thus retain this
/// enum value.
enum EStorageStatus {
STORAGE_2D, //<! 2-D storage
STORAGE_1D_UNPACKED, //<! 1-D "unpacked" storage
STORAGE_1D_PACKED, //<! 1-D "packed" storage
STORAGE_UB //<! Invalid value; upper bound on enum values
};
} // namespace Details
/// \class CrsGraph
/// \brief A distributed graph accessed by rows (adjacency lists)
/// and stored sparsely.
///
/// \tparam LocalOrdinal The type of local indices. See the
/// documentation of Map for requirements.
/// \tparam GlobalOrdinal The type of global indices. See the
/// documentation of Map for requirements.
/// \tparam Node The Kokkos Node type. See the documentation of Map
/// for requirements.
///
/// This class implements a distributed-memory parallel sparse
/// graph. It provides access by rows to the elements of the graph,
/// as if the local data were stored in compressed sparse row format
/// (adjacency lists, in graph terms). (Implementations are
/// <i>not</i> required to store the data in this way internally.)
/// This class has an interface like that of Epetra_CrsGraph, but
/// also allows insertion of data into nonowned rows, much like
/// Epetra_FECrsGraph.
///
/// \section Tpetra_CrsGraph_prereq Prerequisites
///
/// Before reading the rest of this documentation, it helps to know
/// something about the Teuchos memory management classes, in
/// particular Teuchos::RCP, Teuchos::ArrayRCP, and
/// Teuchos::ArrayView. You should also know a little bit about MPI
/// (the Message Passing Interface for distributed-memory
/// programming). You won't have to use MPI directly to use
/// CrsGraph, but it helps to be familiar with the general idea of
/// distributed storage of data over a communicator. Finally, you
/// should read the documentation of Map.
///
/// \section Tpetra_CrsGraph_local_vs_global Local vs. global indices and nonlocal insertion
///
/// Graph entries can be added using either local or global coordinates
/// for the indices. The accessors isGloballyIndexed() and
/// isLocallyIndexed() indicate whether the indices are currently
/// stored as global or local indices. Many of the class methods are
/// divided into global and local versions, which differ only in
/// whether they accept/return indices in the global or local
/// coordinate space. Some of these methods may only be used if the
/// graph coordinates are in the appropriate coordinates. For example,
/// getGlobalRowView() returns a View to the indices in global
/// coordinates; if the indices are not in global coordinates, then no
/// such View can be created.
///
/// The global/local distinction does distinguish between operation
/// on the global/local graph. Almost all methods operate on the
/// local graph, i.e., the rows of the graph associated with the
/// local node, per the distribution specified by the row
/// map. Access to non-local rows requires performing an explicit
/// communication via the import/export capabilities of the CrsGraph
/// object; see DistObject. However, the method
/// insertGlobalIndices() is an exception to this rule, as non-local
/// rows are allowed to be added via the local graph. These rows are
/// stored in the local graph and communicated to the appropriate
/// node on the next call to globalAssemble() or fillComplete() (the
/// latter calls the former).
template <class LocalOrdinal = Details::DefaultTypes::local_ordinal_type,
class GlobalOrdinal = Details::DefaultTypes::global_ordinal_type,
class Node = Details::DefaultTypes::node_type,
const bool classic = Node::classic>
class CrsGraph :
public RowGraph<LocalOrdinal, GlobalOrdinal, Node>,
public DistObject<GlobalOrdinal,
LocalOrdinal,
GlobalOrdinal,
Node>,
public Teuchos::ParameterListAcceptorDefaultBase
{
static_assert (! classic, "The 'classic' version of Tpetra was deprecated long ago, and has been removed.");
template <class S, class LO, class GO, class N, const bool isClassic>
friend class CrsMatrix;
template <class LO2, class GO2, class N2, const bool isClassic>
friend class CrsGraph;
template <class S, class LO, class GO, class N>
friend class ::Tpetra::Experimental::BlockCrsMatrix;
//! The specialization of DistObject that is this class' parent class.
typedef DistObject<GlobalOrdinal, LocalOrdinal, GlobalOrdinal, Node> dist_object_type;
public:
//! This class' first template parameter; the type of local indices.
typedef LocalOrdinal local_ordinal_type;
//! This class' second template parameter; the type of global indices.
typedef GlobalOrdinal global_ordinal_type;
//! This class' Kokkos Node type.
typedef Node node_type;
//! This class' Kokkos device type.
typedef typename Node::device_type device_type;
//! This class' Kokkos execution space.
typedef typename device_type::execution_space execution_space;
//! The type of the part of the sparse graph on each MPI process.
typedef Kokkos::StaticCrsGraph<LocalOrdinal,
Kokkos::LayoutLeft,
execution_space> local_graph_type;
//! DEPRECATED; use local_graph_type (above) instead.
typedef local_graph_type LocalStaticCrsGraphType TPETRA_DEPRECATED;
//! DEPRECATED; use <tt>local_graph_type::row_map_type</tt> instead.
typedef typename local_graph_type::row_map_type t_RowPtrs TPETRA_DEPRECATED;
//! DEPRECATED; use <tt>local_graph_type::row_map_type::non_const_type</tt> instead.
typedef typename local_graph_type::row_map_type::non_const_type t_RowPtrsNC TPETRA_DEPRECATED;
//! DEPRECATED; use <tt>local_graph_type::entries_type::non_const_type</tt> instead.
typedef typename local_graph_type::entries_type::non_const_type t_LocalOrdinal_1D TPETRA_DEPRECATED;
//! The Map specialization used by this class.
typedef Tpetra::Map<LocalOrdinal, GlobalOrdinal, Node> map_type;
//! The Import specialization used by this class.
typedef Tpetra::Import<LocalOrdinal, GlobalOrdinal, Node> import_type;
//! The Export specialization used by this class.
typedef Tpetra::Export<LocalOrdinal, GlobalOrdinal, Node> export_type;
//! @name Constructor/Destructor Methods
//@{
/// \brief Constructor specifying a single upper bound for the
/// number of entries in all rows on the calling process.
///
/// \param rowMap [in] Distribution of rows of the graph.
///
/// \param maxNumEntriesPerRow [in] Maximum number of graph
/// entries per row. If pftype==DynamicProfile, this is only a
/// hint, and you can set this to zero without affecting
/// correctness. If pftype==StaticProfile, this sets the amount
/// of storage allocated, and you cannot exceed this number of
/// entries in any row.
///
/// \param pftype [in] Whether to allocate storage dynamically
/// (DynamicProfile) or statically (StaticProfile).
///
/// \param params [in/out] Optional list of parameters. If not
/// null, any missing parameters will be filled in with their
/// default values.
CrsGraph (const Teuchos::RCP<const map_type>& rowMap,
size_t maxNumEntriesPerRow,
ProfileType pftype = DynamicProfile,
const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
/// \brief Constructor specifying a (possibly different) upper
/// bound for the number of entries in each row.
///
/// \param rowMap [in] Distribution of rows of the graph.
///
/// \param numEntPerRow [in] Maximum number of graph entries to
/// allocate for each row. If pftype==DynamicProfile, this is
/// only a hint. If pftype==StaticProfile, this sets the amount
/// of storage allocated, and you cannot exceed the allocated
/// number of entries for any row.
///
/// \param pftype [in] Whether to allocate storage dynamically
/// (DynamicProfile) or statically (StaticProfile).
///
/// \param params [in/out] Optional list of parameters. If not
/// null, any missing parameters will be filled in with their
/// default values.
CrsGraph (const Teuchos::RCP<const map_type>& rowMap,
const Kokkos::DualView<const size_t*, execution_space>& numEntPerRow,
const ProfileType pftype = DynamicProfile,
const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
/// \brief Constructor specifying a (possibly different) upper
/// bound for the number of entries in each row (legacy
/// KokkosClassic version).
///
/// \param rowMap [in] Distribution of rows of the graph.
///
/// \param numEntPerRow [in] Maximum number of graph entries to
/// allocate for each row. If pftype==DynamicProfile, this is
/// only a hint. If pftype==StaticProfile, this sets the amount
/// of storage allocated, and you cannot exceed the allocated
/// number of entries for any row.
///
/// \param pftype [in] Whether to allocate storage dynamically
/// (DynamicProfile) or statically (StaticProfile).
///
/// \param params [in/out] Optional list of parameters. If not
/// null, any missing parameters will be filled in with their
/// default values.
CrsGraph (const Teuchos::RCP<const map_type>& rowMap,
const Teuchos::ArrayRCP<const size_t>& numEntPerRow,
const ProfileType pftype = DynamicProfile,
const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
/// \brief Constructor specifying column Map and a single upper
/// bound for the number of entries in all rows on the calling
/// process.
///
/// \param rowMap [in] Distribution of rows of the graph.
///
/// \param colMap [in] Distribution of columns of the graph.
///
/// \param maxNumEntriesPerRow [in] Maximum number of graph
/// entries per row. If pftype==DynamicProfile, this is only a
/// hint, and you can set this to zero without affecting
/// correctness. If pftype==StaticProfile, this sets the amount
/// of storage allocated, and you cannot exceed this number of
/// entries in any row.
///
/// \param pftype [in] Whether to allocate storage dynamically
/// (DynamicProfile) or statically (StaticProfile).
///
/// \param params [in/out] Optional list of parameters. If not
/// null, any missing parameters will be filled in with their
/// default values.
CrsGraph (const Teuchos::RCP<const map_type>& rowMap,
const Teuchos::RCP<const map_type>& colMap,
const size_t maxNumEntriesPerRow,
const ProfileType pftype = DynamicProfile,
const Teuchos::RCP<Teuchos::ParameterList>& params = null);
/// \brief Constructor specifying column Map and number of entries in each row.
///
/// \param rowMap [in] Distribution of rows of the graph.
///
/// \param colMap [in] Distribution of columns of the graph.
///
/// \param numEntPerRow [in] Maximum number of graph entries to
/// allocate for each row. If pftype==DynamicProfile, this is
/// only a hint. If pftype==StaticProfile, this sets the amount
/// of storage allocated, and you cannot exceed the allocated
/// number of entries for any row.
///
/// \param pftype [in] Whether to allocate storage dynamically
/// (DynamicProfile) or statically (StaticProfile).
///
/// \param params [in/out] Optional list of parameters. If not
/// null, any missing parameters will be filled in with their
/// default values.
CrsGraph (const Teuchos::RCP<const map_type>& rowMap,
const Teuchos::RCP<const map_type>& colMap,
const Kokkos::DualView<const size_t*, execution_space>& numEntPerRow,
ProfileType pftype = DynamicProfile,
const Teuchos::RCP<Teuchos::ParameterList>& params = null);
/// \brief Constructor specifying column Map and number of entries
/// in each row (legacy KokkosClassic version).
///
/// \param rowMap [in] Distribution of rows of the graph.
///
/// \param colMap [in] Distribution of columns of the graph.
///
/// \param numEntPerRow [in] Maximum number of graph entries to
/// allocate for each row. If pftype==DynamicProfile, this is
/// only a hint. If pftype==StaticProfile, this sets the amount
/// of storage allocated, and you cannot exceed the allocated
/// number of entries for any row.
///
/// \param pftype [in] Whether to allocate storage dynamically
/// (DynamicProfile) or statically (StaticProfile).
///
/// \param params [in/out] Optional list of parameters. If not
/// null, any missing parameters will be filled in with their
/// default values.
CrsGraph (const Teuchos::RCP<const map_type>& rowMap,
const Teuchos::RCP<const map_type>& colMap,
const Teuchos::ArrayRCP<const size_t>& numEntPerRow,
ProfileType pftype = DynamicProfile,
const Teuchos::RCP<Teuchos::ParameterList>& params = null);
/// \brief Constructor specifying column Map and arrays containing the graph in sorted, local ids.
///
///
/// \param rowMap [in] Distribution of rows of the graph.
///
/// \param colMap [in] Distribution of columns of the graph.
///
/// \param rowPointers [in] The beginning of each row in the graph,
/// as in a CSR "rowptr" array. The length of this vector should be
/// equal to the number of rows in the graph, plus one. This last
/// entry should store the nunber of nonzeros in the graph.
///
/// \param columnIndices [in] The local indices of the columns,
/// as in a CSR "colind" array. The length of this vector
/// should be equal to the number of unknowns in the graph.
///
/// \param params [in/out] Optional list of parameters. If not
/// null, any missing parameters will be filled in with their
/// default values.
CrsGraph (const Teuchos::RCP<const map_type>& rowMap,
const Teuchos::RCP<const map_type>& colMap,
const typename local_graph_type::row_map_type& rowPointers,
const typename local_graph_type::entries_type::non_const_type& columnIndices,
const Teuchos::RCP<Teuchos::ParameterList>& params = null);
/// \brief Constructor specifying column Map and arrays containing the graph in sorted, local ids.
///
///
/// \param rowMap [in] Distribution of rows of the graph.
///
/// \param colMap [in] Distribution of columns of the graph.
///
/// \param rowPointers [in] The beginning of each row in the graph,
/// as in a CSR "rowptr" array. The length of this vector should be
/// equal to the number of rows in the graph, plus one. This last
/// entry should store the nunber of nonzeros in the graph.
///
/// \param columnIndices [in] The local indices of the columns,
/// as in a CSR "colind" array. The length of this vector
/// should be equal to the number of unknowns in the graph.
///
/// \param params [in/out] Optional list of parameters. If not
/// null, any missing parameters will be filled in with their
/// default values.
CrsGraph (const Teuchos::RCP<const map_type>& rowMap,
const Teuchos::RCP<const map_type>& colMap,
const Teuchos::ArrayRCP<size_t> & rowPointers,
const Teuchos::ArrayRCP<LocalOrdinal> & columnIndices,
const Teuchos::RCP<Teuchos::ParameterList>& params = null);
/// \brief Constructor specifying column Map and a local (sorted)
/// graph, which the resulting CrsGraph views.
///
/// Unlike most other CrsGraph constructors, successful completion
/// of this constructor will result in a fill-complete graph.
///
/// \param rowMap [in] Distribution of rows of the graph.
///
/// \param colMap [in] Distribution of columns of the graph.
///
/// \param lclGraph [in] A locally indexed Kokkos::StaticCrsGraph
/// whose local row indices come from the specified row Map, and
/// whose local column indices come from the specified column
/// Map.
///
/// \param params [in/out] Optional list of parameters. If not
/// null, any missing parameters will be filled in with their
/// default values.
CrsGraph (const Teuchos::RCP<const map_type>& rowMap,
const Teuchos::RCP<const map_type>& colMap,
const local_graph_type& lclGraph,
const Teuchos::RCP<Teuchos::ParameterList>& params);
/// \brief Create a cloned CrsGraph for a different Node type.
///
/// This method creates a new CrsGraph on a specified Kokkos Node
/// type, with all of the entries of this CrsGraph object.
///
/// \param node2 [in] Kokkos Node instance for constructing the
/// clone CrsGraph and its constituent objects.
///
/// \param params [in/out] Optional list of parameters. If not
/// null, any missing parameters will be filled in with their
/// default values. See the list below for valid options.
///
/// Parameters accepted by this method:
/// - "Static profile clone" [bool, default: true] If \c true,
/// creates the clone with a static allocation profile. If
/// false, a dynamic allocation profile is used.
/// - "Locally indexed clone" [bool] If \c true, fills clone
/// using this graph's column map and local indices (requires
/// that this graph have a column map.) If false, fills clone
/// using global indices and does not provide a column map. By
/// default, will use local indices only if this graph is using
/// local indices.
/// - "fillComplete clone" [boolean, default: true] If \c true,
/// calls fillComplete() on the cloned CrsGraph object, with
/// parameters from \c params sublist "CrsGraph". The domain map
/// and range maps passed to fillComplete() are those of the map
/// being cloned, if they exist. Otherwise, the row map is used.
template<class Node2>
Teuchos::RCP<CrsGraph<LocalOrdinal, GlobalOrdinal, Node2, Node2::classic> >
clone (const Teuchos::RCP<Node2>& node2,
const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null) const
{
typedef CrsGraph<LocalOrdinal, GlobalOrdinal, Node2, Node2::classic> output_crs_graph_type;
typedef CrsGraph<LocalOrdinal, GlobalOrdinal, Node, classic> input_crs_graph_type;
typedef Details::CrsGraphCopier<output_crs_graph_type, input_crs_graph_type> copier_type;
return copier_type::clone (*this, node2, params);
}
//! Destructor.
virtual ~CrsGraph();
//@}
//! @name Implementation of Teuchos::ParameterListAcceptor
//@{
//! Set the given list of parameters (must be nonnull).
void setParameterList (const Teuchos::RCP<Teuchos::ParameterList>& params);
//! Default parameter list suitable for validation.
Teuchos::RCP<const ParameterList> getValidParameters () const;
//@}
//! @name Insertion/Removal Methods
//@{
/// \brief Insert global indices into the graph.
///
/// \pre \c globalRow is a valid index in the row Map. It need
/// not be owned by the calling process.
/// \pre <tt>isLocallyIndexed() == false</tt>
/// \pre <tt>isStorageOptimized() == false</tt>
///
/// \post <tt>indicesAreAllocated() == true</tt>
/// \post <tt>isGloballyIndexed() == true</tt>
///
/// If \c globalRow does not belong to the graph on this process,
/// then it will be communicated to the appropriate process when
/// globalAssemble() is called. (That method will be called
/// automatically during the next call to fillComplete().)
/// Otherwise, the entries will be inserted into the part of the
/// graph owned by the calling process.
///
/// If the graph row already contains entries at the indices
/// corresponding to values in \c indices, then the redundant
/// indices will be eliminated. This may happen either at
/// insertion or during the next call to fillComplete().
void
insertGlobalIndices (GlobalOrdinal globalRow,
const Teuchos::ArrayView<const GlobalOrdinal>& indices);
//! Insert local indices into the graph.
/**
\pre \c localRow is a local row belonging to the graph on this process.
\pre <tt>isGloballyIndexed() == false</tt>
\pre <tt>isStorageOptimized() == false</tt>
\pre <tt>hasColMap() == true</tt>
\post <tt>indicesAreAllocated() == true</tt>
\post <tt>isLocallyIndexed() == true</tt>
\note If the graph row already contains entries at the indices
corresponding to values in \c indices, then the redundant
indices will be eliminated; this may happen at insertion or
during the next call to fillComplete().
*/
void
insertLocalIndices (const LocalOrdinal localRow,
const Teuchos::ArrayView<const LocalOrdinal> &indices);
//! Remove all graph indices from the specified local row.
/**
\pre \c localRow is a local row of this graph.
\pre <tt>isGloballyIndexed() == false</tt>
\pre <tt>isStorageOptimized() == false</tt>
\post <tt>getNumEntriesInLocalRow(localRow) == 0</tt>
\post <tt>indicesAreAllocated() == true</tt>
\post <tt>isLocallyIndexed() == true</tt>
*/
void removeLocalIndices (LocalOrdinal localRow);
//@}
//! @name Transformational Methods
/**
Each of the methods in this group is a global collective. It is
necessary to call these mehtods on all nodes participating in the
communicator associated with this graph.
*/
//@{
/// \brief Communicate non-local contributions to other processes.
///
/// This method is called automatically by fillComplete().
/// Most users do not need to call this themselves,
/// though we do permit this.
void globalAssemble ();
/*! Resume fill operations.
After calling fillComplete(), resumeFill() must be called before initiating any changes to the graph.
resumeFill() may be called repeatedly.
\post <tt>isFillActive() == true<tt>
\post <tt>isFillComplete() == false<tt>
*/
void resumeFill (const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
/*! \brief Signal that data entry is complete, specifying domain and range maps.
Off-process indices are distributed (via globalAssemble()),
indices are sorted, redundant indices are eliminated, and
global indices are transformed to local indices.
\pre <tt>isFillActive() == true<tt>
\pre <tt>isFillComplete()() == false<tt>
\post <tt>isFillActive() == false<tt>
\post <tt>isFillComplete() == true<tt>
Parameters:
- "Optimize Storage" (\c bool): Default is false. If true,
then isStorageOptimized() returns true after fillComplete
finishes. See isStorageOptimized() for consequences.
*/
void
fillComplete (const Teuchos::RCP<const map_type> &domainMap,
const Teuchos::RCP<const map_type> &rangeMap,
const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
/*! \brief Signal that data entry is complete.
Off-node entries are distributed (via globalAssemble()), repeated entries are summed, and global indices are transformed to local indices.
\note This method calls fillComplete( getRowMap(), getRowMap(), os ). See parameter options there.
*/
void fillComplete (const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
/// \brief Perform a fillComplete on a graph that already has
/// data, via setAllIndices().
///
/// The graph must already have filled local 1-D storage. If the
/// graph has been constructed in any other way, this method will
/// throw an exception. This routine is needed to support other
/// Trilinos packages and should not be called by ordinary users.
///
/// \warning This method is intended for expert developer use
/// only, and should never be called by user code.
void
expertStaticFillComplete (const Teuchos::RCP<const map_type> & domainMap,
const Teuchos::RCP<const map_type> & rangeMap,
const Teuchos::RCP<const import_type> &importer=Teuchos::null,
const Teuchos::RCP<const export_type> &exporter=Teuchos::null,
const Teuchos::RCP<Teuchos::ParameterList> ¶ms=Teuchos::null);
//@}
//! @name Methods implementing RowGraph.
//@{
//! Returns the communicator.
Teuchos::RCP<const Comm<int> > getComm() const;
//! Returns the underlying node.
Teuchos::RCP<node_type> getNode() const;
//! Returns the Map that describes the row distribution in this graph.
Teuchos::RCP<const map_type> getRowMap () const;
//! \brief Returns the Map that describes the column distribution in this graph.
Teuchos::RCP<const map_type> getColMap () const;
//! Returns the Map associated with the domain of this graph.
Teuchos::RCP<const map_type> getDomainMap () const;
//! Returns the Map associated with the domain of this graph.
Teuchos::RCP<const map_type> getRangeMap () const;
//! Returns the importer associated with this graph.
Teuchos::RCP<const import_type> getImporter () const;
//! Returns the exporter associated with this graph.
Teuchos::RCP<const export_type> getExporter () const;
//! Returns the number of global rows in the graph.
/** Undefined if isFillActive().
*/
global_size_t getGlobalNumRows() const;
//! \brief Returns the number of global columns in the graph.
/** Returns the number of entries in the domain map of the matrix.
Undefined if isFillActive().
*/
global_size_t getGlobalNumCols() const;
//! Returns the number of graph rows owned on the calling node.
size_t getNodeNumRows() const;
//! Returns the number of columns connected to the locally owned rows of this graph.
/** Throws std::runtime_error if <tt>hasColMap() == false</tt>
*/
size_t getNodeNumCols() const;
//! Returns the index base for global indices for this graph.
GlobalOrdinal getIndexBase() const;
//! Returns the global number of entries in the graph.
/** Undefined if isFillActive().
*/
global_size_t getGlobalNumEntries() const;
//! Returns the local number of entries in the graph.
size_t getNodeNumEntries() const;
//! \brief Returns the current number of entries on this node in the specified global row.
/*! Returns OrdinalTraits<size_t>::invalid() if the specified global row does not belong to this graph. */
size_t getNumEntriesInGlobalRow(GlobalOrdinal globalRow) const;
//! Returns the current number of entries on this node in the specified local row.
/*! Returns OrdinalTraits<size_t>::invalid() if the specified local row is not valid for this graph. */
size_t getNumEntriesInLocalRow(LocalOrdinal localRow) const;
//! \brief Returns the total number of indices allocated for the graph, across all rows on this node.
/*! This is the allocation available to the user. Actual allocation may be larger, for example, after
calling fillComplete(), and thus this does not necessarily reflect the memory consumption of the
this graph.
This quantity is computed during the actual allocation. Therefore, if <tt>indicesAreAllocated() == false</tt>,
this method returns <tt>OrdinalTraits<size_t>::invalid()</tt>.
*/
size_t getNodeAllocationSize() const;
//! \brief Returns the current number of allocated entries for this node in the specified global row .
/** Throws exception std::runtime_error if the specified global row does not belong to this node. */
size_t getNumAllocatedEntriesInGlobalRow(GlobalOrdinal globalRow) const;
//! Returns the current number of allocated entries on this node in the specified local row.
/** Throws exception std::runtime_error if the specified local row is not valid for this node. */
size_t getNumAllocatedEntriesInLocalRow(LocalOrdinal localRow) const;
//! \brief Returns the number of global diagonal entries, based on global row/column index comparisons.
/** Undefined if isFillActive().
*/
global_size_t getGlobalNumDiags() const;
//! \brief Returns the number of local diagonal entries, based on global row/column index comparisons.
/** Undefined if isFillActive().
*/
size_t getNodeNumDiags() const;
/// \brief Maximum number of entries in all rows over all processes.
///
/// \note Undefined if isFillActive().
///
/// \note This is the same as the result of a global maximum of
/// getNodeMaxNumRowEntries() over all processes. That may not
/// necessarily mean what you think it does if some rows of the
/// matrix are owned by multiple processes. In particular, some
/// processes might only own some of the entries in a particular
/// row. This method only counts the number of entries in each
/// row that a process owns, not the total number of entries in
/// the row over all processes.
size_t getGlobalMaxNumRowEntries() const;
//! \brief Maximum number of entries in all rows owned by the calling process.
/** Undefined if isFillActive().
*/
size_t getNodeMaxNumRowEntries() const;
/// \brief Whether the graph has a column Map.
///
/// A CrsGraph has a column Map either because it was given to its
/// constructor, or because it was constructed in fillComplete().
/// Calling fillComplete() always makes a column Map if the graph
/// does not already have one.
///
/// A column Map lets the graph
///
/// - use local indices for storing entries in each row, and
/// - compute an Import from the domain Map to the column Map.
///
/// The latter is mainly useful for a graph associated with a
/// CrsMatrix.
bool hasColMap() const;
/// \brief Whether the graph is locally lower triangular.
///
/// \pre <tt>! isFillActive()</tt>.
/// If fill is active, this method's behavior is undefined.
///
/// \note This is entirely a local property. That means this
/// method may return different results on different processes.
bool isLowerTriangular() const;
/// \brief Whether the graph is locally upper triangular.
///
/// \pre <tt>! isFillActive()</tt>.
/// If fill is active, this method's behavior is undefined.
///
/// \note This is entirely a local property. That means this
/// method may return different results on different processes.
bool isUpperTriangular() const;
//! \brief If graph indices are in the local range, this function returns true. Otherwise, this function returns false. */
bool isLocallyIndexed() const;
//! \brief If graph indices are in the global range, this function returns true. Otherwise, this function returns false. */
bool isGloballyIndexed() const;
//! Returns \c true if fillComplete() has been called and the graph is in compute mode.
bool isFillComplete() const;
//! Returns \c true if resumeFill() has been called and the graph is in edit mode.
bool isFillActive() const;
/// \brief Whether graph indices in all rows are known to be sorted.
///
/// A fill-complete graph is always sorted, as is a newly
/// constructed graph. A graph is sorted immediately after calling
/// resumeFill(), but any changes to the graph may result in the
/// sorting status becoming unknown (and therefore, presumed
/// unsorted).
bool isSorted() const;
//! \brief Returns \c true if storage has been optimized.
/**
Optimized storage means that the allocation of each row is equal to the
number of entries. The effect is that a pass through the matrix, i.e.,
during a mat-vec, requires minimal memory traffic. One limitation of
optimized storage is that no new indices can be added to the graph.
*/
bool isStorageOptimized() const;
//! Returns \c true if the graph was allocated with static data structures.
ProfileType getProfileType() const;
/// \brief Get a copy of the given row, using global indices.
///
/// \param GlobalRow [in] Global index of the row.
/// \param Indices [out] On output: Global column indices.
/// \param NumIndices [out] Number of indices returned.
void
getGlobalRowCopy (GlobalOrdinal GlobalRow,
const Teuchos::ArrayView<GlobalOrdinal>& Indices,
size_t& NumIndices) const;
/// \brief Get a copy of the given row, using local indices.
///
/// \param LocalRow [in] Local index of the row.
/// \param Indices [out] On output: Local column indices.
/// \param NumIndices [out] Number of indices returned.
///
/// \pre <tt>hasColMap()</tt>
void
getLocalRowCopy (LocalOrdinal LocalRow,
const Teuchos::ArrayView<LocalOrdinal>& indices,
size_t& NumIndices) const;
//! Extract a const, non-persisting view of global indices in a specified row of the graph.
/*!
\param GlobalRow - (In) Global row number for which indices are desired.
\param Indices - (Out) Global column indices corresponding to values.
\pre <tt>isLocallyIndexed() == false</tt>
\post <tt>indices.size() == getNumEntriesInGlobalRow(GlobalRow)</tt>
Note: If \c GlobalRow does not belong to this node, then \c indices is set to null.
*/
void
getGlobalRowView (GlobalOrdinal GlobalRow,
Teuchos::ArrayView<const GlobalOrdinal>& Indices) const;
//! Extract a const, non-persisting view of local indices in a specified row of the graph.
/*!
\param LocalRow - (In) Local row number for which indices are desired.
\param Indices - (Out) Global column indices corresponding to values.
\pre <tt>isGloballyIndexed() == false</tt>
\post <tt>indices.size() == getNumEntriesInLocalRow(LocalRow)</tt>
Note: If \c LocalRow does not belong to this node, then \c indices is set to null.
*/
void
getLocalRowView (LocalOrdinal LocalRow,
Teuchos::ArrayView<const LocalOrdinal>& indices) const;
//@}
//! @name Overridden from Teuchos::Describable
//@{
/** \brief Return a simple one-line description of this object. */
std::string description() const;
//! Print the object to the given output stream with given verbosity level.
void
describe (Teuchos::FancyOStream& out,
const Teuchos::EVerbosityLevel verbLevel =
Teuchos::Describable::verbLevel_default) const;
//@}
//! \name Implementation of DistObject
//@{
virtual bool
checkSizes (const SrcDistObject& source);
virtual void
copyAndPermute (const SrcDistObject& source,
size_t numSameIDs,
const Teuchos::ArrayView<const LocalOrdinal> &permuteToLIDs,
const Teuchos::ArrayView<const LocalOrdinal> &permuteFromLIDs);
virtual void
packAndPrepare (const SrcDistObject& source,
const Teuchos::ArrayView<const LocalOrdinal> &exportLIDs,
Teuchos::Array<GlobalOrdinal> &exports,
const Teuchos::ArrayView<size_t> & numPacketsPerLID,
size_t& constantNumPackets,
Distributor &distor);
virtual void
pack (const Teuchos::ArrayView<const LocalOrdinal>& exportLIDs,
Teuchos::Array<GlobalOrdinal>& exports,
const Teuchos::ArrayView<size_t>& numPacketsPerLID,
size_t& constantNumPackets,
Distributor& distor) const;
virtual void
unpackAndCombine (const Teuchos::ArrayView<const LocalOrdinal> &importLIDs,
const Teuchos::ArrayView<const GlobalOrdinal> &imports,
const Teuchos::ArrayView<size_t> &numPacketsPerLID,
size_t constantNumPackets,
Distributor &distor,
CombineMode CM);
//@}
//! \name Advanced methods, at increased risk of deprecation.
//@{
/// \brief Get an upper bound on the number of entries that can be
/// stored in each row.
///
/// When a CrsGraph is constructed, callers must give an upper
/// bound on the number of entries in each local row. They may
/// either supply a single integer which is the upper bound for
/// all local rows, or they may give an array with a possibly
/// different upper bound for each local row.
///
/// This method returns the upper bound for each row. If
/// numEntriesPerLocalRowBound is Teuchos::null on output and
/// boundSameForAllLocalRows is true on output, then
/// numEntriesAllLocalRowsBound is the upper bound for all local
/// rows. If boundSameForAllLocalRows is false on output, then
/// numEntriesPerLocalRowBound has zero or more entries on output,
/// and numEntriesPerLocalRowBound[i_local] is the upper bound for
/// local row i_local.
///
/// The output argument boundSameForAllLocalRows is conservative;
/// it only tells us whether boundForAllLocalRows has a meaningful
/// value on output. We don't necessarily check whether all
/// entries of boundPerLocalRow are the same.
void
getNumEntriesPerLocalRowUpperBound (Teuchos::ArrayRCP<const size_t>& boundPerLocalRow,
size_t& boundForAllLocalRows,
bool& boundSameForAllLocalRows) const;
/// \brief Set the graph's data directly, using 1-D storage.
///
/// \pre <tt>hasColMap() == true</tt>
/// \pre <tt>rowPointers.size() != getNodeNumRows()+1</tt>
/// \pre No insert routines have been called.
///
/// \warning This method is intended for expert developer use
/// only, and should never be called by user code.
void
setAllIndices (const typename local_graph_type::row_map_type& rowPointers,
const typename local_graph_type::entries_type::non_const_type& columnIndices);
/// \brief Set the graph's data directly, using 1-D storage.
///
/// \pre <tt>hasColMap() == true</tt>
/// \pre <tt>rowPointers.size() != getNodeNumRows()+1</tt>
/// \pre No insert routines have been called.
///
/// \warning This method is intended for expert developer use
/// only, and should never be called by user code.
void
setAllIndices (const Teuchos::ArrayRCP<size_t> & rowPointers,
const Teuchos::ArrayRCP<LocalOrdinal> & columnIndices);
/// \brief Get a host view of the row offsets.
///
/// \note Please prefer getLocalGraph() to get the row offsets.
///
/// This may return either a copy or a view of the row offsets.
/// In either case, it will <i>always</i> live in host memory,
/// never in (CUDA) device memory.
Teuchos::ArrayRCP<const size_t> getNodeRowPtrs () const;
//! Get an Teuchos::ArrayRCP of the packed column-indices.
/*! The returned buffer exists in host-memory.
*/
Teuchos::ArrayRCP<const LocalOrdinal> getNodePackedIndices() const;
/// \brief Replace the graph's current column Map with the given Map.
///
/// This <i>only</i> replaces the column Map. It does <i>not</i>
/// change the graph's current column indices, or otherwise apply
/// a permutation. For example, suppose that before calling this
/// method, the calling process owns a row containing local column
/// indices [0, 2, 4]. These indices do <i>not</i> change, nor
/// does their order change, as a result of calling this method.
///
/// \param newColMap [in] New column Map. Must be nonnull.
void replaceColMap (const Teuchos::RCP<const map_type>& newColMap);
/// \brief Reindex the column indices in place, and replace the
/// column Map. Optionally, replace the Import object as well.
///
/// \pre On every calling process, every index owned by the
/// current column Map must also be owned by the new column Map.
///
/// \pre If the new Import object is provided, the new Import
/// object's source Map must be the same as the current domain
/// Map, and the new Import's target Map must be the same as the
/// new column Map.
///
/// \param newColMap [in] New column Map. Must be nonnull.
///
/// \param newImport [in] New Import object. Optional; computed
/// if not provided or if null. Computing an Import is
/// expensive, so it is worth providing this if you can.
///
/// \param sortIndicesInEachRow [in] If true, sort the indices in
/// each row after reindexing.
void
reindexColumns (const Teuchos::RCP<const map_type>& newColMap,
const Teuchos::RCP<const import_type>& newImport = Teuchos::null,
const bool sortIndicesInEachRow = true);
/// \brief Replace the current domain Map and Import with the given parameters.
///
/// \warning This method is ONLY for use by experts.
/// \warning We make NO promises of backwards compatibility.
/// This method may change or disappear at any time.
///
/// \pre <tt>isFillComplete() == true<tt>
/// \pre <tt>isFillActive() == false<tt>
/// \pre Either the given Import object is null, or the target Map
/// of the given Import is the same as this graph's column Map.
/// \pre Either the given Import object is null, or the source Map
/// of the given Import is the same as this graph's domain Map.
void
replaceDomainMapAndImporter (const Teuchos::RCP<const map_type>& newDomainMap,
const Teuchos::RCP<const import_type>& newImporter);
/// \brief Remove processes owning zero rows from the Maps and their communicator.
///
/// \warning This method is ONLY for use by experts. We highly
/// recommend using the nonmember function of the same name
/// defined in Tpetra_DistObject_decl.hpp.
///
/// \warning We make NO promises of backwards compatibility.
/// This method may change or disappear at any time.
///
/// \param newMap [in] This <i>must</i> be the result of calling
/// the removeEmptyProcesses() method on the row Map. If it
/// is not, this method's behavior is undefined. This pointer
/// will be null on excluded processes.
///
/// This method satisfies the strong exception guarantee, as
/// long the destructors of Export, Import, and Map do not throw
/// exceptions. This means that either the method returns
/// normally (without throwing an exception), or there are no
/// externally visible side effects. However, this does not
/// guarantee no deadlock when the graph's original communicator
/// contains more than one process. In order to prevent
/// deadlock, you must still wrap this call in a try/catch block
/// and do an all-reduce over all processes in the original
/// communicator to test whether the call succeeded. This
/// safety measure should usually be unnecessary, since the
/// method call should only fail on user error or failure to
/// allocate memory.
virtual void
removeEmptyProcessesInPlace (const Teuchos::RCP<const map_type>& newMap);
//@}
template<class ViewType, class OffsetViewType >
struct pack_functor {
typedef typename ViewType::execution_space execution_space;
ViewType src;
ViewType dest;
OffsetViewType src_offset;
OffsetViewType dest_offset;
typedef typename OffsetViewType::non_const_value_type ScalarIndx;
pack_functor(ViewType dest_, ViewType src_, OffsetViewType dest_offset_, OffsetViewType src_offset_):
src(src_),dest(dest_),src_offset(src_offset_),dest_offset(dest_offset_) {};
KOKKOS_INLINE_FUNCTION
void operator() (size_t row) const {
ScalarIndx i = src_offset(row);
ScalarIndx j = dest_offset(row);
const ScalarIndx k = dest_offset(row+1);
for(;j<k;j++,i++) {
dest(j) = src(i);
}
}
};
protected:
// these structs are conveniences, to cut down on the number of
// arguments to some of the methods below.
struct SLocalGlobalViews {
Teuchos::ArrayView<const GlobalOrdinal> ginds;
Teuchos::ArrayView<const LocalOrdinal> linds;
};
struct SLocalGlobalNCViews {
Teuchos::ArrayView<GlobalOrdinal> ginds;
Teuchos::ArrayView<LocalOrdinal> linds;
};
bool indicesAreAllocated () const;
void allocateIndices (const ELocalGlobal lg);
template <class T>
Teuchos::ArrayRCP<Teuchos::Array<T> > allocateValues2D () const;
template <class T>
RowInfo updateLocalAllocAndValues (const RowInfo rowInfo,
const size_t newAllocSize,
Teuchos::Array<T>& rowVals)
{
#ifdef HAVE_TPETRA_DEBUG
TEUCHOS_TEST_FOR_EXCEPT( ! isLocallyIndexed () );
TEUCHOS_TEST_FOR_EXCEPT( ! indicesAreAllocated() );
TEUCHOS_TEST_FOR_EXCEPT( newAllocSize == 0 );
TEUCHOS_TEST_FOR_EXCEPT( newAllocSize < rowInfo.allocSize );
TEUCHOS_TEST_FOR_EXCEPT( ! rowMap_->isNodeLocalElement (rowInfo.localRow) );
#endif // HAVE_TPETRA_DEBUG
// Teuchos::ArrayRCP::resize automatically copies over values on reallocation.
lclInds2D_[rowInfo.localRow].resize (newAllocSize);
rowVals.resize (newAllocSize);
nodeNumAllocated_ += (newAllocSize - rowInfo.allocSize);
RowInfo rowInfoOut = rowInfo;
rowInfoOut.allocSize = newAllocSize;
return rowInfoOut;
}
template <class T>
RowInfo
updateGlobalAllocAndValues (const RowInfo rowInfo,
const size_t newAllocSize,
Teuchos::Array<T>& rowVals)
{
#ifdef HAVE_TPETRA_DEBUG
TEUCHOS_TEST_FOR_EXCEPT( ! isGloballyIndexed () );
TEUCHOS_TEST_FOR_EXCEPT( ! indicesAreAllocated () );
TEUCHOS_TEST_FOR_EXCEPT( newAllocSize == 0 );
TEUCHOS_TEST_FOR_EXCEPT( newAllocSize < rowInfo.allocSize );
TEUCHOS_TEST_FOR_EXCEPT( ! rowMap_->isNodeLocalElement (rowInfo.localRow) );
#endif // HAVE_TPETRA_DEBUG
// Teuchos::ArrayRCP::resize automatically copies over values on reallocation.
gblInds2D_[rowInfo.localRow].resize (newAllocSize);
rowVals.resize (newAllocSize);
nodeNumAllocated_ += (newAllocSize - rowInfo.allocSize);
RowInfo rowInfoOut = rowInfo;
rowInfoOut.allocSize = newAllocSize;
return rowInfoOut;
}
//! \name Methods governing changes between global and local indices
//@{
//! Make the graph's column Map, if it does not already have one.
void makeColMap ();
void makeIndicesLocal ();
void makeImportExport ();
//@}
//! \name Methods for inserting indices or transforming values
//@{
template<ELocalGlobal lg>
size_t filterIndices (const SLocalGlobalNCViews& inds) const
{
using Teuchos::ArrayView;
static_assert (lg == GlobalIndices || lg == LocalIndices,
"Tpetra::CrsGraph::filterIndices: The template parameter "
"lg must be either GlobalIndices or LocalIndicies.");
const map_type& cmap = *colMap_;
size_t numFiltered = 0;
#ifdef HAVE_TPETRA_DEBUG
size_t numFiltered_debug = 0;
#endif
if (lg == GlobalIndices) {
ArrayView<GlobalOrdinal> ginds = inds.ginds;
typename ArrayView<GlobalOrdinal>::iterator fend = ginds.begin();
typename ArrayView<GlobalOrdinal>::iterator cptr = ginds.begin();
while (cptr != ginds.end()) {
if (cmap.isNodeGlobalElement(*cptr)) {
*fend++ = *cptr;
#ifdef HAVE_TPETRA_DEBUG
++numFiltered_debug;
#endif
}
++cptr;
}
numFiltered = fend - ginds.begin();
}
else if (lg == LocalIndices) {
ArrayView<LocalOrdinal> linds = inds.linds;
typename ArrayView<LocalOrdinal>::iterator fend = linds.begin();
typename ArrayView<LocalOrdinal>::iterator cptr = linds.begin();
while (cptr != linds.end()) {
if (cmap.isNodeLocalElement(*cptr)) {
*fend++ = *cptr;
#ifdef HAVE_TPETRA_DEBUG
++numFiltered_debug;
#endif
}
++cptr;
}
numFiltered = fend - linds.begin();
}
#ifdef HAVE_TPETRA_DEBUG
TEUCHOS_TEST_FOR_EXCEPT( numFiltered != numFiltered_debug );
#endif
return numFiltered;
}
template<class T>
size_t
filterGlobalIndicesAndValues (const Teuchos::ArrayView<GlobalOrdinal>& ginds,
const Teuchos::ArrayView<T>& vals) const
{
using Teuchos::ArrayView;
const map_type& cmap = *colMap_;
size_t numFiltered = 0;
typename ArrayView<T>::iterator fvalsend = vals.begin();
typename ArrayView<T>::iterator valscptr = vals.begin();
#ifdef HAVE_TPETRA_DEBUG
size_t numFiltered_debug = 0;
#endif
typename ArrayView<GlobalOrdinal>::iterator fend = ginds.begin();
typename ArrayView<GlobalOrdinal>::iterator cptr = ginds.begin();
while (cptr != ginds.end()) {
if (cmap.isNodeGlobalElement (*cptr)) {
*fend++ = *cptr;
*fvalsend++ = *valscptr;
#ifdef HAVE_TPETRA_DEBUG
++numFiltered_debug;
#endif
}
++cptr;
++valscptr;
}
numFiltered = fend - ginds.begin();
#ifdef HAVE_TPETRA_DEBUG
TEUCHOS_TEST_FOR_EXCEPT( numFiltered != numFiltered_debug );
TEUCHOS_TEST_FOR_EXCEPT( valscptr != vals.end() );
const size_t numFilteredActual =
static_cast<size_t> (fvalsend - vals.begin ());
TEUCHOS_TEST_FOR_EXCEPT( numFiltered != numFilteredActual );
#endif // HAVE_TPETRA_DEBUG
return numFiltered;
}
template<class T>
size_t
filterLocalIndicesAndValues (const Teuchos::ArrayView<LocalOrdinal>& linds,
const Teuchos::ArrayView<T>& vals) const
{
using Teuchos::ArrayView;
const map_type& cmap = *colMap_;
size_t numFiltered = 0;
typename ArrayView<T>::iterator fvalsend = vals.begin();
typename ArrayView<T>::iterator valscptr = vals.begin();
#ifdef HAVE_TPETRA_DEBUG
size_t numFiltered_debug = 0;
#endif
typename ArrayView<LocalOrdinal>::iterator fend = linds.begin();
typename ArrayView<LocalOrdinal>::iterator cptr = linds.begin();
while (cptr != linds.end()) {
if (cmap.isNodeLocalElement (*cptr)) {
*fend++ = *cptr;
*fvalsend++ = *valscptr;
#ifdef HAVE_TPETRA_DEBUG
++numFiltered_debug;
#endif
}
++cptr;
++valscptr;
}
numFiltered = fend - linds.begin();
#ifdef HAVE_TPETRA_DEBUG
TEUCHOS_TEST_FOR_EXCEPT( numFiltered != numFiltered_debug );
TEUCHOS_TEST_FOR_EXCEPT( valscptr != vals.end() );
const size_t numFilteredActual =
Teuchos::as<size_t> (fvalsend - vals.begin ());
TEUCHOS_TEST_FOR_EXCEPT( numFiltered != numFilteredActual );
#endif
return numFiltered;
}
/// \brief Insert indices into the given row.
///
/// \pre <tt>! (lg == LocalIndices && I == GlobalIndices)</tt>.
/// It does not make sense to give this method local column
/// indices (meaning that the graph has a column Map), yet to
/// ask it to store global indices.
///
/// \param rowInfo [in] Result of CrsGraph's getRowInfo() or
/// updateAllocAndValues() methods, for the locally owned row
/// (whose local index is <tt>rowInfo.localRow</tt>) for which
/// you want to insert indices.
///
/// \param newInds [in] View of the column indices to insert. If
/// <tt>lg == GlobalIndices</tt>, then newInds.ginds, a
/// <tt>Teuchos::ArrayView<const GlobalOrdinal></tt>, contains
/// the (global) column indices to insert. Otherwise, if <tt>lg
/// == LocalIndices</tt>, then newInds.linds, a
/// <tt>Teuchos::ArrayView<const LocalOrdinal></tt>, contains
/// the (local) column indices to insert.
///
/// \param lg If <tt>lg == GlobalIndices</tt>, then the input
/// indices (in \c newInds) are global indices. Otherwise, if
/// <tt>lg == LocalIndices</tt>, the input indices are local
/// indices.
///
/// \param I If <tt>lg == GlobalIndices</tt>, then this method
/// will store the input indices as global indices. Otherwise,
/// if <tt>I == LocalIndices</tt>, this method will store the
/// input indices as local indices.
size_t
insertIndices (const RowInfo& rowInfo,
const SLocalGlobalViews& newInds,
const ELocalGlobal lg,
const ELocalGlobal I);
/// \brief Insert indices and their values into the given row.
///
/// \tparam Scalar The type of a single value. When this method
/// is called by CrsMatrix, \c Scalar corresponds to the first
/// template parameter of CrsMatrix.
///
/// \pre <tt>! (lg == LocalIndices && I == GlobalIndices)</tt>.
/// It does not make sense to give this method local column
/// indices (meaning that the graph has a column Map), yet to
/// ask it to store global indices.
///
/// \param rowInfo [in] Result of CrsGraph's getRowInfo() or
/// updateAllocAndValues() methods, for the locally owned row
/// (whose local index is <tt>rowInfo.localRow</tt>) for which
/// you want to insert indices.
///
/// \param newInds [in] View of the column indices to insert. If
/// <tt>lg == GlobalIndices</tt>, then newInds.ginds, a
/// <tt>Teuchos::ArrayView<const GlobalOrdinal></tt>, contains
/// the (global) column indices to insert. Otherwise, if <tt>lg
/// == LocalIndices</tt>, then newInds.linds, a
/// <tt>Teuchos::ArrayView<const LocalOrdinal></tt>, contains
/// the (local) column indices to insert.
///
/// \param oldRowVals [out] View of the current values. They will
/// be overwritten with the new values.
///
/// \param newRowVals [in] View of the new values. They will be
/// copied over the old values.
///
/// \param lg If <tt>lg == GlobalIndices</tt>, then the input
/// indices (in \c newInds) are global indices. Otherwise, if
/// <tt>lg == LocalIndices</tt>, the input indices are local
/// indices.
///
/// \param I If <tt>lg == GlobalIndices</tt>, then this method
/// will store the input indices as global indices. Otherwise,
/// if <tt>I == LocalIndices</tt>, this method will store the
/// input indices as local indices.
template<class Scalar>
void
insertIndicesAndValues (const RowInfo& rowInfo,
const SLocalGlobalViews& newInds,
const Teuchos::ArrayView<Scalar>& oldRowVals,
const Teuchos::ArrayView<const Scalar>& newRowVals,
const ELocalGlobal lg,
const ELocalGlobal I);
void
insertGlobalIndicesImpl (const LocalOrdinal myRow,
const Teuchos::ArrayView<const GlobalOrdinal> &indices);
void
insertLocalIndicesImpl (const LocalOrdinal myRow,
const Teuchos::ArrayView<const LocalOrdinal> &indices);
//! Like insertLocalIndices(), but with column Map filtering.
void
insertLocalIndicesFiltered (const LocalOrdinal localRow,
const Teuchos::ArrayView<const LocalOrdinal> &indices);
//! Like insertGlobalIndices(), but with column Map filtering.
void
insertGlobalIndicesFiltered (const GlobalOrdinal localRow,
const Teuchos::ArrayView<const GlobalOrdinal> &indices);
/// \brief Transform the given values using local indices.
///
/// \param rowInfo [in] Information about a given row of the graph.
///
/// \param rowVals [in/out] The values to be transformed. They
/// correspond to the row indicated by rowInfo.
///
/// \param inds [in] The (local) indices in the row, for which
/// to transform the corresponding values in rowVals.
///
/// \param newVals [in] Values to use for transforming rowVals.
/// It's probably OK for these to alias rowVals.
///
/// \param f [in] A binary function used to transform rowVals.
///
/// This method transforms the values using the expression
/// \code
/// newVals[k] = f( rowVals[k], newVals[j] );
/// \endcode
/// where k is the local index corresponding to
/// <tt>inds[j]</tt>. It ignores elements of \c inds that are
/// not owned by the calling process.
///
/// \return The number of valid local column indices. In case of
/// error other than one or more invalid column indices, this
/// method returns
/// Teuchos::OrdinalTraits<LocalOrdinal>::invalid().
template<class Scalar, class BinaryFunction>
LocalOrdinal
transformLocalValues (RowInfo rowInfo,
const Teuchos::ArrayView<Scalar>& rowVals,
const Teuchos::ArrayView<const LocalOrdinal>& inds,
const Teuchos::ArrayView<const Scalar>& newVals,
BinaryFunction f) const
{
typedef typename Teuchos::ArrayView<Scalar>::size_type size_type;
const size_t STINV = Teuchos::OrdinalTraits<size_t>::invalid ();
const size_type numElts = inds.size ();
size_t hint = 0; // Guess for the current index k into rowVals
// Get a view of the column indices in the row. This amortizes
// the cost of getting the view over all the entries of inds.
Teuchos::ArrayView<const LocalOrdinal> colInds = getLocalView (rowInfo);
LocalOrdinal numValid = 0; // number of valid local column indices
for (size_type j = 0; j < numElts; ++j) {
const size_t k = findLocalIndex (rowInfo, inds[j], colInds, hint);
if (k != STINV) {
rowVals[k] = f (rowVals[k], newVals[j]); // use binary function f
hint = k+1;
++numValid;
}
}
return numValid;
}
/// \brief Transform the given values using global indices.
///
/// \param rowInfo [in] Information about a given row of the graph.
///
/// \param rowVals [in/out] The values to be transformed. They
/// correspond to the row indicated by rowInfo.
///
/// \param inds [in] The (global) indices in the row, for which
/// to transform the corresponding values in rowVals.
///
/// \param newVals [in] Values to use for transforming rowVals.
/// It's probably OK for these to alias rowVals.
///
/// \param f [in] A binary function used to transform rowVals.
///
/// \return The number of valid local column indices. In case of
/// error other than one or more invalid column indices, this
/// method returns
/// Teuchos::OrdinalTraits<LocalOrdinal>::invalid().
template<class Scalar, class BinaryFunction>
LocalOrdinal
transformGlobalValues (RowInfo rowInfo,
const Teuchos::ArrayView<Scalar>& rowVals,
const Teuchos::ArrayView<const GlobalOrdinal>& inds,
const Teuchos::ArrayView<const Scalar>& newVals,
BinaryFunction f) const
{
typedef typename Teuchos::ArrayView<Scalar>::size_type size_type;
const size_t STINV = Teuchos::OrdinalTraits<size_t>::invalid ();
const size_type numElts = inds.size ();
size_t hint = 0; // guess at the index's relative offset in the row
LocalOrdinal numValid = 0; // number of valid local column indices
for (size_type j = 0; j < numElts; ++j) {
const size_t k = findGlobalIndex (rowInfo, inds[j], hint);
if (k != STINV) {
rowVals[k] = f (rowVals[k], newVals[j]); // use binary function f
hint = k+1;
numValid++;
}
}
return numValid;
}
//@}
//! \name Methods for sorting and merging column indices.
//@{
//! Whether duplicate column indices in each row have been merged.
bool isMerged () const;
/// \brief Report that we made a local modification to its structure.
///
/// Call this after making a local change to the graph's
/// structure. Changing the structure locally invalidates the "is
/// sorted" and "is merged" states.
void setLocallyModified ();
//! Sort the column indices in all the rows.
void sortAllIndices ();
//! Sort the column indices in the given row.
void sortRowIndices (const RowInfo rowinfo);
/// \brief Sort the column indices and their values in the given row.
///
/// \tparam Scalar The type of the values. When calling this
/// method from CrsMatrix, this should be the same as the
/// <tt>Scalar</tt> template parameter of CrsMatrix.
///
/// \param rowinfo [in] Result of getRowInfo() for the row.
///
/// \param values [in/out] On input: values for the given row. If
/// indices is an array of the column indices in the row, then
/// values and indices should have the same number of entries,
/// and indices[k] should be the column index corresponding to
/// values[k]. On output: the same values, but sorted in the
/// same order as the (now sorted) column indices in the row.
template <class Scalar>
void sortRowIndicesAndValues (const RowInfo rowinfo,
const Teuchos::ArrayView<Scalar>& values);
/// \brief Merge duplicate row indices in all of the rows.
///
/// \pre The graph is locally indexed:
/// <tt>isGloballyIndexed() == false</tt>.
///
/// \pre The graph has not already been merged: <tt>isMerged()
/// == false</tt>. That is, this function would normally only
/// be called after calling sortIndices().
void mergeAllIndices ();
/// \brief Merge duplicate row indices in the given row.
///
/// \pre The graph is not already storage optimized:
/// <tt>isStorageOptimized() == false</tt>
void mergeRowIndices (RowInfo rowinfo);
/// \brief Merge duplicate row indices in the given row, along
/// with their corresponding values.
///
/// This method is only called by CrsMatrix, for a CrsMatrix whose
/// graph is this CrsGraph instance. It is only called when the
/// matrix owns the graph, not when the matrix was constructed
/// with a const graph.
///
/// \pre The graph is not already storage optimized:
/// <tt>isStorageOptimized() == false</tt>
template<class Scalar>
void
mergeRowIndicesAndValues (RowInfo rowinfo,
const Teuchos::ArrayView<Scalar>& rowValues);
//@}
/// Set the domain and range Maps, and invalidate the Import
/// and/or Export objects if necessary.
///
/// If the domain Map has changed, invalidate the Import object
/// (if there is one). Likewise, if the range Map has changed,
/// invalidate the Export object (if there is one).
///
/// \param domainMap [in] The new domain Map
/// \param rangeMap [in] The new range Map
void
setDomainRangeMaps (const Teuchos::RCP<const map_type>& domainMap,
const Teuchos::RCP<const map_type>& rangeMap);
void staticAssertions() const;
void clearGlobalConstants();
void computeGlobalConstants();
/// \brief Get information about the locally owned row with local
/// index myRow.
RowInfo getRowInfo (const size_t myRow) const;
/// \brief Get a const, nonowned, locally indexed view of the
/// locally owned row myRow, such that rowinfo =
/// getRowInfo(myRow).
Teuchos::ArrayView<const LocalOrdinal>
getLocalView (const RowInfo rowinfo) const;
/// \brief Get a nonconst, nonowned, locally indexed view of the
/// locally owned row myRow, such that rowinfo =
/// getRowInfo(myRow).
Teuchos::ArrayView<LocalOrdinal>
getLocalViewNonConst (const RowInfo rowinfo);
/// \brief Get a const, nonowned, globally indexed view of the
/// locally owned row myRow, such that rowinfo =
/// getRowInfo(myRow).
Teuchos::ArrayView<const GlobalOrdinal>
getGlobalView (const RowInfo rowinfo) const;
/// \brief Get a nonconst, nonowned, globally indexed view of the
/// locally owned row myRow, such that rowinfo =
/// getRowInfo(myRow).
Teuchos::ArrayView<GlobalOrdinal>
getGlobalViewNonConst (const RowInfo rowinfo);
/// \brief Find the column offset corresponding to the given
/// (local) column index.
///
/// The name of this method is a bit misleading. It does not
/// actually find the column index. Instead, it takes a local
/// column index \c ind, and returns the corresponding offset
/// into the raw array of column indices (whether that be 1-D or
/// 2-D storage).
///
/// \param rowinfo [in] Result of getRowInfo() for the given row.
/// \param ind [in] (Local) column index for which to find the offset.
/// \param hint [in] Hint for where to find \c ind in the column
/// indices for the given row. If colInds is the ArrayView of
/// the (local) column indices for the given row, and if
/// <tt>colInds[hint] == ind</tt>, then the hint is correct.
/// The hint is ignored if it is out of range (that is,
/// greater than or equal to the number of entries in the
/// given row).
///
/// The hint optimizes for the case of calling this method several
/// times with the same row (as it would be in
/// transformLocalValues) when several index inputs occur in
/// consecutive sequence. This may occur (for example) when there
/// are multiple degrees of freedom per mesh point, and users are
/// handling the assignment of degrees of freedom to global
/// indices manually (rather than letting some other class take
/// care of it). In that case, users might choose to assign the
/// degrees of freedom for a mesh point to consecutive global
/// indices. Epetra implements the hint for this reason.
///
/// The hint only costs two comparisons (one to check range, and
/// the other to see if the hint was correct), and it can save
/// searching for the indices (which may take a lot more than
/// two comparisons).
size_t
findLocalIndex (RowInfo rowinfo,
LocalOrdinal ind,
size_t hint = 0) const;
/// Find the column offset corresponding to the given (local)
/// column index, given a view of the (local) column indices.
///
/// The name of this method is a bit misleading. It does not
/// actually find the column index. Instead, it takes a local
/// column index \c ind, and returns the corresponding offset
/// into the raw array of column indices (whether that be 1-D or
/// 2-D storage).
///
/// It is best to use this method if you plan to call it several
/// times for the same row, like in transformLocalValues(). In
/// that case, it amortizes the overhead of calling
/// getLocalView().
///
/// \param rowinfo [in] Result of getRowInfo() for the given row.
/// \param ind [in] (Local) column index for which to find the offset.
/// \param colInds [in] View of all the (local) column indices
/// for the given row.
/// \param hint [in] Hint for where to find \c ind in the column
/// indices for the given row. If colInds is the ArrayView of
/// the (local) column indices for the given row, and if
/// <tt>colInds[hint] == ind</tt>, then the hint is correct.
/// The hint is ignored if it is out of range (that is,
/// greater than or equal to the number of entries in the
/// given row).
///
/// See the documentation of the three-argument version of this
/// method for an explanation and justification of the hint.
size_t
findLocalIndex (RowInfo rowinfo,
LocalOrdinal ind,
Teuchos::ArrayView<const LocalOrdinal> colInds,
size_t hint = 0) const;
/// \brief Find the column offset corresponding to the given
/// (global) column index.
///
/// The name of this method is a bit misleading. It does not
/// actually find the column index. Instead, it takes a global
/// column index \c ind, and returns the corresponding offset
/// into the raw array of column indices (whether that be 1-D or
/// 2-D storage).
size_t findGlobalIndex (RowInfo rowinfo, GlobalOrdinal ind, size_t hint = 0) const;
/// \brief Get the local graph.
///
/// This is only a valid representation of the local graph if the
/// (global) graph is fill complete.
local_graph_type getLocalGraph () const;
//! Get the local graph (DEPRECATED: call getLocalGraph() instead).
TPETRA_DEPRECATED local_graph_type getLocalGraph_Kokkos () const;
void fillLocalGraph (const Teuchos::RCP<Teuchos::ParameterList>& params);
//! Whether it is correct to call getRowInfo().
bool hasRowInfo () const;
//! Throw an exception if the internal state is not consistent.
void checkInternalState () const;
//! The Map describing the distribution of rows of the graph.
Teuchos::RCP<const map_type> rowMap_;
//! The Map describing the distribution of columns of the graph.
Teuchos::RCP<const map_type> colMap_;
//! The Map describing the range of the (matrix corresponding to the) graph.
Teuchos::RCP<const map_type> rangeMap_;
//! The Map describing the domain of the (matrix corresponding to the) graph.
Teuchos::RCP<const map_type> domainMap_;
/// \brief The Import from the domain Map to the column Map.
///
/// This gets constructed by fillComplete. It may be null if
/// the domain Map and the column Map are the same, since no
/// Import is necessary in that case for sparse matrix-vector
/// multiply.
Teuchos::RCP<const import_type> importer_;
/// \brief The Export from the row Map to the range Map.
///
/// This gets constructed by fillComplete. It may be null if
/// the row Map and the range Map are the same, since no Export
/// is necessary in that case for sparse matrix-vector multiply.
Teuchos::RCP<const export_type> exporter_;
//! Local graph; only initialized after first fillComplete() call.
local_graph_type lclGraph_;
// Local and Global Counts
// nodeNumEntries_ and nodeNumAllocated_ are required to be always consistent
// nodeMaxNumEntries_, nodeNumDiags_ and the global quantities are computed during fillComplete() and only valid when isFillComplete()
global_size_t globalNumEntries_, globalNumDiags_, globalMaxNumRowEntries_;
size_t nodeNumEntries_, nodeNumDiags_, nodeMaxNumRowEntries_, nodeNumAllocated_;
//! Whether the graph was allocated with static or dynamic profile.
ProfileType pftype_;
/// \brief The maximum number of entries to allow in each locally
/// owned row, per row.
///
/// This is an argument to some of the graph's constructors.
/// Either this or numAllocForAllRows_ is used, but not both.
/// allocateIndices, setAllIndices, and expertStaticFillComplete
/// all deallocate this array once they are done with it.
///
/// This array <i>only</i> exists on a process before the graph's
/// indices are allocated on that process. After that point, it
/// is discarded, since the graph's allocation implicitly or
/// explicitly represents the same information.
///
/// FIXME (mfh 07 Aug 2014) We want graph's constructors to
/// allocate, rather than doing lazy allocation at first insert.
/// This will make both k_numAllocPerRow_ and numAllocForAllRows_
/// obsolete.
Kokkos::DualView<const size_t*, Kokkos::LayoutLeft, execution_space> k_numAllocPerRow_;
/// \brief The maximum number of entries to allow in each locally owned row.
///
/// This is an argument to some of the graph's constructors.
/// Either this or k_numAllocPerRow_ is used, but not both.
///
/// FIXME (mfh 07 Aug 2014) We want graph's constructors to
/// allocate, rather than doing lazy allocation at first insert.
/// This will make both k_numAllocPerRow_ and numAllocForAllRows_
/// obsolete.
size_t numAllocForAllRows_;
//! \name 1-D storage (StaticProfile) data structures
//@{
/// \brief Local column indices for all rows.
///
/// This is only allocated if
///
/// - The calling process has a nonzero number of entries
/// - The graph has StaticProfile (1-D storage)
/// - The graph is locally indexed
typename local_graph_type::entries_type::non_const_type k_lclInds1D_;
//! Type of the k_gblInds1D_ array of global column indices.
typedef Kokkos::View<GlobalOrdinal*, execution_space> t_GlobalOrdinal_1D;
/// \brief Global column indices for all rows.
///
/// This is only allocated if
///
/// - The calling process has a nonzero number of entries
/// - The graph has StaticProfile (1-D storage)
/// - The graph is globally indexed
t_GlobalOrdinal_1D k_gblInds1D_;
/// \brief Row offsets for "1-D" storage.
///
/// This is only allocated if "1-D" (StaticProfile) storage is
/// active. In that case, if beg = k_rowPtrs_(i_lcl) and end =
/// k_rowPtrs_(i_lcl+1) for local row index i_lcl, then
///
/// - if the graph is locally indexed, k_lclInds1D_(beg:end-1)
/// (inclusive range) is the space for any local column
/// indices in local row i_lcl, else
/// - if the graph is globally indexed, k_gblInds1D_(beg:end-1)
/// (inclusive range) is the space for any global column
/// indices in local row i_lcl.
///
/// Only the first k_numRowEntries_(i_lcl) of these entries are
/// actual valid column indices. Any remaining entries are "extra
/// space." If the graph's storage is packed, then there is no
/// extra space, and the k_numRowEntries_ array is invalid.
///
/// Both the k_rowPtrs_ and k_numRowEntries_ arrays are not
/// allocated if the graph has 2-D (DynamicProfile) storage.
///
/// If it is allocated, k_rowPtrs_ has length getNodeNumRows()+1.
/// The k_numRowEntries_ array has has length getNodeNumRows(),
/// again if it is allocated.
///
/// [we may delete this to save memory on fillComplete, if "Delete
/// Row Pointers" is specified.]
typename local_graph_type::row_map_type::const_type k_rowPtrs_;
//@}
/// \name 2-D storage (DynamicProfile) data structures
///
/// 2-D storage exists only if the graph was allocated with
/// DynamicProfile. All of these data structures exist in host
/// memory. Currently, NONE of them are thread safe, let alone
/// thread scalable. These data structures only exist to support
/// legacy use cases. At some point, we may add a thread-scalable
/// intermediate level of "dynamicity" between 2-D storage and 1-D
/// storage (StaticProfile), which bounds the <i>total</i> number
/// of entries allowed per process, but does <i>not</i> otherwise
/// bound the number of entries per row.
//@{
/// \brief Local column indices for all rows.
///
/// This is only allocated if
///
/// - The calling process has a nonzero number of entries
/// - The graph has DynamicProfile (2-D storage)
/// - The graph is locally indexed
///
/// In that case, if i_lcl is the local index of a locally owned
/// row, then lclInds2D_[i_lcl] stores the local column indices
/// for that row.
Teuchos::ArrayRCP<Teuchos::Array<LocalOrdinal> > lclInds2D_;
/// \brief Global column indices for all rows.
///
/// This is only allocated if
///
/// - The calling process has a nonzero number of entries
/// - The graph has DynamicProfile (2-D storage)
/// - The graph is globally indexed
///
/// In that case, if i_gbl is the global index of a globally owned
/// row, then gblInds2D_[i_gbl] stores the global column indices
/// for that row.
Teuchos::ArrayRCP<Teuchos::Array<GlobalOrdinal> > gblInds2D_;
typedef Kokkos::DualView<size_t*, Kokkos::LayoutLeft, execution_space> t_numRowEntries_;
/// \brief The number of local entries in each locally owned row.
///
/// This is deallocated in fillComplete() if fillComplete()'s
/// "Optimize Storage" parameter is set to \c true.
///
/// This may also exist with 1-D storage, if storage is unpacked.
t_numRowEntries_ k_numRowEntries_;
//@}
/// \brief Status of the graph's storage, when not in a
/// fill-complete state.
///
/// The phrase "When not in a fill-complete state" is important.
/// When the graph is fill complete, it <i>always</i> uses 1-D
/// "packed" storage. However, if the "Optimize Storage"
/// parameter to fillComplete was false, the graph may keep
/// unpacked 1-D or 2-D storage around and resume it on the next
/// resumeFill call.
Details::EStorageStatus storageStatus_;
bool indicesAreAllocated_;
bool indicesAreLocal_;
bool indicesAreGlobal_;
bool fillComplete_;
//! Whether the graph is locally lower triangular.
bool lowerTriangular_;
//! Whether the graph is locally upper triangular.
bool upperTriangular_;
//! Whether the graph's indices are sorted in each row, on this process.
bool indicesAreSorted_;
/// \brief Whether the graph's indices are non-redundant (merged)
/// in each row, on this process.
bool noRedundancies_;
//! Whether this process has computed local constants.
bool haveLocalConstants_;
//! Whether all processes have computed global constants.
bool haveGlobalConstants_;
//! Nonlocal data given to insertGlobalValues or sumIntoGlobalValues.
std::map<GlobalOrdinal, std::vector<GlobalOrdinal> > nonlocals_;
/// \brief Whether to require makeColMap() (and therefore
/// fillComplete()) to order column Map GIDs associated with
/// each remote process in ascending order.
///
/// makeColMap() always groups remote GIDs by process rank, so
/// that all remote GIDs with the same owning rank occur
/// contiguously. By default, it always sorts remote GIDs in
/// increasing order within those groups. This behavior differs
/// from Epetra, which does not sort remote GIDs with the same
/// owning process.
///
/// This is \c true by default, which means "sort remote GIDs."
/// If you don't want to sort (for compatibility with Epetra),
/// call sortGhostColumnGIDsWithinProcessBlock(false).
bool sortGhostsAssociatedWithEachProcessor_;
}; // class CrsGraph
/// \brief Nonmember function to create an empty CrsGraph given a
/// row Map and the max number of entries allowed locally per row.
///
/// \return A dynamically allocated (DynamicProfile) graph with
/// specified number of nonzeros per row (defaults to zero).
/// \relatesalso CrsGraph
template <class LocalOrdinal, class GlobalOrdinal, class Node, const bool classic = Node::classic>
Teuchos::RCP<CrsGraph<LocalOrdinal, GlobalOrdinal, Node, classic> >
createCrsGraph (const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &map,
size_t maxNumEntriesPerRow = 0,
const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null)
{
using Teuchos::rcp;
typedef CrsGraph<LocalOrdinal, GlobalOrdinal, Node, classic> graph_type;
return rcp (new graph_type (map, maxNumEntriesPerRow, DynamicProfile, params));
}
namespace Details {
template<class LocalOrdinal,
class GlobalOrdinal,
class OutputNodeType,
class InputNodeType>
class CrsGraphCopier<CrsGraph<LocalOrdinal, GlobalOrdinal, OutputNodeType>,
CrsGraph<LocalOrdinal, GlobalOrdinal, InputNodeType> > {
public:
typedef CrsGraph<LocalOrdinal, GlobalOrdinal, InputNodeType> input_crs_graph_type;
typedef CrsGraph<LocalOrdinal, GlobalOrdinal, OutputNodeType> output_crs_graph_type;
static Teuchos::RCP<output_crs_graph_type>
clone (const input_crs_graph_type& graphIn,
const Teuchos::RCP<OutputNodeType> &nodeOut,
const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null)
{
using Teuchos::arcp;
using Teuchos::ArrayRCP;
using Teuchos::ArrayView;
using Teuchos::null;
using Teuchos::outArg;
using Teuchos::ParameterList;
using Teuchos::parameterList;
using Teuchos::RCP;
using Teuchos::rcp;
using Teuchos::REDUCE_MIN;
using Teuchos::reduceAll;
using Teuchos::sublist;
using std::cerr;
using std::endl;
typedef LocalOrdinal LO;
typedef GlobalOrdinal GO;
typedef typename ArrayView<const GO>::size_type size_type;
typedef ::Tpetra::Map<LO, GO, InputNodeType> input_map_type;
typedef ::Tpetra::Map<LO, GO, OutputNodeType> output_map_type;
const char prefix[] = "Tpetra::Details::CrsGraphCopier::clone: ";
// Set parameters' default values.
bool debug = false;
bool fillCompleteClone = true;
bool useLocalIndices = graphIn.hasColMap ();
ProfileType pftype = StaticProfile;
// If the user provided a ParameterList, get values from there.
if (! params.is_null ()) {
fillCompleteClone = params->get ("fillComplete clone", fillCompleteClone);
useLocalIndices = params->get ("Locally indexed clone", useLocalIndices);
if (params->get ("Static profile clone", true) == false) {
pftype = DynamicProfile;
}
debug = params->get ("Debug", debug);
}
const Teuchos::Comm<int>& comm = * (graphIn.getRowMap ()->getComm ());
const int myRank = comm.getRank ();
TEUCHOS_TEST_FOR_EXCEPTION(
! graphIn.hasColMap () && useLocalIndices, std::runtime_error,
prefix << "You asked clone() to use local indices (by setting the "
"\"Locally indexed clone\" parameter to true), but the source graph "
"does not yet have a column Map, so this is impossible.");
if (debug) {
std::ostringstream os;
os << "Process " << myRank << ": Cloning row Map" << endl;
cerr << os.str ();
}
RCP<const output_map_type> clonedRowMap =
graphIn.getRowMap ()->template clone<OutputNodeType> (nodeOut);
// Invoke the output graph's constructor, using the input graph's
// upper bounds on the number of entries in each local row.
RCP<output_crs_graph_type> clonedGraph; // returned by this function
{
ArrayRCP<const size_t> numEntriesPerRow;
size_t numEntriesForAll = 0;
bool boundSameForAllLocalRows = true;
if (debug) {
std::ostringstream os;
os << "Process " << myRank << ": Getting per-row bounds" << endl;
cerr << os.str ();
}
graphIn.getNumEntriesPerLocalRowUpperBound (numEntriesPerRow,
numEntriesForAll,
boundSameForAllLocalRows);
if (debug) {
std::ostringstream os;
os << "Process " << myRank << ": numEntriesForAll = "
<< numEntriesForAll << endl;
cerr << os.str ();
}
if (debug) {
std::ostringstream os;
os << "Process " << myRank << ": graphIn.getNodeMaxNumRowEntries() = "
<< graphIn.getNodeMaxNumRowEntries () << endl;
cerr << os.str ();
}
RCP<ParameterList> graphparams;
if (params.is_null ()) {
graphparams = parameterList ("CrsGraph");
} else {
graphparams = sublist (params, "CrsGraph");
}
if (useLocalIndices) {
RCP<const output_map_type> clonedColMap =
graphIn.getColMap ()->template clone<OutputNodeType> (nodeOut);
if (boundSameForAllLocalRows) {
clonedGraph = rcp (new output_crs_graph_type (clonedRowMap, clonedColMap,
numEntriesForAll, pftype,
graphparams));
} else {
clonedGraph = rcp (new output_crs_graph_type (clonedRowMap, clonedColMap,
numEntriesPerRow, pftype,
graphparams));
}
} else {
if (boundSameForAllLocalRows) {
clonedGraph = rcp (new output_crs_graph_type (clonedRowMap,
numEntriesForAll, pftype,
graphparams));
} else {
clonedGraph = rcp (new output_crs_graph_type (clonedRowMap,
numEntriesPerRow,
pftype, graphparams));
}
}
if (debug) {
std::ostringstream os;
os << "Process " << myRank << ": Invoked output graph's constructor" << endl;
cerr << os.str ();
}
// done with these
numEntriesPerRow = null;
numEntriesForAll = 0;
}
const input_map_type& inputRowMap = * (graphIn.getRowMap ());
const size_type numRows =
static_cast<size_type> (inputRowMap.getNodeNumElements ());
bool failed = false;
if (useLocalIndices) {
const LO localMinLID = inputRowMap.getMinLocalIndex ();
const LO localMaxLID = inputRowMap.getMaxLocalIndex ();
if (graphIn.isLocallyIndexed ()) {
if (numRows != 0) {
try {
ArrayView<const LO> linds;
for (LO lrow = localMinLID; lrow <= localMaxLID; ++lrow) {
graphIn.getLocalRowView (lrow, linds);
if (linds.size () != 0) {
clonedGraph->insertLocalIndices (lrow, linds);
}
}
}
catch (std::exception& e) {
std::ostringstream os;
os << "Process " << myRank << ": copying (reading local by view, "
"writing local) indices into the output graph threw an "
"exception: " << e.what () << endl;
cerr << os.str ();
failed = true;
}
}
}
else { // graphIn.isGloballyIndexed()
TEUCHOS_TEST_FOR_EXCEPTION(
! graphIn.hasColMap () && useLocalIndices, std::invalid_argument,
prefix << "You asked clone() to use local indices (by setting the "
"\"Locally indexed clone\" parameter to true), but the source graph "
"does not yet have a column Map, so this is impossible.");
// The input graph has a column Map, but is globally indexed.
// That's a bit weird, but we'll run with it. In this case,
// getLocalRowView won't work, but getLocalRowCopy should
// still work; it will just have to convert from global to
// local indices internally.
try {
// Make space for getLocalRowCopy to put column indices.
//
// This is only a hint; we may have to resize in the loop
// below. getNodeMaxNumRowEntries() may return nonsense if
// fill is active. The key bool in CrsGraph is
// haveLocalConstants_.
size_t myMaxNumRowEntries =
graphIn.isFillActive () ? static_cast<size_t> (0) :
graphIn.getNodeMaxNumRowEntries ();
Array<LO> linds (myMaxNumRowEntries);
// Copy each row into the new graph, using local indices.
for (LO lrow = localMinLID; lrow <= localMaxLID; ++lrow) {
size_t theNumEntries = graphIn.getNumEntriesInLocalRow (lrow);
if (theNumEntries > myMaxNumRowEntries) {
myMaxNumRowEntries = theNumEntries;
linds.resize (myMaxNumRowEntries);
}
graphIn.getLocalRowCopy (lrow, linds (), theNumEntries);
if (theNumEntries != 0) {
clonedGraph->insertLocalIndices (lrow, linds (0, theNumEntries));
}
}
}
catch (std::exception& e) {
std::ostringstream os;
os << "Process " << myRank << ": copying (reading local by copy, "
"writing local) indices into the output graph threw an exception: "
<< e.what () << endl;
cerr << os.str ();
failed = true;
}
}
}
else { /* useGlobalIndices */
if (numRows != 0) {
const GlobalOrdinal localMinGID = inputRowMap.getMinGlobalIndex ();
const GlobalOrdinal localMaxGID = inputRowMap.getMaxGlobalIndex ();
const bool inputRowMapIsContiguous = inputRowMap.isContiguous ();
if (graphIn.isGloballyIndexed ()) {
ArrayView<const GlobalOrdinal> ginds;
if (inputRowMapIsContiguous) {
try {
for (GO grow = localMinGID; grow <= localMaxGID; ++grow) {
graphIn.getGlobalRowView (grow, ginds);
if (ginds.size () != 0) {
clonedGraph->insertGlobalIndices (grow, ginds);
}
}
}
catch (std::exception& e) {
std::ostringstream os;
os << "Process " << myRank << ": copying (reading global by view, "
"writing global) indices into the output graph threw an "
"exception: " << e.what () << endl;
cerr << os.str ();
failed = true;
}
}
else { // input row Map is not contiguous
try {
ArrayView<const GO> inputRowMapGIDs = inputRowMap.getNodeElementList ();
for (size_type k = 0; k < numRows; ++k) {
const GO grow = inputRowMapGIDs[k];
graphIn.getGlobalRowView (grow, ginds);
if (ginds.size () != 0) {
clonedGraph->insertGlobalIndices (grow, ginds);
}
}
}
catch (std::exception& e) {
std::ostringstream os;
os << "Process " << myRank << ": copying (reading global by view, "
"writing global) indices into the output graph threw an "
"exception: " << e.what () << endl;
cerr << os.str ();
failed = true;
}
}
}
else { // graphIn.isLocallyIndexed()
// Make space for getGlobalRowCopy to put column indices.
//
// This is only a hint; we may have to resize in the loop
// below. getNodeMaxNumRowEntries() may return nonsense if
// fill is active. The key bool in CrsGraph is
// haveLocalConstants_.
size_t myMaxNumRowEntries =
graphIn.isFillActive () ? static_cast<size_t> (0) :
graphIn.getNodeMaxNumRowEntries ();
Array<GO> ginds (myMaxNumRowEntries);
if (inputRowMapIsContiguous) {
try {
for (GO grow = localMinGID; grow <= localMaxGID; ++grow) {
size_t theNumEntries = graphIn.getNumEntriesInGlobalRow (grow);
if (theNumEntries > myMaxNumRowEntries) {
myMaxNumRowEntries = theNumEntries;
ginds.resize (myMaxNumRowEntries);
}
graphIn.getGlobalRowCopy (grow, ginds (), theNumEntries);
if (theNumEntries != 0) {
clonedGraph->insertGlobalIndices (grow, ginds (0, theNumEntries));
}
}
}
catch (std::exception& e) {
std::ostringstream os;
os << "Process " << myRank << ": copying (reading global by copy, "
"writing global) indices into the output graph threw an "
"exception: " << e.what () << endl;
cerr << os.str ();
failed = true;
}
}
else { // input row Map is not contiguous
try {
ArrayView<const GO> inputRowMapGIDs = inputRowMap.getNodeElementList ();
for (size_type k = 0; k < numRows; ++k) {
const GO grow = inputRowMapGIDs[k];
size_t theNumEntries = graphIn.getNumEntriesInGlobalRow (grow);
if (theNumEntries > myMaxNumRowEntries) {
myMaxNumRowEntries = theNumEntries;
ginds.resize (myMaxNumRowEntries);
}
graphIn.getGlobalRowCopy (grow, ginds (), theNumEntries);
if (theNumEntries != 0) {
clonedGraph->insertGlobalIndices (grow, ginds (0, theNumEntries));
}
}
}
catch (std::exception& e) {
std::ostringstream os;
os << "Process " << myRank << ": copying (reading global by copy, "
"writing global) indices into the output graph threw an "
"exception: " << e.what () << endl;
cerr << os.str ();
failed = true;
}
}
}
} // numRows != 0
}
if (debug) {
std::ostringstream os;
os << "Process " << myRank << ": copied entries" << endl;
cerr << os.str ();
}
if (fillCompleteClone) {
RCP<ParameterList> fillparams = params.is_null () ?
parameterList ("fillComplete") :
sublist (params, "fillComplete");
try {
RCP<const output_map_type> clonedRangeMap;
RCP<const output_map_type> clonedDomainMap;
if (! graphIn.getRangeMap ().is_null () &&
graphIn.getRangeMap () != graphIn.getRowMap ()) {
clonedRangeMap =
graphIn.getRangeMap ()->template clone<OutputNodeType> (nodeOut);
}
else {
clonedRangeMap = clonedRowMap;
}
if (! graphIn.getDomainMap ().is_null ()
&& graphIn.getDomainMap () != graphIn.getRowMap ()) {
clonedDomainMap =
graphIn.getDomainMap ()->template clone<OutputNodeType> (nodeOut);
}
else {
clonedDomainMap = clonedRowMap;
}
if (debug) {
std::ostringstream os;
os << "Process " << myRank << ": About to call fillComplete on "
"cloned graph" << endl;
cerr << os.str ();
}
clonedGraph->fillComplete (clonedDomainMap, clonedRangeMap, fillparams);
}
catch (std::exception &e) {
failed = true;
std::ostringstream os;
os << prefix << "Process " << myRank << ": Caught the following "
"exception while calling fillComplete() on clone of type"
<< endl << Teuchos::typeName (*clonedGraph) << endl;
cerr << os.str ();
}
}
int lclSuccess = failed ? 0 : 1;
int gblSuccess = 1;
reduceAll<int, int> (comm, REDUCE_MIN, lclSuccess, outArg (gblSuccess));
TEUCHOS_TEST_FOR_EXCEPTION(
gblSuccess != 1, std::logic_error, prefix <<
"Clone failed on at least one process.");
if (debug) {
std::ostringstream os;
os << "Process " << myRank << ": Done with CrsGraph::clone" << endl;
cerr << os.str ();
}
return clonedGraph;
}
};
} // namespace Details
} // namespace Tpetra
#endif // TPETRA_CRSGRAPH_DECL_HPP
|