2331 localRow <<
") = " << getNumEntriesInLocalRow(localRow) <<
2332 ". Please report this bug to the Tpetra developers.");
2337 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2342 global_inds_host_view_type &indices)
const
2347 (isLocallyIndexed (), std::runtime_error,
"The graph's indices are "
2348 "currently stored as local indices, so we cannot return a view with "
2349 "global column indices. Use getGlobalRowCopy() instead.");
2354 if (
rowInfo.localRow != Teuchos::OrdinalTraits<size_t>::invalid () &&
2356 indices = gblInds_wdv.getHostSubview(
rowInfo.offset1D,
2361 indices =
typename global_inds_dualv_type::t_host::const_type();
2365 (
static_cast<size_t> (indices.size ()) !=
2367 std::logic_error,
"indices.size() = " << indices.extent(0)
2368 <<
" != getNumEntriesInGlobalRow(globalRow=" <<
globalRow <<
") = "
2370 <<
". Please report this bug to the Tpetra developers.");
2375 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2379 const Teuchos::ArrayView<const LocalOrdinal>& indices)
2384 (! isFillActive (), std::runtime_error,
"Fill must be active.");
2386 (isGloballyIndexed (), std::runtime_error,
2387 "Graph indices are global; use insertGlobalIndices().");
2389 (! hasColMap (), std::runtime_error,
2390 "Cannot insert local indices without a column Map.");
2392 (! rowMap_->isNodeLocalElement (localRow), std::runtime_error,
2393 "Local row index " << localRow <<
" is not in the row Map "
2394 "on the calling process.");
2395 if (! indicesAreAllocated ()) {
2396 allocateIndices (LocalIndices, verbose_);
2405 using Teuchos::Array;
2406 using Teuchos::toString;
2408 typedef typename Teuchos::ArrayView<const LocalOrdinal>::size_type size_type;
2413 for (size_type
k = 0;
k < indices.size (); ++
k) {
2414 if (!
colMap.isNodeLocalElement (indices[
k])) {
2420 std::ostringstream
os;
2421 os <<
"Tpetra::CrsGraph::insertLocalIndices: You attempted to insert "
2422 "entries in owned row " << localRow <<
", at the following column "
2423 "indices: " << toString (indices) <<
"." <<
endl;
2424 os <<
"Of those, the following indices are not in the column Map on "
2425 "this process: " << toString (
badColInds) <<
"." <<
endl <<
"Since "
2426 "the graph has a column Map already, it is invalid to insert entries "
2427 "at those locations.";
2433 insertLocalIndicesImpl (localRow, indices);
2437 (! indicesAreAllocated () || ! isLocallyIndexed (), std::logic_error,
2438 "At the end of insertLocalIndices, ! indicesAreAllocated() || "
2439 "! isLocallyIndexed() is true. Please report this bug to the "
2440 "Tpetra developers.");
2444 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2452 this->insertLocalIndices (localRow,
indsT);
2456 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2467 (this->isLocallyIndexed (), std::runtime_error,
2468 "graph indices are local; use insertLocalIndices().");
2474 (! this->isFillActive (), std::runtime_error,
2475 "You are not allowed to call this method if fill is not active. "
2476 "If fillComplete has been called, you must first call resumeFill "
2477 "before you may insert indices.");
2478 if (! indicesAreAllocated ()) {
2479 allocateIndices (GlobalIndices, verbose_);
2481 const LO
lclRow = this->rowMap_->getLocalElement (
gblRow);
2482 if (
lclRow != Tpetra::Details::OrdinalTraits<LO>::invalid ()) {
2484 if (this->hasColMap ()) {
2500 std::ostringstream
os;
2501 os <<
"You attempted to insert entries in owned row " <<
gblRow
2502 <<
", at the following column indices: [";
2509 os <<
"]." <<
endl <<
"Of those, the following indices are not in "
2510 "the column Map on this process: [";
2517 os <<
"]." <<
endl <<
"Since the matrix has a column Map already, "
2518 "it is invalid to insert entries at those locations.";
2520 (
true, std::invalid_argument,
os.str ());
2533 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2544 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2553 const char tfecfFuncName[] =
"insertGlobalIndicesFiltered: ";
2556 (this->isLocallyIndexed (), std::runtime_error,
2557 "Graph indices are local; use insertLocalIndices().");
2563 (! this->isFillActive (), std::runtime_error,
2564 "You are not allowed to call this method if fill is not active. "
2565 "If fillComplete has been called, you must first call resumeFill "
2566 "before you may insert indices.");
2567 if (! indicesAreAllocated ()) {
2568 allocateIndices (GlobalIndices, verbose_);
2573 if (! colMap_.is_null ()) {
2584 if (
lclCol == Tpetra::Details::OrdinalTraits<LO>::invalid ()) {
2608 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2627 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2634 ! isFillActive (), std::runtime_error,
"requires that fill is active.");
2636 isStorageOptimized (), std::runtime_error,
2637 "cannot remove indices after optimizeStorage() has been called.");
2639 isGloballyIndexed (), std::runtime_error,
"graph indices are global.");
2641 ! rowMap_->isNodeLocalElement (
lrow), std::runtime_error,
2642 "Local row " <<
lrow <<
" is not in the row Map on the calling process.");
2643 if (! indicesAreAllocated ()) {
2644 allocateIndices (LocalIndices, verbose_);
2647 if (k_numRowEntries_.extent (0) != 0) {
2648 this->k_numRowEntries_(
lrow) = 0;
2653 (getNumEntriesInLocalRow (
lrow) != 0 ||
2654 ! indicesAreAllocated () ||
2655 ! isLocallyIndexed (), std::logic_error,
2656 "Violated stated post-conditions. Please contact Tpetra team.");
2661 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2665 const typename local_graph_device_type::entries_type::non_const_type&
columnIndices)
2668 ProfilingRegion
region (
"Tpetra::CrsGraph::setAllIndices");
2671 ! hasColMap () || getColMap ().
is_null (), std::runtime_error,
2672 "The graph must have a column Map before you may call this method.");
2679 std::runtime_error,
"Have 0 local rows, but rowPointers.size() is neither 0 nor 1.");
2684 std::runtime_error,
"rowPointers.size() = " <<
rowPtrLen <<
2685 " != this->getLocalNumRows()+1 = " << (
numLocalRows + 1) <<
".");
2690 using exec_space =
typename local_graph_device_type::execution_space;
2693 Kokkos::parallel_reduce(Kokkos::RangePolicy<exec_space>(0,
columnIndices.extent(0)),
2700 auto comm = this->getComm();
2709 message = std::string(
"ERROR, rank ") + std::to_string(comm->getRank()) +
", CrsGraph::setAllIndices(): provided columnIndices are not all within range [0, getLocalNumCols())!\n";
2712 throw std::invalid_argument(
"CrsGraph::setAllIndices(): columnIndices are out of the valid range on at least one process.");
2716 if (debug_ && this->isSorted()) {
2719 using exec_space =
typename local_graph_device_type::execution_space;
2720 using size_type =
typename local_graph_device_type::size_type;
2721 Kokkos::parallel_reduce(Kokkos::RangePolicy<exec_space>(0,
numLocalRows),
2736 auto comm = this->getComm();
2737 Teuchos::reduceAll<int, int> (*comm, Teuchos::REDUCE_MAX,
notSorted,
2745 message = std::string(
"ERROR, rank ") + std::to_string(comm->getRank()) +
", CrsGraph::setAllIndices(): provided columnIndices are not sorted!\n";
2748 throw std::invalid_argument(
"CrsGraph::setAllIndices(): provided columnIndices are not sorted within rows on at least one process.");
2752 indicesAreAllocated_ =
true;
2753 indicesAreLocal_ =
true;
2754 indicesAreSorted_ =
true;
2755 noRedundancies_ =
true;
2757 lclIndsUnpacked_wdv = lclIndsPacked_wdv;
2760 set_need_sync_host_uvm_access();
2764 storageStatus_ = Details::STORAGE_1D_PACKED;
2769 numAllocForAllRows_ = 0;
2770 k_numAllocPerRow_ =
decltype (k_numAllocPerRow_) ();
2772 checkInternalState ();
2776 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2783 typedef typename local_graph_device_type::row_map_type
row_map_type;
2784 typedef typename row_map_type::array_layout
layout_type;
2787 Kokkos::MemoryUnmanaged> input_view_type;
2791 constexpr bool same = std::is_same<size_t, row_offset_type>::value;
2797#ifdef KOKKOS_ENABLE_CXX17
2798 if constexpr (
same) {
2812 Kokkos::Impl::if_c<
same,
2821 std::is_same<
typename row_map_type::memory_space,
2822 Kokkos::HostSpace>::value;
2845 Kokkos::View<LocalOrdinal*, layout_type, device_type>
k_ind =
2846 Kokkos::Compat::getKokkosViewDeepCopy<device_type> (
columnIndices ());
2851 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2856 using Teuchos::Comm;
2857 using Teuchos::outArg;
2860 using Teuchos::REDUCE_MAX;
2861 using Teuchos::REDUCE_MIN;
2862 using Teuchos::reduceAll;
2867 using size_type =
typename Teuchos::Array<GO>::size_type;
2870 std::unique_ptr<std::string>
prefix;
2872 prefix = this->createPrefix(
"CrsGraph",
"globalAssemble");
2873 std::ostringstream
os;
2875 std::cerr <<
os.str();
2880 (! isFillActive (), std::runtime_error,
"Fill must be active before "
2881 "you may call this method.");
2896 std::ostringstream
os;
2898 std::cerr <<
os.str();
2902 else if (verbose_) {
2903 std::ostringstream
os;
2904 os << *
prefix <<
"At least 1 process has nonlocal rows"
2906 std::cerr <<
os.str();
2925 for (
auto mapIter = this->nonlocals_.begin ();
2926 mapIter != this->nonlocals_.end ();
2956 const global_size_t INV = Teuchos::OrdinalTraits<global_size_t>::invalid ();
2961 std::ostringstream
os;
2962 os << *
prefix <<
"nonlocalRowMap->getIndexBase()="
2964 std::cerr <<
os.str();
2976 for (
auto mapIter = this->nonlocals_.begin ();
2977 mapIter != this->nonlocals_.end ();
2986 std::ostringstream
os;
2988 std::cerr <<
os.str();
3004 std::ostringstream
os;
3006 std::cerr <<
os.str();
3014 std::ostringstream
os;
3015 os << *
prefix <<
"Original row Map is NOT 1-to-1" <<
endl;
3016 std::cerr <<
os.str();
3033 std::ostringstream
os;
3035 std::cerr <<
os.str();
3046 std::ostringstream
os;
3048 std::cerr <<
os.str();
3060 checkInternalState ();
3062 std::ostringstream
os;
3064 std::cerr <<
os.str();
3069 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
3074 clearGlobalConstants();
3075 if (
params != Teuchos::null) this->setParameterList (
params);
3077 indicesAreSorted_ =
true;
3078 noRedundancies_ =
true;
3079 fillComplete_ =
false;
3083 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
3098 Teuchos::RCP<const map_type>
domMap = this->getDomainMap ();
3100 domMap = this->getRowMap ();
3102 Teuchos::RCP<const map_type>
ranMap = this->getRangeMap ();
3104 ranMap = this->getRowMap ();
3110 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
3113 fillComplete (
const Teuchos::RCP<const map_type>& domainMap,
3114 const Teuchos::RCP<const map_type>&
rangeMap,
3115 const Teuchos::RCP<Teuchos::ParameterList>&
params)
3119 const bool verbose = verbose_;
3121 std::unique_ptr<std::string>
prefix;
3123 prefix = this->createPrefix(
"CrsGraph",
"fillComplete");
3124 std::ostringstream
os;
3126 std::cerr <<
os.str();
3130 (! isFillActive () || isFillComplete (), std::runtime_error,
3131 "Graph fill state must be active (isFillActive() "
3132 "must be true) before calling fillComplete().");
3134 const int numProcs = getComm ()->getSize ();
3142 if (!
params.is_null ()) {
3143 if (
params->isParameter (
"sort column map ghost gids")) {
3144 sortGhostsAssociatedWithEachProcessor_ =
3145 params->get<
bool> (
"sort column map ghost gids",
3146 sortGhostsAssociatedWithEachProcessor_);
3148 else if (
params->isParameter (
"Sort column Map ghost GIDs")) {
3149 sortGhostsAssociatedWithEachProcessor_ =
3150 params->get<
bool> (
"Sort column Map ghost GIDs",
3151 sortGhostsAssociatedWithEachProcessor_);
3158 if (!
params.is_null ()) {
3166 if (! indicesAreAllocated ()) {
3169 allocateIndices (LocalIndices, verbose);
3172 allocateIndices (GlobalIndices, verbose);
3189 std::ostringstream
os;
3190 os << *
prefix <<
"Do not need to call globalAssemble; "
3191 "assertNoNonlocalInserts="
3195 std::cerr <<
os.str();
3200 std::ostringstream
os;
3202 Details::Impl::verbosePrintMap(
3203 os, nonlocals_.begin(), nonlocals_.end(),
3204 nonlocals_.size(),
"nonlocals_");
3205 std::cerr <<
os.str() <<
endl;
3209 auto map = this->getMap();
3210 auto comm =
map.is_null() ? Teuchos::null :
map->getComm();
3212 if (! comm.is_null()) {
3213 using Teuchos::REDUCE_MAX;
3214 using Teuchos::reduceAll;
3221 "least one process in the CrsGraph's communicator. This "
3222 "means either that you incorrectly set the "
3223 "\"No Nonlocal Changes\" fillComplete parameter to true, "
3224 "or that you inserted invalid entries. "
3225 "Rerun with the environment variable TPETRA_VERBOSE="
3226 "CrsGraph set to see the entries of nonlocals_ on every "
3227 "MPI process (WARNING: lots of output).");
3232 "nonlocals_.size()=" <<
numNonlocals <<
" != 0 on the "
3233 "calling process. This means either that you incorrectly "
3234 "set the \"No Nonlocal Changes\" fillComplete parameter "
3235 "to true, or that you inserted invalid entries. "
3236 "Rerun with the environment "
3237 "variable TPETRA_VERBOSE=CrsGraph set to see the entries "
3238 "of nonlocals_ on every MPI process (WARNING: lots of "
3251 Teuchos::Array<int> remotePIDs (0);
3254 this->makeColMap (remotePIDs);
3260 this->makeIndicesLocal(verbose);
3265 using Teuchos::REDUCE_MIN;
3266 using Teuchos::reduceAll;
3267 using Teuchos::outArg;
3271 if (!
map.is_null ()) {
3272 comm =
map->getComm ();
3274 if (comm.is_null ()) {
3284 std::ostringstream
os;
3287 (
true, std::runtime_error,
os.str ());
3304 this->sortAndMergeAllIndices (this->isSorted (), this->isMerged ());
3312 this->fillLocalGraph (
params);
3315 params->get (
"compute global constants",
true);
3317 this->computeGlobalConstants ();
3320 this->computeLocalConstants ();
3322 this->fillComplete_ =
true;
3323 this->checkInternalState ();
3326 std::ostringstream
os;
3328 std::cerr <<
os.str();
3333 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
3337 const Teuchos::RCP<const map_type>&
rangeMap,
3338 const Teuchos::RCP<const import_type>&
importer,
3339 const Teuchos::RCP<const export_type>&
exporter,
3340 const Teuchos::RCP<Teuchos::ParameterList>&
params)
3343#ifdef HAVE_TPETRA_MMM_TIMINGS
3346 label =
params->get(
"Timer Label",label);
3347 std::string
prefix = std::string(
"Tpetra ")+ label + std::string(
": ");
3348 using Teuchos::TimeMonitor;
3349 Teuchos::RCP<Teuchos::TimeMonitor>
MM = Teuchos::rcp(
new TimeMonitor(*TimeMonitor::getNewTimer(
prefix + std::string(
"ESFC-G-Setup"))));
3355 std::runtime_error,
"The input domain Map and range Map must be nonnull.");
3357 isFillComplete () || ! hasColMap (), std::runtime_error,
"You may not "
3358 "call this method unless the graph has a column Map.");
3362 std::runtime_error,
"The calling process has getLocalNumRows() = "
3363 << getLocalNumRows () <<
" > 0 rows, but the row offsets array has not "
3367 std::runtime_error,
"The row offsets array has length " <<
3369 (getLocalNumRows () + 1) <<
".");
3384 numAllocForAllRows_ = 0;
3385 k_numAllocPerRow_ =
decltype (k_numAllocPerRow_) ();
3386 indicesAreAllocated_ =
true;
3391 indicesAreLocal_ =
true;
3392 indicesAreGlobal_ =
false;
3395#ifdef HAVE_TPETRA_MMM_TIMINGS
3397 MM = Teuchos::rcp(
new TimeMonitor(*TimeMonitor::getNewTimer(
prefix + std::string(
"ESFC-G-Maps"))));
3402 indicesAreSorted_ =
true;
3403 noRedundancies_ =
true;
3406#ifdef HAVE_TPETRA_MMM_TIMINGS
3408 MM = Teuchos::rcp(
new TimeMonitor(*TimeMonitor::getNewTimer(
prefix + std::string(
"ESFC-G-mIXcheckI"))));
3411 importer_ = Teuchos::null;
3412 exporter_ = Teuchos::null;
3415 !
importer->getSourceMap ()->isSameAs (*getDomainMap ()) ||
3416 !
importer->getTargetMap ()->isSameAs (*getColMap ()),
3417 std::invalid_argument,
": importer does not match matrix maps.");
3422#ifdef HAVE_TPETRA_MMM_TIMINGS
3424 MM = Teuchos::rcp(
new TimeMonitor(*TimeMonitor::getNewTimer(
prefix + std::string(
"ESFC-G-mIXcheckE"))));
3429 !
exporter->getSourceMap ()->isSameAs (*getRowMap ()) ||
3430 !
exporter->getTargetMap ()->isSameAs (*getRangeMap ()),
3431 std::invalid_argument,
": exporter does not match matrix maps.");
3435#ifdef HAVE_TPETRA_MMM_TIMINGS
3437 MM = Teuchos::rcp(
new TimeMonitor(*TimeMonitor::getNewTimer(
prefix + std::string(
"ESFC-G-mIXmake"))));
3439 Teuchos::Array<int> remotePIDs (0);
3440 this->makeImportExport (remotePIDs,
false);
3442#ifdef HAVE_TPETRA_MMM_TIMINGS
3444 MM = Teuchos::rcp(
new TimeMonitor(*TimeMonitor::getNewTimer(
prefix + std::string(
"ESFC-G-fLG"))));
3446 this->fillLocalGraph (
params);
3449 params->get (
"compute global constants",
true);
3452#ifdef HAVE_TPETRA_MMM_TIMINGS
3454 MM = Teuchos::rcp(
new TimeMonitor(*TimeMonitor::getNewTimer(
prefix + std::string(
"ESFC-G-cGC (const)"))));
3456 this->computeGlobalConstants ();
3459#ifdef HAVE_TPETRA_MMM_TIMINGS
3461 MM = Teuchos::rcp(
new TimeMonitor(*TimeMonitor::getNewTimer(
prefix + std::string(
"ESFC-G-cGC (noconst)"))));
3463 this->computeLocalConstants ();
3466 fillComplete_ =
true;
3468#ifdef HAVE_TPETRA_MMM_TIMINGS
3470 MM = Teuchos::rcp(
new TimeMonitor(*TimeMonitor::getNewTimer(
prefix + std::string(
"ESFC-G-cIS"))));
3472 checkInternalState ();
3476 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
3481 using ::Tpetra::Details::computeOffsetsFromCounts;
3483 typedef typename local_graph_device_type::row_map_type
row_map_type;
3485 typedef typename local_graph_device_type::entries_type::non_const_type
lclinds_1d_type;
3486 const char tfecfFuncName[] =
"fillLocalGraph (called from fillComplete or "
3487 "expertStaticFillComplete): ";
3488 const size_t lclNumRows = this->getLocalNumRows ();
3494 if (!
params.is_null () && !
params->get (
"Optimize Storage",
true)) {
3503 auto rowPtrsUnpacked = this->getRowPtrsUnpackedHost();
3505 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC
3506 (rowPtrsUnpacked.extent (0) == 0, std::logic_error,
3507 "rowPtrsUnpacked_host_ has size zero, but shouldn't");
3508 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC
3509 (rowPtrsUnpacked.extent (0) != lclNumRows + 1, std::logic_error,
3510 "rowPtrsUnpacked_host_.extent(0) = "
3511 << rowPtrsUnpacked.extent (0) <<
" != (lclNumRows + 1) = "
3512 << (lclNumRows + 1) <<
".");
3513 const size_t numOffsets = rowPtrsUnpacked.extent (0);
3514 const auto valToCheck = rowPtrsUnpacked(numOffsets-1);
3515 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC
3517 lclIndsUnpacked_wdv.extent (0) != valToCheck,
3518 std::logic_error,
"numOffsets=" << numOffsets <<
" != 0 "
3519 " and lclIndsUnpacked_wdv.extent(0)=" << lclIndsUnpacked_wdv.extent(0)
3520 <<
" != rowPtrsUnpacked_host_(" << numOffsets <<
")=" << valToCheck
3524 size_t allocSize = 0;
3526 allocSize = this->getLocalAllocationSize ();
3528 catch (std::logic_error& e) {
3529 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC
3530 (
true, std::logic_error,
"getLocalAllocationSize threw "
3531 "std::logic_error: " << e.what ());
3533 catch (std::runtime_error& e) {
3534 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC
3535 (
true, std::runtime_error,
"getLocalAllocationSize threw "
3536 "std::runtime_error: " << e.what ());
3538 catch (std::exception& e) {
3539 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC
3540 (
true, std::runtime_error,
"getLocalAllocationSize threw "
3541 "std::exception: " << e.what ());
3544 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC
3545 (
true, std::runtime_error,
"getLocalAllocationSize threw "
3546 "an exception not a subclass of std::exception.");
3549 if (this->getLocalNumEntries () != allocSize) {
3552 non_const_row_map_type ptr_d;
3553 row_map_type ptr_d_const;
3562 auto rowPtrsUnpacked = this->getRowPtrsUnpackedHost();
3563 if (rowPtrsUnpacked.extent (0) != 0) {
3564 const size_t numOffsets =
3565 static_cast<size_t> (rowPtrsUnpacked.extent (0));
3566 const auto valToCheck = rowPtrsUnpacked(numOffsets - 1);
3567 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC
3568 (valToCheck !=
size_t(lclIndsUnpacked_wdv.extent(0)),
3569 std::logic_error,
"(Unpacked branch) Before allocating "
3570 "or packing, k_rowPtrs_(" << (numOffsets-1) <<
")="
3571 << valToCheck <<
" != lclIndsUnpacked_wdv.extent(0)="
3572 << lclIndsUnpacked_wdv.extent (0) <<
".");
3582 size_t lclTotalNumEntries = 0;
3586 non_const_row_map_type (
"Tpetra::CrsGraph::ptr", lclNumRows + 1);
3587 ptr_d_const = ptr_d;
3591 typename row_entries_type::const_type numRowEnt_h = k_numRowEntries_;
3593 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC
3594 (
size_t(numRowEnt_h.extent (0)) != lclNumRows,
3595 std::logic_error,
"(Unpacked branch) "
3596 "numRowEnt_h.extent(0)=" << numRowEnt_h.extent(0)
3597 <<
" != getLocalNumRows()=" << lclNumRows <<
"");
3603 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC
3604 (
static_cast<size_t> (ptr_d.extent (0)) != lclNumRows + 1,
3605 std::logic_error,
"(Unpacked branch) After allocating "
3606 "ptr_d, ptr_d.extent(0) = " << ptr_d.extent(0)
3607 <<
" != lclNumRows+1 = " << (lclNumRows+1) <<
".");
3608 const auto valToCheck =
3609 ::Tpetra::Details::getEntryOnHost (ptr_d, lclNumRows);
3610 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC
3611 (valToCheck != lclTotalNumEntries, std::logic_error,
3612 "Tpetra::CrsGraph::fillLocalGraph: In unpacked branch, "
3613 "after filling ptr_d, ptr_d(lclNumRows=" << lclNumRows
3614 <<
") = " << valToCheck <<
" != total number of entries "
3615 "on the calling process = " << lclTotalNumEntries
3621 lclinds_1d_type ind_d =
3622 lclinds_1d_type (
"Tpetra::CrsGraph::lclInd", lclTotalNumEntries);
3634 typedef pack_functor<
3635 typename local_graph_device_type::entries_type::non_const_type,
3636 typename local_inds_dualv_type::t_dev::const_type,
3638 typename local_graph_device_type::row_map_type> inds_packer_type;
3639 inds_packer_type f (ind_d,
3640 lclIndsUnpacked_wdv.getDeviceView(Access::ReadOnly),
3641 ptr_d, this->getRowPtrsUnpackedDevice());
3643 typedef typename decltype (ind_d)::execution_space exec_space;
3644 typedef Kokkos::RangePolicy<exec_space, LocalOrdinal> range_type;
3645 Kokkos::parallel_for (range_type (0, lclNumRows), f);
3649 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC
3650 (ptr_d.extent (0) == 0, std::logic_error,
3651 "(\"Optimize Storage\"=true branch) After packing, "
3652 "ptr_d.extent(0)=0.");
3653 if (ptr_d.extent (0) != 0) {
3654 const size_t numOffsets =
static_cast<size_t> (ptr_d.extent (0));
3655 const auto valToCheck =
3656 ::Tpetra::Details::getEntryOnHost (ptr_d, numOffsets - 1);
3657 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC
3658 (
static_cast<size_t> (valToCheck) != ind_d.extent (0),
3659 std::logic_error,
"(\"Optimize Storage\"=true branch) "
3660 "After packing, ptr_d(" << (numOffsets-1) <<
")="
3661 << valToCheck <<
" != ind_d.extent(0)="
3662 << ind_d.extent(0) <<
".");
3666 if (requestOptimizedStorage)
3667 setRowPtrs(ptr_d_const);
3669 setRowPtrsPacked(ptr_d_const);
3670 lclIndsPacked_wdv = local_inds_wdv_type(ind_d);
3674 this->setRowPtrs(rowPtrsUnpacked_dev_);
3675 lclIndsPacked_wdv = lclIndsUnpacked_wdv;
3678 auto rowPtrsPacked_dev = this->getRowPtrsPackedDevice();
3679 auto rowPtrsPacked_host = this->getRowPtrsPackedHost();
3680 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC
3681 (rowPtrsPacked_dev.extent (0) == 0, std::logic_error,
3682 "(\"Optimize Storage\"=false branch) "
3683 "rowPtrsPacked_dev_.extent(0) = 0.");
3684 if (rowPtrsPacked_dev.extent (0) != 0) {
3685 const size_t numOffsets =
3686 static_cast<size_t> (rowPtrsPacked_dev.extent (0));
3687 const size_t valToCheck =
3688 rowPtrsPacked_host(numOffsets - 1);
3689 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC
3690 (valToCheck !=
size_t(lclIndsPacked_wdv.extent (0)),
3691 std::logic_error,
"(\"Optimize Storage\"=false branch) "
3692 "rowPtrsPacked_dev_(" << (numOffsets-1) <<
")="
3694 <<
" != lclIndsPacked_wdv.extent(0)="
3695 << lclIndsPacked_wdv.extent (0) <<
".");
3701 auto rowPtrsPacked_dev = this->getRowPtrsPackedDevice();
3702 auto rowPtrsPacked_host = this->getRowPtrsPackedHost();
3703 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC
3704 (
static_cast<size_t> (rowPtrsPacked_dev.extent (0)) != lclNumRows + 1,
3705 std::logic_error,
"After packing, rowPtrsPacked_dev_.extent(0) = " <<
3706 rowPtrsPacked_dev.extent (0) <<
" != lclNumRows+1 = " << (lclNumRows+1)
3708 if (rowPtrsPacked_dev.extent (0) != 0) {
3709 const size_t numOffsets =
static_cast<size_t> (rowPtrsPacked_dev.extent (0));
3710 const auto valToCheck = rowPtrsPacked_host(numOffsets - 1);
3711 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC
3712 (
static_cast<size_t> (valToCheck) != lclIndsPacked_wdv.extent (0),
3713 std::logic_error,
"After packing, rowPtrsPacked_dev_(" << (numOffsets-1)
3714 <<
") = " << valToCheck <<
" != lclIndsPacked_wdv.extent(0) = "
3715 << lclIndsPacked_wdv.extent (0) <<
".");
3719 if (requestOptimizedStorage) {
3725 k_numRowEntries_ = row_entries_type ();
3728 lclIndsUnpacked_wdv = lclIndsPacked_wdv;
3730 storageStatus_ = Details::STORAGE_1D_PACKED;
3733 set_need_sync_host_uvm_access();
3736 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
3750 isLocallyIndexed () || isGloballyIndexed (), std::runtime_error,
3751 "Requires matching maps and non-static graph.");
3755 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
3759 const Teuchos::RCP<const import_type>&
newImport,
3762 using Teuchos::REDUCE_MIN;
3763 using Teuchos::reduceAll;
3767 typedef typename local_inds_dualv_type::t_host
col_inds_type;
3771 isFillComplete (), std::runtime_error,
"The graph is fill complete "
3772 "(isFillComplete() returns true). You must call resumeFill() before "
3773 "you may call this method.");
3791 const LO
lclNumRows =
static_cast<LO
> (this->getLocalNumRows ());
3820 auto oldLclInds1D = lclIndsUnpacked_wdv.getHostView(Access::ReadOnly);
3825 if (indicesAreAllocated ()) {
3826 if (isLocallyIndexed ()) {
3830 const size_t allocSize = this->getLocalAllocationSize ();
3840 if (
oldLclCol == Teuchos::OrdinalTraits<LO>::invalid ()) {
3849 if (
gblCol == Teuchos::OrdinalTraits<GO>::invalid ()) {
3855 if (
newLclCol == Teuchos::OrdinalTraits<LO>::invalid ()) {
3890 for (
size_t k = 0;
k <
rowInfo.numEntries; ++
k) {
3909 getRowMap ().is_null () ? Teuchos::null : getRowMap ()->getComm ();
3910 if (! comm.is_null ()) {
3915 gblSuccess[0] == 0, std::runtime_error,
"It is not possible to continue."
3916 " The most likely reason is that the graph is locally indexed, but the "
3917 "column Map is missing (null) on some processes, due to a previous call "
3918 "to replaceColMap().");
3921 gblSuccess[1] == 0, std::runtime_error,
"On some process, the graph "
3922 "contains column indices that are in the old column Map, but not in the "
3923 "new column Map (on that process). This method does NOT redistribute "
3924 "data; it does not claim to do the work of an Import or Export operation."
3925 " This means that for all processess, the calling process MUST own all "
3926 "column indices, in both the old column Map and the new column Map. In "
3927 "this case, you will need to do an Import or Export operation to "
3928 "redistribute data.");
3931 if (isLocallyIndexed ()) {
3934 Kokkos::view_alloc(
"Tpetra::CrsGraph::lclIndReindexed",
3935 Kokkos::WithoutInitializing),
3947 indicesAreSorted_ =
false;
3955 const bool sorted =
false;
3956 const bool merged =
true;
3970 if (! domainMap_.is_null ()) {
3971 if (! domainMap_->isSameAs (*
newColMap)) {
3974 importer_ = Teuchos::null;
3983 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
3988 const char prefix[] =
"Tpetra::CrsGraph::replaceDomainMap: ";
3990 colMap_.is_null (), std::invalid_argument,
prefix <<
"You may not call "
3991 "this method unless the graph already has a column Map.");
3994 prefix <<
"The new domain Map must be nonnull.");
3997 Teuchos::RCP<const import_type>
newImporter = Teuchos::null;
4004 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
4008 const Teuchos::RCP<const import_type>&
newImporter)
4010 const char prefix[] =
"Tpetra::CrsGraph::replaceDomainMapAndImporter: ";
4012 colMap_.is_null (), std::invalid_argument,
prefix <<
"You may not call "
4013 "this method unless the graph already has a column Map.");
4016 prefix <<
"The new domain Map must be nonnull.");
4026 (!
colSameAsDom, std::invalid_argument,
"If the new Import is null, "
4027 "then the new domain Map must be the same as the current column Map.");
4031 colMap_->isSameAs (* (
newImporter->getTargetMap ()));
4036 "new Import is nonnull, then the current column Map must be the same "
4037 "as the new Import's target Map, and the new domain Map must be the "
4038 "same as the new Import's source Map.");
4043 importer_ = Teuchos::rcp_const_cast<import_type> (
newImporter);
4046 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
4051 const char prefix[] =
"Tpetra::CrsGraph::replaceRangeMap: ";
4053 rowMap_.is_null (), std::invalid_argument,
prefix <<
"You may not call "
4054 "this method unless the graph already has a row Map.");
4057 prefix <<
"The new range Map must be nonnull.");
4060 Teuchos::RCP<const export_type>
newExporter = Teuchos::null;
4067 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
4071 const Teuchos::RCP<const export_type>&
newExporter)
4073 const char prefix[] =
"Tpetra::CrsGraph::replaceRangeMapAndExporter: ";
4075 rowMap_.is_null (), std::invalid_argument,
prefix <<
"You may not call "
4076 "this method unless the graph already has a column Map.");
4079 prefix <<
"The new domain Map must be nonnull.");
4089 (!
rowSameAsRange, std::invalid_argument,
"If the new Export is null, "
4090 "then the new range Map must be the same as the current row Map.");
4096 rowMap_->isSameAs (* (
newExporter->getSourceMap ()));
4099 "new Export is nonnull, then the current row Map must be the same "
4100 "as the new Export's source Map, and the new range Map must be the "
4101 "same as the new Export's target Map.");
4106 exporter_ = Teuchos::rcp_const_cast<export_type> (
newExporter);
4110 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
4116 lclIndsPacked_wdv.getDeviceView(Access::ReadWrite),
4117 this->getRowPtrsPackedDevice());
4120 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
4125 return local_graph_host_type(
4126 lclIndsPacked_wdv.getHostView(Access::ReadWrite),
4127 this->getRowPtrsPackedHost());
4130 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
4135 using ::Tpetra::Details::ProfilingRegion;
4136 using Teuchos::ArrayView;
4137 using Teuchos::outArg;
4138 using Teuchos::reduceAll;
4141 ProfilingRegion
regionCGC (
"Tpetra::CrsGraph::computeGlobalConstants");
4143 this->computeLocalConstants ();
4148 if (! this->haveGlobalConstants_) {
4149 const Teuchos::Comm<int>& comm = * (this->getComm ());
4163 lcl =
static_cast<GST> (this->getLocalNumEntries ());
4166 this->globalNumEntries_ =
gbl;
4170 outArg (this->globalMaxNumRowEntries_));
4171 this->haveGlobalConstants_ =
true;
4176 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
4181 using ::Tpetra::Details::ProfilingRegion;
4183 ProfilingRegion
regionCLC (
"Tpetra::CrsGraph::computeLocalConstants");
4184 if (this->haveLocalConstants_) {
4189 this->nodeMaxNumRowEntries_ =
4190 Teuchos::OrdinalTraits<size_t>::invalid();
4194 auto ptr = this->getRowPtrsPackedDevice();
4196 static_cast<LO
> (0) :
4197 (
static_cast<LO
> (
ptr.extent(0)) -
static_cast<LO
> (1));
4200 ::Tpetra::Details::maxDifference (
"Tpetra::CrsGraph: nodeMaxNumRowEntries",
4203 this->haveLocalConstants_ =
true;
4207 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
4208 std::pair<size_t, std::string>
4213 using Teuchos::arcp;
4214 using Teuchos::Array;
4219 typedef typename local_graph_device_type::row_map_type::non_const_value_type offset_type;
4221 typedef typename row_entries_type::non_const_value_type
num_ent_type;
4225 std::unique_ptr<std::string>
prefix;
4227 prefix = this->createPrefix(
"CrsGraph",
"makeIndicesLocal");
4228 std::ostringstream
os;
4229 os << *
prefix <<
"lclNumRows: " << getLocalNumRows() <<
endl;
4230 std::cerr <<
os.str();
4236 (! this->hasColMap (), std::logic_error,
"The graph does not have a "
4237 "column Map yet. This method should never be called in that case. "
4238 "Please report this bug to the Tpetra developers.");
4240 (this->getColMap ().
is_null (), std::logic_error,
"The graph claims "
4241 "that it has a column Map, because hasColMap() returns true. However, "
4242 "the result of getColMap() is null. This should never happen. Please "
4243 "report this bug to the Tpetra developers.");
4251 const LO
lclNumRows =
static_cast<LO
> (this->getLocalNumRows ());
4254 if (this->isGloballyIndexed () &&
lclNumRows != 0) {
4256 typename row_entries_type::const_type
h_numRowEnt =
4257 this->k_numRowEntries_;
4263 errStrm <<
"Unpacked row pointers (rowPtrsUnpacked_dev_) has length 0. This should never "
4264 "happen here. Please report this bug to the Tpetra developers."
4267 return std::make_pair(Tpetra::Details::OrdinalTraits<size_t>::invalid (),
4279 using Kokkos::view_alloc;
4280 using Kokkos::WithoutInitializing;
4290 const std::string label (
"Tpetra::CrsGraph::lclInd");
4292 std::ostringstream
os;
4293 os << *
prefix <<
"(Re)allocate lclInd_wdv: old="
4294 << lclIndsUnpacked_wdv.extent(0) <<
", new=" <<
numEnt <<
endl;
4295 std::cerr <<
os.str();
4312 std::ostringstream
os;
4313 os << *
prefix <<
"Allocate device mirror k_numRowEnt: "
4315 std::cerr <<
os.str();
4320 using ::Tpetra::Details::convertColumnIndicesFromGlobalToLocal;
4323 lclIndsUnpacked_wdv.getDeviceView(Access::OverwriteAll),
4324 gblInds_wdv.getDeviceView(Access::ReadOnly),
4325 this->getRowPtrsUnpackedDevice(),
4329 const int myRank = [
this] () {
4330 auto map = this->getMap ();
4331 if (
map.is_null ()) {
4335 auto comm =
map->getComm ();
4336 return comm.is_null () ? 0 : comm->getRank ();
4340 errStrm <<
"(Process " <<
myRank <<
") When converting column "
4341 "indices from global to local, we encountered " <<
lclNumErrs
4344 <<
" not live in the column Map on this process." <<
endl;
4351 std::ostringstream
os;
4352 os << *
prefix <<
"Free gblInds_wdv: "
4353 << gblInds_wdv.extent(0) <<
endl;
4354 std::cerr <<
os.str();
4359 this->indicesAreLocal_ =
true;
4360 this->indicesAreGlobal_ =
false;
4361 this->checkInternalState ();
4366 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
4376 std::unique_ptr<std::string>
prefix;
4379 std::ostringstream
os;
4381 std::cerr <<
os.str();
4389 Teuchos::RCP<const map_type>
colMap = this->colMap_;
4391 this->sortGhostsAssociatedWithEachProcessor_;
4401 using Teuchos::outArg;
4402 using Teuchos::REDUCE_MIN;
4403 using Teuchos::reduceAll;
4409 auto comm = this->getComm ();
4410 if (! comm.is_null ()) {
4416 std::ostringstream
os;
4419 (
true, std::runtime_error,
": An error happened on at "
4420 "least one process in the CrsGraph's communicator. "
4421 "Here are all processes' error messages:" << std::endl
4435 checkInternalState ();
4437 std::ostringstream
os;
4439 std::cerr <<
os.str();
4444 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
4451 using host_execution_space =
4452 typename Kokkos::View<LO*, device_type>::HostMirror::
4454 using range_type = Kokkos::RangePolicy<host_execution_space, LO>;
4457 (
"Tpetra::CrsGraph::sortAndMergeAllIndices");
4459 std::unique_ptr<std::string>
prefix;
4462 std::ostringstream
os;
4464 <<
"sorted=" << (
sorted ?
"true" :
"false")
4465 <<
", merged=" << (
merged ?
"true" :
"false") <<
endl;
4466 std::cerr <<
os.str();
4468 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC
4469 (this->isGloballyIndexed(), std::logic_error,
4470 "This method may only be called after makeIndicesLocal." );
4471 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC
4472 (! merged && this->isStorageOptimized(), std::logic_error,
4473 "The graph is already storage optimized, so we shouldn't be "
4474 "merging any indices. "
4475 "Please report this bug to the Tpetra developers.");
4477 if (! sorted || ! merged) {
4478 const LO lclNumRows(this->getLocalNumRows());
4479 auto range = range_type(0, lclNumRows);
4482 size_t totalNumDups = 0;
4484 lclIndsUnpacked_wdv.getHostView(Access::ReadWrite);
4486 Kokkos::parallel_reduce(range,
4487 [
this, sorted, merged] (
const LO lclRow,
size_t& numDups)
4489 const RowInfo rowInfo = this->getRowInfo(lclRow);
4490 numDups += this->sortAndMergeRowIndices(rowInfo, sorted, merged);
4494 std::ostringstream os;
4495 os << *prefix <<
"totalNumDups=" << totalNumDups << endl;
4496 std::cerr << os.str();
4500 lclIndsUnpacked_wdv.getHostView(Access::ReadWrite);
4502 Kokkos::parallel_for(range,
4503 [
this, sorted, merged] (
const LO lclRow)
4505 const RowInfo rowInfo = this->getRowInfo(lclRow);
4506 this->sortAndMergeRowIndices(rowInfo, sorted, merged);
4510 this->indicesAreSorted_ =
true;
4511 this->noRedundancies_ =
true;
4515 std::ostringstream os;
4516 os << *prefix <<
"Done" << endl;
4517 std::cerr << os.str();
4521 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
4527 using ::Tpetra::Details::ProfilingRegion;
4528 using Teuchos::ParameterList;
4532 ProfilingRegion
regionMIE (
"Tpetra::CrsGraph::makeImportExport");
4535 (! this->hasColMap (), std::logic_error,
4536 "This method may not be called unless the graph has a column Map.");
4546 if (importer_.is_null ()) {
4548 if (domainMap_ != colMap_ && (! domainMap_->isSameAs (*colMap_))) {
4549 if (
params.is_null () || !
params->isSublist (
"Import")) {
4551 importer_ =
rcp (
new import_type (domainMap_, colMap_, remotePIDs));
4574 if (exporter_.is_null ()) {
4576 if (rangeMap_ != rowMap_ && ! rangeMap_->isSameAs (*rowMap_)) {
4577 if (
params.is_null () || !
params->isSublist (
"Export")) {
4589 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
4594 std::ostringstream
oss;
4595 oss << dist_object_type::description ();
4596 if (isFillComplete ()) {
4597 oss <<
"{status = fill complete"
4598 <<
", global rows = " << getGlobalNumRows()
4599 <<
", global cols = " << getGlobalNumCols()
4600 <<
", global num entries = " << getGlobalNumEntries()
4604 oss <<
"{status = fill not complete"
4605 <<
", global rows = " << getGlobalNumRows()
4612 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
4616 const Teuchos::EVerbosityLevel
verbLevel)
const
4618 using Teuchos::ArrayView;
4619 using Teuchos::Comm;
4621 using Teuchos::VERB_DEFAULT;
4622 using Teuchos::VERB_NONE;
4623 using Teuchos::VERB_LOW;
4624 using Teuchos::VERB_MEDIUM;
4625 using Teuchos::VERB_HIGH;
4626 using Teuchos::VERB_EXTREME;
4636 for (
size_t dec=10;
dec<getGlobalNumRows();
dec *= 10) {
4639 width = std::max<size_t> (
width,
static_cast<size_t> (11)) + 2;
4640 Teuchos::OSTab
tab (
out);
4649 if (
myImageID == 0)
out << this->description() << std::endl;
4651 if (isFillComplete() &&
myImageID == 0) {
4652 out <<
"Global max number of row entries = " << globalMaxNumRowEntries_ << std::endl;
4657 rowMap_->describe(
out,
vl);
4658 if (colMap_ != Teuchos::null) {
4659 if (
myImageID == 0)
out <<
"\nColumn map: " << std::endl;
4660 colMap_->describe(
out,
vl);
4662 if (domainMap_ != Teuchos::null) {
4663 if (
myImageID == 0)
out <<
"\nDomain map: " << std::endl;
4664 domainMap_->describe(
out,
vl);
4666 if (rangeMap_ != Teuchos::null) {
4667 if (
myImageID == 0)
out <<
"\nRange map: " << std::endl;
4668 rangeMap_->describe(
out,
vl);
4676 <<
"Node number of entries = " << this->getLocalNumEntries () << std::endl
4677 <<
"Node max number of entries = " << nodeMaxNumRowEntries_ << std::endl;
4678 if (! indicesAreAllocated ()) {
4679 out <<
"Indices are not allocated." << std::endl;
4691 out << std::setw(
width) <<
"Node ID"
4692 << std::setw(
width) <<
"Global Row"
4693 << std::setw(
width) <<
"Num Entries";
4708 if (isGloballyIndexed()) {
4709 auto rowview = gblInds_wdv.getHostView(Access::ReadOnly);
4710 for (
size_t j=0;
j <
rowinfo.numEntries; ++
j){
4715 else if (isLocallyIndexed()) {
4716 auto rowview = lclIndsUnpacked_wdv.getHostView(Access::ReadOnly);
4717 for (
size_t j=0;
j <
rowinfo.numEntries; ++
j) {
4719 out << colMap_->getGlobalElement(
collid) <<
" ";
4735 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
4746 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
4751 const size_t numSameIDs,
4763 const bool verbose = verbose_;
4765 std::unique_ptr<std::string>
prefix;
4767 prefix = this->createPrefix(
"CrsGraph",
"copyAndPermute");
4768 std::ostringstream
os;
4770 std::cerr <<
os.str ();
4775 std::runtime_error,
"permuteToLIDs.extent(0) = "
4776 <<
permuteToLIDs.extent (0) <<
" != permuteFromLIDs.extent(0) = "
4785 std::ostringstream
os;
4787 std::cerr <<
os.str ();
4791 applyCrsPadding(*
padding, verbose);
4802 nonconst_global_inds_host_view_type
row_copy;
4810 std::ostringstream
os;
4811 os << *
prefix <<
"src_filled || srcCrsGraph == nullptr" <<
endl;
4812 std::cerr <<
os.str ();
4819 for (
size_t i = 0;
i < numSameIDs; ++
i, ++
myid) {
4829 std::ostringstream
os;
4830 os << *
prefix <<
"! src_filled && srcCrsGraph != nullptr" <<
endl;
4831 std::cerr <<
os.str ();
4833 for (
size_t i = 0;
i < numSameIDs; ++
i, ++
myid) {
4835 global_inds_host_view_type row;
4837 this->insertGlobalIndices (
gid, row.extent(0), row.data());
4861 global_inds_host_view_type row;
4863 this->insertGlobalIndices (
mygid, row.extent(0), row.data());
4868 std::ostringstream
os;
4870 std::cerr <<
os.str ();
4874 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
4883 using LO = local_ordinal_type;
4884 using row_ptrs_type =
4885 typename local_graph_device_type::row_map_type::non_const_type;
4887 Kokkos::RangePolicy<execution_space, Kokkos::IndexType<LO>>;
4889 ProfilingRegion
regionCAP(
"Tpetra::CrsGraph::applyCrsPadding");
4891 std::unique_ptr<std::string>
prefix;
4894 std::ostringstream
os;
4898 std::cerr <<
os.str();
4900 const int myRank = ! verbose ? -1 : [&] () {
4901 auto map = this->getMap();
4902 if (map.is_null()) {
4905 auto comm = map->getComm();
4906 if (comm.is_null()) {
4909 return comm->getRank();
4918 if (! indicesAreAllocated()) {
4920 std::ostringstream os;
4921 os << *prefix <<
"Call allocateIndices" << endl;
4922 std::cerr << os.str();
4924 allocateIndices(GlobalIndices, verbose);
4926 TEUCHOS_ASSERT( indicesAreAllocated() );
4931 auto rowPtrsUnpacked_dev = this->getRowPtrsUnpackedDevice();
4933 std::ostringstream os;
4934 os << *prefix <<
"Allocate row_ptrs_beg: "
4935 << rowPtrsUnpacked_dev.extent(0) << endl;
4936 std::cerr << os.str();
4938 using Kokkos::view_alloc;
4939 using Kokkos::WithoutInitializing;
4940 row_ptrs_type row_ptrs_beg(
4941 view_alloc(
"row_ptrs_beg", WithoutInitializing),
4942 rowPtrsUnpacked_dev.extent(0));
4944 Kokkos::deep_copy(execution_space(),row_ptrs_beg, rowPtrsUnpacked_dev);
4946 const size_t N = row_ptrs_beg.extent(0) == 0 ? size_t(0) :
4947 size_t(row_ptrs_beg.extent(0) - 1);
4949 std::ostringstream os;
4950 os << *prefix <<
"Allocate row_ptrs_end: " << N << endl;
4951 std::cerr << os.str();
4953 row_ptrs_type row_ptrs_end(
4954 view_alloc(
"row_ptrs_end", WithoutInitializing), N);
4955 row_ptrs_type num_row_entries;
4957 const bool refill_num_row_entries = k_numRowEntries_.extent(0) != 0;
4959 execution_space().fence();
4961 if (refill_num_row_entries) {
4965 row_ptrs_type(view_alloc(
"num_row_entries", WithoutInitializing), N);
4966 Kokkos::deep_copy(num_row_entries, this->k_numRowEntries_);
4967 Kokkos::parallel_for
4968 (
"Fill end row pointers", range_policy(0, N),
4969 KOKKOS_LAMBDA (
const size_t i) {
4970 row_ptrs_end(i) = row_ptrs_beg(i) + num_row_entries(i);
4977 Kokkos::parallel_for
4978 (
"Fill end row pointers", range_policy(0, N),
4979 KOKKOS_LAMBDA (
const size_t i) {
4980 row_ptrs_end(i) = row_ptrs_beg(i+1);
4984 if (isGloballyIndexed()) {
4986 padding, myRank, verbose);
4989 padCrsArrays(row_ptrs_beg, row_ptrs_end, lclIndsUnpacked_wdv,
4990 padding, myRank, verbose);
4993 if (refill_num_row_entries) {
4994 Kokkos::parallel_for
4995 (
"Fill num entries", range_policy(0, N),
4996 KOKKOS_LAMBDA (
const size_t i) {
4997 num_row_entries(i) = row_ptrs_end(i) - row_ptrs_beg(i);
4999 Kokkos::deep_copy(this->k_numRowEntries_, num_row_entries);
5002 std::ostringstream os;
5003 os << *prefix <<
"Reassign k_rowPtrs_; old size: "
5004 << rowPtrsUnpacked_dev.extent(0) <<
", new size: "
5005 << row_ptrs_beg.extent(0) << endl;
5006 std::cerr << os.str();
5007 TEUCHOS_ASSERT( rowPtrsUnpacked_dev.extent(0) == row_ptrs_beg.extent(0) );
5010 setRowPtrsUnpacked(row_ptrs_beg);
5013 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
5015 typename CrsGraph<LocalOrdinal, GlobalOrdinal, Node>::padding_type
5017 CrsGraph<LocalOrdinal, GlobalOrdinal, Node>::
5019 const RowGraph<LocalOrdinal,GlobalOrdinal,Node>& source,
5020 const size_t numSameIDs,
5021 const Kokkos::DualView<
const local_ordinal_type*,
5022 buffer_device_type>& permuteToLIDs,
5023 const Kokkos::DualView<
const local_ordinal_type*,
5024 buffer_device_type>& permuteFromLIDs,
5025 const bool verbose)
const
5030 std::unique_ptr<std::string> prefix;
5033 "computeCrsPadding(same & permute)");
5034 std::ostringstream os;
5035 os << *prefix <<
"{numSameIDs: " << numSameIDs
5036 <<
", numPermutes: " << permuteFromLIDs.extent(0) <<
"}"
5038 std::cerr << os.str();
5041 const int myRank = [&] () {
5042 auto comm = rowMap_.is_null() ? Teuchos::null :
5044 return comm.is_null() ? -1 : comm->getRank();
5046 std::unique_ptr<padding_type> padding(
5047 new padding_type(myRank, numSameIDs,
5048 permuteFromLIDs.extent(0)));
5050 computeCrsPaddingForSameIDs(*padding, source,
5051 static_cast<LO
>(numSameIDs));
5052 computeCrsPaddingForPermutedIDs(*padding, source, permuteToLIDs,
5057 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
5059 CrsGraph<LocalOrdinal, GlobalOrdinal, Node>::
5060 computeCrsPaddingForSameIDs(
5061 padding_type& padding,
5062 const RowGraph<local_ordinal_type, global_ordinal_type,
5064 const local_ordinal_type numSameIDs)
const
5067 using GO = global_ordinal_type;
5068 using Details::Impl::getRowGraphGlobalRow;
5070 const char tfecfFuncName[] =
"computeCrsPaddingForSameIds";
5072 std::unique_ptr<std::string> prefix;
5073 const bool verbose = verbose_;
5075 prefix = this->
createPrefix(
"CrsGraph", tfecfFuncName);
5076 std::ostringstream os;
5077 os << *prefix <<
"numSameIDs: " << numSameIDs << endl;
5078 std::cerr << os.str();
5081 if (numSameIDs == 0) {
5085 const map_type& srcRowMap = *(source.getRowMap());
5086 const map_type& tgtRowMap = *rowMap_;
5087 using this_CRS_type = CrsGraph<LocalOrdinal, GlobalOrdinal, Node>;
5088 const this_CRS_type* srcCrs =
dynamic_cast<const this_CRS_type*
>(&source);
5089 const bool src_is_unique =
5090 srcCrs ==
nullptr ? false : srcCrs->isMerged();
5091 const bool tgt_is_unique = this->isMerged();
5093 std::vector<GO> srcGblColIndsScratch;
5094 std::vector<GO> tgtGblColIndsScratch;
5096 execute_sync_host_uvm_access();
5097 for (LO lclRowInd = 0; lclRowInd < numSameIDs; ++lclRowInd) {
5098 const GO srcGblRowInd = srcRowMap.getGlobalElement(lclRowInd);
5099 const GO tgtGblRowInd = tgtRowMap.getGlobalElement(lclRowInd);
5100 auto srcGblColInds = getRowGraphGlobalRow(
5101 srcGblColIndsScratch, source, srcGblRowInd);
5102 auto tgtGblColInds = getRowGraphGlobalRow(
5103 tgtGblColIndsScratch, *
this, tgtGblRowInd);
5104 padding.update_same(lclRowInd, tgtGblColInds.getRawPtr(),
5105 tgtGblColInds.size(), tgt_is_unique,
5106 srcGblColInds.getRawPtr(),
5107 srcGblColInds.size(), src_is_unique);
5110 std::ostringstream os;
5111 os << *prefix <<
"Done" << endl;
5112 std::cerr << os.str();
5116 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
5118 CrsGraph<LocalOrdinal, GlobalOrdinal, Node>::
5119 computeCrsPaddingForPermutedIDs(
5120 padding_type& padding,
5121 const RowGraph<local_ordinal_type, global_ordinal_type,
5123 const Kokkos::DualView<
const local_ordinal_type*,
5124 buffer_device_type>& permuteToLIDs,
5125 const Kokkos::DualView<
const local_ordinal_type*,
5126 buffer_device_type>& permuteFromLIDs)
const
5129 using GO = global_ordinal_type;
5130 using Details::Impl::getRowGraphGlobalRow;
5132 const char tfecfFuncName[] =
"computeCrsPaddingForPermutedIds";
5134 std::unique_ptr<std::string> prefix;
5135 const bool verbose = verbose_;
5137 prefix = this->
createPrefix(
"CrsGraph", tfecfFuncName);
5138 std::ostringstream os;
5139 os << *prefix <<
"permuteToLIDs.extent(0): "
5140 << permuteToLIDs.extent(0)
5141 <<
", permuteFromLIDs.extent(0): "
5142 << permuteFromLIDs.extent(0) << endl;
5143 std::cerr << os.str();
5146 if (permuteToLIDs.extent(0) == 0) {
5150 const map_type& srcRowMap = *(source.getRowMap());
5151 const map_type& tgtRowMap = *rowMap_;
5152 using this_CRS_type = CrsGraph<LocalOrdinal, GlobalOrdinal, Node>;
5153 const this_CRS_type* srcCrs =
dynamic_cast<const this_CRS_type*
>(&source);
5154 const bool src_is_unique =
5155 srcCrs ==
nullptr ? false : srcCrs->isMerged();
5156 const bool tgt_is_unique = this->isMerged();
5158 TEUCHOS_ASSERT( ! permuteToLIDs.need_sync_host() );
5159 auto permuteToLIDs_h = permuteToLIDs.view_host();
5160 TEUCHOS_ASSERT( ! permuteFromLIDs.need_sync_host() );
5161 auto permuteFromLIDs_h = permuteFromLIDs.view_host();
5163 std::vector<GO> srcGblColIndsScratch;
5164 std::vector<GO> tgtGblColIndsScratch;
5165 const LO numPermutes =
static_cast<LO
>(permuteToLIDs_h.extent(0));
5167 execute_sync_host_uvm_access();
5168 for (LO whichPermute = 0; whichPermute < numPermutes; ++whichPermute) {
5169 const LO srcLclRowInd = permuteFromLIDs_h[whichPermute];
5170 const GO srcGblRowInd = srcRowMap.getGlobalElement(srcLclRowInd);
5171 auto srcGblColInds = getRowGraphGlobalRow(
5172 srcGblColIndsScratch, source, srcGblRowInd);
5173 const LO tgtLclRowInd = permuteToLIDs_h[whichPermute];
5174 const GO tgtGblRowInd = tgtRowMap.getGlobalElement(tgtLclRowInd);
5175 auto tgtGblColInds = getRowGraphGlobalRow(
5176 tgtGblColIndsScratch, *
this, tgtGblRowInd);
5177 padding.update_permute(whichPermute, tgtLclRowInd,
5178 tgtGblColInds.getRawPtr(),
5179 tgtGblColInds.size(), tgt_is_unique,
5180 srcGblColInds.getRawPtr(),
5181 srcGblColInds.size(), src_is_unique);
5185 std::ostringstream os;
5186 os << *prefix <<
"Done" << endl;
5187 std::cerr << os.str();
5191 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
5193 typename CrsGraph<LocalOrdinal, GlobalOrdinal, Node>::padding_type
5195 CrsGraph<LocalOrdinal, GlobalOrdinal, Node>::
5196 computeCrsPaddingForImports(
5197 const Kokkos::DualView<
const local_ordinal_type*,
5198 buffer_device_type>& importLIDs,
5199 Kokkos::DualView<packet_type*, buffer_device_type> imports,
5200 Kokkos::DualView<size_t*, buffer_device_type> numPacketsPerLID,
5201 const bool verbose)
const
5203 using Details::Impl::getRowGraphGlobalRow;
5206 using GO = global_ordinal_type;
5207 const char tfecfFuncName[] =
"computeCrsPaddingForImports";
5209 std::unique_ptr<std::string> prefix;
5211 prefix = this->
createPrefix(
"CrsGraph", tfecfFuncName);
5212 std::ostringstream os;
5213 os << *prefix <<
"importLIDs.extent(0): "
5214 << importLIDs.extent(0)
5215 <<
", imports.extent(0): "
5216 << imports.extent(0)
5217 <<
", numPacketsPerLID.extent(0): "
5218 << numPacketsPerLID.extent(0) << endl;
5219 std::cerr << os.str();
5222 const LO numImports =
static_cast<LO
>(importLIDs.extent(0));
5223 const int myRank = [&] () {
5224 auto comm = rowMap_.is_null() ? Teuchos::null :
5226 return comm.is_null() ? -1 : comm->getRank();
5228 std::unique_ptr<padding_type> padding(
5229 new padding_type(myRank, numImports));
5231 if (imports.need_sync_host()) {
5232 imports.sync_host();
5234 auto imports_h = imports.view_host();
5235 if (numPacketsPerLID.need_sync_host ()) {
5236 numPacketsPerLID.sync_host();
5238 auto numPacketsPerLID_h = numPacketsPerLID.view_host();
5240 TEUCHOS_ASSERT( ! importLIDs.need_sync_host() );
5241 auto importLIDs_h = importLIDs.view_host();
5243 const map_type& tgtRowMap = *rowMap_;
5247 constexpr bool src_is_unique =
false;
5248 const bool tgt_is_unique = isMerged();
5250 std::vector<GO> tgtGblColIndsScratch;
5252 execute_sync_host_uvm_access();
5253 for (LO whichImport = 0; whichImport < numImports; ++whichImport) {
5258 const LO origSrcNumEnt =
5259 static_cast<LO
>(numPacketsPerLID_h[whichImport]);
5260 GO*
const srcGblColInds = imports_h.data() + offset;
5262 const LO tgtLclRowInd = importLIDs_h[whichImport];
5263 const GO tgtGblRowInd =
5264 tgtRowMap.getGlobalElement(tgtLclRowInd);
5265 auto tgtGblColInds = getRowGraphGlobalRow(
5266 tgtGblColIndsScratch, *
this, tgtGblRowInd);
5267 const size_t origTgtNumEnt(tgtGblColInds.size());
5269 padding->update_import(whichImport, tgtLclRowInd,
5270 tgtGblColInds.getRawPtr(),
5271 origTgtNumEnt, tgt_is_unique,
5273 origSrcNumEnt, src_is_unique);
5274 offset += origSrcNumEnt;
5278 std::ostringstream os;
5279 os << *prefix <<
"Done" << endl;
5280 std::cerr << os.str();
5285 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
5287 typename CrsGraph<LocalOrdinal, GlobalOrdinal, Node>::padding_type
5289 CrsGraph<LocalOrdinal, GlobalOrdinal, Node>::
5290 computePaddingForCrsMatrixUnpack(
5291 const Kokkos::DualView<
const local_ordinal_type*,
5292 buffer_device_type>& importLIDs,
5293 Kokkos::DualView<char*, buffer_device_type> imports,
5294 Kokkos::DualView<size_t*, buffer_device_type> numPacketsPerLID,
5295 const bool verbose)
const
5297 using Details::Impl::getRowGraphGlobalRow;
5298 using Details::PackTraits;
5301 using GO = global_ordinal_type;
5302 const char tfecfFuncName[] =
"computePaddingForCrsMatrixUnpack";
5304 std::unique_ptr<std::string> prefix;
5306 prefix = this->
createPrefix(
"CrsGraph", tfecfFuncName);
5307 std::ostringstream os;
5308 os << *prefix <<
"importLIDs.extent(0): "
5309 << importLIDs.extent(0)
5310 <<
", imports.extent(0): "
5311 << imports.extent(0)
5312 <<
", numPacketsPerLID.extent(0): "
5313 << numPacketsPerLID.extent(0) << endl;
5314 std::cerr << os.str();
5316 const bool extraVerbose =
5319 const LO numImports =
static_cast<LO
>(importLIDs.extent(0));
5320 TEUCHOS_ASSERT( LO(numPacketsPerLID.extent(0)) >= numImports );
5321 const int myRank = [&] () {
5322 auto comm = rowMap_.is_null() ? Teuchos::null :
5324 return comm.is_null() ? -1 : comm->getRank();
5326 std::unique_ptr<padding_type> padding(
5327 new padding_type(myRank, numImports));
5329 if (imports.need_sync_host()) {
5330 imports.sync_host();
5332 auto imports_h = imports.view_host();
5333 if (numPacketsPerLID.need_sync_host ()) {
5334 numPacketsPerLID.sync_host();
5336 auto numPacketsPerLID_h = numPacketsPerLID.view_host();
5338 TEUCHOS_ASSERT( ! importLIDs.need_sync_host() );
5339 auto importLIDs_h = importLIDs.view_host();
5341 const map_type& tgtRowMap = *rowMap_;
5345 constexpr bool src_is_unique =
false;
5346 const bool tgt_is_unique = isMerged();
5348 std::vector<GO> srcGblColIndsScratch;
5349 std::vector<GO> tgtGblColIndsScratch;
5351 execute_sync_host_uvm_access();
5352 for (LO whichImport = 0; whichImport < numImports; ++whichImport) {
5357 const size_t numBytes = numPacketsPerLID_h[whichImport];
5359 std::ostringstream os;
5360 os << *prefix <<
"whichImport=" << whichImport
5361 <<
", numImports=" << numImports
5362 <<
", numBytes=" << numBytes << endl;
5363 std::cerr << os.str();
5365 if (numBytes == 0) {
5368 LO origSrcNumEnt = 0;
5369 const size_t numEntBeg = offset;
5370 const size_t numEntLen =
5371 PackTraits<LO>::packValueCount(origSrcNumEnt);
5372 TEUCHOS_ASSERT( numBytes >= numEntLen );
5373 TEUCHOS_ASSERT( imports_h.extent(0) >= numEntBeg + numEntLen );
5374 PackTraits<LO>::unpackValue(origSrcNumEnt,
5375 imports_h.data() + numEntBeg);
5377 std::ostringstream os;
5378 os << *prefix <<
"whichImport=" << whichImport
5379 <<
", numImports=" << numImports
5380 <<
", origSrcNumEnt=" << origSrcNumEnt << endl;
5381 std::cerr << os.str();
5383 TEUCHOS_ASSERT( origSrcNumEnt >= LO(0) );
5384 TEUCHOS_ASSERT( numBytes >=
size_t(numEntLen + origSrcNumEnt *
sizeof(GO)) );
5385 const size_t gidsBeg = numEntBeg + numEntLen;
5386 if (srcGblColIndsScratch.size() <
size_t(origSrcNumEnt)) {
5387 srcGblColIndsScratch.resize(origSrcNumEnt);
5389 GO*
const srcGblColInds = srcGblColIndsScratch.data();
5390 PackTraits<GO>::unpackArray(srcGblColInds,
5391 imports_h.data() + gidsBeg,
5393 const LO tgtLclRowInd = importLIDs_h[whichImport];
5394 const GO tgtGblRowInd =
5395 tgtRowMap.getGlobalElement(tgtLclRowInd);
5396 auto tgtGblColInds = getRowGraphGlobalRow(
5397 tgtGblColIndsScratch, *
this, tgtGblRowInd);
5398 const size_t origNumTgtEnt(tgtGblColInds.size());
5401 std::ostringstream os;
5402 os << *prefix <<
"whichImport=" << whichImport
5403 <<
", numImports=" << numImports
5404 <<
": Call padding->update_import" << endl;
5405 std::cerr << os.str();
5407 padding->update_import(whichImport, tgtLclRowInd,
5408 tgtGblColInds.getRawPtr(),
5409 origNumTgtEnt, tgt_is_unique,
5411 origSrcNumEnt, src_is_unique);
5416 std::ostringstream os;
5417 os << *prefix <<
"Done" << endl;
5418 std::cerr << os.str();
5423 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
5425 CrsGraph<LocalOrdinal, GlobalOrdinal, Node>::
5427 (
const SrcDistObject& source,
5428 const Kokkos::DualView<
const local_ordinal_type*,
5429 buffer_device_type>& exportLIDs,
5430 Kokkos::DualView<packet_type*,
5431 buffer_device_type>& exports,
5432 Kokkos::DualView<
size_t*,
5433 buffer_device_type> numPacketsPerLID,
5434 size_t& constantNumPackets)
5437 using GO = global_ordinal_type;
5439 using crs_graph_type =
5440 CrsGraph<local_ordinal_type, global_ordinal_type, node_type>;
5441 const char tfecfFuncName[] =
"packAndPrepare: ";
5442 ProfilingRegion region_papn (
"Tpetra::CrsGraph::packAndPrepare");
5444 const bool verbose = verbose_;
5445 std::unique_ptr<std::string> prefix;
5447 prefix = this->
createPrefix(
"CrsGraph",
"packAndPrepare");
5448 std::ostringstream os;
5449 os << *prefix <<
"Start" << endl;
5450 std::cerr << os.str();
5453 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC
5454 (exportLIDs.extent (0) != numPacketsPerLID.extent (0),
5456 "exportLIDs.extent(0) = " << exportLIDs.extent (0)
5457 <<
" != numPacketsPerLID.extent(0) = " << numPacketsPerLID.extent (0)
5459 const row_graph_type* srcRowGraphPtr =
5460 dynamic_cast<const row_graph_type*
> (&source);
5461 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC
5462 (srcRowGraphPtr ==
nullptr, std::invalid_argument,
"Source of an Export "
5463 "or Import operation to a CrsGraph must be a RowGraph with the same "
5464 "template parameters.");
5468 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC
5469 (this->isFillComplete (), std::runtime_error,
5470 "The target graph of an Import or Export must not be fill complete.");
5472 const crs_graph_type* srcCrsGraphPtr =
5473 dynamic_cast<const crs_graph_type*
> (&source);
5475 if (srcCrsGraphPtr ==
nullptr) {
5476 using Teuchos::ArrayView;
5480 std::ostringstream os;
5481 os << *prefix <<
"Source is a RowGraph but not a CrsGraph"
5483 std::cerr << os.str();
5490 TEUCHOS_ASSERT( ! exportLIDs.need_sync_host () );
5491 auto exportLIDs_h = exportLIDs.view_host ();
5492 ArrayView<const LO> exportLIDs_av (exportLIDs_h.data (),
5493 exportLIDs_h.extent (0));
5494 Teuchos::Array<GO> exports_a;
5496 numPacketsPerLID.clear_sync_state ();
5497 numPacketsPerLID.modify_host ();
5498 auto numPacketsPerLID_h = numPacketsPerLID.view_host ();
5499 ArrayView<size_t> numPacketsPerLID_av (numPacketsPerLID_h.data (),
5500 numPacketsPerLID_h.extent (0));
5501 srcRowGraphPtr->pack (exportLIDs_av, exports_a, numPacketsPerLID_av,
5502 constantNumPackets);
5503 const size_t newSize =
static_cast<size_t> (exports_a.size ());
5504 if (
static_cast<size_t> (exports.extent (0)) != newSize) {
5505 using exports_dv_type = Kokkos::DualView<packet_type*, buffer_device_type>;
5506 exports = exports_dv_type (
"exports", newSize);
5508 Kokkos::View<
const packet_type*, Kokkos::HostSpace,
5509 Kokkos::MemoryUnmanaged> exports_a_h (exports_a.getRawPtr (), newSize);
5510 exports.clear_sync_state ();
5511 exports.modify_host ();
5513 Kokkos::deep_copy (exports.view_host (), exports_a_h);
5516 else if (! getColMap ().is_null () &&
5517 (this->getRowPtrsPackedDevice().extent (0) != 0 ||
5518 getRowMap ()->getLocalNumElements () == 0)) {
5520 std::ostringstream os;
5521 os << *prefix <<
"packCrsGraphNew path" << endl;
5522 std::cerr << os.str();
5524 using export_pids_type =
5525 Kokkos::DualView<const int*, buffer_device_type>;
5526 export_pids_type exportPIDs;
5528 using NT = node_type;
5530 packCrsGraphNew<LO,GO,NT> (*srcCrsGraphPtr, exportLIDs, exportPIDs,
5531 exports, numPacketsPerLID,
5532 constantNumPackets,
false);
5535 srcCrsGraphPtr->packFillActiveNew (exportLIDs, exports, numPacketsPerLID,
5536 constantNumPackets);
5540 std::ostringstream os;
5541 os << *prefix <<
"Done" << endl;
5542 std::cerr << os.str();
5546 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
5550 Teuchos::Array<GlobalOrdinal>& exports,
5554 auto col_map = this->getColMap();
5556 if( !
col_map.is_null() && (
this->getRowPtrsPackedDevice().extent(0) != 0 || getRowMap()->getLocalNumElements() ==0)) {
5567 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
5571 Teuchos::Array<GlobalOrdinal>& exports,
5578 using host_execution_space =
5579 typename Kokkos::View<size_t*, device_type>::
5580 HostMirror::execution_space;
5582 const bool verbose = verbose_;
5585 std::unique_ptr<std::string>
prefix;
5587 prefix = this->createPrefix(
"CrsGraph",
"allocateIndices");
5588 std::ostringstream
os;
5590 std::cerr <<
os.str();
5592 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC
5593 (numExportLIDs != numPacketsPerLID.size (), std::runtime_error,
5594 "exportLIDs.size() = " << numExportLIDs <<
" != numPacketsPerLID.size()"
5595 " = " << numPacketsPerLID.size () <<
".");
5597 const map_type&
rowMap = * (this->getRowMap ());
5598 const map_type*
const colMapPtr = this->colMap_.getRawPtr ();
5599 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC
5600 (this->isLocallyIndexed () && colMapPtr ==
nullptr, std::logic_error,
5601 "This graph claims to be locally indexed, but its column Map is nullptr. "
5602 "This should never happen. Please report this bug to the Tpetra "
5606 constantNumPackets = 0;
5610 size_t*
const numPacketsPerLID_raw = numPacketsPerLID.getRawPtr ();
5611 const LO*
const exportLIDs_raw = exportLIDs.getRawPtr ();
5618 Kokkos::RangePolicy<host_execution_space, LO> inputRange (0, numExportLIDs);
5619 size_t totalNumPackets = 0;
5620 size_t errCount = 0;
5623 typedef Kokkos::Device<host_execution_space, Kokkos::HostSpace>
5625 Kokkos::View<size_t, host_device_type> errCountView (&errCount);
5626 constexpr size_t ONE = 1;
5628 execute_sync_host_uvm_access();
5629 Kokkos::parallel_reduce (
"Tpetra::CrsGraph::pack: totalNumPackets",
5631 [=] (
const LO& i,
size_t& curTotalNumPackets) {
5632 const GO gblRow =
rowMap.getGlobalElement (exportLIDs_raw[i]);
5633 if (gblRow == Tpetra::Details::OrdinalTraits<GO>::invalid ()) {
5634 Kokkos::atomic_add (&errCountView(), ONE);
5635 numPacketsPerLID_raw[i] = 0;
5638 const size_t numEnt = this->getNumEntriesInGlobalRow (gblRow);
5639 numPacketsPerLID_raw[i] = numEnt;
5640 curTotalNumPackets += numEnt;
5646 std::ostringstream os;
5647 os << *prefix <<
"totalNumPackets=" << totalNumPackets << endl;
5648 std::cerr << os.str();
5650 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC
5651 (errCount != 0, std::logic_error,
"totalNumPackets count encountered "
5652 "one or more errors! errCount = " << errCount
5653 <<
", totalNumPackets = " << totalNumPackets <<
".");
5657 exports.resize (totalNumPackets);
5659 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC
5660 (! this->supportsRowViews (), std::logic_error,
5661 "this->supportsRowViews() returns false; this should never happen. "
5662 "Please report this bug to the Tpetra developers.");
5668 std::ostringstream os;
5669 os << *prefix <<
"Pack into exports" << endl;
5670 std::cerr << os.str();
5675 GO*
const exports_raw = exports.getRawPtr ();
5677 Kokkos::parallel_scan (
"Tpetra::CrsGraph::pack: pack from views",
5678 inputRange, [=, &prefix]
5679 (
const LO i,
size_t& exportsOffset,
const bool final) {
5680 const size_t curOffset = exportsOffset;
5681 const GO gblRow =
rowMap.getGlobalElement (exportLIDs_raw[i]);
5682 const RowInfo rowInfo =
5683 this->getRowInfoFromGlobalRowIndex (gblRow);
5685 using TDO = Tpetra::Details::OrdinalTraits<size_t>;
5686 if (rowInfo.localRow == TDO::invalid ()) {
5688 std::ostringstream os;
5689 os << *prefix <<
": INVALID rowInfo: i=" << i
5690 <<
", lclRow=" << exportLIDs_raw[i] << endl;
5691 std::cerr << os.str();
5693 Kokkos::atomic_add (&errCountView(), ONE);
5695 else if (curOffset + rowInfo.numEntries > totalNumPackets) {
5697 std::ostringstream os;
5698 os << *prefix <<
": UH OH! For i=" << i <<
", lclRow="
5699 << exportLIDs_raw[i] <<
", gblRow=" << gblRow <<
", curOffset "
5700 "(= " << curOffset <<
") + numEnt (= " << rowInfo.numEntries
5701 <<
") > totalNumPackets (= " << totalNumPackets <<
")."
5703 std::cerr << os.str();
5705 Kokkos::atomic_add (&errCountView(), ONE);
5708 const LO numEnt =
static_cast<LO
> (rowInfo.numEntries);
5709 if (this->isLocallyIndexed ()) {
5710 auto lclColInds = getLocalIndsViewHost (rowInfo);
5712 for (LO k = 0; k < numEnt; ++k) {
5713 const LO lclColInd = lclColInds(k);
5714 const GO gblColInd = colMapPtr->getGlobalElement (lclColInd);
5718 exports_raw[curOffset + k] = gblColInd;
5721 exportsOffset = curOffset + numEnt;
5723 else if (this->isGloballyIndexed ()) {
5724 auto gblColInds = getGlobalIndsViewHost (rowInfo);
5726 for (LO k = 0; k < numEnt; ++k) {
5727 const GO gblColInd = gblColInds(k);
5731 exports_raw[curOffset + k] = gblColInd;
5734 exportsOffset = curOffset + numEnt;
5742 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC
5743 (errCount != 0, std::logic_error,
"Packing encountered "
5744 "one or more errors! errCount = " << errCount
5745 <<
", totalNumPackets = " << totalNumPackets <<
".");
5748 std::ostringstream os;
5749 os << *prefix <<
"Done" << endl;
5750 std::cerr << os.str();
5754 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
5756 CrsGraph<LocalOrdinal, GlobalOrdinal, Node>::
5757 packFillActiveNew (
const Kokkos::DualView<
const local_ordinal_type*,
5758 buffer_device_type>& exportLIDs,
5759 Kokkos::DualView<packet_type*,
5760 buffer_device_type>& exports,
5761 Kokkos::DualView<
size_t*,
5762 buffer_device_type> numPacketsPerLID,
5763 size_t& constantNumPackets)
const
5767 using GO = global_ordinal_type;
5768 using host_execution_space =
typename Kokkos::View<
size_t*,
5769 device_type>::HostMirror::execution_space;
5770 using host_device_type =
5771 Kokkos::Device<host_execution_space, Kokkos::HostSpace>;
5772 using exports_dv_type =
5773 Kokkos::DualView<packet_type*, buffer_device_type>;
5774 const char tfecfFuncName[] =
"packFillActiveNew: ";
5775 const bool verbose = verbose_;
5777 const auto numExportLIDs = exportLIDs.extent (0);
5778 std::unique_ptr<std::string> prefix;
5780 prefix = this->
createPrefix(
"CrsGraph",
"packFillActiveNew");
5781 std::ostringstream os;
5782 os << *prefix <<
"numExportLIDs: " << numExportLIDs
5783 <<
", numPacketsPerLID.extent(0): "
5784 << numPacketsPerLID.extent(0) << endl;
5785 std::cerr << os.str();
5787 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC
5788 (numExportLIDs != numPacketsPerLID.extent (0), std::runtime_error,
5789 "exportLIDs.extent(0) = " << numExportLIDs
5790 <<
" != numPacketsPerLID.extent(0) = "
5791 << numPacketsPerLID.extent (0) <<
".");
5792 TEUCHOS_ASSERT( ! exportLIDs.need_sync_host () );
5793 auto exportLIDs_h = exportLIDs.view_host ();
5795 const map_type&
rowMap = * (this->getRowMap ());
5796 const map_type*
const colMapPtr = this->colMap_.getRawPtr ();
5797 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC
5798 (this->isLocallyIndexed () && colMapPtr ==
nullptr, std::logic_error,
5799 "This graph claims to be locally indexed, but its column Map is nullptr. "
5800 "This should never happen. Please report this bug to the Tpetra "
5804 constantNumPackets = 0;
5806 numPacketsPerLID.clear_sync_state ();
5807 numPacketsPerLID.modify_host ();
5808 auto numPacketsPerLID_h = numPacketsPerLID.view_host ();
5815 using range_type = Kokkos::RangePolicy<host_execution_space, LO>;
5816 range_type inputRange (0, numExportLIDs);
5817 size_t totalNumPackets = 0;
5818 size_t errCount = 0;
5821 Kokkos::View<size_t, host_device_type> errCountView (&errCount);
5822 constexpr size_t ONE = 1;
5825 std::ostringstream os;
5826 os << *prefix <<
"Compute totalNumPackets" << endl;
5827 std::cerr << os.str ();
5830 execute_sync_host_uvm_access();
5831 Kokkos::parallel_reduce
5832 (
"Tpetra::CrsGraph::pack: totalNumPackets",
5834 [=, &prefix] (
const LO i,
size_t& curTotalNumPackets) {
5835 const LO lclRow = exportLIDs_h[i];
5836 const GO gblRow =
rowMap.getGlobalElement (lclRow);
5837 if (gblRow == Tpetra::Details::OrdinalTraits<GO>::invalid ()) {
5839 std::ostringstream os;
5840 os << *prefix <<
"For i=" << i <<
", lclRow=" << lclRow
5841 <<
" not in row Map on this process" << endl;
5842 std::cerr << os.str();
5844 Kokkos::atomic_add (&errCountView(), ONE);
5845 numPacketsPerLID_h(i) = 0;
5848 const size_t numEnt = this->getNumEntriesInGlobalRow (gblRow);
5849 numPacketsPerLID_h(i) = numEnt;
5850 curTotalNumPackets += numEnt;
5856 std::ostringstream os;
5857 os << *prefix <<
"totalNumPackets: " << totalNumPackets
5858 <<
", errCount: " << errCount << endl;
5859 std::cerr << os.str ();
5861 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC
5862 (errCount != 0, std::logic_error,
"totalNumPackets count encountered "
5863 "one or more errors! totalNumPackets: " << totalNumPackets
5864 <<
", errCount: " << errCount <<
".");
5867 if (
size_t(exports.extent (0)) < totalNumPackets) {
5869 exports = exports_dv_type (
"exports", totalNumPackets);
5872 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC
5873 (! this->supportsRowViews (), std::logic_error,
5874 "this->supportsRowViews() returns false; this should never happen. "
5875 "Please report this bug to the Tpetra developers.");
5881 std::ostringstream os;
5882 os << *prefix <<
"Pack into exports buffer" << endl;
5883 std::cerr << os.str();
5886 exports.clear_sync_state ();
5887 exports.modify_host ();
5888 auto exports_h = exports.view_host ();
5894 if(isLocallyIndexed())
5895 lclIndsUnpacked_wdv.getHostView(Access::ReadOnly);
5896 else if(isGloballyIndexed())
5897 gblInds_wdv.getHostView(Access::ReadOnly);
5900 Kokkos::parallel_scan
5901 (
"Tpetra::CrsGraph::packFillActiveNew: Pack exports",
5902 inputRange, [=, &prefix]
5903 (
const LO i,
size_t& exportsOffset,
const bool final) {
5904 const size_t curOffset = exportsOffset;
5905 const LO lclRow = exportLIDs_h(i);
5906 const GO gblRow =
rowMap.getGlobalElement (lclRow);
5907 if (gblRow == Details::OrdinalTraits<GO>::invalid ()) {
5909 std::ostringstream os;
5910 os << *prefix <<
"For i=" << i <<
", lclRow=" << lclRow
5911 <<
" not in row Map on this process" << endl;
5912 std::cerr << os.str();
5914 Kokkos::atomic_add (&errCountView(), ONE);
5918 const RowInfo rowInfo = this->getRowInfoFromGlobalRowIndex (gblRow);
5919 if (rowInfo.localRow == Details::OrdinalTraits<size_t>::invalid ()) {
5921 std::ostringstream os;
5922 os << *prefix <<
"For i=" << i <<
", lclRow=" << lclRow
5923 <<
", gblRow=" << gblRow <<
": invalid rowInfo"
5925 std::cerr << os.str();
5927 Kokkos::atomic_add (&errCountView(), ONE);
5931 if (curOffset + rowInfo.numEntries > totalNumPackets) {
5933 std::ostringstream os;
5934 os << *prefix <<
"For i=" << i <<
", lclRow=" << lclRow
5935 <<
", gblRow=" << gblRow <<
", curOffset (= "
5936 << curOffset <<
") + numEnt (= " << rowInfo.numEntries
5937 <<
") > totalNumPackets (= " << totalNumPackets
5939 std::cerr << os.str();
5941 Kokkos::atomic_add (&errCountView(), ONE);
5945 const LO numEnt =
static_cast<LO
> (rowInfo.numEntries);
5946 if (this->isLocallyIndexed ()) {
5947 auto lclColInds = getLocalIndsViewHost(rowInfo);
5949 for (LO k = 0; k < numEnt; ++k) {
5950 const LO lclColInd = lclColInds(k);
5951 const GO gblColInd = colMapPtr->getGlobalElement (lclColInd);
5955 exports_h(curOffset + k) = gblColInd;
5958 exportsOffset = curOffset + numEnt;
5960 else if (this->isGloballyIndexed ()) {
5961 auto gblColInds = getGlobalIndsViewHost(rowInfo);
5963 for (LO k = 0; k < numEnt; ++k) {
5964 const GO gblColInd = gblColInds(k);
5968 exports_h(curOffset + k) = gblColInd;
5971 exportsOffset = curOffset + numEnt;
5985 std::ostringstream os;
5986 os << *prefix <<
"errCount=" << errCount <<
"; Done" << endl;
5987 std::cerr << os.str();
5991 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
5999 Kokkos::DualView<
size_t*,
6010 ProfilingRegion
regionCGC(
"Tpetra::CrsGraph::unpackAndCombine");
6011 const bool verbose = verbose_;
6013 std::unique_ptr<std::string>
prefix;
6016 std::ostringstream
os;
6018 std::cerr <<
os.str ();
6021 auto padding = computeCrsPaddingForImports(
6023 applyCrsPadding(*
padding, verbose);
6025 std::ostringstream
os;
6026 os << *
prefix <<
"Done computing & applying padding" <<
endl;
6027 std::cerr <<
os.str ();
6050 std::runtime_error,
": importLIDs.extent(0) = "
6051 <<
importLIDs.extent (0) <<
" != numPacketsPerLID.extent(0) = "
6054 (isFillComplete (), std::runtime_error,
6055 ": Import or Export operations are not allowed on a target "
6056 "CrsGraph that is fillComplete.");
6063 if (imports.need_sync_host()) {
6064 imports.sync_host();
6072 if (isLocallyIndexed()) {
6074 std::ostringstream
os;
6075 os << *
prefix <<
"Preallocate local indices scratch" <<
endl;
6076 std::cerr <<
os.str();
6083 std::ostringstream
os;
6084 os << *
prefix <<
"Local indices scratch size: "
6086 std::cerr <<
os.str();
6092 std::ostringstream
os;
6094 if (isGloballyIndexed()) {
6095 os <<
"Graph is globally indexed";
6098 os <<
"Graph is neither locally nor globally indexed";
6101 std::cerr <<
os.str();
6112 std::ostringstream
os;
6113 os << *
prefix <<
"i=" <<
i <<
", numImportLIDs="
6115 std::cerr <<
os.str();
6122 (
gblRow == Teuchos::OrdinalTraits<GO>::invalid(),
6123 std::logic_error,
"importLIDs[i=" <<
i <<
"]="
6124 <<
lclRow <<
" is not in the row Map on the calling "
6129 if (! isLocallyIndexed()) {
6143 catch (std::exception&
e) {
6145 (
true, std::runtime_error,
6146 "Tpetra::CrsGraph::unpackAndCombine: Insert loop threw an "
6147 "exception: " <<
endl <<
e.what());
6151 std::ostringstream
os;
6153 std::cerr <<
os.str();
6157 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
6162 using Teuchos::Comm;
6163 using Teuchos::null;
6164 using Teuchos::ParameterList;
6178 if (! domainMap_.is_null ()) {
6179 if (domainMap_.getRawPtr () == rowMap_.getRawPtr ()) {
6189 if (! rangeMap_.is_null ()) {
6190 if (rangeMap_.getRawPtr () == rowMap_.getRawPtr ()) {
6200 if (! colMap_.is_null ()) {
6214 if (! rangeMap_.is_null () &&
6217 if (
params.is_null () || !
params->isSublist (
"Export")) {
6226 if (! domainMap_.is_null () &&
6229 if (
params.is_null () || !
params->isSublist (
"Import")) {
6255 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
6258 getLocalDiagOffsets (
const Kokkos::View<size_t*, device_type, Kokkos::MemoryUnmanaged>& offsets)
const
6264 const bool verbose = verbose_;
6266 std::unique_ptr<std::string>
prefix;
6268 prefix = this->createPrefix(
"CrsGraph",
"getLocalDiagOffsets");
6269 std::ostringstream
os;
6270 os << *
prefix <<
"offsets.extent(0)=" << offsets.extent(0)
6272 std::cerr <<
os.str();
6276 (! hasColMap (), std::runtime_error,
"The graph must have a column Map.");
6277 const LO
lclNumRows =
static_cast<LO
> (this->getLocalNumRows ());
6279 (
static_cast<LO
> (offsets.extent (0)) <
lclNumRows,
6280 std::invalid_argument,
"offsets.extent(0) = " <<
6281 offsets.extent (0) <<
" < getLocalNumRows() = " <<
lclNumRows <<
".");
6306 const bool sorted = this->isSorted ();
6307 if (isFillComplete ()) {
6308 auto lclGraph = this->getLocalGraphDevice ();
6317 auto offsets_h = Kokkos::create_mirror_view (offsets);
6327 if (
lclColInd == Tpetra::Details::OrdinalTraits<LO>::invalid ()) {
6337 const size_t hint = 0;
6348 typename local_inds_dualv_type::t_host::const_type
lclColInds;
6385 std::ostringstream
os;
6386 os << *
prefix <<
"Wrong offsets: [";
6395 std::cerr <<
os.str();
6399 using Teuchos::reduceAll;
6401 Teuchos::RCP<const Teuchos::Comm<int> > comm = this->getComm ();
6425 std::ostringstream
os;
6426 os <<
"Issue(s) that we noticed (on Process " <<
gblResults[4] <<
", "
6427 "possibly among others): " <<
endl;
6429 os <<
" - The column Map does not contain at least one diagonal entry "
6430 "of the graph." <<
endl;
6433 os <<
" - On one or more processes, some row does not contain a "
6434 "diagonal entry." <<
endl;
6437 os <<
" - On one or more processes, some offsets are incorrect."
6441 os <<
" - One or more processes had some other error."
6449 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
6456 const bool verbose = verbose_;
6458 std::unique_ptr<std::string>
prefix;
6460 prefix = this->createPrefix(
"CrsGraph",
"getLocalOffRankOffsets");
6461 std::ostringstream
os;
6462 os << *
prefix <<
"offsets.extent(0)=" << offsets.extent(0)
6464 std::cerr <<
os.str();
6468 (! hasColMap (), std::runtime_error,
"The graph must have a column Map.");
6471 const size_t lclNumRows = this->getLocalNumRows ();
6473 if (haveLocalOffRankOffsets_ && k_offRankOffsets_.extent(0) ==
lclNumRows+1) {
6474 offsets = k_offRankOffsets_;
6477 haveLocalOffRankOffsets_ =
false;
6478 k_offRankOffsets_ = offset_device_view_type(Kokkos::ViewAllocateWithoutInitializing(
"offRankOffset"),
lclNumRows+1);
6479 offsets = k_offRankOffsets_;
6494 if (isFillComplete ()) {
6495 auto lclGraph = this->getLocalGraphDevice ();
6496 ::Tpetra::Details::getGraphOffRankOffsets (k_offRankOffsets_,
6499 haveLocalOffRankOffsets_ =
true;
6521 template<
class DeviceType,
6523 std::is_same<
typename DeviceType::memory_space,
6524 Kokkos::HostSpace>::value>
6525 struct HelpGetLocalDiagOffsets {};
6527 template<
class DeviceType>
6528 struct HelpGetLocalDiagOffsets<DeviceType, true> {
6529 typedef DeviceType device_type;
6530 typedef Kokkos::View<
size_t*, Kokkos::HostSpace,
6531 Kokkos::MemoryUnmanaged> device_offsets_type;
6532 typedef Kokkos::View<
size_t*, Kokkos::HostSpace,
6533 Kokkos::MemoryUnmanaged> host_offsets_type;
6535 static device_offsets_type
6536 getDeviceOffsets (
const host_offsets_type& hostOffsets)
6544 copyBackIfNeeded (
const host_offsets_type& ,
6545 const device_offsets_type& )
6549 template<
class DeviceType>
6550 struct HelpGetLocalDiagOffsets<DeviceType, false> {
6551 typedef DeviceType device_type;
6555 typedef Kokkos::View<size_t*, device_type> device_offsets_type;
6556 typedef Kokkos::View<
size_t*, Kokkos::HostSpace,
6557 Kokkos::MemoryUnmanaged> host_offsets_type;
6559 static device_offsets_type
6560 getDeviceOffsets (
const host_offsets_type& hostOffsets)
6564 return device_offsets_type (
"offsets", hostOffsets.extent (0));
6568 copyBackIfNeeded (
const host_offsets_type& hostOffsets,
6569 const device_offsets_type& deviceOffsets)
6572 Kokkos::deep_copy (hostOffsets, deviceOffsets);
6578 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
6586 (! this->hasColMap (), std::runtime_error,
6587 "The graph does not yet have a column Map.");
6588 const LO
myNumRows =
static_cast<LO
> (this->getLocalNumRows ());
6589 if (
static_cast<LO
> (offsets.size ()) !=
myNumRows) {
6606 typedef typename helper_type::host_offsets_type host_offsets_type;
6616 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
6623 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
6627 const ::Tpetra::Details::Transfer<LocalOrdinal, GlobalOrdinal, Node>&
rowTransfer,
6628 const Teuchos::RCP<const ::Tpetra::Details::Transfer<LocalOrdinal, GlobalOrdinal, Node> > &
domainTransfer,
6629 const Teuchos::RCP<const map_type>& domainMap,
6630 const Teuchos::RCP<const map_type>&
rangeMap,
6631 const Teuchos::RCP<Teuchos::ParameterList>&
params)
const
6637 using Teuchos::ArrayRCP;
6638 using Teuchos::ArrayView;
6639 using Teuchos::Comm;
6640 using Teuchos::ParameterList;
6643#ifdef HAVE_TPETRA_MMM_TIMINGS
6645 using Teuchos::TimeMonitor;
6650 using NT = node_type;
6654 const char*
prefix =
"Tpetra::CrsGraph::transferAndFillComplete: ";
6656#ifdef HAVE_TPETRA_MMM_TIMINGS
6658 if(!
params.is_null()) label =
params->get(
"Timer Label", label);
6659 string prefix2 =
string(
"Tpetra ")+ label + std::string(
": CrsGraph TAFC ");
6673 prefix <<
"The 'rowTransfer' input argument must be either an Import or "
6674 "an Export, and its template parameters must match the corresponding "
6675 "template parameters of the CrsGraph.");
6691 prefix <<
"The 'domainTransfer' input argument must be either an "
6692 "Import or an Export, and its template parameters must match the "
6693 "corresponding template parameters of the CrsGraph.");
6699 prefix <<
"The 'rowTransfer' and 'domainTransfer' input arguments "
6700 "must be of the same type (either Import or Export).");
6706 prefix <<
"The 'rowTransfer' and 'domainTransfer' input arguments "
6707 "must be of the same type (either Import or Export).");
6714 const bool communication_needed = rowTransfer.getSourceMap()->isDistributed();
6720 bool reverseMode =
false;
6721 bool restrictComm =
false;
6722 RCP<ParameterList> graphparams;
6723 if (! params.is_null()) {
6724 reverseMode = params->get(
"Reverse Mode", reverseMode);
6725 restrictComm = params->get(
"Restrict Communicator", restrictComm);
6726 graphparams = sublist(params,
"CrsGraph");
6731 RCP<const map_type> MyRowMap = reverseMode ?
6732 rowTransfer.getSourceMap() : rowTransfer.getTargetMap();
6733 RCP<const map_type> MyColMap;
6734 RCP<const map_type> MyDomainMap = !
domainMap.is_null() ?
domainMap : getDomainMap();
6735 RCP<const map_type> MyRangeMap = ! rangeMap.is_null() ? rangeMap : getRangeMap();
6736 RCP<const map_type> BaseRowMap = MyRowMap;
6737 RCP<const map_type> BaseDomainMap = MyDomainMap;
6745 if (! destGraph.is_null()) {
6756 const bool NewFlag =
6757 ! destGraph->isLocallyIndexed() && ! destGraph->isGloballyIndexed();
6758 TEUCHOS_TEST_FOR_EXCEPTION(! NewFlag, std::invalid_argument,
6759 prefix <<
"The input argument 'destGraph' is only allowed to be nonnull, "
6760 "if its graph is empty (neither locally nor globally indexed).");
6769 TEUCHOS_TEST_FOR_EXCEPTION(
6770 ! destGraph->getRowMap()->isSameAs(*MyRowMap), std::invalid_argument,
6771 prefix <<
"The (row) Map of the input argument 'destGraph' is not the "
6772 "same as the (row) Map specified by the input argument 'rowTransfer'.");
6774 TEUCHOS_TEST_FOR_EXCEPTION(
6775 ! destGraph->checkSizes(*
this), std::invalid_argument,
6776 prefix <<
"You provided a nonnull destination graph, but checkSizes() "
6777 "indicates that it is not a legal legal target for redistribution from "
6778 "the source graph (*this). This may mean that they do not have the "
6779 "same dimensions.");
6793 TEUCHOS_TEST_FOR_EXCEPTION(
6794 ! (reverseMode || getRowMap()->isSameAs(*rowTransfer.getSourceMap())),
6795 std::invalid_argument, prefix <<
6796 "rowTransfer->getSourceMap() must match this->getRowMap() in forward mode.");
6798 TEUCHOS_TEST_FOR_EXCEPTION(
6799 ! (! reverseMode || getRowMap()->isSameAs(*rowTransfer.getTargetMap())),
6800 std::invalid_argument, prefix <<
6801 "rowTransfer->getTargetMap() must match this->getRowMap() in reverse mode.");
6804 TEUCHOS_TEST_FOR_EXCEPTION(
6805 ! xferDomainAsImport.is_null() && ! xferDomainAsImport->getTargetMap()->isSameAs(*
domainMap),
6806 std::invalid_argument,
6807 prefix <<
"The target map of the 'domainTransfer' input argument must be "
6808 "the same as the rebalanced domain map 'domainMap'");
6810 TEUCHOS_TEST_FOR_EXCEPTION(
6811 ! xferDomainAsExport.is_null() && ! xferDomainAsExport->getSourceMap()->isSameAs(*
domainMap),
6812 std::invalid_argument,
6813 prefix <<
"The source map of the 'domainTransfer' input argument must be "
6814 "the same as the rebalanced domain map 'domainMap'");
6827 const size_t NumSameIDs = rowTransfer.getNumSameIDs();
6828 ArrayView<const LO> ExportLIDs = reverseMode ?
6829 rowTransfer.getRemoteLIDs() : rowTransfer.getExportLIDs();
6830 ArrayView<const LO> RemoteLIDs = reverseMode ?
6831 rowTransfer.getExportLIDs() : rowTransfer.getRemoteLIDs();
6832 ArrayView<const LO> PermuteToLIDs = reverseMode ?
6833 rowTransfer.getPermuteFromLIDs() : rowTransfer.getPermuteToLIDs();
6834 ArrayView<const LO> PermuteFromLIDs = reverseMode ?
6835 rowTransfer.getPermuteToLIDs() : rowTransfer.getPermuteFromLIDs();
6836 Distributor& Distor = rowTransfer.getDistributor();
6839 Teuchos::Array<int> SourcePids;
6840 Teuchos::Array<int> TargetPids;
6841 int MyPID = getComm()->getRank();
6844 RCP<const map_type> ReducedRowMap, ReducedColMap,
6845 ReducedDomainMap, ReducedRangeMap;
6846 RCP<const Comm<int> > ReducedComm;
6850 if (destGraph.is_null()) {
6851 destGraph = rcp(
new this_CRS_type(MyRowMap, 0, graphparams));
6858 ReducedRowMap = MyRowMap->removeEmptyProcesses();
6859 ReducedComm = ReducedRowMap.is_null() ?
6861 ReducedRowMap->getComm();
6862 destGraph->removeEmptyProcessesInPlace(ReducedRowMap);
6864 ReducedDomainMap = MyRowMap.getRawPtr() == MyDomainMap.getRawPtr() ?
6866 MyDomainMap->replaceCommWithSubset(ReducedComm);
6867 ReducedRangeMap = MyRowMap.getRawPtr() == MyRangeMap.getRawPtr() ?
6869 MyRangeMap->replaceCommWithSubset(ReducedComm);
6872 MyRowMap = ReducedRowMap;
6873 MyDomainMap = ReducedDomainMap;
6874 MyRangeMap = ReducedRangeMap;
6877 if (! ReducedComm.is_null()) {
6878 MyPID = ReducedComm->getRank();
6885 ReducedComm = MyRowMap->getComm();
6891#ifdef HAVE_TPETRA_MMM_TIMINGS
6893 MM = rcp(
new TimeMonitor(*TimeMonitor::getNewTimer(prefix2+
string(
"ImportSetup"))));
6896 RCP<const import_type> MyImporter = getImporter();
6899 bool bSameDomainMap = BaseDomainMap->isSameAs(*getDomainMap());
6901 if (! restrictComm && ! MyImporter.is_null() && bSameDomainMap ) {
6908 Import_Util::getPids(*MyImporter, SourcePids,
false);
6910 else if (restrictComm && ! MyImporter.is_null() && bSameDomainMap) {
6913 ivector_type SourceDomain_pids(getDomainMap(),
true);
6914 ivector_type SourceCol_pids(getColMap());
6916 SourceDomain_pids.putScalar(MyPID);
6918 SourceCol_pids.doImport(SourceDomain_pids, *MyImporter,
INSERT);
6919 SourcePids.resize(getColMap()->getLocalNumElements());
6920 SourceCol_pids.get1dCopy(SourcePids());
6922 else if (MyImporter.is_null() && bSameDomainMap) {
6924 SourcePids.resize(getColMap()->getLocalNumElements());
6925 SourcePids.assign(getColMap()->getLocalNumElements(), MyPID);
6927 else if ( ! MyImporter.is_null() &&
6928 ! domainTransfer.is_null() ) {
6935 ivector_type TargetDomain_pids(
domainMap);
6936 TargetDomain_pids.putScalar(MyPID);
6939 ivector_type SourceDomain_pids(getDomainMap());
6942 ivector_type SourceCol_pids(getColMap());
6944 if (! reverseMode && ! xferDomainAsImport.is_null() ) {
6945 SourceDomain_pids.doExport(TargetDomain_pids, *xferDomainAsImport,
INSERT);
6947 else if (reverseMode && ! xferDomainAsExport.is_null() ) {
6948 SourceDomain_pids.doExport(TargetDomain_pids, *xferDomainAsExport,
INSERT);
6950 else if (! reverseMode && ! xferDomainAsExport.is_null() ) {
6951 SourceDomain_pids.doImport(TargetDomain_pids, *xferDomainAsExport,
INSERT);
6953 else if (reverseMode && ! xferDomainAsImport.is_null() ) {
6954 SourceDomain_pids.doImport(TargetDomain_pids, *xferDomainAsImport,
INSERT);
6957 TEUCHOS_TEST_FOR_EXCEPTION(
6958 true, std::logic_error,
6959 prefix <<
"Should never get here! Please report this bug to a Tpetra developer.");
6961 SourceCol_pids.doImport(SourceDomain_pids, *MyImporter,
INSERT);
6962 SourcePids.resize(getColMap()->getLocalNumElements());
6963 SourceCol_pids.get1dCopy(SourcePids());
6965 else if (BaseDomainMap->isSameAs(*BaseRowMap) &&
6966 getDomainMap()->isSameAs(*getRowMap())) {
6969 ivector_type SourceRow_pids(getRowMap());
6970 ivector_type SourceCol_pids(getColMap());
6972 TargetRow_pids.putScalar(MyPID);
6973 if (! reverseMode && xferAsImport !=
nullptr) {
6974 SourceRow_pids.doExport(TargetRow_pids, *xferAsImport,
INSERT);
6976 else if (reverseMode && xferAsExport !=
nullptr) {
6977 SourceRow_pids.doExport(TargetRow_pids, *xferAsExport,
INSERT);
6979 else if (! reverseMode && xferAsExport !=
nullptr) {
6980 SourceRow_pids.doImport(TargetRow_pids, *xferAsExport,
INSERT);
6982 else if (reverseMode && xferAsImport !=
nullptr) {
6983 SourceRow_pids.doImport(TargetRow_pids, *xferAsImport,
INSERT);
6986 TEUCHOS_TEST_FOR_EXCEPTION(
6987 true, std::logic_error,
6988 prefix <<
"Should never get here! Please report this bug to a Tpetra developer.");
6990 SourceCol_pids.doImport(SourceRow_pids, *MyImporter,
INSERT);
6991 SourcePids.resize(getColMap()->getLocalNumElements());
6992 SourceCol_pids.get1dCopy(SourcePids());
6995 TEUCHOS_TEST_FOR_EXCEPTION(
6996 true, std::invalid_argument,
6997 prefix <<
"This method only allows either domainMap == getDomainMap(), "
6998 "or (domainMap == rowTransfer.getTargetMap() and getDomainMap() == getRowMap()).");
7002 size_t constantNumPackets = destGraph->constantNumberOfPackets();
7003 if (constantNumPackets == 0) {
7004 destGraph->reallocArraysForNumPacketsPerLid(ExportLIDs.size(),
7012 const size_t rbufLen = RemoteLIDs.size() * constantNumPackets;
7013 destGraph->reallocImportsIfNeeded(rbufLen,
false,
nullptr);
7018 destGraph->numExportPacketsPerLID_.modify_host();
7019 Teuchos::ArrayView<size_t> numExportPacketsPerLID =
7024 numExportPacketsPerLID, ExportLIDs,
7025 SourcePids, constantNumPackets);
7029#ifdef HAVE_TPETRA_MMM_TIMINGS
7031 MM = rcp(
new TimeMonitor(*TimeMonitor::getNewTimer(prefix2+
string(
"Transfer"))));
7034 if (communication_needed) {
7036 if (constantNumPackets == 0) {
7040 destGraph->numExportPacketsPerLID_.sync_host();
7041 Teuchos::ArrayView<const size_t> numExportPacketsPerLID =
7043 destGraph->numImportPacketsPerLID_.sync_host();
7044 Teuchos::ArrayView<size_t> numImportPacketsPerLID =
7047 Distor.doReversePostsAndWaits(destGraph->numExportPacketsPerLID_.view_host(), 1,
7048 destGraph->numImportPacketsPerLID_.view_host());
7049 size_t totalImportPackets = 0;
7051 totalImportPackets += numImportPacketsPerLID[i];
7056 destGraph->reallocImportsIfNeeded(totalImportPackets,
false,
nullptr);
7057 destGraph->imports_.modify_host();
7058 auto hostImports = destGraph->imports_.view_host();
7061 destGraph->exports_.sync_host();
7062 auto hostExports = destGraph->exports_.view_host();
7063 Distor.doReversePostsAndWaits(hostExports,
7064 numExportPacketsPerLID,
7066 numImportPacketsPerLID);
7069 destGraph->imports_.modify_host();
7070 auto hostImports = destGraph->imports_.view_host();
7073 destGraph->exports_.sync_host();
7074 auto hostExports = destGraph->exports_.view_host();
7075 Distor.doReversePostsAndWaits(hostExports,
7081 if (constantNumPackets == 0) {
7085 destGraph->numExportPacketsPerLID_.sync_host();
7086 destGraph->numImportPacketsPerLID_.sync_host();
7087 Distor.doPostsAndWaits(destGraph->numExportPacketsPerLID_.view_host(), 1,
7088 destGraph->numImportPacketsPerLID_.view_host());
7090 Teuchos::ArrayView<const size_t> numImportPacketsPerLID =
7092 size_t totalImportPackets = 0;
7094 totalImportPackets += numImportPacketsPerLID[i];
7099 destGraph->reallocImportsIfNeeded(totalImportPackets,
false,
nullptr);
7100 destGraph->imports_.modify_host();
7101 auto hostImports = destGraph->imports_.view_host();
7104 destGraph->exports_.sync_host();
7105 auto hostExports = destGraph->exports_.view_host();
7106 Teuchos::ArrayView<const size_t> numExportPacketsPerLID =
7108 Distor.doPostsAndWaits(hostExports, numExportPacketsPerLID, hostImports, numImportPacketsPerLID);
7111 destGraph->imports_.modify_host();
7112 auto hostImports = destGraph->imports_.view_host();
7115 destGraph->exports_.sync_host();
7116 auto hostExports = destGraph->exports_.view_host();
7117 Distor.doPostsAndWaits(hostExports, constantNumPackets, hostImports);
7126#ifdef HAVE_TPETRA_MMM_TIMINGS
7128 MM = rcp(
new TimeMonitor(*TimeMonitor::getNewTimer(prefix2+
string(
"Unpack-1"))));
7132 destGraph->numImportPacketsPerLID_.sync_host();
7133 Teuchos::ArrayView<const size_t> numImportPacketsPerLID =
7135 destGraph->imports_.sync_host();
7136 Teuchos::ArrayView<const packet_type> hostImports =
7140 numImportPacketsPerLID,
7141 constantNumPackets,
INSERT,
7142 NumSameIDs, PermuteToLIDs, PermuteFromLIDs);
7143 size_t N = BaseRowMap->getLocalNumElements();
7146 ArrayRCP<size_t> CSR_rowptr(N+1);
7147 ArrayRCP<GO> CSR_colind_GID;
7148 ArrayRCP<LO> CSR_colind_LID;
7149 CSR_colind_GID.resize(mynnz);
7153 if (
typeid(LO) ==
typeid(GO)) {
7154 CSR_colind_LID = Teuchos::arcp_reinterpret_cast<LO>(CSR_colind_GID);
7157 CSR_colind_LID.resize(mynnz);
7166 numImportPacketsPerLID, constantNumPackets,
7167 INSERT, NumSameIDs, PermuteToLIDs,
7168 PermuteFromLIDs, N, mynnz, MyPID,
7169 CSR_rowptr(), CSR_colind_GID(),
7170 SourcePids(), TargetPids);
7175#ifdef HAVE_TPETRA_MMM_TIMINGS
7177 MM = rcp(
new TimeMonitor(*TimeMonitor::getNewTimer(prefix2+
string(
"Unpack-2"))));
7182 Teuchos::Array<int> RemotePids;
7183 Import_Util::lowCommunicationMakeColMapAndReindex(CSR_rowptr(),
7187 TargetPids, RemotePids,
7194 ReducedColMap = (MyRowMap.getRawPtr() == MyColMap.getRawPtr()) ?
7196 MyColMap->replaceCommWithSubset(ReducedComm);
7197 MyColMap = ReducedColMap;
7201 destGraph->replaceColMap(MyColMap);
7208 if (ReducedComm.is_null()) {
7215 if ((! reverseMode && xferAsImport !=
nullptr) ||
7216 (reverseMode && xferAsExport !=
nullptr)) {
7217 Import_Util::sortCrsEntries(CSR_rowptr(),
7220 else if ((! reverseMode && xferAsExport !=
nullptr) ||
7221 (reverseMode && xferAsImport !=
nullptr)) {
7222 Import_Util::sortAndMergeCrsEntries(CSR_rowptr(),
7224 if (CSR_rowptr[N] != mynnz) {
7225 CSR_colind_LID.resize(CSR_rowptr[N]);
7229 TEUCHOS_TEST_FOR_EXCEPTION(
7230 true, std::logic_error,
7231 prefix <<
"Should never get here! Please report this bug to a Tpetra developer.");
7239 destGraph->setAllIndices(CSR_rowptr, CSR_colind_LID);
7245 Teuchos::ParameterList esfc_params;
7246#ifdef HAVE_TPETRA_MMM_TIMINGS
7248 MM = rcp(
new TimeMonitor(*TimeMonitor::getNewTimer(prefix2+
string(
"CreateImporter"))));
7250 RCP<import_type> MyImport = rcp(
new import_type(MyDomainMap, MyColMap, RemotePids));
7251#ifdef HAVE_TPETRA_MMM_TIMINGS
7253 MM = rcp(
new TimeMonitor(*TimeMonitor::getNewTimer(prefix2+
string(
"ESFC"))));
7255 esfc_params.set(
"Timer Label",prefix + std::string(
"TAFC"));
7257 if(!params.is_null())
7258 esfc_params.set(
"compute global constants",params->get(
"compute global constants",
true));
7260 destGraph->expertStaticFillComplete(MyDomainMap, MyRangeMap,
7261 MyImport, Teuchos::null, rcp(&esfc_params,
false));
7265 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
7270 const Teuchos::RCP<const map_type>& domainMap,
7271 const Teuchos::RCP<const map_type>&
rangeMap,
7272 const Teuchos::RCP<Teuchos::ParameterList>&
params)
const
7277 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
7283 const Teuchos::RCP<const map_type>& domainMap,
7284 const Teuchos::RCP<const map_type>&
rangeMap,
7285 const Teuchos::RCP<Teuchos::ParameterList>&
params)
const
7290 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
7295 const Teuchos::RCP<const map_type>& domainMap,
7296 const Teuchos::RCP<const map_type>&
rangeMap,
7297 const Teuchos::RCP<Teuchos::ParameterList>&
params)
const
7302 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
7308 const Teuchos::RCP<const map_type>& domainMap,
7309 const Teuchos::RCP<const map_type>&
rangeMap,
7310 const Teuchos::RCP<Teuchos::ParameterList>&
params)
const
7316 template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
7321 std::swap(
graph.need_sync_host_uvm_access,
this->need_sync_host_uvm_access);
7323 std::swap(
graph.rowMap_,
this->rowMap_);
7324 std::swap(
graph.colMap_,
this->colMap_);
7325 std::swap(
graph.rangeMap_,
this->rangeMap_);
7326 std::swap(
graph.domainMap_,
this->domainMap_);
7328 std::swap(
graph.importer_,
this->importer_);
7329 std::swap(
graph.exporter_,
this->exporter_);
7331 std::swap(
graph.nodeMaxNumRowEntries_,
this->nodeMaxNumRowEntries_);
7333 std::swap(
graph.globalNumEntries_,
this->globalNumEntries_);
7334 std::swap(
graph.globalMaxNumRowEntries_,
this->globalMaxNumRowEntries_);
7336 std::swap(
graph.numAllocForAllRows_,
this->numAllocForAllRows_);
7338 std::swap(
graph.rowPtrsPacked_dev_,
this->rowPtrsPacked_dev_);
7339 std::swap(
graph.rowPtrsPacked_host_,
this->rowPtrsPacked_host_);
7341 std::swap(
graph.rowPtrsUnpacked_dev_,
this->rowPtrsUnpacked_dev_);
7342 std::swap(
graph.rowPtrsUnpacked_host_,
this->rowPtrsUnpacked_host_);
7343 std::swap(
graph.packedUnpackedRowPtrsMatch_,
this->packedUnpackedRowPtrsMatch_);
7345 std::swap(
graph.k_offRankOffsets_,
this->k_offRankOffsets_);
7347 std::swap(
graph.lclIndsUnpacked_wdv,
this->lclIndsUnpacked_wdv);
7348 std::swap(
graph.gblInds_wdv,
this->gblInds_wdv);
7349 std::swap(
graph.lclIndsPacked_wdv,
this->lclIndsPacked_wdv);
7351 std::swap(
graph.storageStatus_,
this->storageStatus_);
7353 std::swap(
graph.indicesAreAllocated_,
this->indicesAreAllocated_);
7354 std::swap(
graph.indicesAreLocal_,
this->indicesAreLocal_);
7355 std::swap(
graph.indicesAreGlobal_,
this->indicesAreGlobal_);
7356 std::swap(
graph.fillComplete_,
this->fillComplete_);
7357 std::swap(
graph.indicesAreSorted_,
this->indicesAreSorted_);
7358 std::swap(
graph.noRedundancies_,
this->noRedundancies_);
7359 std::swap(
graph.haveLocalConstants_,
this->haveLocalConstants_);
7360 std::swap(
graph.haveGlobalConstants_,
this->haveGlobalConstants_);
7361 std::swap(
graph.haveLocalOffRankOffsets_,
this->haveLocalOffRankOffsets_);
7363 std::swap(
graph.sortGhostsAssociatedWithEachProcessor_,
this->sortGhostsAssociatedWithEachProcessor_);
7365 std::swap(
graph.k_numAllocPerRow_,
this->k_numAllocPerRow_);
7366 std::swap(
graph.k_numRowEntries_,
this->k_numRowEntries_);
7367 std::swap(
graph.nonlocals_,
this->nonlocals_);
7371 template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
7385 auto v1 =
m1.find(
key)->second;
7386 auto v2 =
m2.find(
key)->second;
7387 std::sort(
v1.begin(),
v1.end());
7388 std::sort(
v2.begin(),
v2.end());
7407 output = this->nodeMaxNumRowEntries_ ==
graph.nodeMaxNumRowEntries_ ?
output :
false;
7410 output = this->globalMaxNumRowEntries_ ==
graph.globalMaxNumRowEntries_ ?
output :
false;
7412 output = this->numAllocForAllRows_ ==
graph.numAllocForAllRows_ ?
output :
false;
7416 output = this->indicesAreAllocated_ ==
graph.indicesAreAllocated_ ?
output :
false;
7422 output = this->haveLocalConstants_ ==
graph.haveLocalConstants_ ?
output :
false;
7423 output = this->haveGlobalConstants_ ==
graph.haveGlobalConstants_ ?
output :
false;
7424 output = this->haveLocalOffRankOffsets_ ==
graph.haveLocalOffRankOffsets_ ?
output :
false;
7425 output = this->sortGhostsAssociatedWithEachProcessor_ == this->sortGhostsAssociatedWithEachProcessor_ ?
output :
false;
7433 output = this->k_numAllocPerRow_.extent(0) ==
graph.k_numAllocPerRow_.extent(0) ?
output :
false;
7434 if(
output && this->k_numAllocPerRow_.extent(0) > 0)
7436 for(
size_t i=0;
output &&
i<this->k_numAllocPerRow_.extent(0);
i++)
7442 output = this->k_numRowEntries_.extent(0) ==
graph.k_numRowEntries_.extent(0) ?
output :
false;
7443 if(
output && this->k_numRowEntries_.extent(0) > 0)
7445 for(
size_t i = 0;
output &&
i < this->k_numRowEntries_.extent(0);
i++)
7451 auto rowPtrsThis = this->getRowPtrsUnpackedHost();
7459 output = this->lclIndsUnpacked_wdv.extent(0) ==
graph.lclIndsUnpacked_wdv.extent(0) ?
output :
false;
7460 if(
output && this->lclIndsUnpacked_wdv.extent(0) > 0)
7462 auto indThis = this->lclIndsUnpacked_wdv.getHostView(Access::ReadOnly);
7463 auto indGraph =
graph.lclIndsUnpacked_wdv.getHostView(Access::ReadOnly);
7469 output = this->gblInds_wdv.extent(0) ==
graph.gblInds_wdv.extent(0) ?
output :
false;
7470 if(
output && this->gblInds_wdv.extent(0) > 0)
7472 auto indtThis = this->gblInds_wdv.getHostView(Access::ReadOnly);
7473 auto indtGraph =
graph.gblInds_wdv.getHostView(Access::ReadOnly);
7546#define TPETRA_CRSGRAPH_IMPORT_AND_FILL_COMPLETE_INSTANT(LO,GO,NODE) \
7548 Teuchos::RCP<CrsGraph<LO,GO,NODE> > \
7549 importAndFillCompleteCrsGraph(const Teuchos::RCP<const CrsGraph<LO,GO,NODE> >& sourceGraph, \
7550 const Import<CrsGraph<LO,GO,NODE>::local_ordinal_type, \
7551 CrsGraph<LO,GO,NODE>::global_ordinal_type, \
7552 CrsGraph<LO,GO,NODE>::node_type>& importer, \
7553 const Teuchos::RCP<const Map<CrsGraph<LO,GO,NODE>::local_ordinal_type, \
7554 CrsGraph<LO,GO,NODE>::global_ordinal_type, \
7555 CrsGraph<LO,GO,NODE>::node_type> >& domainMap, \
7556 const Teuchos::RCP<const Map<CrsGraph<LO,GO,NODE>::local_ordinal_type, \
7557 CrsGraph<LO,GO,NODE>::global_ordinal_type, \
7558 CrsGraph<LO,GO,NODE>::node_type> >& rangeMap, \
7559 const Teuchos::RCP<Teuchos::ParameterList>& params);
7561#define TPETRA_CRSGRAPH_IMPORT_AND_FILL_COMPLETE_INSTANT_TWO(LO,GO,NODE) \
7563 Teuchos::RCP<CrsGraph<LO,GO,NODE> > \
7564 importAndFillCompleteCrsGraph(const Teuchos::RCP<const CrsGraph<LO,GO,NODE> >& sourceGraph, \
7565 const Import<CrsGraph<LO,GO,NODE>::local_ordinal_type, \
7566 CrsGraph<LO,GO,NODE>::global_ordinal_type, \
7567 CrsGraph<LO,GO,NODE>::node_type>& rowImporter, \
7568 const Import<CrsGraph<LO,GO,NODE>::local_ordinal_type, \
7569 CrsGraph<LO,GO,NODE>::global_ordinal_type, \
7570 CrsGraph<LO,GO,NODE>::node_type>& domainImporter, \
7571 const Teuchos::RCP<const Map<CrsGraph<LO,GO,NODE>::local_ordinal_type, \
7572 CrsGraph<LO,GO,NODE>::global_ordinal_type, \
7573 CrsGraph<LO,GO,NODE>::node_type> >& domainMap, \
7574 const Teuchos::RCP<const Map<CrsGraph<LO,GO,NODE>::local_ordinal_type, \
7575 CrsGraph<LO,GO,NODE>::global_ordinal_type, \
7576 CrsGraph<LO,GO,NODE>::node_type> >& rangeMap, \
7577 const Teuchos::RCP<Teuchos::ParameterList>& params);
7580#define TPETRA_CRSGRAPH_EXPORT_AND_FILL_COMPLETE_INSTANT(LO,GO,NODE) \
7582 Teuchos::RCP<CrsGraph<LO,GO,NODE> > \
7583 exportAndFillCompleteCrsGraph(const Teuchos::RCP<const CrsGraph<LO,GO,NODE> >& sourceGraph, \
7584 const Export<CrsGraph<LO,GO,NODE>::local_ordinal_type, \
7585 CrsGraph<LO,GO,NODE>::global_ordinal_type, \
7586 CrsGraph<LO,GO,NODE>::node_type>& exporter, \
7587 const Teuchos::RCP<const Map<CrsGraph<LO,GO,NODE>::local_ordinal_type, \
7588 CrsGraph<LO,GO,NODE>::global_ordinal_type, \
7589 CrsGraph<LO,GO,NODE>::node_type> >& domainMap, \
7590 const Teuchos::RCP<const Map<CrsGraph<LO,GO,NODE>::local_ordinal_type, \
7591 CrsGraph<LO,GO,NODE>::global_ordinal_type, \
7592 CrsGraph<LO,GO,NODE>::node_type> >& rangeMap, \
7593 const Teuchos::RCP<Teuchos::ParameterList>& params);
7595#define TPETRA_CRSGRAPH_EXPORT_AND_FILL_COMPLETE_INSTANT_TWO(LO,GO,NODE) \
7597 Teuchos::RCP<CrsGraph<LO,GO,NODE> > \
7598 exportAndFillCompleteCrsGraph(const Teuchos::RCP<const CrsGraph<LO,GO,NODE> >& sourceGraph, \
7599 const Export<CrsGraph<LO,GO,NODE>::local_ordinal_type, \
7600 CrsGraph<LO,GO,NODE>::global_ordinal_type, \
7601 CrsGraph<LO,GO,NODE>::node_type>& rowExporter, \
7602 const Export<CrsGraph<LO,GO,NODE>::local_ordinal_type, \
7603 CrsGraph<LO,GO,NODE>::global_ordinal_type, \
7604 CrsGraph<LO,GO,NODE>::node_type>& domainExporter, \
7605 const Teuchos::RCP<const Map<CrsGraph<LO,GO,NODE>::local_ordinal_type, \
7606 CrsGraph<LO,GO,NODE>::global_ordinal_type, \
7607 CrsGraph<LO,GO,NODE>::node_type> >& domainMap, \
7608 const Teuchos::RCP<const Map<CrsGraph<LO,GO,NODE>::local_ordinal_type, \
7609 CrsGraph<LO,GO,NODE>::global_ordinal_type, \
7610 CrsGraph<LO,GO,NODE>::node_type> >& rangeMap, \
7611 const Teuchos::RCP<Teuchos::ParameterList>& params);
7614#define TPETRA_CRSGRAPH_INSTANT( LO, GO, NODE ) \
7615 template class CrsGraph<LO, GO, NODE>; \
7616 TPETRA_CRSGRAPH_IMPORT_AND_FILL_COMPLETE_INSTANT(LO,GO,NODE) \
7617 TPETRA_CRSGRAPH_EXPORT_AND_FILL_COMPLETE_INSTANT(LO,GO,NODE) \
7618 TPETRA_CRSGRAPH_IMPORT_AND_FILL_COMPLETE_INSTANT_TWO(LO,GO,NODE) \
7619 TPETRA_CRSGRAPH_EXPORT_AND_FILL_COMPLETE_INSTANT_TWO(LO,GO,NODE)