/usr/include/trilinos/Xpetra_EpetraCrsMatrix.hpp is in libtrilinos-xpetra-dev 12.10.1-3.
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 | // @HEADER
//
// ***********************************************************************
//
// Xpetra: A linear algebra interface package
// Copyright 2012 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
// Jonathan Hu (jhu@sandia.gov)
// Andrey Prokopenko (aprokop@sandia.gov)
// Ray Tuminaro (rstumin@sandia.gov)
//
// ***********************************************************************
//
// @HEADER
#ifndef XPETRA_EPETRACRSMATRIX_HPP
#define XPETRA_EPETRACRSMATRIX_HPP
/* this file is automatically generated - do not edit (see script/epetra.py) */
#ifdef HAVE_XPETRA_KOKKOS_REFACTOR
#ifdef HAVE_XPETRA_TPETRA
#include <Kokkos_View.hpp>
#endif
#endif
#include "Xpetra_EpetraConfigDefs.hpp"
#include "Xpetra_CrsMatrix.hpp"
#include <Epetra_CrsMatrix.h>
#include <Epetra_Map.h>
#include "Xpetra_EpetraMap.hpp"
#include "Xpetra_EpetraVector.hpp"
#include "Xpetra_EpetraMultiVector.hpp"
#include "Xpetra_EpetraCrsGraph.hpp"
#include "Xpetra_MapFactory.hpp"
#include "Xpetra_Utils.hpp"
#include "Xpetra_Exceptions.hpp"
namespace Xpetra {
// general implementation: empty stub
template<class EpetraGlobalOrdinal, class Node>
class EpetraCrsMatrixT
: public CrsMatrix<double, int, EpetraGlobalOrdinal, Node>
{
typedef EpetraGlobalOrdinal GlobalOrdinal;
typedef typename CrsMatrix<double, int, GlobalOrdinal, Node>::scalar_type Scalar;
typedef typename CrsMatrix<double, int, GlobalOrdinal, Node>::local_ordinal_type LocalOrdinal;
#ifdef HAVE_XPETRA_KOKKOS_REFACTOR
#ifdef HAVE_XPETRA_TPETRA
typedef typename Xpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>::local_matrix_type local_matrix_type;
typedef typename Xpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>::node_type node_type;
#endif
#endif
public:
EpetraCrsMatrixT(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rowMap, size_t maxNumEntriesPerRow, ProfileType pftype=DynamicProfile, const Teuchos::RCP< Teuchos::ParameterList > ¶ms=Teuchos::null) {
TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::RuntimeError,
"Xpetra::EpetraCrsMatrix only available for GO=int or GO=long long with EpetraNode (Serial or OpenMP depending on configuration)");
}
EpetraCrsMatrixT(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rowMap, const ArrayRCP< const size_t > &NumEntriesPerRowToAlloc, ProfileType pftype=DynamicProfile, const Teuchos::RCP< Teuchos::ParameterList > ¶ms=Teuchos::null) {
TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::RuntimeError,
"Xpetra::EpetraCrsMatrix only available for GO=int or GO=long long with EpetraNode (Serial or OpenMP depending on configuration)");
}
EpetraCrsMatrixT(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rowMap, const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &colMap, size_t maxNumEntriesPerRow, ProfileType pftype=DynamicProfile, const Teuchos::RCP< Teuchos::ParameterList > ¶ms=Teuchos::null) { TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::RuntimeError, "Xpetra::EpetraCrsMatrix only available for GO=int or GO=long long with Node=Kokkos::Compat::KokkosSerialWrapperNode."); }
EpetraCrsMatrixT(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rowMap, const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &colMap, const ArrayRCP< const size_t > &NumEntriesPerRowToAlloc, ProfileType pftype=DynamicProfile, const Teuchos::RCP< Teuchos::ParameterList > ¶ms=Teuchos::null) { TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::RuntimeError, "Xpetra::EpetraCrsMatrix only available for GO=int or GO=long long with Node=Kokkos::Compat::KokkosSerialWrapperNode."); }
EpetraCrsMatrixT(const Teuchos::RCP< const CrsGraph< LocalOrdinal, GlobalOrdinal, Node> > &graph, const Teuchos::RCP< Teuchos::ParameterList > ¶ms=Teuchos::null) { TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::RuntimeError, "Xpetra::EpetraCrsMatrix only available for GO=int or GO=long long with Node=Kokkos::Compat::KokkosSerialWrapperNode."); }
EpetraCrsMatrixT(const Teuchos::RCP<const CrsMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> >& sourceMatrix,
const Import<LocalOrdinal,GlobalOrdinal,Node> &importer,
const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & domainMap = Teuchos::null,
const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & rangeMap = Teuchos::null,
const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null) {
TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::RuntimeError,
"Xpetra::EpetraCrsMatrix only available for GO=int or GO=long long with EpetraNode (Serial or OpenMP depending on configuration)");
}
EpetraCrsMatrixT(const Teuchos::RCP<const CrsMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> >& sourceMatrix,
const Export<LocalOrdinal,GlobalOrdinal,Node> &exporter,
const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & domainMap = Teuchos::null,
const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & rangeMap = Teuchos::null,
const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null) {
TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::RuntimeError,
"Xpetra::EpetraCrsMatrix only available for GO=int or GO=long long with EpetraNode (Serial or OpenMP depending on configuration)");
}
EpetraCrsMatrixT(const Teuchos::RCP<const CrsMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> >& sourceMatrix,
const Import<LocalOrdinal,GlobalOrdinal,Node> &RowImporter,
const Teuchos::RCP<const Import<LocalOrdinal,GlobalOrdinal,Node> > DomainImporter,
const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & domainMap,
const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & rangeMap,
const Teuchos::RCP<Teuchos::ParameterList>& params) {
TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::RuntimeError,
"Xpetra::EpetraCrsMatrix only available for GO=int or GO=long long with EpetraNode (Serial or OpenMP depending on configuration)");
}
EpetraCrsMatrixT(const Teuchos::RCP<const CrsMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> >& sourceMatrix,
const Export<LocalOrdinal,GlobalOrdinal,Node> &RowExporter,
const Teuchos::RCP<const Export<LocalOrdinal,GlobalOrdinal,Node> > DomainExporter,
const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & domainMap,
const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & rangeMap,
const Teuchos::RCP<Teuchos::ParameterList>& params) {
TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::RuntimeError,
"Xpetra::EpetraCrsMatrix only available for GO=int or GO=long long with EpetraNode (Serial or OpenMP depending on configuration)");
}
#ifdef HAVE_XPETRA_KOKKOS_REFACTOR
#ifdef HAVE_XPETRA_TPETRA
EpetraCrsMatrixT (const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> >& rowMap,
const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> >& colMap,
const local_matrix_type& lclMatrix,
const Teuchos::RCP<Teuchos::ParameterList>& params = null) {
TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::RuntimeError,
"Xpetra::EpetraCrsMatrix only available for GO=int or GO=long long with EpetraNode (Serial or OpenMP depending on configuration)");
}
#endif
#endif
virtual ~EpetraCrsMatrixT() { }
void insertGlobalValues(GlobalOrdinal globalRow, const ArrayView< const GlobalOrdinal > &cols, const ArrayView< const Scalar > &vals) {}
void insertLocalValues(LocalOrdinal localRow, const ArrayView< const LocalOrdinal > &cols, const ArrayView< const Scalar > &vals) { }
void replaceGlobalValues(GlobalOrdinal globalRow, const ArrayView< const GlobalOrdinal > &cols, const ArrayView< const Scalar > &vals) { }
void replaceLocalValues(LocalOrdinal localRow, const ArrayView< const LocalOrdinal > &cols, const ArrayView< const Scalar > &vals) { }
void setAllToScalar(const Scalar &alpha) { }
void scale(const Scalar &alpha) { }
void allocateAllValues(size_t numNonZeros,ArrayRCP<size_t> & rowptr, ArrayRCP<LocalOrdinal> & colind, ArrayRCP<Scalar> & values) { }
void setAllValues(const ArrayRCP<size_t> & rowptr, const ArrayRCP<LocalOrdinal> & colind, const ArrayRCP<Scalar> & values) { }
void getAllValues(ArrayRCP<const size_t>& rowptr, ArrayRCP<const LocalOrdinal>& colind, ArrayRCP<const Scalar>& values) const { }
void expertStaticFillComplete(const RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & domainMap,
const RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & rangeMap,
const RCP<const Import<LocalOrdinal,GlobalOrdinal,Node> > &importer=Teuchos::null,
const RCP<const Export<LocalOrdinal,GlobalOrdinal,Node> > &exporter=Teuchos::null,
const RCP<ParameterList> ¶ms=Teuchos::null) { }
void resumeFill(const RCP< ParameterList > ¶ms=null) { }
void fillComplete(const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &domainMap, const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rangeMap, const RCP< ParameterList > ¶ms=null) { }
void fillComplete(const RCP< ParameterList > ¶ms=null) { }
void replaceDomainMapAndImporter(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > >& newDomainMap, Teuchos::RCP<const Import<LocalOrdinal,GlobalOrdinal,Node> > & newImporter) { }
const RCP< const Comm< int > > getComm() const { return Teuchos::null; }
const RCP< const Map<LocalOrdinal, GlobalOrdinal, Node> > getRowMap() const { return Teuchos::null; }
const RCP< const Map<LocalOrdinal, GlobalOrdinal, Node> > getColMap() const { return Teuchos::null; }
RCP< const CrsGraph<LocalOrdinal, GlobalOrdinal, Node> > getCrsGraph() const { return Teuchos::null; }
global_size_t getGlobalNumRows() const { return 0; }
global_size_t getGlobalNumCols() const { return 0; }
size_t getNodeNumRows() const { return 0; }
size_t getNodeNumCols() const { return 0; }
global_size_t getGlobalNumEntries() const { return 0; }
size_t getNodeNumEntries() const { return 0; }
size_t getNumEntriesInLocalRow(LocalOrdinal localRow) const { return 0; }
global_size_t getGlobalNumDiags() const { return 0; }
size_t getNodeNumDiags() const { return 0; }
size_t getGlobalMaxNumRowEntries() const { return 0; }
size_t getNodeMaxNumRowEntries() const { return 0; }
bool isLocallyIndexed() const { return false; }
bool isGloballyIndexed() const { return false; }
bool isFillComplete() const { return false; }
bool isFillActive() const { return false; }
typename ScalarTraits< Scalar >::magnitudeType getFrobeniusNorm() const { return ScalarTraits< Scalar >::magnitude(ScalarTraits< Scalar >::zero()); }
bool supportsRowViews() const { return false; }
void getLocalRowCopy(LocalOrdinal LocalRow, const ArrayView< LocalOrdinal > &Indices, const ArrayView< Scalar > &Values, size_t &NumEntries) const { }
void getGlobalRowCopy(GlobalOrdinal GlobalRow, const ArrayView< GlobalOrdinal > &Indices, const ArrayView< Scalar > &Values, size_t &NumEntries) const { }
void getGlobalRowView(GlobalOrdinal GlobalRow, ArrayView< const GlobalOrdinal > &indices, ArrayView< const Scalar > &values) const { }
void getLocalRowView(LocalOrdinal LocalRow, ArrayView< const LocalOrdinal > &indices, ArrayView< const Scalar > &values) const { }
void getLocalDiagCopy(Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &diag) const { }
void getLocalDiagOffsets(Teuchos::ArrayRCP<size_t> &offsets) const { }
void getLocalDiagCopy(Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &diag, const Teuchos::ArrayView<const size_t> &offsets) const { }
void leftScale (const Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node>& x) { };
void rightScale (const Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node>& x) { };
void apply(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &X, MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &Y, Teuchos::ETransp mode=Teuchos::NO_TRANS, Scalar alpha=ScalarTraits< Scalar >::one(), Scalar beta=ScalarTraits< Scalar >::zero()) const { }
const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getDomainMap() const { return Teuchos::null; }
const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getRangeMap() const { return Teuchos::null; }
std::string description() const { return std::string(""); }
void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const { }
EpetraCrsMatrixT(const EpetraCrsMatrixT& matrix) {
TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::RuntimeError,
"Xpetra::EpetraCrsMatrix only available for GO=int or GO=long long with EpetraNode (Serial or OpenMP depending on configuration)");
}
Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getMap() const { return Teuchos::null; }
void doImport(const DistObject<char, LocalOrdinal, GlobalOrdinal, Node> &source, const Import< LocalOrdinal, GlobalOrdinal, Node > &importer, CombineMode CM) { }
void doExport(const DistObject<char, LocalOrdinal, GlobalOrdinal, Node> &dest, const Import< LocalOrdinal, GlobalOrdinal, Node >& importer, CombineMode CM) { }
void doImport(const DistObject<char, LocalOrdinal, GlobalOrdinal, Node> &source, const Export< LocalOrdinal, GlobalOrdinal, Node >& exporter, CombineMode CM) { }
void doExport(const DistObject<char, LocalOrdinal, GlobalOrdinal, Node> &dest, const Export< LocalOrdinal, GlobalOrdinal, Node >& exporter, CombineMode CM) { }
void removeEmptyProcessesInPlace (const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> >& newMap) { }
bool hasMatrix() const { return false; }
EpetraCrsMatrixT(const Teuchos::RCP<Epetra_CrsMatrix > &mtx) {
TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::RuntimeError,
"Xpetra::EpetraCrsMatrix only available for GO=int or GO=long long with EpetraNode (Serial or OpenMP depending on configuration)");
}
RCP<const Epetra_CrsMatrix> getEpetra_CrsMatrix() const { return Teuchos::null; }
RCP<Epetra_CrsMatrix> getEpetra_CrsMatrixNonConst() const { return Teuchos::null; } //TODO: remove
#ifdef HAVE_XPETRA_KOKKOS_REFACTOR
#ifdef HAVE_XPETRA_TPETRA
local_matrix_type getLocalMatrix () const {
TEUCHOS_TEST_FOR_EXCEPTION(isFillComplete() == false, std::runtime_error,
"Xpetra::EpetraCrsMatrix::getLocalMatrix: matrix must be filled and completed before you can access the data through the Kokkos interface!");
return localMatrix_;
}
private:
mutable
local_matrix_type localMatrix_;
#else
#ifdef __GNUC__
#warning "Xpetra Kokkos interface for CrsMatrix is enabled (HAVE_XPETRA_KOKKOS_REFACTOR) but Tpetra is disabled. The Kokkos interface needs Tpetra to be enabled, too."
#endif
#endif
#endif
}; // EpetraCrsMatrixT class (specialization on GO=long, empty stub implementation)
#ifndef XPETRA_EPETRA_NO_32BIT_GLOBAL_INDICES
template<>
class EpetraCrsMatrixT <int, EpetraNode>
: public CrsMatrix <double, int, int, EpetraNode>
{
typedef int GlobalOrdinal;
typedef EpetraNode Node;
typedef CrsMatrix<double, int, GlobalOrdinal, Node>::scalar_type Scalar;
typedef CrsMatrix<double, int, GlobalOrdinal, Node>::local_ordinal_type LocalOrdinal;
// The following typedefs are used by the Kokkos interface
#ifdef HAVE_XPETRA_KOKKOS_REFACTOR
#ifdef HAVE_XPETRA_TPETRA
typedef typename Xpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>::local_matrix_type local_matrix_type;
typedef typename Xpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>::node_type node_type;
#endif
#endif
public:
//! @name Constructor/Destructor Methods
//@{
//! Constructor specifying fixed number of entries for each row.
EpetraCrsMatrixT(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rowMap, size_t maxNumEntriesPerRow, ProfileType pftype=DynamicProfile, const Teuchos::RCP< Teuchos::ParameterList > &plist = Teuchos::null)
: mtx_(Teuchos::rcp(new Epetra_CrsMatrix(Copy, toEpetra<GlobalOrdinal,Node>(rowMap), maxNumEntriesPerRow, toEpetra(pftype)))), isFillResumed_(false)
#ifdef HAVE_XPETRA_KOKKOS_REFACTOR
#ifdef HAVE_XPETRA_TPETRA
, isInitializedLocalMatrix_(false)
#endif
#endif
{ }
//! Constructor specifying (possibly different) number of entries in each row.
EpetraCrsMatrixT(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rowMap, const ArrayRCP< const size_t > &NumEntriesPerRowToAlloc, ProfileType pftype=DynamicProfile, const Teuchos::RCP< Teuchos::ParameterList > &plist=Teuchos::null)
: isFillResumed_(false)
#ifdef HAVE_XPETRA_KOKKOS_REFACTOR
#ifdef HAVE_XPETRA_TPETRA
, isInitializedLocalMatrix_(false)
#endif
#endif
{
Teuchos::Array<int> numEntriesPerRowToAlloc(NumEntriesPerRowToAlloc.begin(), NumEntriesPerRowToAlloc.end()); // convert array of "size_t" to array of "int"
mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(Copy, toEpetra<GlobalOrdinal,Node>(rowMap), numEntriesPerRowToAlloc.getRawPtr(), toEpetra(pftype)));
}
//! Constructor specifying column Map and fixed number of entries for each row.
EpetraCrsMatrixT(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rowMap, const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &colMap, size_t maxNumEntriesPerRow, ProfileType pftype=DynamicProfile, const Teuchos::RCP< Teuchos::ParameterList > &plist=Teuchos::null)
: mtx_(Teuchos::rcp(new Epetra_CrsMatrix(Copy, toEpetra<GlobalOrdinal,Node>(rowMap), toEpetra<GlobalOrdinal,Node>(colMap), maxNumEntriesPerRow, toEpetra(pftype)))), isFillResumed_(false)
#ifdef HAVE_XPETRA_KOKKOS_REFACTOR
#ifdef HAVE_XPETRA_TPETRA
, isInitializedLocalMatrix_(false)
#endif
#endif
{ }
//! Constructor specifying column Map and number of entries in each row.
EpetraCrsMatrixT(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rowMap, const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &colMap, const ArrayRCP< const size_t > &NumEntriesPerRowToAlloc, ProfileType pftype=DynamicProfile, const Teuchos::RCP< Teuchos::ParameterList > &plist=Teuchos::null)
: isFillResumed_(false)
#ifdef HAVE_XPETRA_KOKKOS_REFACTOR
#ifdef HAVE_XPETRA_TPETRA
, isInitializedLocalMatrix_(false)
#endif
#endif
{
Teuchos::Array<int> numEntriesPerRowToAlloc(NumEntriesPerRowToAlloc.begin(), NumEntriesPerRowToAlloc.end()); // convert array of "size_t" to array of "int"
mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(Copy, toEpetra<GlobalOrdinal,Node>(rowMap), toEpetra<GlobalOrdinal,Node>(colMap), numEntriesPerRowToAlloc.getRawPtr(), toEpetra(pftype)));
}
//! Constructor specifying a previously constructed graph.
EpetraCrsMatrixT(const Teuchos::RCP< const CrsGraph< LocalOrdinal, GlobalOrdinal, Node> > &graph, const Teuchos::RCP< Teuchos::ParameterList > &plist=Teuchos::null)
: mtx_(Teuchos::rcp(new Epetra_CrsMatrix(Copy, toEpetra<GlobalOrdinal,Node>(graph)))), isFillResumed_(false)
#ifdef HAVE_XPETRA_KOKKOS_REFACTOR
#ifdef HAVE_XPETRA_TPETRA
, isInitializedLocalMatrix_(false)
#endif
#endif
{ }
//! Constructor for a fused import
EpetraCrsMatrixT(const Teuchos::RCP<const CrsMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> >& sourceMatrix,
const Import<LocalOrdinal,GlobalOrdinal,Node> &importer,
const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & domainMap = Teuchos::null,
const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & rangeMap = Teuchos::null,
const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null):
isFillResumed_(false)
#ifdef HAVE_XPETRA_KOKKOS_REFACTOR
#ifdef HAVE_XPETRA_TPETRA
, isInitializedLocalMatrix_(false)
#endif
#endif
{
XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, *sourceMatrix, tSourceMatrix, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraCrsMatrixT as an input argument.");
XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, importer, tImporter, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraImportT as an input argument.");
const Epetra_Map* myDomainMap = (domainMap!=Teuchos::null)? &toEpetra<GlobalOrdinal,Node>(domainMap): 0;
const Epetra_Map* myRangeMap = (rangeMap !=Teuchos::null)? &toEpetra<GlobalOrdinal,Node>(rangeMap) : 0;
// Follows the Tpetra parameters
bool restrictComm=false;
if(!params.is_null()) restrictComm = params->get("Restrict Communicator",restrictComm);
mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(*tSourceMatrix.getEpetra_CrsMatrix(),*tImporter.getEpetra_Import(),myDomainMap,myRangeMap,restrictComm));
if(restrictComm && mtx_->NumMyRows()==0)
mtx_=Teuchos::null;
}
//! Constructor for a fused export
EpetraCrsMatrixT(const Teuchos::RCP<const CrsMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> >& sourceMatrix,
const Export<LocalOrdinal,GlobalOrdinal,Node> &exporter,
const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & domainMap = Teuchos::null,
const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & rangeMap = Teuchos::null,
const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null) :
isFillResumed_(false)
#ifdef HAVE_XPETRA_KOKKOS_REFACTOR
#ifdef HAVE_XPETRA_TPETRA
, isInitializedLocalMatrix_(false)
#endif
#endif
{
XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, *sourceMatrix, tSourceMatrix, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraCrsMatrixT as an input argument.");
XPETRA_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, exporter, tExporter, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraExportT as an input argument.");
const Epetra_Map* myDomainMap = (domainMap!=Teuchos::null)? &toEpetra<GlobalOrdinal,Node>(domainMap): 0;
const Epetra_Map* myRangeMap = (rangeMap !=Teuchos::null)? &toEpetra<GlobalOrdinal,Node>(rangeMap) : 0;
// Follows the Tpetra parameters
bool restrictComm=false;
if(!params.is_null()) restrictComm = params->get("Restrict Communicator",restrictComm);
mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(*tSourceMatrix.getEpetra_CrsMatrix(),*tExporter.getEpetra_Export(),myDomainMap,myRangeMap,restrictComm));
}
EpetraCrsMatrixT(const Teuchos::RCP<const CrsMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> >& sourceMatrix,
const Import<LocalOrdinal,GlobalOrdinal,Node> &RowImporter,
const Teuchos::RCP<const Import<LocalOrdinal,GlobalOrdinal,Node> > DomainImporter,
const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & domainMap,
const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & rangeMap,
const Teuchos::RCP<Teuchos::ParameterList>& params) :
isFillResumed_(false)
#ifdef HAVE_XPETRA_KOKKOS_REFACTOR
#ifdef HAVE_XPETRA_TPETRA
, isInitializedLocalMatrix_(false)
#endif
#endif
{
XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, *sourceMatrix, tSourceMatrix, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraCrsMatrixT as an input argument.");
XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, RowImporter, tImporter, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraImportT as an input argument.");
XPETRA_RCP_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, DomainImporter, tdImporter, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraImportT as an input argument.");
const Epetra_Map* myDomainMap = (domainMap!=Teuchos::null)? &toEpetra<GlobalOrdinal,Node>(domainMap): 0;
const Epetra_Map* myRangeMap = (rangeMap !=Teuchos::null)? &toEpetra<GlobalOrdinal,Node>(rangeMap) : 0;
// Follows the Tpetra parameters
bool restrictComm=false;
if(!params.is_null()) restrictComm = params->get("Restrict Communicator",restrictComm);
mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(*tSourceMatrix.getEpetra_CrsMatrix(),*tImporter.getEpetra_Import(),tdImporter->getEpetra_Import().get(),myDomainMap,myRangeMap,restrictComm));
if(restrictComm && mtx_->NumMyRows()==0)
mtx_=Teuchos::null;
}
EpetraCrsMatrixT(const Teuchos::RCP<const CrsMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> >& sourceMatrix,
const Export<LocalOrdinal,GlobalOrdinal,Node> &RowExporter,
const Teuchos::RCP<const Export<LocalOrdinal,GlobalOrdinal,Node> > DomainExporter,
const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & domainMap,
const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & rangeMap,
const Teuchos::RCP<Teuchos::ParameterList>& params) :
isFillResumed_(false)
#ifdef HAVE_XPETRA_KOKKOS_REFACTOR
#ifdef HAVE_XPETRA_TPETRA
, isInitializedLocalMatrix_(false)
#endif
#endif
{
XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, *sourceMatrix, tSourceMatrix, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraCrsMatrixT as an input argument.");
XPETRA_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, RowExporter, tExporter, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraExportT as an input argument.");
XPETRA_RCP_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, DomainExporter, tdExporter, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraExportT as an input argument.");
const Epetra_Map* myDomainMap = (domainMap!=Teuchos::null)? &toEpetra<GlobalOrdinal,Node>(domainMap): 0;
const Epetra_Map* myRangeMap = (rangeMap !=Teuchos::null)? &toEpetra<GlobalOrdinal,Node>(rangeMap) : 0;
// Follows the Tpetra parameters
bool restrictComm=false;
if(!params.is_null()) restrictComm = params->get("Restrict Communicator",restrictComm);
mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(*tSourceMatrix.getEpetra_CrsMatrix(),*tExporter.getEpetra_Export(),tdExporter->getEpetra_Export().get(),myDomainMap,myRangeMap,restrictComm));
}
#ifdef HAVE_XPETRA_KOKKOS_REFACTOR
#ifdef HAVE_XPETRA_TPETRA
/// \brief Constructor specifying column Map and a local matrix,
/// which the resulting CrsMatrix views.
///
/// Unlike most other CrsMatrix constructors, successful
/// completion of this constructor will result in a fill-complete
/// matrix.
///
/// \param rowMap [in] Distribution of rows of the matrix.
///
/// \param colMap [in] Distribution of columns of the matrix.
///
/// \param lclMatrix [in] A local CrsMatrix containing all local
/// matrix values as well as a local graph. The graph's local
/// row indices must come from the specified row Map, and its
/// local column indices must 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.
EpetraCrsMatrixT (const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> >& rowMap,
const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> >& colMap,
const local_matrix_type& lclMatrix,
const Teuchos::RCP<Teuchos::ParameterList>& params = null) {
// local typedefs from local_matrix_type
//typedef typename local_matrix_type::size_type size_type;
typedef typename local_matrix_type::value_type value_type;
typedef typename local_matrix_type::ordinal_type ordinal_type;
// The number of rows in the sparse matrix.
ordinal_type lclNumRows = lclMatrix.numRows ();
ordinal_type lclNumCols = lclMatrix.numCols (); // do we need this?
// plausibility checks
TEUCHOS_TEST_FOR_EXCEPTION(lclNumRows != Teuchos::as<ordinal_type>(rowMap->getNodeNumElements()), Xpetra::Exceptions::RuntimeError, "Xpetra::EpetraCrsMatrixT: number of rows in local matrix and number of local entries in row map do not match!");
TEUCHOS_TEST_FOR_EXCEPTION(lclNumCols != Teuchos::as<ordinal_type>(colMap->getNodeNumElements()), Xpetra::Exceptions::RuntimeError, "Xpetra::EpetraCrsMatrixT: number of columns in local matrix and number of local entries in column map do not match!");
std::vector<GlobalOrdinal> domainMapGids; // vector for collecting domain map GIDs
Teuchos::ArrayRCP< size_t > NumEntriesPerRowToAlloc(lclNumRows);
for (ordinal_type r = 0; r < lclNumRows; ++r) {
// extract data from current row r
auto rowview = lclMatrix.row (r);
NumEntriesPerRowToAlloc[r] = rowview.length;
}
// setup matrix
isFillResumed_ = false;
Teuchos::Array<int> numEntriesPerRowToAlloc(NumEntriesPerRowToAlloc.begin(), NumEntriesPerRowToAlloc.end()); // convert array of "size_t" to array of "int"
mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(Copy, toEpetra<GlobalOrdinal,Node>(rowMap), toEpetra<GlobalOrdinal,Node>(colMap), numEntriesPerRowToAlloc.getRawPtr(), toEpetra(DynamicProfile)));
// loop over all rows and colums of local matrix and fill matrix
for (ordinal_type r = 0; r < lclNumRows; ++r) {
// extract data from current row r
auto rowview = lclMatrix.row (r);
// arrays for current row data
Teuchos::ArrayRCP<ordinal_type> indout(rowview.length,Teuchos::ScalarTraits<ordinal_type>::zero());
Teuchos::ArrayRCP<value_type> valout(rowview.length,Teuchos::ScalarTraits<value_type>::zero());
for(ordinal_type c = 0; c < rowview.length; c++) {
value_type value = rowview.value (c);
ordinal_type colidx = rowview.colidx (c);
TEUCHOS_TEST_FOR_EXCEPTION(colMap->isNodeLocalElement(colidx) == false, Xpetra::Exceptions::RuntimeError, "Xpetra::EpetraCrsMatrixT: local matrix contains column elements which are not in the provided column map!");
indout [c] = colidx;
valout [c] = value;
// collect GIDs for domain map
GlobalOrdinal gcid = colMap->getGlobalElement(c);
if(rowMap->isNodeGlobalElement(gcid)) domainMapGids.push_back(gcid);
}
insertLocalValues(r, indout.view(0,indout.size()), valout.view(0,valout.size()));
}
// sort entries in domainMapGids and remove duplicates
const GlobalOrdinal INVALID = Teuchos::OrdinalTraits<Xpetra::global_size_t>::invalid();
std::sort(domainMapGids.begin(), domainMapGids.end());
domainMapGids.erase(std::unique(domainMapGids.begin(), domainMapGids.end()), domainMapGids.end());
Teuchos::ArrayView<GlobalOrdinal> domainMapGidsView(&domainMapGids[0], domainMapGids.size());
Teuchos::RCP<const Xpetra::Map<LocalOrdinal,GlobalOrdinal,Node> > domainMap =
Xpetra::MapFactory<LocalOrdinal,GlobalOrdinal,Node>::Build(colMap->lib(), INVALID, domainMapGidsView, colMap->getIndexBase(), colMap->getComm());
// call fill complete
this->fillComplete(domainMap, rowMap, params);
// AP (2015/10/22): Could probably be optimized using provided lclMatrix, but lets not worry about that
isInitializedLocalMatrix_ = false;
}
#endif
#endif
//! Destructor.
virtual ~EpetraCrsMatrixT() { }
//@}
//! @name Insertion/Removal Methods
//@{
//! Insert matrix entries, using global IDs.
void insertGlobalValues(GlobalOrdinal globalRow, const ArrayView<const GlobalOrdinal> &cols, const ArrayView<const Scalar> &vals) {
XPETRA_MONITOR("EpetraCrsMatrixT::insertGlobalValues");
XPETRA_ERR_CHECK(mtx_->InsertGlobalValues(globalRow, vals.size(), vals.getRawPtr(), cols.getRawPtr()));
}
//! Insert matrix entries, using local IDs.
void insertLocalValues(LocalOrdinal localRow, const ArrayView<const LocalOrdinal> &cols, const ArrayView<const Scalar> &vals) {
XPETRA_MONITOR("EpetraCrsMatrixT::insertLocalValues");
XPETRA_ERR_CHECK(mtx_->InsertMyValues(localRow, vals.size(), vals.getRawPtr(), cols.getRawPtr()));
}
//! Replace matrix entries, using global IDs.
void replaceGlobalValues(GlobalOrdinal globalRow, const ArrayView< const GlobalOrdinal > &indices, const ArrayView< const Scalar > &values) {
XPETRA_MONITOR("EpetraCrsMatrixT::replaceGlobalValues");
{
const std::string tfecfFuncName("replaceGlobalValues");
TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(! isFillActive(), std::runtime_error,
": Fill must be active in order to call this method. If you have already "
"called fillComplete(), you need to call resumeFill() before you can "
"replace values.");
TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(values.size() != indices.size(),
std::runtime_error, ": values.size() must equal indices.size().");
}
XPETRA_ERR_CHECK(mtx_->ReplaceGlobalValues(globalRow, indices.size(), values.getRawPtr(), indices.getRawPtr()));
}
//! Replace matrix entries, using local IDs.
void replaceLocalValues(LocalOrdinal localRow, const ArrayView< const LocalOrdinal > &indices, const ArrayView< const Scalar > &values) {
XPETRA_MONITOR("EpetraCrsMatrixT::replaceLocalValues");
{
const std::string tfecfFuncName("replaceLocalValues");
TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(! isFillActive(), std::runtime_error,
": Fill must be active in order to call this method. If you have already "
"called fillComplete(), you need to call resumeFill() before you can "
"replace values.");
TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(values.size() != indices.size(),
std::runtime_error, ": values.size() must equal indices.size().");
}
XPETRA_ERR_CHECK(mtx_->ReplaceMyValues(localRow, indices.size(), values.getRawPtr(), indices.getRawPtr()));
}
//! Set all matrix entries equal to scalarThis.
void setAllToScalar(const Scalar &alpha) { XPETRA_MONITOR("EpetraCrsMatrixT::setAllToScalar"); mtx_->PutScalar(alpha); }
//! Scale the current values of a matrix, this = alpha*this.
void scale(const Scalar &alpha) { XPETRA_MONITOR("EpetraCrsMatrixT::scale"); mtx_->Scale(alpha); }
//! Allocates and returns ArrayRCPs of the Crs arrays --- This is an Xpetra-only routine.
//** \warning This is an expert-only routine and should not be called from user code. */
void allocateAllValues(size_t numNonZeros, ArrayRCP<size_t>& rowptr, ArrayRCP<LocalOrdinal>& colind, ArrayRCP<Scalar>& values) {
XPETRA_MONITOR("EpetraCrsMatrixT::allocateAllValues");
// Row offsets
// Unfortunately, we cannot do this in the same manner as column indices
// and values (see below). The problem is that Tpetra insists on using
// size_t, and Epetra uses int internally. So we only resize here, and
// will need to copy in setAllValues
rowptr.resize(getNodeNumRows()+1);
int lowerOffset = 0;
bool ownMemory = false;
// Column indices
// Extract, resize, set colind
Epetra_IntSerialDenseVector& myColind = mtx_->ExpertExtractIndices();
myColind.Resize(numNonZeros);
colind = Teuchos::arcp(myColind.Values(), lowerOffset, numNonZeros, ownMemory);
// Values
// Extract, reallocate, set values
double *& myValues = mtx_->ExpertExtractValues();
delete [] myValues;
myValues = new double[numNonZeros];
values = Teuchos::arcp(myValues,lowerOffset,numNonZeros,ownMemory);
}
//! Sets the 1D pointer arrays of the graph.
void setAllValues(const ArrayRCP<size_t>& rowptr, const ArrayRCP<LocalOrdinal>& colind, const ArrayRCP<Scalar>& values) {
XPETRA_MONITOR("EpetraCrsMatrixT::setAllValues");
// Check sizes
TEUCHOS_TEST_FOR_EXCEPTION(Teuchos::as<size_t>(rowptr.size()) != getNodeNumRows()+1, Xpetra::Exceptions::RuntimeError,
"An exception is thrown to let you know that the size of your rowptr array is incorrect.");
TEUCHOS_TEST_FOR_EXCEPTION(values.size() != colind.size(), Xpetra::Exceptions::RuntimeError,
"An exception is thrown to let you know that you mismatched your pointers.");
// Check pointers
if (values.size() > 0) {
TEUCHOS_TEST_FOR_EXCEPTION(colind.getRawPtr() != mtx_->ExpertExtractIndices().Values(), Xpetra::Exceptions::RuntimeError,
"An exception is thrown to let you know that you mismatched your pointers.");
TEUCHOS_TEST_FOR_EXCEPTION(values.getRawPtr() != mtx_->ExpertExtractValues(), Xpetra::Exceptions::RuntimeError,
"An exception is thrown to let you know that you mismatched your pointers.");
}
// We have to make a copy here, it is unavoidable
// See comments in allocateAllValues
const size_t N = getNodeNumRows();
Epetra_IntSerialDenseVector& myRowptr = mtx_->ExpertExtractIndexOffset();
myRowptr.Resize(N+1);
for (size_t i = 0; i < N+1; i++)
myRowptr[i] = Teuchos::as<int>(rowptr[i]);
}
//! Gets the 1D pointer arrays of the graph.
void getAllValues(ArrayRCP<const size_t>& rowptr, ArrayRCP<const LocalOrdinal>& colind, ArrayRCP<const Scalar>& values) const {
XPETRA_MONITOR("EpetraCrsMatrixT::getAllValues");
int lowerOffset = 0;
bool ownMemory = false;
const size_t n = getNodeNumRows();
const size_t nnz = getNodeNumEntries();
// Row offsets
// We have to make a copy here, it is unavoidable (see comments in allocateAllValues)
Epetra_IntSerialDenseVector& myRowptr = mtx_->ExpertExtractIndexOffset();
rowptr.resize(n+1);
for (size_t i = 0; i < n+1; i++)
(*const_cast<size_t*>(&rowptr[i])) = Teuchos::as<size_t>(myRowptr[i]);
// Column indices
colind = Teuchos::arcp(mtx_->ExpertExtractIndices().Values(), lowerOffset, nnz, ownMemory);
// Values
values = Teuchos::arcp(mtx_->ExpertExtractValues(), lowerOffset, nnz, ownMemory);
}
//! Expert static fill complete
//** \warning This is an expert-only routine and should not be called from user code. */
void expertStaticFillComplete(const RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & domainMap,
const RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & rangeMap,
const RCP<const Import<LocalOrdinal,GlobalOrdinal,Node> > &importer=Teuchos::null,
const RCP<const Export<LocalOrdinal,GlobalOrdinal,Node> > &exporter=Teuchos::null,
const RCP<ParameterList> & params=Teuchos::null) {
XPETRA_MONITOR("EpetraCrsMatrixT::expertStaticFillComplete");
int rv=0;
const Epetra_Import * myimport =0;
const Epetra_Export * myexport =0;
if(!importer.is_null()) {
XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, *importer, eImporter, "Xpetra::EpetraCrsMatrixT::expertStaticFillComplete only accepts Xpetra::EpetraImportT.");
myimport = eImporter.getEpetra_Import().getRawPtr();
}
if(!exporter.is_null()) {
XPETRA_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, *exporter, eExporter, "Xpetra::EpetraCrsMatrixT::expertStaticFillComplete only accepts Xpetra::EpetraImportT.");
myexport = eExporter.getEpetra_Export().getRawPtr();
}
rv=mtx_->ExpertStaticFillComplete(toEpetra<GlobalOrdinal,Node>(domainMap), toEpetra<GlobalOrdinal,Node>(rangeMap), myimport, myexport);
TEUCHOS_TEST_FOR_EXCEPTION(rv != 0, std::runtime_error, "Xpetra::EpetraCrsMatrixT::expertStaticFillComplete FAILED!");
}
//@}
//! @name Transformational Methods
//@{
//!
void resumeFill(const RCP< ParameterList > ¶ms=Teuchos::null) {
XPETRA_MONITOR("EpetraCrsMatrixT::resumeFill");
// According to Tpetra documentation, resumeFill() may be called repeatedly.
isFillResumed_ = true;
}
//! Signal that data entry is complete, specifying domain and range maps.
void fillComplete(const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &domainMap, const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rangeMap, const RCP< ParameterList > ¶ms=Teuchos::null) {
XPETRA_MONITOR("EpetraCrsMatrixT::fillComplete");
// For Epetra matrices, resumeFill() is a fictive operation. There is no need for a fillComplete after some resumeFill() operations.
if (isFillResumed_ == true) { isFillResumed_ = false; return; }
bool doOptimizeStorage = true;
if (params != null && params->get("Optimize Storage",true) == false) doOptimizeStorage = false;
mtx_->FillComplete(toEpetra<GlobalOrdinal,Node>(domainMap), toEpetra<GlobalOrdinal,Node>(rangeMap), doOptimizeStorage);
}
//! Signal that data entry is complete.
void fillComplete(const RCP< ParameterList > ¶ms=Teuchos::null) {
XPETRA_MONITOR("EpetraCrsMatrixT::fillComplete");
// For Epetra matrices, resumeFill() is a fictive operation. There is no need for a fillComplete after some resumeFill() operations.
if (isFillResumed_ == true) { isFillResumed_ = false; return; }
bool doOptimizeStorage = true;
if (params != null && params->get("Optimize Storage",true) == false) doOptimizeStorage = false;
mtx_->FillComplete(doOptimizeStorage);
}
//! Replaces the current domainMap and importer with the user-specified objects.
void replaceDomainMapAndImporter(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > >& newDomainMap, Teuchos::RCP<const Import<LocalOrdinal,GlobalOrdinal,Node> > & newImporter) {
XPETRA_MONITOR("EpetraCrsMatrixT::replaceDomainMapAndImporter");
XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, *newImporter, eImporter, "Xpetra::EpetraCrsMatrixT::replaceDomainMapAndImporter only accepts Xpetra::EpetraImportT.");
const RCP<const Epetra_Import> & myImport = eImporter.getEpetra_Import();
int rv=0;
if(myImport==Teuchos::null)
rv=mtx_->ReplaceDomainMapAndImporter( toEpetra<GlobalOrdinal,Node>(newDomainMap),0);
else
rv=mtx_->ReplaceDomainMapAndImporter( toEpetra<GlobalOrdinal,Node>(newDomainMap),&*myImport);
TEUCHOS_TEST_FOR_EXCEPTION(rv != 0, std::runtime_error, "Xpetra::EpetraCrsMatrixT::replaceDomainMapAndImporter FAILED!");
}
//@}
//! @name Methods implementing RowMatrix
//@{
//! Returns the communicator.
const RCP< const Comm< int > > getComm() const { XPETRA_MONITOR("EpetraCrsMatrixT::getComm"); return toXpetra(mtx_->Comm()); }
//! Returns the Map that describes the row distribution in this matrix.
const RCP< const Map<LocalOrdinal, GlobalOrdinal, Node> > getRowMap() const { XPETRA_MONITOR("EpetraCrsMatrixT::getRowMap"); return toXpetra<GlobalOrdinal,Node>(mtx_->RowMap()); }
//! Returns the Map that describes the column distribution in this matrix.
const RCP< const Map<LocalOrdinal, GlobalOrdinal, Node> > getColMap() const { XPETRA_MONITOR("EpetraCrsMatrixT::getColMap"); return toXpetra<GlobalOrdinal,Node>(mtx_->ColMap()); }
//! Returns the CrsGraph associated with this matrix.
RCP< const CrsGraph<LocalOrdinal, GlobalOrdinal, Node> > getCrsGraph() const { XPETRA_MONITOR("EpetraCrsMatrixT::getCrsGraph"); return toXpetra<GlobalOrdinal,Node>(mtx_->Graph()); }
//! Number of global elements in the row map of this matrix.
global_size_t getGlobalNumRows() const { XPETRA_MONITOR("EpetraCrsMatrixT::getGlobalNumRows"); return mtx_->NumGlobalRows64(); }
//! Number of global columns in the matrix.
global_size_t getGlobalNumCols() const { XPETRA_MONITOR("EpetraCrsMatrixT::getGlobalNumCols"); return mtx_->NumGlobalCols64(); }
//! Returns the number of matrix rows owned on the calling node.
size_t getNodeNumRows() const { XPETRA_MONITOR("EpetraCrsMatrixT::getNodeNumRows"); return mtx_->NumMyRows(); }
//! Returns the number of columns connected to the locally owned rows of this matrix.
size_t getNodeNumCols() const { XPETRA_MONITOR("EpetraCrsMatrixT::getNodeNumCols"); return mtx_->NumMyCols(); }
//! Returns the global number of entries in this matrix.
global_size_t getGlobalNumEntries() const { XPETRA_MONITOR("EpetraCrsMatrixT::getGlobalNumEntries"); return mtx_->NumGlobalNonzeros64(); }
//! Returns the local number of entries in this matrix.
size_t getNodeNumEntries() const { XPETRA_MONITOR("EpetraCrsMatrixT::getNodeNumEntries"); return mtx_->NumMyNonzeros(); }
//! Returns the current number of entries on this node in the specified local row.
size_t getNumEntriesInLocalRow(LocalOrdinal localRow) const { XPETRA_MONITOR("EpetraCrsMatrixT::getNumEntriesInLocalRow"); return mtx_->NumMyEntries(localRow); }
//! Returns the number of global diagonal entries, based on global row/column index comparisons.
global_size_t getGlobalNumDiags() const { XPETRA_MONITOR("EpetraCrsMatrixT::getGlobalNumDiags"); return mtx_->NumGlobalDiagonals64(); }
//! Returns the number of local diagonal entries, based on global row/column index comparisons.
size_t getNodeNumDiags() const { XPETRA_MONITOR("EpetraCrsMatrixT::getNodeNumDiags"); return mtx_->NumMyDiagonals(); }
//! Returns the maximum number of entries across all rows/columns on all nodes.
size_t getGlobalMaxNumRowEntries() const { XPETRA_MONITOR("EpetraCrsMatrixT::getGlobalMaxNumRowEntries"); return mtx_->GlobalMaxNumEntries(); }
//! Returns the maximum number of entries across all rows/columns on this node.
size_t getNodeMaxNumRowEntries() const { XPETRA_MONITOR("EpetraCrsMatrixT::getNodeMaxNumRowEntries"); return mtx_->MaxNumEntries(); }
//! If matrix indices are in the local range, this function returns true. Otherwise, this function returns false.
bool isLocallyIndexed() const { XPETRA_MONITOR("EpetraCrsMatrixT::isLocallyIndexed"); return mtx_->IndicesAreLocal(); }
//! If matrix indices are in the global range, this function returns true. Otherwise, this function returns false.
bool isGloballyIndexed() const { XPETRA_MONITOR("EpetraCrsMatrixT::isGloballyIndexed"); return mtx_->IndicesAreGlobal(); }
//! Returns true if the matrix is in compute mode, i.e. if fillComplete() has been called.
bool isFillComplete() const { XPETRA_MONITOR("EpetraCrsMatrixT::isFillComplete"); if (isFillResumed_) return false; else return mtx_->Filled(); }
//! Returns true if the matrix is in edit mode.
bool isFillActive() const { XPETRA_MONITOR("EpetraCrsMatrixT::isFillActive"); return !isFillComplete(); }
//! Returns the Frobenius norm of the matrix.
ScalarTraits< Scalar >::magnitudeType getFrobeniusNorm() const { XPETRA_MONITOR("EpetraCrsMatrixT::getFrobeniusNorm"); return mtx_->NormFrobenius(); }
//! Returns true if getLocalRowView() and getGlobalRowView() are valid for this class.
bool supportsRowViews() const { XPETRA_MONITOR("EpetraCrsMatrixT::supportsRowViews"); return true; }
//! Extract a list of entries in a specified local row of the matrix. Put into storage allocated by calling routine.
void getLocalRowCopy(LocalOrdinal LocalRow, const ArrayView<LocalOrdinal> &Indices, const ArrayView<Scalar> &Values, size_t &NumEntries) const {
XPETRA_MONITOR("EpetraCrsMatrixT::getLocalRowCopy");
int numEntries = -1;
XPETRA_ERR_CHECK(mtx_->ExtractMyRowCopy(LocalRow, Indices.size(), numEntries, Values.getRawPtr(), Indices.getRawPtr()));
NumEntries = numEntries;
}
//! Extract a list of entries in a specified global row of this matrix. Put into pre-allocated storage.
void getGlobalRowCopy(GlobalOrdinal GlobalRow, const ArrayView<GlobalOrdinal> &Indices, const ArrayView<Scalar> &Values, size_t &NumEntries) const {
XPETRA_MONITOR("EpetraCrsMatrixT::getGlobalRowCopy");
int numEntries = -1;
XPETRA_ERR_CHECK(mtx_->ExtractGlobalRowCopy(GlobalRow, Indices.size(), numEntries, Values.getRawPtr(), Indices.getRawPtr()));
NumEntries = numEntries;
}
//! Extract a const, non-persisting view of global indices in a specified row of the matrix.
void getGlobalRowView(GlobalOrdinal GlobalRow, ArrayView<const GlobalOrdinal> &indices, ArrayView<const Scalar> &values) const {
XPETRA_MONITOR("EpetraCrsMatrixT::getGlobalRowView");
int numEntries;
double * eValues;
GlobalOrdinal * eIndices;
XPETRA_ERR_CHECK(mtx_->ExtractGlobalRowView(GlobalRow, numEntries, eValues, eIndices));
if (numEntries == 0) { eValues = NULL; eIndices = NULL; } // Cf. TEUCHOS_TEST_FOR_EXCEPT( p == 0 && size_in != 0 ) in Teuchos ArrayView constructor.
indices = ArrayView<const GlobalOrdinal>(eIndices, numEntries);
values = ArrayView<const double>(eValues, numEntries);
}
//! Extract a const, non-persisting view of local indices in a specified row of the matrix.
void getLocalRowView(LocalOrdinal LocalRow, ArrayView<const LocalOrdinal> &indices, ArrayView<const Scalar> &values) const {
XPETRA_MONITOR("EpetraCrsMatrixT::getLocalRowView");
int numEntries;
double * eValues;
int * eIndices;
XPETRA_ERR_CHECK(mtx_->ExtractMyRowView(LocalRow, numEntries, eValues, eIndices));
if (numEntries == 0) { eValues = NULL; eIndices = NULL; } // Cf. TEUCHOS_TEST_FOR_EXCEPT( p == 0 && size_in != 0 ) in Teuchos ArrayView constructor.
indices = ArrayView<const int>(eIndices, numEntries);
values = ArrayView<const double>(eValues, numEntries);
}
//! Get a copy of the diagonal entries owned by this node, with local row indices.
void getLocalDiagCopy(Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &diag) const { XPETRA_MONITOR("EpetraCrsMatrixT::getLocalDiagCopy"); mtx_->ExtractDiagonalCopy(toEpetra<GlobalOrdinal,Node>(diag)); }
//! Get offsets of the diagonal entries in the matrix.
void getLocalDiagOffsets(Teuchos::ArrayRCP<size_t> &offsets) const {
TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::NotImplemented, "Xpetra::EpetraCrsMatrixT.getLocalDiagOffsets() is not implemented or supported.");
}
//! Get a copy of the diagonal entries owned by this node, with local row indices, using row offsets.
void getLocalDiagCopy(Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &diag, const Teuchos::ArrayView<const size_t> &offsets) const {
TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::NotImplemented, "Xpetra::EpetraCrsMatrixT.getLocalDiagCopy using offsets is not implemented or supported.");
}
void leftScale (const Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node>& x) {
XPETRA_ERR_CHECK(mtx_->LeftScale(toEpetra<GlobalOrdinal,Node>(x)));
};
void rightScale (const Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node>& x) {
XPETRA_ERR_CHECK(mtx_->RightScale(toEpetra<GlobalOrdinal,Node>(x)));
};
//@}
//! @name Methods implementing Operator
//@{
//! Computes the sparse matrix-multivector multiplication.
void apply(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &X, MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &Y, Teuchos::ETransp mode=Teuchos::NO_TRANS, Scalar alpha=ScalarTraits< Scalar >::one(), Scalar beta=ScalarTraits< Scalar >::zero()) const {
XPETRA_MONITOR("EpetraCrsMatrixT::apply");
//TEUCHOS_TEST_FOR_EXCEPTION((alpha != 1) || (beta != 0), Xpetra::Exceptions::NotImplemented, "Xpetra::EpetraCrsMatrixT.multiply() only accept alpha==1 and beta==0");
XPETRA_DYNAMIC_CAST(const EpetraMultiVectorT<GlobalOrdinal XPETRA_COMMA Node>, X, eX, "Xpetra::EpetraCrsMatrixT->apply() only accept Xpetra::EpetraMultiVectorT as input arguments.");
XPETRA_DYNAMIC_CAST( EpetraMultiVectorT<GlobalOrdinal XPETRA_COMMA Node>, Y, eY, "Xpetra::EpetraCrsMatrixT->apply() only accept Xpetra::EpetraMultiVectorT as input arguments.");
TEUCHOS_TEST_FOR_EXCEPTION((mode != Teuchos::NO_TRANS) && (mode != Teuchos::TRANS), Xpetra::Exceptions::NotImplemented, "Xpetra::EpetraCrsMatrixT->apply() only accept mode == NO_TRANS or mode == TRANS");
bool eTrans = toEpetra(mode);
// /!\ UseTranspose value
TEUCHOS_TEST_FOR_EXCEPTION(mtx_->UseTranspose(), Xpetra::Exceptions::NotImplemented, "An exception is throw to let you know that Xpetra::EpetraCrsMatrixT->apply() do not take into account the UseTranspose() parameter of Epetra_CrsMatrix.");
RCP<Epetra_MultiVector> epY = eY.getEpetra_MultiVector();
// helper vector: tmp = A*x
RCP<Epetra_MultiVector> tmp = Teuchos::rcp(new Epetra_MultiVector(*epY));
tmp->PutScalar(0.0);
XPETRA_ERR_CHECK(mtx_->Multiply(eTrans, *eX.getEpetra_MultiVector(), *tmp));
// calculate alpha * A * x + beta * y
XPETRA_ERR_CHECK(eY.getEpetra_MultiVector()->Update(alpha,*tmp,beta));
}
//! Returns the Map associated with the domain of this operator. This will be null until fillComplete() is called.
const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getDomainMap() const { XPETRA_MONITOR("EpetraCrsMatrixT::getDomainMap"); return toXpetra<GlobalOrdinal, Node>(mtx_->DomainMap()); }
//!
const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getRangeMap() const { XPETRA_MONITOR("EpetraCrsMatrixT::getRangeMap"); return toXpetra<GlobalOrdinal, Node>(mtx_->RangeMap()); }
//@}
//! @name Overridden from Teuchos::Describable
//@{
//! A simple one-line description of this object.
std::string description() const {
XPETRA_MONITOR("EpetraCrsMatrixT::description");
// This implementation come from Tpetra_CrsMatrix_def.hpp (without modification)
std::ostringstream oss;
//TODO: oss << DistObject<char, LocalOrdinal,GlobalOrdinal>::description();
if (isFillComplete()) {
oss << "{status = fill complete"
<< ", global rows = " << getGlobalNumRows()
<< ", global cols = " << getGlobalNumCols()
<< ", global num entries = " << getGlobalNumEntries()
<< "}";
}
else {
oss << "{status = fill not complete"
<< ", global rows = " << getGlobalNumRows()
<< "}";
}
return oss.str();
}
//! Print the object with some verbosity level to an FancyOStream object.
void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const {
XPETRA_MONITOR("EpetraCrsMatrixT::describe");
// This implementation come from Tpetra_CrsMatrix_def.hpp (without modification)
using std::endl;
using std::setw;
using Teuchos::VERB_DEFAULT;
using Teuchos::VERB_NONE;
using Teuchos::VERB_LOW;
using Teuchos::VERB_MEDIUM;
using Teuchos::VERB_HIGH;
using Teuchos::VERB_EXTREME;
Teuchos::EVerbosityLevel vl = verbLevel;
if (vl == VERB_DEFAULT) vl = VERB_LOW;
RCP<const Comm<int> > comm = this->getComm();
const int myImageID = comm->getRank(),
numImages = comm->getSize();
size_t width = 1;
for (size_t dec=10; dec<getGlobalNumRows(); dec *= 10) {
++width;
}
width = std::max<size_t>(width,11) + 2;
Teuchos::OSTab tab(out);
// none: print nothing
// low: print O(1) info from node 0
// medium: print O(P) info, num entries per node
// high: print O(N) info, num entries per row
// extreme: print O(NNZ) info: print indices and values
//
// for medium and higher, print constituent objects at specified verbLevel
if (vl != VERB_NONE) {
if (myImageID == 0) out << this->description() << std::endl;
// O(1) globals, minus what was already printed by description()
if (isFillComplete() && myImageID == 0) {
out << "Global number of diagonals = " << getGlobalNumDiags() << std::endl;
out << "Global max number of entries = " << getGlobalMaxNumRowEntries() << std::endl;
}
// constituent objects
if (vl == VERB_MEDIUM || vl == VERB_HIGH || vl == VERB_EXTREME) {
if (myImageID == 0) out << "\nRow map: " << std::endl;
getRowMap()->describe(out,vl);
//
if (getColMap() != null) {
if (getColMap() == getRowMap()) {
if (myImageID == 0) out << "\nColumn map is row map.";
}
else {
if (myImageID == 0) out << "\nColumn map: " << std::endl;
getColMap()->describe(out,vl);
}
}
if (getDomainMap() != null) {
if (getDomainMap() == getRowMap()) {
if (myImageID == 0) out << "\nDomain map is row map.";
}
else if (getDomainMap() == getColMap()) {
if (myImageID == 0) out << "\nDomain map is row map.";
}
else {
if (myImageID == 0) out << "\nDomain map: " << std::endl;
getDomainMap()->describe(out,vl);
}
}
if (getRangeMap() != null) {
if (getRangeMap() == getDomainMap()) {
if (myImageID == 0) out << "\nRange map is domain map." << std::endl;
}
else if (getRangeMap() == getRowMap()) {
if (myImageID == 0) out << "\nRange map is row map." << std::endl;
}
else {
if (myImageID == 0) out << "\nRange map: " << std::endl;
getRangeMap()->describe(out,vl);
}
}
if (myImageID == 0) out << std::endl;
}
// O(P) data
if (vl == VERB_MEDIUM || vl == VERB_HIGH || vl == VERB_EXTREME) {
for (int imageCtr = 0; imageCtr < numImages; ++imageCtr) {
if (myImageID == imageCtr) {
out << "Node ID = " << imageCtr << std::endl;
// TODO: need a graph
// if (staticGraph_->indicesAreAllocated() == false) {
// out << "Node not allocated" << std::endl;
// }
// else {
// out << "Node number of allocated entries = " << staticGraph_->getNodeAllocationSize() << std::endl;
// }
// TMP:
// const Epetra_CrsGraph & staticGraph_ = mtx_->Graph();
// End of TMP
out << "Node number of entries = " << getNodeNumEntries() << std::endl;
if (isFillComplete()) {
out << "Node number of diagonals = " << getNodeNumDiags() << std::endl;
}
out << "Node max number of entries = " << getNodeMaxNumRowEntries() << std::endl;
}
comm->barrier();
comm->barrier();
comm->barrier();
}
}
// O(N) and O(NNZ) data
if (vl == VERB_HIGH || vl == VERB_EXTREME) {
for (int imageCtr = 0; imageCtr < numImages; ++imageCtr) {
if (myImageID == imageCtr) {
out << std::setw(width) << "Node ID"
<< std::setw(width) << "Global Row"
<< std::setw(width) << "Num Entries";
if (vl == VERB_EXTREME) {
out << std::setw(width) << "(Index,Value)";
}
out << std::endl;
for (size_t r=0; r < getNodeNumRows(); ++r) {
const size_t nE = getNumEntriesInLocalRow(r);
GlobalOrdinal gid = getRowMap()->getGlobalElement(r);
out << std::setw(width) << myImageID
<< std::setw(width) << gid
<< std::setw(width) << nE;
if (vl == VERB_EXTREME) {
if (isGloballyIndexed()) {
ArrayView<const GlobalOrdinal> rowinds;
ArrayView<const Scalar> rowvals;
getGlobalRowView(gid,rowinds,rowvals);
for (size_t j=0; j < nE; ++j) {
out << " (" << rowinds[j]
<< ", " << rowvals[j]
<< ") ";
}
}
else if (isLocallyIndexed()) {
ArrayView<const LocalOrdinal> rowinds;
ArrayView<const Scalar> rowvals;
getLocalRowView(r,rowinds,rowvals);
for (size_t j=0; j < nE; ++j) {
out << " (" << getColMap()->getGlobalElement(rowinds[j])
<< ", " << rowvals[j]
<< ") ";
}
}
}
out << std::endl;
}
}
comm->barrier();
comm->barrier();
comm->barrier();
}
}
}
}
//@}
//! Deep copy constructor
EpetraCrsMatrixT(const EpetraCrsMatrixT& matrix)
: mtx_(Teuchos::rcp(new Epetra_CrsMatrix(*(matrix.mtx_)))), isFillResumed_(false)
#ifdef HAVE_XPETRA_KOKKOS_REFACTOR
#ifdef HAVE_XPETRA_TPETRA
, isInitializedLocalMatrix_(false)
#endif
#endif
{ }
//! Implements DistObject interface
//{@
//! Access function for the Tpetra::Map this DistObject was constructed with.
Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getMap() const { XPETRA_MONITOR("EpetraCrsMatrixT::getMap"); return toXpetra<GlobalOrdinal,Node>(mtx_->Map()); }
//! Import.
void doImport(const DistObject<char, LocalOrdinal, GlobalOrdinal, Node> &source,
const Import<LocalOrdinal, GlobalOrdinal, Node> &importer, CombineMode CM) {
XPETRA_MONITOR("EpetraCrsMatrixT::doImport");
XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, source, tSource, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraCrsMatrixT as input arguments.");
XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, importer, tImporter, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraImportT as input arguments.");
RCP<const Epetra_CrsMatrix> v = tSource.getEpetra_CrsMatrix();
int err = mtx_->Import(*v, *tImporter.getEpetra_Import(), toEpetra(CM));
TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error, "Catch error code returned by Epetra.");
}
//! Export.
void doExport(const DistObject<char, LocalOrdinal, GlobalOrdinal, Node> &dest,
const Import<LocalOrdinal, GlobalOrdinal, Node>& importer, CombineMode CM) {
XPETRA_MONITOR("EpetraCrsMatrixT::doExport");
XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, dest, tDest, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraCrsMatrixT as input arguments.");
XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, importer, tImporter, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraImportT as input arguments.");
RCP<const Epetra_CrsMatrix> v = tDest.getEpetra_CrsMatrix();
int err = mtx_->Export(*v, *tImporter.getEpetra_Import(), toEpetra(CM));
TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error, "Catch error code returned by Epetra.");
}
//! Import (using an Exporter).
void doImport(const DistObject<char, LocalOrdinal, GlobalOrdinal, Node> &source,
const Export<LocalOrdinal, GlobalOrdinal, Node>& exporter, CombineMode CM) {
XPETRA_MONITOR("EpetraCrsMatrixT::doImport");
XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, source, tSource, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraCrsMatrixT as input arguments.");
XPETRA_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, exporter, tExporter, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraImportT as input arguments.");
RCP<const Epetra_CrsMatrix> v = tSource.getEpetra_CrsMatrix();
int err = mtx_->Import(*v, *tExporter.getEpetra_Export(), toEpetra(CM));
TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error, "Catch error code returned by Epetra.");
}
//! Export (using an Importer).
void doExport(const DistObject<char, LocalOrdinal, GlobalOrdinal, Node> &dest,
const Export<LocalOrdinal, GlobalOrdinal, Node>& exporter, CombineMode CM) {
XPETRA_MONITOR("EpetraCrsMatrixT::doExport");
XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, dest, tDest, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraCrsMatrixT as input arguments.");
XPETRA_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, exporter, tExporter, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraImportT as input arguments.");
RCP<const Epetra_CrsMatrix> v = tDest.getEpetra_CrsMatrix();
int err = mtx_->Export(*v, *tExporter.getEpetra_Export(), toEpetra(CM));
TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error, "Catch error code returned by Epetra.");
}
void removeEmptyProcessesInPlace (const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> >& newMap) { }
//@}
//! @name Xpetra specific
//@{
//! Does this have an underlying matrix
bool hasMatrix() const { return !mtx_.is_null();}
//! EpetraCrsMatrixT constructor to wrap a Epetra_CrsMatrix object
EpetraCrsMatrixT(const Teuchos::RCP<Epetra_CrsMatrix > &mtx) : mtx_(mtx), isFillResumed_(false) { }
//! Get the underlying Epetra matrix
RCP<const Epetra_CrsMatrix> getEpetra_CrsMatrix() const { return mtx_; }
//! Get the underlying Epetra matrix
RCP<Epetra_CrsMatrix> getEpetra_CrsMatrixNonConst() const { return mtx_; } //TODO: remove
#ifdef HAVE_XPETRA_KOKKOS_REFACTOR
#ifdef HAVE_XPETRA_TPETRA
/// \brief Compatibility layer for accessing the matrix data through a Kokkos interface
local_matrix_type getLocalMatrix () const {
TEUCHOS_TEST_FOR_EXCEPTION(isFillComplete() == false, std::runtime_error,
"Xpetra::EpetraCrsMatrix::getLocalMatrix: matrix must be filled and completed before you can access the data through the Kokkos interface!");
if (isInitializedLocalMatrix_)
return localMatrix_;
RCP<Epetra_CrsMatrix> matrix = getEpetra_CrsMatrixNonConst();
const int numRows = matrix->NumMyRows();
const int numCols = matrix->NumMyCols();
const int nnz = matrix->NumMyNonzeros();
int* rowptr;
int* colind;
double* vals;
int rv = matrix->ExtractCrsDataPointers(rowptr, colind, vals);
TEUCHOS_TEST_FOR_EXCEPTION(rv, std::runtime_error, "Xpetra::CrsMatrix<>::getLocalMatrix: failed in ExtractCrsDataPointers");
// Transform int* rowptr array to size_type* array
typename local_matrix_type::row_map_type::non_const_type kokkosRowPtr("local row map", numRows+1);
for (size_t i = 0; i < kokkosRowPtr.size(); i++)
kokkosRowPtr(i) = Teuchos::asSafe<typename local_matrix_type::row_map_type::value_type>(rowptr[i]);
// create Kokkos::Views
typename local_matrix_type::index_type kokkosColind(colind, nnz);
typename local_matrix_type::values_type kokkosVals (vals, nnz);
localMatrix_ = local_matrix_type("LocalMatrix", numRows, numCols, nnz, kokkosVals, kokkosRowPtr, kokkosColind);
isInitializedLocalMatrix_ = true;
return localMatrix_;
}
#else
#ifdef __GNUC__
#warning "Xpetra Kokkos interface for CrsMatrix is enabled (HAVE_XPETRA_KOKKOS_REFACTOR) but Tpetra is disabled. The Kokkos interface needs Tpetra to be enabled, too."
#endif
#endif
#endif
//@}
private:
RCP<Epetra_CrsMatrix> mtx_;
bool isFillResumed_; //< For Epetra, fillResume() is a fictive operation but we need to keep track of it. This boolean is true only is resumeFill() have been called and fillComplete() have not been called afterward.
#ifdef HAVE_XPETRA_KOKKOS_REFACTOR
#ifdef HAVE_XPETRA_TPETRA
mutable
local_matrix_type localMatrix_;
mutable
bool isInitializedLocalMatrix_;
#else
#ifdef __GNUC__
#warning "Xpetra Kokkos interface for CrsMatrix is enabled (HAVE_XPETRA_KOKKOS_REFACTOR) but Tpetra is disabled. The Kokkos interface needs Tpetra to be enabled, too."
#endif
#endif
#endif
}; // EpetraCrsMatrixT class
#endif //#ifndef XPETRA_EPETRA_NO_32BIT_GLOBAL_INDICES
#ifndef XPETRA_EPETRA_NO_64BIT_GLOBAL_INDICES
template<>
class EpetraCrsMatrixT <long long, EpetraNode>
: public CrsMatrix <double, int, long long, EpetraNode>
{
typedef long long GlobalOrdinal;
typedef EpetraNode Node;
typedef typename CrsMatrix<double, int, GlobalOrdinal, Node>::scalar_type Scalar;
typedef typename CrsMatrix<double, int, GlobalOrdinal, Node>::local_ordinal_type LocalOrdinal;
// The following typedefs are used by the Kokkos interface
#ifdef HAVE_XPETRA_KOKKOS_REFACTOR
#ifdef HAVE_XPETRA_TPETRA
typedef typename Xpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>::local_matrix_type local_matrix_type;
typedef typename Xpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>::node_type node_type;
#endif
#endif
public:
//! @name Constructor/Destructor Methods
//@{
//! Constructor specifying fixed number of entries for each row.
EpetraCrsMatrixT(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rowMap, size_t maxNumEntriesPerRow, ProfileType pftype=DynamicProfile, const Teuchos::RCP< Teuchos::ParameterList > &plist = Teuchos::null)
: mtx_(Teuchos::rcp(new Epetra_CrsMatrix(Copy, toEpetra<GlobalOrdinal,Node>(rowMap), maxNumEntriesPerRow, toEpetra(pftype)))), isFillResumed_(false)
#ifdef HAVE_XPETRA_KOKKOS_REFACTOR
#ifdef HAVE_XPETRA_TPETRA
, isInitializedLocalMatrix_(false)
#endif
#endif
{ }
//! Constructor specifying (possibly different) number of entries in each row.
EpetraCrsMatrixT(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rowMap, const ArrayRCP< const size_t > &NumEntriesPerRowToAlloc, ProfileType pftype=DynamicProfile, const Teuchos::RCP< Teuchos::ParameterList > &plist=Teuchos::null)
: isFillResumed_(false)
#ifdef HAVE_XPETRA_KOKKOS_REFACTOR
#ifdef HAVE_XPETRA_TPETRA
, isInitializedLocalMatrix_(false)
#endif
#endif
{
Teuchos::Array<int> numEntriesPerRowToAlloc(NumEntriesPerRowToAlloc.begin(), NumEntriesPerRowToAlloc.end()); // convert array of "size_t" to array of "int"
mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(Copy, toEpetra<GlobalOrdinal,Node>(rowMap), numEntriesPerRowToAlloc.getRawPtr(), toEpetra(pftype)));
}
//! Constructor specifying column Map and fixed number of entries for each row.
EpetraCrsMatrixT(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rowMap, const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &colMap, size_t maxNumEntriesPerRow, ProfileType pftype=DynamicProfile, const Teuchos::RCP< Teuchos::ParameterList > &plist=Teuchos::null)
: mtx_(Teuchos::rcp(new Epetra_CrsMatrix(Copy, toEpetra<GlobalOrdinal,Node>(rowMap), toEpetra<GlobalOrdinal,Node>(colMap), maxNumEntriesPerRow, toEpetra(pftype)))), isFillResumed_(false)
#ifdef HAVE_XPETRA_KOKKOS_REFACTOR
#ifdef HAVE_XPETRA_TPETRA
, isInitializedLocalMatrix_(false)
#endif
#endif
{ }
//! Constructor specifying column Map and number of entries in each row.
EpetraCrsMatrixT(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rowMap, const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &colMap, const ArrayRCP< const size_t > &NumEntriesPerRowToAlloc, ProfileType pftype=DynamicProfile, const Teuchos::RCP< Teuchos::ParameterList > &plist=Teuchos::null)
: isFillResumed_(false)
#ifdef HAVE_XPETRA_KOKKOS_REFACTOR
#ifdef HAVE_XPETRA_TPETRA
, isInitializedLocalMatrix_(false)
#endif
#endif
{
Teuchos::Array<int> numEntriesPerRowToAlloc(NumEntriesPerRowToAlloc.begin(), NumEntriesPerRowToAlloc.end()); // convert array of "size_t" to array of "int"
mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(Copy, toEpetra<GlobalOrdinal,Node>(rowMap), toEpetra<GlobalOrdinal,Node>(colMap), numEntriesPerRowToAlloc.getRawPtr(), toEpetra(pftype)));
}
//! Constructor specifying a previously constructed graph.
EpetraCrsMatrixT(const Teuchos::RCP< const CrsGraph< LocalOrdinal, GlobalOrdinal, Node> > &graph, const Teuchos::RCP< Teuchos::ParameterList > &plist=Teuchos::null)
: mtx_(Teuchos::rcp(new Epetra_CrsMatrix(Copy, toEpetra<GlobalOrdinal,Node>(graph)))), isFillResumed_(false)
#ifdef HAVE_XPETRA_KOKKOS_REFACTOR
#ifdef HAVE_XPETRA_TPETRA
, isInitializedLocalMatrix_(false)
#endif
#endif
{ }
//! Constructor for a fused import
EpetraCrsMatrixT(const Teuchos::RCP<const CrsMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> >& sourceMatrix,
const Import<LocalOrdinal,GlobalOrdinal,Node> &importer,
const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & domainMap = Teuchos::null,
const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & rangeMap = Teuchos::null,
const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null):
isFillResumed_(false)
#ifdef HAVE_XPETRA_KOKKOS_REFACTOR
#ifdef HAVE_XPETRA_TPETRA
, isInitializedLocalMatrix_(false)
#endif
#endif
{
XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, *sourceMatrix, tSourceMatrix, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraCrsMatrixT as an input argument.");
XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, importer, tImporter, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraImportT as an input argument.");
const Epetra_Map* myDomainMap = (domainMap!=Teuchos::null)? &toEpetra<GlobalOrdinal,Node>(domainMap): 0;
const Epetra_Map* myRangeMap = (rangeMap !=Teuchos::null)? &toEpetra<GlobalOrdinal,Node>(rangeMap) : 0;
// Follows the Tpetra parameters
bool restrictComm=false;
if(!params.is_null()) restrictComm = params->get("Restrict Communicator",restrictComm);
mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(*tSourceMatrix.getEpetra_CrsMatrix(),*tImporter.getEpetra_Import(),myDomainMap,myRangeMap,restrictComm));
if(restrictComm && mtx_->NumMyRows()==0)
mtx_=Teuchos::null;
}
//! Constructor for a fused export
EpetraCrsMatrixT(const Teuchos::RCP<const CrsMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> >& sourceMatrix,
const Export<LocalOrdinal,GlobalOrdinal,Node> &exporter,
const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & domainMap = Teuchos::null,
const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & rangeMap = Teuchos::null,
const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null) :
isFillResumed_(false)
#ifdef HAVE_XPETRA_KOKKOS_REFACTOR
#ifdef HAVE_XPETRA_TPETRA
, isInitializedLocalMatrix_(false)
#endif
#endif
{
XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, *sourceMatrix, tSourceMatrix, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraCrsMatrixT as an input argument.");
XPETRA_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, exporter, tExporter, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraExportT as an input argument.");
const Epetra_Map* myDomainMap = (domainMap!=Teuchos::null)? &toEpetra<GlobalOrdinal,Node>(domainMap): 0;
const Epetra_Map* myRangeMap = (rangeMap !=Teuchos::null)? &toEpetra<GlobalOrdinal,Node>(rangeMap) : 0;
// Follows the Tpetra parameters
bool restrictComm=false;
if(!params.is_null()) restrictComm = params->get("Restrict Communicator",restrictComm);
mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(*tSourceMatrix.getEpetra_CrsMatrix(),*tExporter.getEpetra_Export(),myDomainMap,myRangeMap,restrictComm));
}
EpetraCrsMatrixT(const Teuchos::RCP<const CrsMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> >& sourceMatrix,
const Import<LocalOrdinal,GlobalOrdinal,Node> &RowImporter,
const Teuchos::RCP<const Import<LocalOrdinal,GlobalOrdinal,Node> > DomainImporter,
const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & domainMap,
const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & rangeMap,
const Teuchos::RCP<Teuchos::ParameterList>& params) :
isFillResumed_(false)
#ifdef HAVE_XPETRA_KOKKOS_REFACTOR
#ifdef HAVE_XPETRA_TPETRA
, isInitializedLocalMatrix_(false)
#endif
#endif
{
XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, *sourceMatrix, tSourceMatrix, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraCrsMatrixT as an input argument.");
XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, RowImporter, tImporter, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraImportT as an input argument.");
XPETRA_RCP_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, DomainImporter, tdImporter, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraImportT as an input argument.");
const Epetra_Map* myDomainMap = (domainMap!=Teuchos::null)? &toEpetra<GlobalOrdinal,Node>(domainMap): 0;
const Epetra_Map* myRangeMap = (rangeMap !=Teuchos::null)? &toEpetra<GlobalOrdinal,Node>(rangeMap) : 0;
// Follows the Tpetra parameters
bool restrictComm=false;
if(!params.is_null()) restrictComm = params->get("Restrict Communicator",restrictComm);
mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(*tSourceMatrix.getEpetra_CrsMatrix(),*tImporter.getEpetra_Import(),tdImporter->getEpetra_Import().get(),myDomainMap,myRangeMap,restrictComm));
if(restrictComm && mtx_->NumMyRows()==0)
mtx_=Teuchos::null;
}
EpetraCrsMatrixT(const Teuchos::RCP<const CrsMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> >& sourceMatrix,
const Export<LocalOrdinal,GlobalOrdinal,Node> &RowExporter,
const Teuchos::RCP<const Export<LocalOrdinal,GlobalOrdinal,Node> > DomainExporter,
const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & domainMap,
const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & rangeMap,
const Teuchos::RCP<Teuchos::ParameterList>& params) :
isFillResumed_(false)
#ifdef HAVE_XPETRA_KOKKOS_REFACTOR
#ifdef HAVE_XPETRA_TPETRA
, isInitializedLocalMatrix_(false)
#endif
#endif
{
XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, *sourceMatrix, tSourceMatrix, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraCrsMatrixT as an input argument.");
XPETRA_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, RowExporter, tExporter, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraExportT as an input argument.");
XPETRA_RCP_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, DomainExporter, tdExporter, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraExportT as an input argument.");
const Epetra_Map* myDomainMap = (domainMap!=Teuchos::null)? &toEpetra<GlobalOrdinal,Node>(domainMap): 0;
const Epetra_Map* myRangeMap = (rangeMap !=Teuchos::null)? &toEpetra<GlobalOrdinal,Node>(rangeMap) : 0;
// Follows the Tpetra parameters
bool restrictComm=false;
if(!params.is_null()) restrictComm = params->get("Restrict Communicator",restrictComm);
mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(*tSourceMatrix.getEpetra_CrsMatrix(),*tExporter.getEpetra_Export(),tdExporter->getEpetra_Export().get(),myDomainMap,myRangeMap,restrictComm));
}
#ifdef HAVE_XPETRA_KOKKOS_REFACTOR
#ifdef HAVE_XPETRA_TPETRA
/// \brief Constructor specifying column Map and a local matrix,
/// which the resulting CrsMatrix views.
///
/// Unlike most other CrsMatrix constructors, successful
/// completion of this constructor will result in a fill-complete
/// matrix.
///
/// \param rowMap [in] Distribution of rows of the matrix.
///
/// \param colMap [in] Distribution of columns of the matrix.
///
/// \param lclMatrix [in] A local CrsMatrix containing all local
/// matrix values as well as a local graph. The graph's local
/// row indices must come from the specified row Map, and its
/// local column indices must 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.
EpetraCrsMatrixT (const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> >& rowMap,
const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> >& colMap,
const local_matrix_type& lclMatrix,
const Teuchos::RCP<Teuchos::ParameterList>& params = null) {
// local typedefs from local_matrix_type
//typedef typename local_matrix_type::size_type size_type;
typedef typename local_matrix_type::value_type value_type;
typedef typename local_matrix_type::ordinal_type ordinal_type;
// The number of rows in the sparse matrix.
ordinal_type lclNumRows = lclMatrix.numRows ();
ordinal_type lclNumCols = lclMatrix.numCols (); // do we need this?
// plausibility checks
TEUCHOS_TEST_FOR_EXCEPTION(lclNumRows != Teuchos::as<ordinal_type>(rowMap->getNodeNumElements()), Xpetra::Exceptions::RuntimeError, "Xpetra::EpetraCrsMatrixT: number of rows in local matrix and number of local entries in row map do not match!");
TEUCHOS_TEST_FOR_EXCEPTION(lclNumCols != Teuchos::as<ordinal_type>(colMap->getNodeNumElements()), Xpetra::Exceptions::RuntimeError, "Xpetra::EpetraCrsMatrixT: number of columns in local matrix and number of local entries in column map do not match!");
std::vector<GlobalOrdinal> domainMapGids; // vector for collecting domain map GIDs
Teuchos::ArrayRCP< size_t > NumEntriesPerRowToAlloc(lclNumRows);
for (ordinal_type r = 0; r < lclNumRows; ++r) {
// extract data from current row r
auto rowview = lclMatrix.row (r);
NumEntriesPerRowToAlloc[r] = rowview.length;
}
// setup matrix
isFillResumed_ = false;
Teuchos::Array<int> numEntriesPerRowToAlloc(NumEntriesPerRowToAlloc.begin(), NumEntriesPerRowToAlloc.end()); // convert array of "size_t" to array of "int"
mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(Copy, toEpetra<GlobalOrdinal,Node>(rowMap), toEpetra<GlobalOrdinal,Node>(colMap), numEntriesPerRowToAlloc.getRawPtr(), toEpetra(DynamicProfile)));
// loop over all rows and colums of local matrix and fill matrix
for (ordinal_type r = 0; r < lclNumRows; ++r) {
// extract data from current row r
auto rowview = lclMatrix.row (r);
// arrays for current row data
Teuchos::ArrayRCP<ordinal_type> indout(rowview.length,Teuchos::ScalarTraits<ordinal_type>::zero());
Teuchos::ArrayRCP<value_type> valout(rowview.length,Teuchos::ScalarTraits<value_type>::zero());
for(ordinal_type c = 0; c < rowview.length; c++) {
value_type value = rowview.value (c);
ordinal_type colidx = rowview.colidx (c);
TEUCHOS_TEST_FOR_EXCEPTION(colMap->isNodeLocalElement(colidx) == false, Xpetra::Exceptions::RuntimeError, "Xpetra::EpetraCrsMatrixT: local matrix contains column elements which are not in the provided column map!");
indout [c] = colidx;
valout [c] = value;
// collect GIDs for domain map
GlobalOrdinal gcid = colMap->getGlobalElement(c);
if(rowMap->isNodeGlobalElement(gcid)) domainMapGids.push_back(gcid);
}
insertLocalValues(r, indout.view(0,indout.size()), valout.view(0,valout.size()));
}
// sort entries in domainMapGids and remove duplicates
const GlobalOrdinal INVALID = Teuchos::OrdinalTraits<Xpetra::global_size_t>::invalid();
std::sort(domainMapGids.begin(), domainMapGids.end());
domainMapGids.erase(std::unique(domainMapGids.begin(), domainMapGids.end()), domainMapGids.end());
Teuchos::ArrayView<GlobalOrdinal> domainMapGidsView(&domainMapGids[0], domainMapGids.size());
Teuchos::RCP<const Xpetra::Map<LocalOrdinal,GlobalOrdinal,Node> > domainMap =
Xpetra::MapFactory<LocalOrdinal,GlobalOrdinal,Node>::Build(colMap->lib(), INVALID, domainMapGidsView, colMap->getIndexBase(), colMap->getComm());
// call fill complete
this->fillComplete(domainMap, rowMap, params);
// AP (2015/10/22): Could probably be optimized using provided lclMatrix, but lets not worry about that
isInitializedLocalMatrix_ = false;
}
#endif
#endif
//! Destructor.
virtual ~EpetraCrsMatrixT() { }
//@}
//! @name Insertion/Removal Methods
//@{
//! Insert matrix entries, using global IDs.
void insertGlobalValues(GlobalOrdinal globalRow, const ArrayView<const GlobalOrdinal> &cols, const ArrayView<const Scalar> &vals) {
XPETRA_MONITOR("EpetraCrsMatrixT::insertGlobalValues");
XPETRA_ERR_CHECK(mtx_->InsertGlobalValues(globalRow, vals.size(), vals.getRawPtr(), cols.getRawPtr()));
}
//! Insert matrix entries, using local IDs.
void insertLocalValues(LocalOrdinal localRow, const ArrayView<const LocalOrdinal> &cols, const ArrayView<const Scalar> &vals) {
XPETRA_MONITOR("EpetraCrsMatrixT::insertLocalValues");
XPETRA_ERR_CHECK(mtx_->InsertMyValues(localRow, vals.size(), vals.getRawPtr(), cols.getRawPtr()));
}
//! Replace matrix entries, using global IDs.
void replaceGlobalValues(GlobalOrdinal globalRow, const ArrayView< const GlobalOrdinal > &indices, const ArrayView< const Scalar > &values) {
XPETRA_MONITOR("EpetraCrsMatrixT::replaceGlobalValues");
{
const std::string tfecfFuncName("replaceGlobalValues");
TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(! isFillActive(), std::runtime_error,
": Fill must be active in order to call this method. If you have already "
"called fillComplete(), you need to call resumeFill() before you can "
"replace values.");
TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(values.size() != indices.size(),
std::runtime_error, ": values.size() must equal indices.size().");
}
XPETRA_ERR_CHECK(mtx_->ReplaceGlobalValues(globalRow, indices.size(), values.getRawPtr(), indices.getRawPtr()));
}
//! Replace matrix entries, using local IDs.
void replaceLocalValues(LocalOrdinal localRow, const ArrayView< const LocalOrdinal > &indices, const ArrayView< const Scalar > &values) {
XPETRA_MONITOR("EpetraCrsMatrixT::replaceLocalValues");
{
const std::string tfecfFuncName("replaceLocalValues");
TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(! isFillActive(), std::runtime_error,
": Fill must be active in order to call this method. If you have already "
"called fillComplete(), you need to call resumeFill() before you can "
"replace values.");
TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(values.size() != indices.size(),
std::runtime_error, ": values.size() must equal indices.size().");
}
XPETRA_ERR_CHECK(mtx_->ReplaceMyValues(localRow, indices.size(), values.getRawPtr(), indices.getRawPtr()));
}
//! Set all matrix entries equal to scalarThis.
void setAllToScalar(const Scalar &alpha) { XPETRA_MONITOR("EpetraCrsMatrixT::setAllToScalar"); mtx_->PutScalar(alpha); }
//! Scale the current values of a matrix, this = alpha*this.
void scale(const Scalar &alpha) { XPETRA_MONITOR("EpetraCrsMatrixT::scale"); mtx_->Scale(alpha); }
//! Allocates and returns ArrayRCPs of the Crs arrays --- This is an Xpetra-only routine.
//** \warning This is an expert-only routine and should not be called from user code. */
void allocateAllValues(size_t numNonZeros, ArrayRCP<size_t>& rowptr, ArrayRCP<LocalOrdinal>& colind, ArrayRCP<Scalar>& values) {
XPETRA_MONITOR("EpetraCrsMatrixT::allocateAllValues");
// Row offsets
// Unfortunately, we cannot do this in the same manner as column indices
// and values (see below). The problem is that Tpetra insists on using
// size_t, and Epetra uses int internally. So we only resize here, and
// will need to copy in setAllValues
rowptr.resize(getNodeNumRows()+1);
int lowerOffset = 0;
bool ownMemory = false;
// Column indices
// Extract, resize, set colind
Epetra_IntSerialDenseVector& myColind = mtx_->ExpertExtractIndices();
myColind.Resize(numNonZeros);
colind = Teuchos::arcp(myColind.Values(), lowerOffset, numNonZeros, ownMemory);
// Values
// Extract, reallocate, set values
double *& myValues = mtx_->ExpertExtractValues();
delete [] myValues;
myValues = new double[numNonZeros];
values = Teuchos::arcp(myValues,lowerOffset,numNonZeros,ownMemory);
}
//! Sets the 1D pointer arrays of the graph.
void setAllValues(const ArrayRCP<size_t>& rowptr, const ArrayRCP<LocalOrdinal>& colind, const ArrayRCP<Scalar>& values) {
XPETRA_MONITOR("EpetraCrsMatrixT::setAllValues");
// Check sizes
TEUCHOS_TEST_FOR_EXCEPTION(Teuchos::as<size_t>(rowptr.size()) != getNodeNumRows()+1, Xpetra::Exceptions::RuntimeError,
"An exception is thrown to let you know that the size of your rowptr array is incorrect.");
TEUCHOS_TEST_FOR_EXCEPTION(values.size() != colind.size(), Xpetra::Exceptions::RuntimeError,
"An exception is thrown to let you know that you mismatched your pointers.");
// Check pointers
if (values.size() > 0) {
TEUCHOS_TEST_FOR_EXCEPTION(colind.getRawPtr() != mtx_->ExpertExtractIndices().Values(), Xpetra::Exceptions::RuntimeError,
"An exception is thrown to let you know that you mismatched your pointers.");
TEUCHOS_TEST_FOR_EXCEPTION(values.getRawPtr() != mtx_->ExpertExtractValues(), Xpetra::Exceptions::RuntimeError,
"An exception is thrown to let you know that you mismatched your pointers.");
}
// We have to make a copy here, it is unavoidable
// See comments in allocateAllValues
const size_t N = getNodeNumRows();
Epetra_IntSerialDenseVector& myRowptr = mtx_->ExpertExtractIndexOffset();
myRowptr.Resize(N+1);
for (size_t i = 0; i < N+1; i++)
myRowptr[i] = Teuchos::as<int>(rowptr[i]);
}
//! Gets the 1D pointer arrays of the graph.
void getAllValues(ArrayRCP<const size_t>& rowptr, ArrayRCP<const LocalOrdinal>& colind, ArrayRCP<const Scalar>& values) const {
XPETRA_MONITOR("EpetraCrsMatrixT::getAllValues");
int lowerOffset = 0;
bool ownMemory = false;
const size_t n = getNodeNumRows();
const size_t nnz = getNodeNumEntries();
// Row offsets
// We have to make a copy here, it is unavoidable (see comments in allocateAllValues)
Epetra_IntSerialDenseVector& myRowptr = mtx_->ExpertExtractIndexOffset();
rowptr.resize(n+1);
for (size_t i = 0; i < n+1; i++)
(*const_cast<size_t*>(&rowptr[i])) = Teuchos::as<size_t>(myRowptr[i]);
// Column indices
colind = Teuchos::arcp(mtx_->ExpertExtractIndices().Values(), lowerOffset, nnz, ownMemory);
// Values
values = Teuchos::arcp(mtx_->ExpertExtractValues(), lowerOffset, nnz, ownMemory);
}
//! Expert static fill complete
//** \warning This is an expert-only routine and should not be called from user code. */
void expertStaticFillComplete(const RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & domainMap,
const RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & rangeMap,
const RCP<const Import<LocalOrdinal,GlobalOrdinal,Node> > &importer=Teuchos::null,
const RCP<const Export<LocalOrdinal,GlobalOrdinal,Node> > &exporter=Teuchos::null,
const RCP<ParameterList> & params=Teuchos::null) {
XPETRA_MONITOR("EpetraCrsMatrixT::expertStaticFillComplete");
int rv=0;
const Epetra_Import * myimport =0;
const Epetra_Export * myexport =0;
if(!importer.is_null()) {
XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, *importer, eImporter, "Xpetra::EpetraCrsMatrixT::expertStaticFillComplete only accepts Xpetra::EpetraImportT.");
myimport = eImporter.getEpetra_Import().getRawPtr();
}
if(!exporter.is_null()) {
XPETRA_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, *exporter, eExporter, "Xpetra::EpetraCrsMatrixT::expertStaticFillComplete only accepts Xpetra::EpetraImportT.");
myexport = eExporter.getEpetra_Export().getRawPtr();
}
rv=mtx_->ExpertStaticFillComplete(toEpetra<GlobalOrdinal,Node>(domainMap), toEpetra<GlobalOrdinal,Node>(rangeMap), myimport, myexport);
TEUCHOS_TEST_FOR_EXCEPTION(rv != 0, std::runtime_error, "Xpetra::EpetraCrsMatrixT::expertStaticFillComplete FAILED!");
}
//@}
//! @name Transformational Methods
//@{
//!
void resumeFill(const RCP< ParameterList > ¶ms=Teuchos::null) {
XPETRA_MONITOR("EpetraCrsMatrixT::resumeFill");
// According to Tpetra documentation, resumeFill() may be called repeatedly.
isFillResumed_ = true;
}
//! Signal that data entry is complete, specifying domain and range maps.
void fillComplete(const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &domainMap, const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rangeMap, const RCP< ParameterList > ¶ms=Teuchos::null) {
XPETRA_MONITOR("EpetraCrsMatrixT::fillComplete");
// For Epetra matrices, resumeFill() is a fictive operation. There is no need for a fillComplete after some resumeFill() operations.
if (isFillResumed_ == true) { isFillResumed_ = false; return; }
bool doOptimizeStorage = true;
if (params != null && params->get("Optimize Storage",true) == false) doOptimizeStorage = false;
mtx_->FillComplete(toEpetra<GlobalOrdinal,Node>(domainMap), toEpetra<GlobalOrdinal,Node>(rangeMap), doOptimizeStorage);
}
//! Signal that data entry is complete.
void fillComplete(const RCP< ParameterList > ¶ms=Teuchos::null) {
XPETRA_MONITOR("EpetraCrsMatrixT::fillComplete");
// For Epetra matrices, resumeFill() is a fictive operation. There is no need for a fillComplete after some resumeFill() operations.
if (isFillResumed_ == true) { isFillResumed_ = false; return; }
bool doOptimizeStorage = true;
if (params != null && params->get("Optimize Storage",true) == false) doOptimizeStorage = false;
mtx_->FillComplete(doOptimizeStorage);
}
//! Replaces the current domainMap and importer with the user-specified objects.
void replaceDomainMapAndImporter(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > >& newDomainMap, Teuchos::RCP<const Import<LocalOrdinal,GlobalOrdinal,Node> > & newImporter) {
XPETRA_MONITOR("EpetraCrsMatrixT::replaceDomainMapAndImporter");
XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, *newImporter, eImporter, "Xpetra::EpetraCrsMatrixT::replaceDomainMapAndImporter only accepts Xpetra::EpetraImportT.");
const RCP<const Epetra_Import> & myImport = eImporter.getEpetra_Import();
int rv=0;
if(myImport==Teuchos::null)
rv=mtx_->ReplaceDomainMapAndImporter( toEpetra<GlobalOrdinal,Node>(newDomainMap),0);
else
rv=mtx_->ReplaceDomainMapAndImporter( toEpetra<GlobalOrdinal,Node>(newDomainMap),&*myImport);
TEUCHOS_TEST_FOR_EXCEPTION(rv != 0, std::runtime_error, "Xpetra::EpetraCrsMatrixT::replaceDomainMapAndImporter FAILED!");
}
//@}
//! @name Methods implementing RowMatrix
//@{
//! Returns the communicator.
const RCP< const Comm< int > > getComm() const { XPETRA_MONITOR("EpetraCrsMatrixT::getComm"); return toXpetra(mtx_->Comm()); }
//! Returns the Map that describes the row distribution in this matrix.
const RCP< const Map<LocalOrdinal, GlobalOrdinal, Node> > getRowMap() const { XPETRA_MONITOR("EpetraCrsMatrixT::getRowMap"); return toXpetra<GlobalOrdinal,Node>(mtx_->RowMap()); }
//! Returns the Map that describes the column distribution in this matrix.
const RCP< const Map<LocalOrdinal, GlobalOrdinal, Node> > getColMap() const { XPETRA_MONITOR("EpetraCrsMatrixT::getColMap"); return toXpetra<GlobalOrdinal,Node>(mtx_->ColMap()); }
//! Returns the CrsGraph associated with this matrix.
RCP< const CrsGraph<LocalOrdinal, GlobalOrdinal, Node> > getCrsGraph() const { XPETRA_MONITOR("EpetraCrsMatrixT::getCrsGraph"); return toXpetra<GlobalOrdinal,Node>(mtx_->Graph()); }
//! Number of global elements in the row map of this matrix.
global_size_t getGlobalNumRows() const { XPETRA_MONITOR("EpetraCrsMatrixT::getGlobalNumRows"); return mtx_->NumGlobalRows64(); }
//! Number of global columns in the matrix.
global_size_t getGlobalNumCols() const { XPETRA_MONITOR("EpetraCrsMatrixT::getGlobalNumCols"); return mtx_->NumGlobalCols64(); }
//! Returns the number of matrix rows owned on the calling node.
size_t getNodeNumRows() const { XPETRA_MONITOR("EpetraCrsMatrixT::getNodeNumRows"); return mtx_->NumMyRows(); }
//! Returns the number of columns connected to the locally owned rows of this matrix.
size_t getNodeNumCols() const { XPETRA_MONITOR("EpetraCrsMatrixT::getNodeNumCols"); return mtx_->NumMyCols(); }
//! Returns the global number of entries in this matrix.
global_size_t getGlobalNumEntries() const { XPETRA_MONITOR("EpetraCrsMatrixT::getGlobalNumEntries"); return mtx_->NumGlobalNonzeros64(); }
//! Returns the local number of entries in this matrix.
size_t getNodeNumEntries() const { XPETRA_MONITOR("EpetraCrsMatrixT::getNodeNumEntries"); return mtx_->NumMyNonzeros(); }
//! Returns the current number of entries on this node in the specified local row.
size_t getNumEntriesInLocalRow(LocalOrdinal localRow) const { XPETRA_MONITOR("EpetraCrsMatrixT::getNumEntriesInLocalRow"); return mtx_->NumMyEntries(localRow); }
//! Returns the number of global diagonal entries, based on global row/column index comparisons.
global_size_t getGlobalNumDiags() const { XPETRA_MONITOR("EpetraCrsMatrixT::getGlobalNumDiags"); return mtx_->NumGlobalDiagonals64(); }
//! Returns the number of local diagonal entries, based on global row/column index comparisons.
size_t getNodeNumDiags() const { XPETRA_MONITOR("EpetraCrsMatrixT::getNodeNumDiags"); return mtx_->NumMyDiagonals(); }
//! Returns the maximum number of entries across all rows/columns on all nodes.
size_t getGlobalMaxNumRowEntries() const { XPETRA_MONITOR("EpetraCrsMatrixT::getGlobalMaxNumRowEntries"); return mtx_->GlobalMaxNumEntries(); }
//! Returns the maximum number of entries across all rows/columns on this node.
size_t getNodeMaxNumRowEntries() const { XPETRA_MONITOR("EpetraCrsMatrixT::getNodeMaxNumRowEntries"); return mtx_->MaxNumEntries(); }
//! If matrix indices are in the local range, this function returns true. Otherwise, this function returns false.
bool isLocallyIndexed() const { XPETRA_MONITOR("EpetraCrsMatrixT::isLocallyIndexed"); return mtx_->IndicesAreLocal(); }
//! If matrix indices are in the global range, this function returns true. Otherwise, this function returns false.
bool isGloballyIndexed() const { XPETRA_MONITOR("EpetraCrsMatrixT::isGloballyIndexed"); return mtx_->IndicesAreGlobal(); }
//! Returns true if the matrix is in compute mode, i.e. if fillComplete() has been called.
bool isFillComplete() const { XPETRA_MONITOR("EpetraCrsMatrixT::isFillComplete"); if (isFillResumed_) return false; else return mtx_->Filled(); }
//! Returns true if the matrix is in edit mode.
bool isFillActive() const { XPETRA_MONITOR("EpetraCrsMatrixT::isFillActive"); return !isFillComplete(); }
//! Returns the Frobenius norm of the matrix.
typename ScalarTraits< Scalar >::magnitudeType getFrobeniusNorm() const { XPETRA_MONITOR("EpetraCrsMatrixT::getFrobeniusNorm"); return mtx_->NormFrobenius(); }
//! Returns true if getLocalRowView() and getGlobalRowView() are valid for this class.
bool supportsRowViews() const { XPETRA_MONITOR("EpetraCrsMatrixT::supportsRowViews"); return true; }
//! Extract a list of entries in a specified local row of the matrix. Put into storage allocated by calling routine.
void getLocalRowCopy(LocalOrdinal LocalRow, const ArrayView<LocalOrdinal> &Indices, const ArrayView<Scalar> &Values, size_t &NumEntries) const {
XPETRA_MONITOR("EpetraCrsMatrixT::getLocalRowCopy");
int numEntries = -1;
XPETRA_ERR_CHECK(mtx_->ExtractMyRowCopy(LocalRow, Indices.size(), numEntries, Values.getRawPtr(), Indices.getRawPtr()));
NumEntries = numEntries;
}
//! Extract a list of entries in a specified global row of this matrix. Put into pre-allocated storage.
void getGlobalRowCopy(GlobalOrdinal GlobalRow, const ArrayView<GlobalOrdinal> &Indices, const ArrayView<Scalar> &Values, size_t &NumEntries) const {
XPETRA_MONITOR("EpetraCrsMatrixT::getGlobalRowCopy");
int numEntries = -1;
XPETRA_ERR_CHECK(mtx_->ExtractGlobalRowCopy(GlobalRow, Indices.size(), numEntries, Values.getRawPtr(), Indices.getRawPtr()));
NumEntries = numEntries;
}
//! Extract a const, non-persisting view of global indices in a specified row of the matrix.
void getGlobalRowView(GlobalOrdinal GlobalRow, ArrayView<const GlobalOrdinal> &indices, ArrayView<const Scalar> &values) const {
XPETRA_MONITOR("EpetraCrsMatrixT::getGlobalRowView");
int numEntries;
double * eValues;
GlobalOrdinal * eIndices;
XPETRA_ERR_CHECK(mtx_->ExtractGlobalRowView(GlobalRow, numEntries, eValues, eIndices));
if (numEntries == 0) { eValues = NULL; eIndices = NULL; } // Cf. TEUCHOS_TEST_FOR_EXCEPT( p == 0 && size_in != 0 ) in Teuchos ArrayView constructor.
indices = ArrayView<const GlobalOrdinal>(eIndices, numEntries);
values = ArrayView<const double>(eValues, numEntries);
}
//! Extract a const, non-persisting view of local indices in a specified row of the matrix.
void getLocalRowView(LocalOrdinal LocalRow, ArrayView<const LocalOrdinal> &indices, ArrayView<const Scalar> &values) const {
XPETRA_MONITOR("EpetraCrsMatrixT::getLocalRowView");
int numEntries;
double * eValues;
int * eIndices;
XPETRA_ERR_CHECK(mtx_->ExtractMyRowView(LocalRow, numEntries, eValues, eIndices));
if (numEntries == 0) { eValues = NULL; eIndices = NULL; } // Cf. TEUCHOS_TEST_FOR_EXCEPT( p == 0 && size_in != 0 ) in Teuchos ArrayView constructor.
indices = ArrayView<const int>(eIndices, numEntries);
values = ArrayView<const double>(eValues, numEntries);
}
//! Get a copy of the diagonal entries owned by this node, with local row indices.
void getLocalDiagCopy(Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &diag) const { XPETRA_MONITOR("EpetraCrsMatrixT::getLocalDiagCopy"); mtx_->ExtractDiagonalCopy(toEpetra<GlobalOrdinal,Node>(diag)); }
//! Get offsets of the diagonal entries in the matrix.
void getLocalDiagOffsets(Teuchos::ArrayRCP<size_t> &offsets) const {
TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::NotImplemented, "Xpetra::EpetraCrsMatrixT.getLocalDiagOffsets() is not implemented or supported.");
}
//! Get a copy of the diagonal entries owned by this node, with local row indices, using row offsets.
void getLocalDiagCopy(Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &diag, const Teuchos::ArrayView<const size_t> &offsets) const {
TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::NotImplemented, "Xpetra::EpetraCrsMatrixT.getLocalDiagCopy using offsets is not implemented or supported.");
}
void leftScale (const Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node>& x) {
XPETRA_ERR_CHECK(mtx_->LeftScale(toEpetra<GlobalOrdinal,Node>(x)));
};
void rightScale (const Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node>& x) {
XPETRA_ERR_CHECK(mtx_->RightScale(toEpetra<GlobalOrdinal,Node>(x)));
};
//@}
//! @name Methods implementing Operator
//@{
//! Computes the sparse matrix-multivector multiplication.
void apply(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &X, MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &Y, Teuchos::ETransp mode=Teuchos::NO_TRANS, Scalar alpha=ScalarTraits< Scalar >::one(), Scalar beta=ScalarTraits< Scalar >::zero()) const {
XPETRA_MONITOR("EpetraCrsMatrixT::apply");
//TEUCHOS_TEST_FOR_EXCEPTION((alpha != 1) || (beta != 0), Xpetra::Exceptions::NotImplemented, "Xpetra::EpetraCrsMatrixT.multiply() only accept alpha==1 and beta==0");
XPETRA_DYNAMIC_CAST(const EpetraMultiVectorT<GlobalOrdinal XPETRA_COMMA Node>, X, eX, "Xpetra::EpetraCrsMatrixT->apply() only accept Xpetra::EpetraMultiVectorT as input arguments.");
XPETRA_DYNAMIC_CAST( EpetraMultiVectorT<GlobalOrdinal XPETRA_COMMA Node>, Y, eY, "Xpetra::EpetraCrsMatrixT->apply() only accept Xpetra::EpetraMultiVectorT as input arguments.");
TEUCHOS_TEST_FOR_EXCEPTION((mode != Teuchos::NO_TRANS) && (mode != Teuchos::TRANS), Xpetra::Exceptions::NotImplemented, "Xpetra::EpetraCrsMatrixT->apply() only accept mode == NO_TRANS or mode == TRANS");
bool eTrans = toEpetra(mode);
// /!\ UseTranspose value
TEUCHOS_TEST_FOR_EXCEPTION(mtx_->UseTranspose(), Xpetra::Exceptions::NotImplemented, "An exception is throw to let you know that Xpetra::EpetraCrsMatrixT->apply() do not take into account the UseTranspose() parameter of Epetra_CrsMatrix.");
RCP<Epetra_MultiVector> epY = eY.getEpetra_MultiVector();
// helper vector: tmp = A*x
RCP<Epetra_MultiVector> tmp = Teuchos::rcp(new Epetra_MultiVector(*epY));
tmp->PutScalar(0.0);
XPETRA_ERR_CHECK(mtx_->Multiply(eTrans, *eX.getEpetra_MultiVector(), *tmp));
// calculate alpha * A * x + beta * y
XPETRA_ERR_CHECK(eY.getEpetra_MultiVector()->Update(alpha,*tmp,beta));
}
//! Returns the Map associated with the domain of this operator. This will be null until fillComplete() is called.
const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getDomainMap() const { XPETRA_MONITOR("EpetraCrsMatrixT::getDomainMap"); return toXpetra<GlobalOrdinal, Node>(mtx_->DomainMap()); }
//!
const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getRangeMap() const { XPETRA_MONITOR("EpetraCrsMatrixT::getRangeMap"); return toXpetra<GlobalOrdinal, Node>(mtx_->RangeMap()); }
//@}
//! @name Overridden from Teuchos::Describable
//@{
//! A simple one-line description of this object.
std::string description() const {
XPETRA_MONITOR("EpetraCrsMatrixT::description");
// This implementation come from Tpetra_CrsMatrix_def.hpp (without modification)
std::ostringstream oss;
//TODO: oss << DistObject<char, LocalOrdinal,GlobalOrdinal>::description();
if (isFillComplete()) {
oss << "{status = fill complete"
<< ", global rows = " << getGlobalNumRows()
<< ", global cols = " << getGlobalNumCols()
<< ", global num entries = " << getGlobalNumEntries()
<< "}";
}
else {
oss << "{status = fill not complete"
<< ", global rows = " << getGlobalNumRows()
<< "}";
}
return oss.str();
}
//! Print the object with some verbosity level to an FancyOStream object.
void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const {
XPETRA_MONITOR("EpetraCrsMatrixT::describe");
// This implementation come from Tpetra_CrsMatrix_def.hpp (without modification)
using std::endl;
using std::setw;
using Teuchos::VERB_DEFAULT;
using Teuchos::VERB_NONE;
using Teuchos::VERB_LOW;
using Teuchos::VERB_MEDIUM;
using Teuchos::VERB_HIGH;
using Teuchos::VERB_EXTREME;
Teuchos::EVerbosityLevel vl = verbLevel;
if (vl == VERB_DEFAULT) vl = VERB_LOW;
RCP<const Comm<int> > comm = this->getComm();
const int myImageID = comm->getRank(),
numImages = comm->getSize();
size_t width = 1;
for (size_t dec=10; dec<getGlobalNumRows(); dec *= 10) {
++width;
}
width = std::max<size_t>(width,11) + 2;
Teuchos::OSTab tab(out);
// none: print nothing
// low: print O(1) info from node 0
// medium: print O(P) info, num entries per node
// high: print O(N) info, num entries per row
// extreme: print O(NNZ) info: print indices and values
//
// for medium and higher, print constituent objects at specified verbLevel
if (vl != VERB_NONE) {
if (myImageID == 0) out << this->description() << std::endl;
// O(1) globals, minus what was already printed by description()
if (isFillComplete() && myImageID == 0) {
out << "Global number of diagonals = " << getGlobalNumDiags() << std::endl;
out << "Global max number of entries = " << getGlobalMaxNumRowEntries() << std::endl;
}
// constituent objects
if (vl == VERB_MEDIUM || vl == VERB_HIGH || vl == VERB_EXTREME) {
if (myImageID == 0) out << "\nRow map: " << std::endl;
getRowMap()->describe(out,vl);
//
if (getColMap() != null) {
if (getColMap() == getRowMap()) {
if (myImageID == 0) out << "\nColumn map is row map.";
}
else {
if (myImageID == 0) out << "\nColumn map: " << std::endl;
getColMap()->describe(out,vl);
}
}
if (getDomainMap() != null) {
if (getDomainMap() == getRowMap()) {
if (myImageID == 0) out << "\nDomain map is row map.";
}
else if (getDomainMap() == getColMap()) {
if (myImageID == 0) out << "\nDomain map is row map.";
}
else {
if (myImageID == 0) out << "\nDomain map: " << std::endl;
getDomainMap()->describe(out,vl);
}
}
if (getRangeMap() != null) {
if (getRangeMap() == getDomainMap()) {
if (myImageID == 0) out << "\nRange map is domain map." << std::endl;
}
else if (getRangeMap() == getRowMap()) {
if (myImageID == 0) out << "\nRange map is row map." << std::endl;
}
else {
if (myImageID == 0) out << "\nRange map: " << std::endl;
getRangeMap()->describe(out,vl);
}
}
if (myImageID == 0) out << std::endl;
}
// O(P) data
if (vl == VERB_MEDIUM || vl == VERB_HIGH || vl == VERB_EXTREME) {
for (int imageCtr = 0; imageCtr < numImages; ++imageCtr) {
if (myImageID == imageCtr) {
out << "Node ID = " << imageCtr << std::endl;
// TODO: need a graph
// if (staticGraph_->indicesAreAllocated() == false) {
// out << "Node not allocated" << std::endl;
// }
// else {
// out << "Node number of allocated entries = " << staticGraph_->getNodeAllocationSize() << std::endl;
// }
// TMP:
// const Epetra_CrsGraph & staticGraph_ = mtx_->Graph();
// End of TMP
out << "Node number of entries = " << getNodeNumEntries() << std::endl;
if (isFillComplete()) {
out << "Node number of diagonals = " << getNodeNumDiags() << std::endl;
}
out << "Node max number of entries = " << getNodeMaxNumRowEntries() << std::endl;
}
comm->barrier();
comm->barrier();
comm->barrier();
}
}
// O(N) and O(NNZ) data
if (vl == VERB_HIGH || vl == VERB_EXTREME) {
for (int imageCtr = 0; imageCtr < numImages; ++imageCtr) {
if (myImageID == imageCtr) {
out << std::setw(width) << "Node ID"
<< std::setw(width) << "Global Row"
<< std::setw(width) << "Num Entries";
if (vl == VERB_EXTREME) {
out << std::setw(width) << "(Index,Value)";
}
out << std::endl;
for (size_t r=0; r < getNodeNumRows(); ++r) {
const size_t nE = getNumEntriesInLocalRow(r);
GlobalOrdinal gid = getRowMap()->getGlobalElement(r);
out << std::setw(width) << myImageID
<< std::setw(width) << gid
<< std::setw(width) << nE;
if (vl == VERB_EXTREME) {
if (isGloballyIndexed()) {
ArrayView<const GlobalOrdinal> rowinds;
ArrayView<const Scalar> rowvals;
getGlobalRowView(gid,rowinds,rowvals);
for (size_t j=0; j < nE; ++j) {
out << " (" << rowinds[j]
<< ", " << rowvals[j]
<< ") ";
}
}
else if (isLocallyIndexed()) {
ArrayView<const LocalOrdinal> rowinds;
ArrayView<const Scalar> rowvals;
getLocalRowView(r,rowinds,rowvals);
for (size_t j=0; j < nE; ++j) {
out << " (" << getColMap()->getGlobalElement(rowinds[j])
<< ", " << rowvals[j]
<< ") ";
}
}
}
out << std::endl;
}
}
comm->barrier();
comm->barrier();
comm->barrier();
}
}
}
}
//@}
//! Deep copy constructor
EpetraCrsMatrixT(const EpetraCrsMatrixT& matrix)
: mtx_(Teuchos::rcp(new Epetra_CrsMatrix(*(matrix.mtx_)))), isFillResumed_(false)
#ifdef HAVE_XPETRA_KOKKOS_REFACTOR
#ifdef HAVE_XPETRA_TPETRA
, isInitializedLocalMatrix_(false)
#endif
#endif
{ }
//! Implements DistObject interface
//{@
//! Access function for the Tpetra::Map this DistObject was constructed with.
Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getMap() const { XPETRA_MONITOR("EpetraCrsMatrixT::getMap"); return toXpetra<GlobalOrdinal,Node>(mtx_->Map()); }
//! Import.
void doImport(const DistObject<char, LocalOrdinal, GlobalOrdinal, Node> &source,
const Import<LocalOrdinal, GlobalOrdinal, Node> &importer, CombineMode CM) {
XPETRA_MONITOR("EpetraCrsMatrixT::doImport");
XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, source, tSource, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraCrsMatrixT as input arguments.");
XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, importer, tImporter, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraImportT as input arguments.");
RCP<const Epetra_CrsMatrix> v = tSource.getEpetra_CrsMatrix();
int err = mtx_->Import(*v, *tImporter.getEpetra_Import(), toEpetra(CM));
TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error, "Catch error code returned by Epetra.");
}
//! Export.
void doExport(const DistObject<char, LocalOrdinal, GlobalOrdinal, Node> &dest,
const Import<LocalOrdinal, GlobalOrdinal, Node>& importer, CombineMode CM) {
XPETRA_MONITOR("EpetraCrsMatrixT::doExport");
XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, dest, tDest, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraCrsMatrixT as input arguments.");
XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, importer, tImporter, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraImportT as input arguments.");
RCP<const Epetra_CrsMatrix> v = tDest.getEpetra_CrsMatrix();
int err = mtx_->Export(*v, *tImporter.getEpetra_Import(), toEpetra(CM));
TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error, "Catch error code returned by Epetra.");
}
//! Import (using an Exporter).
void doImport(const DistObject<char, LocalOrdinal, GlobalOrdinal, Node> &source,
const Export<LocalOrdinal, GlobalOrdinal, Node>& exporter, CombineMode CM) {
XPETRA_MONITOR("EpetraCrsMatrixT::doImport");
XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, source, tSource, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraCrsMatrixT as input arguments.");
XPETRA_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, exporter, tExporter, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraImportT as input arguments.");
RCP<const Epetra_CrsMatrix> v = tSource.getEpetra_CrsMatrix();
int err = mtx_->Import(*v, *tExporter.getEpetra_Export(), toEpetra(CM));
TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error, "Catch error code returned by Epetra.");
}
//! Export (using an Importer).
void doExport(const DistObject<char, LocalOrdinal, GlobalOrdinal, Node> &dest,
const Export<LocalOrdinal, GlobalOrdinal, Node>& exporter, CombineMode CM) {
XPETRA_MONITOR("EpetraCrsMatrixT::doExport");
XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, dest, tDest, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraCrsMatrixT as input arguments.");
XPETRA_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, exporter, tExporter, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraImportT as input arguments.");
RCP<const Epetra_CrsMatrix> v = tDest.getEpetra_CrsMatrix();
int err = mtx_->Export(*v, *tExporter.getEpetra_Export(), toEpetra(CM));
TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error, "Catch error code returned by Epetra.");
}
void removeEmptyProcessesInPlace (const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> >& newMap) { }
//@}
//! @name Xpetra specific
//@{
//! Does this have an underlying matrix
bool hasMatrix() const { return !mtx_.is_null();}
//! EpetraCrsMatrixT constructor to wrap a Epetra_CrsMatrix object
EpetraCrsMatrixT(const Teuchos::RCP<Epetra_CrsMatrix > &mtx) : mtx_(mtx), isFillResumed_(false) { }
//! Get the underlying Epetra matrix
RCP<const Epetra_CrsMatrix> getEpetra_CrsMatrix() const { return mtx_; }
//! Get the underlying Epetra matrix
RCP<Epetra_CrsMatrix> getEpetra_CrsMatrixNonConst() const { return mtx_; } //TODO: remove
#ifdef HAVE_XPETRA_KOKKOS_REFACTOR
#ifdef HAVE_XPETRA_TPETRA
/// \brief Compatibility layer for accessing the matrix data through a Kokkos interface
local_matrix_type getLocalMatrix () const {
TEUCHOS_TEST_FOR_EXCEPTION(isFillComplete() == false, std::runtime_error,
"Xpetra::EpetraCrsMatrix::getLocalMatrix: matrix must be filled and completed before you can access the data through the Kokkos interface!");
if (isInitializedLocalMatrix_)
return localMatrix_;
RCP<Epetra_CrsMatrix> matrix = getEpetra_CrsMatrixNonConst();
const int numRows = matrix->NumMyRows();
const int numCols = matrix->NumMyCols();
const int nnz = matrix->NumMyNonzeros();
int* rowptr;
int* colind;
double* vals;
int rv = matrix->ExtractCrsDataPointers(rowptr, colind, vals);
TEUCHOS_TEST_FOR_EXCEPTION(rv, std::runtime_error, "Xpetra::CrsMatrix<>::getLocalMatrix: failed in ExtractCrsDataPointers");
// Transform int* rowptr array to size_type* array
typename local_matrix_type::row_map_type::non_const_type kokkosRowPtr("local row map", numRows+1);
for (size_t i = 0; i < kokkosRowPtr.size(); i++)
kokkosRowPtr(i) = Teuchos::asSafe<typename local_matrix_type::row_map_type::value_type>(rowptr[i]);
// create Kokkos::Views
typename local_matrix_type::index_type kokkosColind(colind, nnz);
typename local_matrix_type::values_type kokkosVals (vals, nnz);
localMatrix_ = local_matrix_type("LocalMatrix", numRows, numCols, nnz, kokkosVals, kokkosRowPtr, kokkosColind);
isInitializedLocalMatrix_ = true;
return localMatrix_;
}
#else
#ifdef __GNUC__
#warning "Xpetra Kokkos interface for CrsMatrix is enabled (HAVE_XPETRA_KOKKOS_REFACTOR) but Tpetra is disabled. The Kokkos interface needs Tpetra to be enabled, too."
#endif
#endif
#endif
//@}
private:
RCP<Epetra_CrsMatrix> mtx_;
bool isFillResumed_; //< For Epetra, fillResume() is a fictive operation but we need to keep track of it. This boolean is true only is resumeFill() have been called and fillComplete() have not been called afterward.
#ifdef HAVE_XPETRA_KOKKOS_REFACTOR
#ifdef HAVE_XPETRA_TPETRA
mutable
local_matrix_type localMatrix_;
mutable
bool isInitializedLocalMatrix_;
#else
#ifdef __GNUC__
#warning "Xpetra Kokkos interface for CrsMatrix is enabled (HAVE_XPETRA_KOKKOS_REFACTOR) but Tpetra is disabled. The Kokkos interface needs Tpetra to be enabled, too."
#endif
#endif
#endif
}; // EpetraCrsMatrixT class
#endif // #ifndef XPETRA_EPETRA_NO_64BIT_GLOBAL_INDICES
} // Xpetra namespace
#define XPETRA_EPETRACRSMATRIX_SHORT
#endif // XPETRA_EPETRACRSMATRIX_HPP
|