2353 (isGloballyIndexed (), std::runtime_error,
"The graph's indices are "
2354 "currently stored as global indices, so we cannot return a view with "
2355 "local column indices, whether or not the graph has a column Map. If "
2356 "the graph _does_ have a column Map, use getLocalRowCopy() instead.");
2359 if (
rowInfo.localRow != Teuchos::OrdinalTraits<size_t>::invalid () &&
2361 indices = lclIndsUnpacked_wdv.getHostSubview(
rowInfo.offset1D,
2368 indices = local_inds_host_view_type();
2372 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC
2373 (
static_cast<size_t> (indices.size ()) !=
2374 getNumEntriesInLocalRow (localRow), std::logic_error,
"indices.size() "
2375 "= " << indices.extent(0) <<
" != getNumEntriesInLocalRow(localRow=" <<
2376 localRow <<
") = " << getNumEntriesInLocalRow(localRow) <<
2377 ". Please report this bug to the Tpetra developers.");
2382 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2387 global_inds_host_view_type &indices)
const
2392 (isLocallyIndexed (), std::runtime_error,
"The graph's indices are "
2393 "currently stored as local indices, so we cannot return a view with "
2394 "global column indices. Use getGlobalRowCopy() instead.");
2399 if (
rowInfo.localRow != Teuchos::OrdinalTraits<size_t>::invalid () &&
2401 indices = gblInds_wdv.getHostSubview(
rowInfo.offset1D,
2406 indices =
typename global_inds_dualv_type::t_host::const_type();
2410 (
static_cast<size_t> (indices.size ()) !=
2412 std::logic_error,
"indices.size() = " << indices.extent(0)
2413 <<
" != getNumEntriesInGlobalRow(globalRow=" <<
globalRow <<
") = "
2415 <<
". Please report this bug to the Tpetra developers.");
2420 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2424 const Teuchos::ArrayView<const LocalOrdinal>& indices)
2429 (! isFillActive (), std::runtime_error,
"Fill must be active.");
2431 (isGloballyIndexed (), std::runtime_error,
2432 "Graph indices are global; use insertGlobalIndices().");
2434 (! hasColMap (), std::runtime_error,
2435 "Cannot insert local indices without a column Map.");
2437 (! rowMap_->isNodeLocalElement (localRow), std::runtime_error,
2438 "Local row index " << localRow <<
" is not in the row Map "
2439 "on the calling process.");
2440 if (! indicesAreAllocated ()) {
2441 allocateIndices (LocalIndices, verbose_);
2450 using Teuchos::Array;
2451 using Teuchos::toString;
2453 typedef typename Teuchos::ArrayView<const LocalOrdinal>::size_type size_type;
2458 for (size_type
k = 0;
k < indices.size (); ++
k) {
2459 if (!
colMap.isNodeLocalElement (indices[
k])) {
2465 std::ostringstream
os;
2466 os <<
"Tpetra::CrsGraph::insertLocalIndices: You attempted to insert "
2467 "entries in owned row " << localRow <<
", at the following column "
2468 "indices: " << toString (indices) <<
"." <<
endl;
2469 os <<
"Of those, the following indices are not in the column Map on "
2470 "this process: " << toString (
badColInds) <<
"." <<
endl <<
"Since "
2471 "the graph has a column Map already, it is invalid to insert entries "
2472 "at those locations.";
2478 insertLocalIndicesImpl (localRow, indices);
2482 (! indicesAreAllocated () || ! isLocallyIndexed (), std::logic_error,
2483 "At the end of insertLocalIndices, ! indicesAreAllocated() || "
2484 "! isLocallyIndexed() is true. Please report this bug to the "
2485 "Tpetra developers.");
2489 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2497 this->insertLocalIndices (localRow,
indsT);
2501 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2512 (this->isLocallyIndexed (), std::runtime_error,
2513 "graph indices are local; use insertLocalIndices().");
2519 (! this->isFillActive (), std::runtime_error,
2520 "You are not allowed to call this method if fill is not active. "
2521 "If fillComplete has been called, you must first call resumeFill "
2522 "before you may insert indices.");
2523 if (! indicesAreAllocated ()) {
2524 allocateIndices (GlobalIndices, verbose_);
2526 const LO
lclRow = this->rowMap_->getLocalElement (
gblRow);
2527 if (
lclRow != Tpetra::Details::OrdinalTraits<LO>::invalid ()) {
2529 if (this->hasColMap ()) {
2545 std::ostringstream
os;
2546 os <<
"You attempted to insert entries in owned row " <<
gblRow
2547 <<
", at the following column indices: [";
2554 os <<
"]." <<
endl <<
"Of those, the following indices are not in "
2555 "the column Map on this process: [";
2562 os <<
"]." <<
endl <<
"Since the matrix has a column Map already, "
2563 "it is invalid to insert entries at those locations.";
2565 (
true, std::invalid_argument,
os.str ());
2578 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2589 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2598 const char tfecfFuncName[] =
"insertGlobalIndicesFiltered: ";
2601 (this->isLocallyIndexed (), std::runtime_error,
2602 "Graph indices are local; use insertLocalIndices().");
2608 (! this->isFillActive (), std::runtime_error,
2609 "You are not allowed to call this method if fill is not active. "
2610 "If fillComplete has been called, you must first call resumeFill "
2611 "before you may insert indices.");
2612 if (! indicesAreAllocated ()) {
2613 allocateIndices (GlobalIndices, verbose_);
2618 if (! colMap_.is_null ()) {
2629 if (
lclCol == Tpetra::Details::OrdinalTraits<LO>::invalid ()) {
2653 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2672 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2679 ! isFillActive (), std::runtime_error,
"requires that fill is active.");
2681 isStorageOptimized (), std::runtime_error,
2682 "cannot remove indices after optimizeStorage() has been called.");
2684 isGloballyIndexed (), std::runtime_error,
"graph indices are global.");
2686 ! rowMap_->isNodeLocalElement (
lrow), std::runtime_error,
2687 "Local row " <<
lrow <<
" is not in the row Map on the calling process.");
2688 if (! indicesAreAllocated ()) {
2689 allocateIndices (LocalIndices, verbose_);
2692 if (k_numRowEntries_.extent (0) != 0) {
2693 this->k_numRowEntries_(
lrow) = 0;
2698 (getNumEntriesInLocalRow (
lrow) != 0 ||
2699 ! indicesAreAllocated () ||
2700 ! isLocallyIndexed (), std::logic_error,
2701 "Violated stated post-conditions. Please contact Tpetra team.");
2706 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2710 const typename local_graph_device_type::entries_type::non_const_type&
columnIndices)
2713 ProfilingRegion
region (
"Tpetra::CrsGraph::setAllIndices");
2716 ! hasColMap () || getColMap ().
is_null (), std::runtime_error,
2717 "The graph must have a column Map before you may call this method.");
2724 std::runtime_error,
"Have 0 local rows, but rowPointers.size() is neither 0 nor 1.");
2729 std::runtime_error,
"rowPointers.size() = " <<
rowPtrLen <<
2730 " != this->getLocalNumRows()+1 = " << (
numLocalRows + 1) <<
".");
2735 using exec_space =
typename local_graph_device_type::execution_space;
2738 Kokkos::parallel_reduce(Kokkos::RangePolicy<exec_space>(0,
columnIndices.extent(0)),
2745 auto comm = this->getComm();
2754 message = std::string(
"ERROR, rank ") + std::to_string(comm->getRank()) +
", CrsGraph::setAllIndices(): provided columnIndices are not all within range [0, getLocalNumCols())!\n";
2757 throw std::invalid_argument(
"CrsGraph::setAllIndices(): columnIndices are out of the valid range on at least one process.");
2761 if (debug_ && this->isSorted()) {
2764 using exec_space =
typename local_graph_device_type::execution_space;
2765 using size_type =
typename local_graph_device_type::size_type;
2766 Kokkos::parallel_reduce(Kokkos::RangePolicy<exec_space>(0,
numLocalRows),
2781 auto comm = this->getComm();
2782 Teuchos::reduceAll<int, int> (*comm, Teuchos::REDUCE_MAX,
notSorted,
2790 message = std::string(
"ERROR, rank ") + std::to_string(comm->getRank()) +
", CrsGraph::setAllIndices(): provided columnIndices are not sorted!\n";
2793 throw std::invalid_argument(
"CrsGraph::setAllIndices(): provided columnIndices are not sorted within rows on at least one process.");
2797 indicesAreAllocated_ =
true;
2798 indicesAreLocal_ =
true;
2799 indicesAreSorted_ =
true;
2800 noRedundancies_ =
true;
2802 lclIndsUnpacked_wdv = lclIndsPacked_wdv;
2805 set_need_sync_host_uvm_access();
2809 storageStatus_ = Details::STORAGE_1D_PACKED;
2814 numAllocForAllRows_ = 0;
2815 k_numAllocPerRow_ =
decltype (k_numAllocPerRow_) ();
2817 checkInternalState ();
2821 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2828 typedef typename local_graph_device_type::row_map_type
row_map_type;
2829 typedef typename row_map_type::array_layout
layout_type;
2832 Kokkos::MemoryUnmanaged> input_view_type;
2836 constexpr bool same = std::is_same<size_t, row_offset_type>::value;
2842#ifdef KOKKOS_ENABLE_CXX17
2843 if constexpr (
same) {
2857 Kokkos::Impl::if_c<
same,
2866 std::is_same<
typename row_map_type::memory_space,
2867 Kokkos::HostSpace>::value;
2890 Kokkos::View<LocalOrdinal*, layout_type, device_type>
k_ind =
2891 Kokkos::Compat::getKokkosViewDeepCopy<device_type> (
columnIndices ());
2896 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2901 using Teuchos::Comm;
2902 using Teuchos::outArg;
2905 using Teuchos::REDUCE_MAX;
2906 using Teuchos::REDUCE_MIN;
2907 using Teuchos::reduceAll;
2912 using size_type =
typename Teuchos::Array<GO>::size_type;
2915 std::unique_ptr<std::string>
prefix;
2917 prefix = this->createPrefix(
"CrsGraph",
"globalAssemble");
2918 std::ostringstream
os;
2920 std::cerr <<
os.str();
2925 (! isFillActive (), std::runtime_error,
"Fill must be active before "
2926 "you may call this method.");
2941 std::ostringstream
os;
2943 std::cerr <<
os.str();
2947 else if (verbose_) {
2948 std::ostringstream
os;
2949 os << *
prefix <<
"At least 1 process has nonlocal rows"
2951 std::cerr <<
os.str();
2970 for (
auto mapIter = this->nonlocals_.begin ();
2971 mapIter != this->nonlocals_.end ();
3001 const global_size_t INV = Teuchos::OrdinalTraits<global_size_t>::invalid ();
3006 std::ostringstream
os;
3007 os << *
prefix <<
"nonlocalRowMap->getIndexBase()="
3009 std::cerr <<
os.str();
3021 for (
auto mapIter = this->nonlocals_.begin ();
3022 mapIter != this->nonlocals_.end ();
3031 std::ostringstream
os;
3033 std::cerr <<
os.str();
3049 std::ostringstream
os;
3051 std::cerr <<
os.str();
3059 std::ostringstream
os;
3060 os << *
prefix <<
"Original row Map is NOT 1-to-1" <<
endl;
3061 std::cerr <<
os.str();
3078 std::ostringstream
os;
3080 std::cerr <<
os.str();
3091 std::ostringstream
os;
3093 std::cerr <<
os.str();
3105 checkInternalState ();
3107 std::ostringstream
os;
3109 std::cerr <<
os.str();
3114 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
3119 clearGlobalConstants();
3120 if (
params != Teuchos::null) this->setParameterList (
params);
3122 indicesAreSorted_ =
true;
3123 noRedundancies_ =
true;
3124 fillComplete_ =
false;
3128 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
3143 Teuchos::RCP<const map_type>
domMap = this->getDomainMap ();
3145 domMap = this->getRowMap ();
3147 Teuchos::RCP<const map_type>
ranMap = this->getRangeMap ();
3149 ranMap = this->getRowMap ();
3155 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
3158 fillComplete (
const Teuchos::RCP<const map_type>& domainMap,
3159 const Teuchos::RCP<const map_type>&
rangeMap,
3160 const Teuchos::RCP<Teuchos::ParameterList>&
params)
3164 const bool verbose = verbose_;
3166 std::unique_ptr<std::string>
prefix;
3168 prefix = this->createPrefix(
"CrsGraph",
"fillComplete");
3169 std::ostringstream
os;
3171 std::cerr <<
os.str();
3175 (! isFillActive () || isFillComplete (), std::runtime_error,
3176 "Graph fill state must be active (isFillActive() "
3177 "must be true) before calling fillComplete().");
3179 const int numProcs = getComm ()->getSize ();
3187 if (!
params.is_null ()) {
3188 if (
params->isParameter (
"sort column map ghost gids")) {
3189 sortGhostsAssociatedWithEachProcessor_ =
3190 params->get<
bool> (
"sort column map ghost gids",
3191 sortGhostsAssociatedWithEachProcessor_);
3193 else if (
params->isParameter (
"Sort column Map ghost GIDs")) {
3194 sortGhostsAssociatedWithEachProcessor_ =
3195 params->get<
bool> (
"Sort column Map ghost GIDs",
3196 sortGhostsAssociatedWithEachProcessor_);
3203 if (!
params.is_null ()) {
3211 if (! indicesAreAllocated ()) {
3214 allocateIndices (LocalIndices, verbose);
3217 allocateIndices (GlobalIndices, verbose);
3234 std::ostringstream
os;
3235 os << *
prefix <<
"Do not need to call globalAssemble; "
3236 "assertNoNonlocalInserts="
3240 std::cerr <<
os.str();
3245 std::ostringstream
os;
3247 Details::Impl::verbosePrintMap(
3248 os, nonlocals_.begin(), nonlocals_.end(),
3249 nonlocals_.size(),
"nonlocals_");
3250 std::cerr <<
os.str() <<
endl;
3254 auto map = this->getMap();
3255 auto comm =
map.is_null() ? Teuchos::null :
map->getComm();
3257 if (! comm.is_null()) {
3258 using Teuchos::REDUCE_MAX;
3259 using Teuchos::reduceAll;
3266 "least one process in the CrsGraph's communicator. This "
3267 "means either that you incorrectly set the "
3268 "\"No Nonlocal Changes\" fillComplete parameter to true, "
3269 "or that you inserted invalid entries. "
3270 "Rerun with the environment variable TPETRA_VERBOSE="
3271 "CrsGraph set to see the entries of nonlocals_ on every "
3272 "MPI process (WARNING: lots of output).");
3277 "nonlocals_.size()=" <<
numNonlocals <<
" != 0 on the "
3278 "calling process. This means either that you incorrectly "
3279 "set the \"No Nonlocal Changes\" fillComplete parameter "
3280 "to true, or that you inserted invalid entries. "
3281 "Rerun with the environment "
3282 "variable TPETRA_VERBOSE=CrsGraph set to see the entries "
3283 "of nonlocals_ on every MPI process (WARNING: lots of "
3296 Teuchos::Array<int> remotePIDs (0);
3299 this->makeColMap (remotePIDs);
3305 this->makeIndicesLocal(verbose);
3310 using Teuchos::REDUCE_MIN;
3311 using Teuchos::reduceAll;
3312 using Teuchos::outArg;
3316 if (!
map.is_null ()) {
3317 comm =
map->getComm ();
3319 if (comm.is_null ()) {
3329 std::ostringstream
os;
3332 (
true, std::runtime_error,
os.str ());
3349 this->sortAndMergeAllIndices (this->isSorted (), this->isMerged ());
3357 this->fillLocalGraph (
params);
3360 params->get (
"compute global constants",
true);
3362 this->computeGlobalConstants ();
3365 this->computeLocalConstants ();
3367 this->fillComplete_ =
true;
3368 this->checkInternalState ();
3371 std::ostringstream
os;
3373 std::cerr <<
os.str();
3378 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
3382 const Teuchos::RCP<const map_type>&
rangeMap,
3383 const Teuchos::RCP<const import_type>&
importer,
3384 const Teuchos::RCP<const export_type>&
exporter,
3385 const Teuchos::RCP<Teuchos::ParameterList>&
params)
3388#ifdef HAVE_TPETRA_MMM_TIMINGS
3391 label =
params->get(
"Timer Label",label);
3392 std::string
prefix = std::string(
"Tpetra ")+ label + std::string(
": ");
3393 using Teuchos::TimeMonitor;
3394 Teuchos::RCP<Teuchos::TimeMonitor>
MM = Teuchos::rcp(
new TimeMonitor(*TimeMonitor::getNewTimer(
prefix + std::string(
"ESFC-G-Setup"))));
3400 std::runtime_error,
"The input domain Map and range Map must be nonnull.");
3402 isFillComplete () || ! hasColMap (), std::runtime_error,
"You may not "
3403 "call this method unless the graph has a column Map.");
3407 std::runtime_error,
"The calling process has getLocalNumRows() = "
3408 << getLocalNumRows () <<
" > 0 rows, but the row offsets array has not "
3412 std::runtime_error,
"The row offsets array has length " <<
3414 (getLocalNumRows () + 1) <<
".");
3429 numAllocForAllRows_ = 0;
3430 k_numAllocPerRow_ =
decltype (k_numAllocPerRow_) ();
3431 indicesAreAllocated_ =
true;
3436 indicesAreLocal_ =
true;
3437 indicesAreGlobal_ =
false;
3440#ifdef HAVE_TPETRA_MMM_TIMINGS
3442 MM = Teuchos::rcp(
new TimeMonitor(*TimeMonitor::getNewTimer(
prefix + std::string(
"ESFC-G-Maps"))));
3447 indicesAreSorted_ =
true;
3448 noRedundancies_ =
true;
3451#ifdef HAVE_TPETRA_MMM_TIMINGS
3453 MM = Teuchos::rcp(
new TimeMonitor(*TimeMonitor::getNewTimer(
prefix + std::string(
"ESFC-G-mIXcheckI"))));
3456 importer_ = Teuchos::null;
3457 exporter_ = Teuchos::null;
3460 !
importer->getSourceMap ()->isSameAs (*getDomainMap ()) ||
3461 !
importer->getTargetMap ()->isSameAs (*getColMap ()),
3462 std::invalid_argument,
": importer does not match matrix maps.");
3467#ifdef HAVE_TPETRA_MMM_TIMINGS
3469 MM = Teuchos::rcp(
new TimeMonitor(*TimeMonitor::getNewTimer(
prefix + std::string(
"ESFC-G-mIXcheckE"))));
3474 !
exporter->getSourceMap ()->isSameAs (*getRowMap ()) ||
3475 !
exporter->getTargetMap ()->isSameAs (*getRangeMap ()),
3476 std::invalid_argument,
": exporter does not match matrix maps.");
3480#ifdef HAVE_TPETRA_MMM_TIMINGS
3482 MM = Teuchos::rcp(
new TimeMonitor(*TimeMonitor::getNewTimer(
prefix + std::string(
"ESFC-G-mIXmake"))));
3484 Teuchos::Array<int> remotePIDs (0);
3485 this->makeImportExport (remotePIDs,
false);
3487#ifdef HAVE_TPETRA_MMM_TIMINGS
3489 MM = Teuchos::rcp(
new TimeMonitor(*TimeMonitor::getNewTimer(
prefix + std::string(
"ESFC-G-fLG"))));
3491 this->fillLocalGraph (
params);
3494 params->get (
"compute global constants",
true);
3497#ifdef HAVE_TPETRA_MMM_TIMINGS
3499 MM = Teuchos::rcp(
new TimeMonitor(*TimeMonitor::getNewTimer(
prefix + std::string(
"ESFC-G-cGC (const)"))));
3501 this->computeGlobalConstants ();
3504#ifdef HAVE_TPETRA_MMM_TIMINGS
3506 MM = Teuchos::rcp(
new TimeMonitor(*TimeMonitor::getNewTimer(
prefix + std::string(
"ESFC-G-cGC (noconst)"))));
3508 this->computeLocalConstants ();
3511 fillComplete_ =
true;
3513#ifdef HAVE_TPETRA_MMM_TIMINGS
3515 MM = Teuchos::rcp(
new TimeMonitor(*TimeMonitor::getNewTimer(
prefix + std::string(
"ESFC-G-cIS"))));
3517 checkInternalState ();
3521 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
3526 using ::Tpetra::Details::computeOffsetsFromCounts;
3527 typedef typename local_graph_device_type::row_map_type
row_map_type;
3529 typedef typename local_graph_device_type::entries_type::non_const_type
lclinds_1d_type;
3530 const char tfecfFuncName[] =
"fillLocalGraph (called from fillComplete or "
3531 "expertStaticFillComplete): ";
3532 const size_t lclNumRows = this->getLocalNumRows ();
3538 if (!
params.is_null () && !
params->get (
"Optimize Storage",
true)) {
3547 auto rowPtrsUnpacked = this->getRowPtrsUnpackedHost();
3549 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC
3550 (rowPtrsUnpacked.extent (0) == 0, std::logic_error,
3551 "rowPtrsUnpacked_host_ has size zero, but shouldn't");
3552 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC
3553 (rowPtrsUnpacked.extent (0) != lclNumRows + 1, std::logic_error,
3554 "rowPtrsUnpacked_host_.extent(0) = "
3555 << rowPtrsUnpacked.extent (0) <<
" != (lclNumRows + 1) = "
3556 << (lclNumRows + 1) <<
".");
3557 const size_t numOffsets = rowPtrsUnpacked.extent (0);
3558 const auto valToCheck = rowPtrsUnpacked(numOffsets-1);
3559 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC
3561 lclIndsUnpacked_wdv.extent (0) != valToCheck,
3562 std::logic_error,
"numOffsets=" << numOffsets <<
" != 0 "
3563 " and lclIndsUnpacked_wdv.extent(0)=" << lclIndsUnpacked_wdv.extent(0)
3564 <<
" != rowPtrsUnpacked_host_(" << numOffsets <<
")=" << valToCheck
3568 size_t allocSize = 0;
3570 allocSize = this->getLocalAllocationSize ();
3572 catch (std::logic_error& e) {
3573 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC
3574 (
true, std::logic_error,
"getLocalAllocationSize threw "
3575 "std::logic_error: " << e.what ());
3577 catch (std::runtime_error& e) {
3578 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC
3579 (
true, std::runtime_error,
"getLocalAllocationSize threw "
3580 "std::runtime_error: " << e.what ());
3582 catch (std::exception& e) {
3583 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC
3584 (
true, std::runtime_error,
"getLocalAllocationSize threw "
3585 "std::exception: " << e.what ());
3588 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC
3589 (
true, std::runtime_error,
"getLocalAllocationSize threw "
3590 "an exception not a subclass of std::exception.");
3593 if (this->getLocalNumEntries () != allocSize) {
3596 non_const_row_map_type ptr_d;
3597 row_map_type ptr_d_const;
3606 auto rowPtrsUnpacked = this->getRowPtrsUnpackedHost();
3607 if (rowPtrsUnpacked.extent (0) != 0) {
3608 const size_t numOffsets =
3609 static_cast<size_t> (rowPtrsUnpacked.extent (0));
3610 const auto valToCheck = rowPtrsUnpacked(numOffsets - 1);
3611 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC
3612 (valToCheck !=
size_t(lclIndsUnpacked_wdv.extent(0)),
3613 std::logic_error,
"(Unpacked branch) Before allocating "
3614 "or packing, k_rowPtrs_(" << (numOffsets-1) <<
")="
3615 << valToCheck <<
" != lclIndsUnpacked_wdv.extent(0)="
3616 << lclIndsUnpacked_wdv.extent (0) <<
".");
3626 size_t lclTotalNumEntries = 0;
3630 non_const_row_map_type (
"Tpetra::CrsGraph::ptr", lclNumRows + 1);
3631 ptr_d_const = ptr_d;
3635 typename num_row_entries_type::const_type numRowEnt_h = k_numRowEntries_;
3637 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC
3638 (
size_t(numRowEnt_h.extent (0)) != lclNumRows,
3639 std::logic_error,
"(Unpacked branch) "
3640 "numRowEnt_h.extent(0)=" << numRowEnt_h.extent(0)
3641 <<
" != getLocalNumRows()=" << lclNumRows <<
"");
3647 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC
3648 (
static_cast<size_t> (ptr_d.extent (0)) != lclNumRows + 1,
3649 std::logic_error,
"(Unpacked branch) After allocating "
3650 "ptr_d, ptr_d.extent(0) = " << ptr_d.extent(0)
3651 <<
" != lclNumRows+1 = " << (lclNumRows+1) <<
".");
3652 const auto valToCheck =
3653 ::Tpetra::Details::getEntryOnHost (ptr_d, lclNumRows);
3654 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC
3655 (valToCheck != lclTotalNumEntries, std::logic_error,
3656 "Tpetra::CrsGraph::fillLocalGraph: In unpacked branch, "
3657 "after filling ptr_d, ptr_d(lclNumRows=" << lclNumRows
3658 <<
") = " << valToCheck <<
" != total number of entries "
3659 "on the calling process = " << lclTotalNumEntries
3665 lclinds_1d_type ind_d =
3666 lclinds_1d_type (
"Tpetra::CrsGraph::lclInd", lclTotalNumEntries);
3678 typedef pack_functor<
3679 typename local_graph_device_type::entries_type::non_const_type,
3680 typename local_inds_dualv_type::t_dev::const_type,
3682 typename local_graph_device_type::row_map_type> inds_packer_type;
3683 inds_packer_type f (ind_d,
3684 lclIndsUnpacked_wdv.getDeviceView(Access::ReadOnly),
3685 ptr_d, this->getRowPtrsUnpackedDevice());
3687 typedef typename decltype (ind_d)::execution_space exec_space;
3688 typedef Kokkos::RangePolicy<exec_space, LocalOrdinal> range_type;
3689 Kokkos::parallel_for (range_type (0, lclNumRows), f);
3693 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC
3694 (ptr_d.extent (0) == 0, std::logic_error,
3695 "(\"Optimize Storage\"=true branch) After packing, "
3696 "ptr_d.extent(0)=0.");
3697 if (ptr_d.extent (0) != 0) {
3698 const size_t numOffsets =
static_cast<size_t> (ptr_d.extent (0));
3699 const auto valToCheck =
3700 ::Tpetra::Details::getEntryOnHost (ptr_d, numOffsets - 1);
3701 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC
3702 (
static_cast<size_t> (valToCheck) != ind_d.extent (0),
3703 std::logic_error,
"(\"Optimize Storage\"=true branch) "
3704 "After packing, ptr_d(" << (numOffsets-1) <<
")="
3705 << valToCheck <<
" != ind_d.extent(0)="
3706 << ind_d.extent(0) <<
".");
3710 if (requestOptimizedStorage)
3711 setRowPtrs(ptr_d_const);
3713 setRowPtrsPacked(ptr_d_const);
3714 lclIndsPacked_wdv = local_inds_wdv_type(ind_d);
3718 this->setRowPtrs(rowPtrsUnpacked_dev_);
3719 lclIndsPacked_wdv = lclIndsUnpacked_wdv;
3722 auto rowPtrsPacked_dev = this->getRowPtrsPackedDevice();
3723 auto rowPtrsPacked_host = this->getRowPtrsPackedHost();
3724 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC
3725 (rowPtrsPacked_dev.extent (0) == 0, std::logic_error,
3726 "(\"Optimize Storage\"=false branch) "
3727 "rowPtrsPacked_dev_.extent(0) = 0.");
3728 if (rowPtrsPacked_dev.extent (0) != 0) {
3729 const size_t numOffsets =
3730 static_cast<size_t> (rowPtrsPacked_dev.extent (0));
3731 const size_t valToCheck =
3732 rowPtrsPacked_host(numOffsets - 1);
3733 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC
3734 (valToCheck !=
size_t(lclIndsPacked_wdv.extent (0)),
3735 std::logic_error,
"(\"Optimize Storage\"=false branch) "
3736 "rowPtrsPacked_dev_(" << (numOffsets-1) <<
")="
3738 <<
" != lclIndsPacked_wdv.extent(0)="
3739 << lclIndsPacked_wdv.extent (0) <<
".");
3745 auto rowPtrsPacked_dev = this->getRowPtrsPackedDevice();
3746 auto rowPtrsPacked_host = this->getRowPtrsPackedHost();
3747 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC
3748 (
static_cast<size_t> (rowPtrsPacked_dev.extent (0)) != lclNumRows + 1,
3749 std::logic_error,
"After packing, rowPtrsPacked_dev_.extent(0) = " <<
3750 rowPtrsPacked_dev.extent (0) <<
" != lclNumRows+1 = " << (lclNumRows+1)
3752 if (rowPtrsPacked_dev.extent (0) != 0) {
3753 const size_t numOffsets =
static_cast<size_t> (rowPtrsPacked_dev.extent (0));
3754 const auto valToCheck = rowPtrsPacked_host(numOffsets - 1);
3755 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC
3756 (
static_cast<size_t> (valToCheck) != lclIndsPacked_wdv.extent (0),
3757 std::logic_error,
"After packing, rowPtrsPacked_dev_(" << (numOffsets-1)
3758 <<
") = " << valToCheck <<
" != lclIndsPacked_wdv.extent(0) = "
3759 << lclIndsPacked_wdv.extent (0) <<
".");
3763 if (requestOptimizedStorage) {
3769 k_numRowEntries_ = num_row_entries_type ();
3772 lclIndsUnpacked_wdv = lclIndsPacked_wdv;
3774 storageStatus_ = Details::STORAGE_1D_PACKED;
3777 set_need_sync_host_uvm_access();
3780 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
3794 isLocallyIndexed () || isGloballyIndexed (), std::runtime_error,
3795 "Requires matching maps and non-static graph.");
3799 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
3803 const Teuchos::RCP<const import_type>&
newImport,
3806 using Teuchos::REDUCE_MIN;
3807 using Teuchos::reduceAll;
3811 typedef typename local_inds_dualv_type::t_host
col_inds_type;
3815 isFillComplete (), std::runtime_error,
"The graph is fill complete "
3816 "(isFillComplete() returns true). You must call resumeFill() before "
3817 "you may call this method.");
3835 const LO
lclNumRows =
static_cast<LO
> (this->getLocalNumRows ());
3864 auto oldLclInds1D = lclIndsUnpacked_wdv.getHostView(Access::ReadOnly);
3869 if (indicesAreAllocated ()) {
3870 if (isLocallyIndexed ()) {
3874 const size_t allocSize = this->getLocalAllocationSize ();
3884 if (
oldLclCol == Teuchos::OrdinalTraits<LO>::invalid ()) {
3893 if (
gblCol == Teuchos::OrdinalTraits<GO>::invalid ()) {
3899 if (
newLclCol == Teuchos::OrdinalTraits<LO>::invalid ()) {
3934 for (
size_t k = 0;
k <
rowInfo.numEntries; ++
k) {
3953 getRowMap ().is_null () ? Teuchos::null : getRowMap ()->getComm ();
3954 if (! comm.is_null ()) {
3959 gblSuccess[0] == 0, std::runtime_error,
"It is not possible to continue."
3960 " The most likely reason is that the graph is locally indexed, but the "
3961 "column Map is missing (null) on some processes, due to a previous call "
3962 "to replaceColMap().");
3965 gblSuccess[1] == 0, std::runtime_error,
"On some process, the graph "
3966 "contains column indices that are in the old column Map, but not in the "
3967 "new column Map (on that process). This method does NOT redistribute "
3968 "data; it does not claim to do the work of an Import or Export operation."
3969 " This means that for all processess, the calling process MUST own all "
3970 "column indices, in both the old column Map and the new column Map. In "
3971 "this case, you will need to do an Import or Export operation to "
3972 "redistribute data.");
3975 if (isLocallyIndexed ()) {
3978 Kokkos::view_alloc(
"Tpetra::CrsGraph::lclIndReindexed",
3979 Kokkos::WithoutInitializing),
3991 indicesAreSorted_ =
false;
3999 const bool sorted =
false;
4000 const bool merged =
true;
4014 if (! domainMap_.is_null ()) {
4015 if (! domainMap_->isSameAs (*
newColMap)) {
4018 importer_ = Teuchos::null;
4027 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
4032 const char prefix[] =
"Tpetra::CrsGraph::replaceDomainMap: ";
4034 colMap_.is_null (), std::invalid_argument,
prefix <<
"You may not call "
4035 "this method unless the graph already has a column Map.");
4038 prefix <<
"The new domain Map must be nonnull.");
4041 Teuchos::RCP<const import_type>
newImporter = Teuchos::null;
4048 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
4052 const Teuchos::RCP<const import_type>&
newImporter)
4054 const char prefix[] =
"Tpetra::CrsGraph::replaceDomainMapAndImporter: ";
4056 colMap_.is_null (), std::invalid_argument,
prefix <<
"You may not call "
4057 "this method unless the graph already has a column Map.");
4060 prefix <<
"The new domain Map must be nonnull.");
4070 (!
colSameAsDom, std::invalid_argument,
"If the new Import is null, "
4071 "then the new domain Map must be the same as the current column Map.");
4075 colMap_->isSameAs (* (
newImporter->getTargetMap ()));
4080 "new Import is nonnull, then the current column Map must be the same "
4081 "as the new Import's target Map, and the new domain Map must be the "
4082 "same as the new Import's source Map.");
4087 importer_ = Teuchos::rcp_const_cast<import_type> (
newImporter);
4090 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
4095 const char prefix[] =
"Tpetra::CrsGraph::replaceRangeMap: ";
4097 rowMap_.is_null (), std::invalid_argument,
prefix <<
"You may not call "
4098 "this method unless the graph already has a row Map.");
4101 prefix <<
"The new range Map must be nonnull.");
4104 Teuchos::RCP<const export_type>
newExporter = Teuchos::null;
4111 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
4115 const Teuchos::RCP<const export_type>&
newExporter)
4117 const char prefix[] =
"Tpetra::CrsGraph::replaceRangeMapAndExporter: ";
4119 rowMap_.is_null (), std::invalid_argument,
prefix <<
"You may not call "
4120 "this method unless the graph already has a column Map.");
4123 prefix <<
"The new domain Map must be nonnull.");
4133 (!
rowSameAsRange, std::invalid_argument,
"If the new Export is null, "
4134 "then the new range Map must be the same as the current row Map.");
4140 rowMap_->isSameAs (* (
newExporter->getSourceMap ()));
4143 "new Export is nonnull, then the current row Map must be the same "
4144 "as the new Export's source Map, and the new range Map must be the "
4145 "same as the new Export's target Map.");
4150 exporter_ = Teuchos::rcp_const_cast<export_type> (
newExporter);
4154 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
4160 lclIndsPacked_wdv.getDeviceView(Access::ReadWrite),
4161 this->getRowPtrsPackedDevice());
4164 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
4169 return local_graph_host_type(
4170 lclIndsPacked_wdv.getHostView(Access::ReadWrite),
4171 this->getRowPtrsPackedHost());
4174 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
4179 using ::Tpetra::Details::ProfilingRegion;
4180 using Teuchos::ArrayView;
4181 using Teuchos::outArg;
4182 using Teuchos::reduceAll;
4185 ProfilingRegion
regionCGC (
"Tpetra::CrsGraph::computeGlobalConstants");
4187 this->computeLocalConstants ();
4192 if (! this->haveGlobalConstants_) {
4193 const Teuchos::Comm<int>& comm = * (this->getComm ());
4207 lcl =
static_cast<GST> (this->getLocalNumEntries ());
4210 this->globalNumEntries_ =
gbl;
4214 outArg (this->globalMaxNumRowEntries_));
4215 this->haveGlobalConstants_ =
true;
4220 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
4225 using ::Tpetra::Details::ProfilingRegion;
4227 ProfilingRegion
regionCLC (
"Tpetra::CrsGraph::computeLocalConstants");
4228 if (this->haveLocalConstants_) {
4233 this->nodeMaxNumRowEntries_ =
4234 Teuchos::OrdinalTraits<size_t>::invalid();
4238 auto ptr = this->getRowPtrsPackedDevice();
4240 static_cast<LO
> (0) :
4241 (
static_cast<LO
> (
ptr.extent(0)) -
static_cast<LO
> (1));
4244 ::Tpetra::Details::maxDifference (
"Tpetra::CrsGraph: nodeMaxNumRowEntries",
4247 this->haveLocalConstants_ =
true;
4251 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
4252 std::pair<size_t, std::string>
4257 using Teuchos::arcp;
4258 using Teuchos::Array;
4263 typedef typename local_graph_device_type::row_map_type::non_const_value_type offset_type;
4264 typedef typename num_row_entries_type::non_const_value_type
num_ent_type;
4268 std::unique_ptr<std::string>
prefix;
4270 prefix = this->createPrefix(
"CrsGraph",
"makeIndicesLocal");
4271 std::ostringstream
os;
4272 os << *
prefix <<
"lclNumRows: " << getLocalNumRows() <<
endl;
4273 std::cerr <<
os.str();
4279 (! this->hasColMap (), std::logic_error,
"The graph does not have a "
4280 "column Map yet. This method should never be called in that case. "
4281 "Please report this bug to the Tpetra developers.");
4283 (this->getColMap ().
is_null (), std::logic_error,
"The graph claims "
4284 "that it has a column Map, because hasColMap() returns true. However, "
4285 "the result of getColMap() is null. This should never happen. Please "
4286 "report this bug to the Tpetra developers.");
4294 const LO
lclNumRows =
static_cast<LO
> (this->getLocalNumRows ());
4297 if (this->isGloballyIndexed () &&
lclNumRows != 0) {
4299 typename num_row_entries_type::const_type
h_numRowEnt =
4300 this->k_numRowEntries_;
4306 errStrm <<
"Unpacked row pointers (rowPtrsUnpacked_dev_) has length 0. This should never "
4307 "happen here. Please report this bug to the Tpetra developers."
4310 return std::make_pair(Tpetra::Details::OrdinalTraits<size_t>::invalid (),
4322 using Kokkos::view_alloc;
4323 using Kokkos::WithoutInitializing;
4333 const std::string label (
"Tpetra::CrsGraph::lclInd");
4335 std::ostringstream
os;
4336 os << *
prefix <<
"(Re)allocate lclInd_wdv: old="
4337 << lclIndsUnpacked_wdv.extent(0) <<
", new=" <<
numEnt <<
endl;
4338 std::cerr <<
os.str();
4355 std::ostringstream
os;
4356 os << *
prefix <<
"Allocate device mirror k_numRowEnt: "
4358 std::cerr <<
os.str();
4363 using ::Tpetra::Details::convertColumnIndicesFromGlobalToLocal;
4366 lclIndsUnpacked_wdv.getDeviceView(Access::OverwriteAll),
4367 gblInds_wdv.getDeviceView(Access::ReadOnly),
4368 this->getRowPtrsUnpackedDevice(),
4372 const int myRank = [
this] () {
4373 auto map = this->getMap ();
4374 if (
map.is_null ()) {
4378 auto comm =
map->getComm ();
4379 return comm.is_null () ? 0 : comm->getRank ();
4383 errStrm <<
"(Process " <<
myRank <<
") When converting column "
4384 "indices from global to local, we encountered " <<
lclNumErrs
4387 <<
" not live in the column Map on this process." <<
endl;
4394 std::ostringstream
os;
4395 os << *
prefix <<
"Free gblInds_wdv: "
4396 << gblInds_wdv.extent(0) <<
endl;
4397 std::cerr <<
os.str();
4402 this->indicesAreLocal_ =
true;
4403 this->indicesAreGlobal_ =
false;
4404 this->checkInternalState ();
4409 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
4419 std::unique_ptr<std::string>
prefix;
4422 std::ostringstream
os;
4424 std::cerr <<
os.str();
4432 Teuchos::RCP<const map_type>
colMap = this->colMap_;
4434 this->sortGhostsAssociatedWithEachProcessor_;
4444 using Teuchos::outArg;
4445 using Teuchos::REDUCE_MIN;
4446 using Teuchos::reduceAll;
4452 auto comm = this->getComm ();
4453 if (! comm.is_null ()) {
4459 std::ostringstream
os;
4462 (
true, std::runtime_error,
": An error happened on at "
4463 "least one process in the CrsGraph's communicator. "
4464 "Here are all processes' error messages:" << std::endl
4478 checkInternalState ();
4480 std::ostringstream
os;
4482 std::cerr <<
os.str();
4487 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
4494 using host_execution_space =
4495 typename Kokkos::View<LO*, device_type>::HostMirror::
4497 using range_type = Kokkos::RangePolicy<host_execution_space, LO>;
4500 (
"Tpetra::CrsGraph::sortAndMergeAllIndices");
4502 std::unique_ptr<std::string>
prefix;
4505 std::ostringstream
os;
4507 <<
"sorted=" << (
sorted ?
"true" :
"false")
4508 <<
", merged=" << (
merged ?
"true" :
"false") <<
endl;
4509 std::cerr <<
os.str();
4511 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC
4512 (this->isGloballyIndexed(), std::logic_error,
4513 "This method may only be called after makeIndicesLocal." );
4514 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC
4515 (! merged && this->isStorageOptimized(), std::logic_error,
4516 "The graph is already storage optimized, so we shouldn't be "
4517 "merging any indices. "
4518 "Please report this bug to the Tpetra developers.");
4520 if (! sorted || ! merged) {
4521 const LO lclNumRows(this->getLocalNumRows());
4522 auto range = range_type(0, lclNumRows);
4525 size_t totalNumDups = 0;
4527 lclIndsUnpacked_wdv.getHostView(Access::ReadWrite);
4529 Kokkos::parallel_reduce(range,
4530 [
this, sorted, merged] (
const LO lclRow,
size_t& numDups)
4532 const RowInfo rowInfo = this->getRowInfo(lclRow);
4533 numDups += this->sortAndMergeRowIndices(rowInfo, sorted, merged);
4537 std::ostringstream os;
4538 os << *prefix <<
"totalNumDups=" << totalNumDups << endl;
4539 std::cerr << os.str();
4543 lclIndsUnpacked_wdv.getHostView(Access::ReadWrite);
4545 Kokkos::parallel_for(range,
4546 [
this, sorted, merged] (
const LO lclRow)
4548 const RowInfo rowInfo = this->getRowInfo(lclRow);
4549 this->sortAndMergeRowIndices(rowInfo, sorted, merged);
4553 this->indicesAreSorted_ =
true;
4554 this->noRedundancies_ =
true;
4558 std::ostringstream os;
4559 os << *prefix <<
"Done" << endl;
4560 std::cerr << os.str();
4564 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
4570 using ::Tpetra::Details::ProfilingRegion;
4571 using Teuchos::ParameterList;
4575 ProfilingRegion
regionMIE (
"Tpetra::CrsGraph::makeImportExport");
4578 (! this->hasColMap (), std::logic_error,
4579 "This method may not be called unless the graph has a column Map.");
4589 if (importer_.is_null ()) {
4591 if (domainMap_ != colMap_ && (! domainMap_->isSameAs (*colMap_))) {
4592 if (
params.is_null () || !
params->isSublist (
"Import")) {
4594 importer_ =
rcp (
new import_type (domainMap_, colMap_, remotePIDs));
4617 if (exporter_.is_null ()) {
4619 if (rangeMap_ != rowMap_ && ! rangeMap_->isSameAs (*rowMap_)) {
4620 if (
params.is_null () || !
params->isSublist (
"Export")) {
4632 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
4637 std::ostringstream
oss;
4638 oss << dist_object_type::description ();
4639 if (isFillComplete ()) {
4640 oss <<
"{status = fill complete"
4641 <<
", global rows = " << getGlobalNumRows()
4642 <<
", global cols = " << getGlobalNumCols()
4643 <<
", global num entries = " << getGlobalNumEntries()
4647 oss <<
"{status = fill not complete"
4648 <<
", global rows = " << getGlobalNumRows()
4655 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
4659 const Teuchos::EVerbosityLevel
verbLevel)
const
4661 using Teuchos::ArrayView;
4662 using Teuchos::Comm;
4664 using Teuchos::VERB_DEFAULT;
4665 using Teuchos::VERB_NONE;
4666 using Teuchos::VERB_LOW;
4667 using Teuchos::VERB_MEDIUM;
4668 using Teuchos::VERB_HIGH;
4669 using Teuchos::VERB_EXTREME;
4679 for (
size_t dec=10;
dec<getGlobalNumRows();
dec *= 10) {
4682 width = std::max<size_t> (
width,
static_cast<size_t> (11)) + 2;
4683 Teuchos::OSTab
tab (
out);
4692 if (
myImageID == 0)
out << this->description() << std::endl;
4694 if (isFillComplete() &&
myImageID == 0) {
4695 out <<
"Global max number of row entries = " << globalMaxNumRowEntries_ << std::endl;
4700 rowMap_->describe(
out,
vl);
4701 if (colMap_ != Teuchos::null) {
4702 if (
myImageID == 0)
out <<
"\nColumn map: " << std::endl;
4703 colMap_->describe(
out,
vl);
4705 if (domainMap_ != Teuchos::null) {
4706 if (
myImageID == 0)
out <<
"\nDomain map: " << std::endl;
4707 domainMap_->describe(
out,
vl);
4709 if (rangeMap_ != Teuchos::null) {
4710 if (
myImageID == 0)
out <<
"\nRange map: " << std::endl;
4711 rangeMap_->describe(
out,
vl);
4719 <<
"Node number of entries = " << this->getLocalNumEntries () << std::endl
4720 <<
"Node max number of entries = " << nodeMaxNumRowEntries_ << std::endl;
4721 if (! indicesAreAllocated ()) {
4722 out <<
"Indices are not allocated." << std::endl;
4734 out << std::setw(
width) <<
"Node ID"
4735 << std::setw(
width) <<
"Global Row"
4736 << std::setw(
width) <<
"Num Entries";
4751 if (isGloballyIndexed()) {
4752 auto rowview = gblInds_wdv.getHostView(Access::ReadOnly);
4753 for (
size_t j=0;
j <
rowinfo.numEntries; ++
j){
4758 else if (isLocallyIndexed()) {
4759 auto rowview = lclIndsUnpacked_wdv.getHostView(Access::ReadOnly);
4760 for (
size_t j=0;
j <
rowinfo.numEntries; ++
j) {
4762 out << colMap_->getGlobalElement(
collid) <<
" ";
4778 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
4789 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
4794 const size_t numSameIDs,
4806 const bool verbose = verbose_;
4808 std::unique_ptr<std::string>
prefix;
4810 prefix = this->createPrefix(
"CrsGraph",
"copyAndPermute");
4811 std::ostringstream
os;
4813 std::cerr <<
os.str ();
4818 std::runtime_error,
"permuteToLIDs.extent(0) = "
4819 <<
permuteToLIDs.extent (0) <<
" != permuteFromLIDs.extent(0) = "
4828 std::ostringstream
os;
4830 std::cerr <<
os.str ();
4834 applyCrsPadding(*
padding, verbose);
4845 nonconst_global_inds_host_view_type
row_copy;
4853 std::ostringstream
os;
4854 os << *
prefix <<
"src_filled || srcCrsGraph == nullptr" <<
endl;
4855 std::cerr <<
os.str ();
4862 for (
size_t i = 0;
i < numSameIDs; ++
i, ++
myid) {
4872 std::ostringstream
os;
4873 os << *
prefix <<
"! src_filled && srcCrsGraph != nullptr" <<
endl;
4874 std::cerr <<
os.str ();
4876 for (
size_t i = 0;
i < numSameIDs; ++
i, ++
myid) {
4878 global_inds_host_view_type row;
4880 this->insertGlobalIndices (
gid, row.extent(0), row.data());
4904 global_inds_host_view_type row;
4906 this->insertGlobalIndices (
mygid, row.extent(0), row.data());
4911 std::ostringstream
os;
4913 std::cerr <<
os.str ();
4917 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
4926 using LO = local_ordinal_type;
4927 using row_ptrs_type =
4928 typename local_graph_device_type::row_map_type::non_const_type;
4930 Kokkos::RangePolicy<execution_space, Kokkos::IndexType<LO>>;
4932 ProfilingRegion
regionCAP(
"Tpetra::CrsGraph::applyCrsPadding");
4934 std::unique_ptr<std::string>
prefix;
4937 std::ostringstream
os;
4941 std::cerr <<
os.str();
4943 const int myRank = ! verbose ? -1 : [&] () {
4944 auto map = this->getMap();
4945 if (map.is_null()) {
4948 auto comm = map->getComm();
4949 if (comm.is_null()) {
4952 return comm->getRank();
4961 if (! indicesAreAllocated()) {
4963 std::ostringstream os;
4964 os << *prefix <<
"Call allocateIndices" << endl;
4965 std::cerr << os.str();
4967 allocateIndices(GlobalIndices, verbose);
4969 TEUCHOS_ASSERT( indicesAreAllocated() );
4974 auto rowPtrsUnpacked_dev = this->getRowPtrsUnpackedDevice();
4976 std::ostringstream os;
4977 os << *prefix <<
"Allocate row_ptrs_beg: "
4978 << rowPtrsUnpacked_dev.extent(0) << endl;
4979 std::cerr << os.str();
4981 using Kokkos::view_alloc;
4982 using Kokkos::WithoutInitializing;
4983 row_ptrs_type row_ptrs_beg(
4984 view_alloc(
"row_ptrs_beg", WithoutInitializing),
4985 rowPtrsUnpacked_dev.extent(0));
4987 Kokkos::deep_copy(execution_space(),row_ptrs_beg, rowPtrsUnpacked_dev);
4989 const size_t N = row_ptrs_beg.extent(0) == 0 ? size_t(0) :
4990 size_t(row_ptrs_beg.extent(0) - 1);
4992 std::ostringstream os;
4993 os << *prefix <<
"Allocate row_ptrs_end: " << N << endl;
4994 std::cerr << os.str();
4996 row_ptrs_type row_ptrs_end(
4997 view_alloc(
"row_ptrs_end", WithoutInitializing), N);
4998 row_ptrs_type num_row_entries;
5000 const bool refill_num_row_entries = k_numRowEntries_.extent(0) != 0;
5002 execution_space().fence();
5004 if (refill_num_row_entries) {
5008 row_ptrs_type(view_alloc(
"num_row_entries", WithoutInitializing), N);
5009 Kokkos::deep_copy(num_row_entries, this->k_numRowEntries_);
5010 Kokkos::parallel_for
5011 (
"Fill end row pointers", range_policy(0, N),
5012 KOKKOS_LAMBDA (
const size_t i) {
5013 row_ptrs_end(i) = row_ptrs_beg(i) + num_row_entries(i);
5020 Kokkos::parallel_for
5021 (
"Fill end row pointers", range_policy(0, N),
5022 KOKKOS_LAMBDA (
const size_t i) {
5023 row_ptrs_end(i) = row_ptrs_beg(i+1);
5027 if (isGloballyIndexed()) {
5029 padding, myRank, verbose);
5032 padCrsArrays(row_ptrs_beg, row_ptrs_end, lclIndsUnpacked_wdv,
5033 padding, myRank, verbose);
5036 if (refill_num_row_entries) {
5037 Kokkos::parallel_for
5038 (
"Fill num entries", range_policy(0, N),
5039 KOKKOS_LAMBDA (
const size_t i) {
5040 num_row_entries(i) = row_ptrs_end(i) - row_ptrs_beg(i);
5042 Kokkos::deep_copy(this->k_numRowEntries_, num_row_entries);
5045 std::ostringstream os;
5046 os << *prefix <<
"Reassign k_rowPtrs_; old size: "
5047 << rowPtrsUnpacked_dev.extent(0) <<
", new size: "
5048 << row_ptrs_beg.extent(0) << endl;
5049 std::cerr << os.str();
5050 TEUCHOS_ASSERT( rowPtrsUnpacked_dev.extent(0) == row_ptrs_beg.extent(0) );
5053 setRowPtrsUnpacked(row_ptrs_beg);
5056 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
5058 typename CrsGraph<LocalOrdinal, GlobalOrdinal, Node>::padding_type
5060 CrsGraph<LocalOrdinal, GlobalOrdinal, Node>::
5062 const RowGraph<LocalOrdinal,GlobalOrdinal,Node>& source,
5063 const size_t numSameIDs,
5064 const Kokkos::DualView<
const local_ordinal_type*,
5065 buffer_device_type>& permuteToLIDs,
5066 const Kokkos::DualView<
const local_ordinal_type*,
5067 buffer_device_type>& permuteFromLIDs,
5068 const bool verbose)
const
5073 std::unique_ptr<std::string> prefix;
5076 "computeCrsPadding(same & permute)");
5077 std::ostringstream os;
5078 os << *prefix <<
"{numSameIDs: " << numSameIDs
5079 <<
", numPermutes: " << permuteFromLIDs.extent(0) <<
"}"
5081 std::cerr << os.str();
5084 const int myRank = [&] () {
5085 auto comm = rowMap_.is_null() ? Teuchos::null :
5087 return comm.is_null() ? -1 : comm->getRank();
5089 std::unique_ptr<padding_type> padding(
5090 new padding_type(myRank, numSameIDs,
5091 permuteFromLIDs.extent(0)));
5093 computeCrsPaddingForSameIDs(*padding, source,
5094 static_cast<LO
>(numSameIDs));
5095 computeCrsPaddingForPermutedIDs(*padding, source, permuteToLIDs,
5100 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
5102 CrsGraph<LocalOrdinal, GlobalOrdinal, Node>::
5103 computeCrsPaddingForSameIDs(
5104 padding_type& padding,
5105 const RowGraph<local_ordinal_type, global_ordinal_type,
5107 const local_ordinal_type numSameIDs)
const
5110 using GO = global_ordinal_type;
5111 using Details::Impl::getRowGraphGlobalRow;
5113 const char tfecfFuncName[] =
"computeCrsPaddingForSameIds";
5115 std::unique_ptr<std::string> prefix;
5116 const bool verbose = verbose_;
5118 prefix = this->
createPrefix(
"CrsGraph", tfecfFuncName);
5119 std::ostringstream os;
5120 os << *prefix <<
"numSameIDs: " << numSameIDs << endl;
5121 std::cerr << os.str();
5124 if (numSameIDs == 0) {
5128 const map_type& srcRowMap = *(source.getRowMap());
5129 const map_type& tgtRowMap = *rowMap_;
5130 using this_CRS_type = CrsGraph<LocalOrdinal, GlobalOrdinal, Node>;
5131 const this_CRS_type* srcCrs =
dynamic_cast<const this_CRS_type*
>(&source);
5132 const bool src_is_unique =
5133 srcCrs ==
nullptr ? false : srcCrs->isMerged();
5134 const bool tgt_is_unique = this->isMerged();
5136 std::vector<GO> srcGblColIndsScratch;
5137 std::vector<GO> tgtGblColIndsScratch;
5139 execute_sync_host_uvm_access();
5140 for (LO lclRowInd = 0; lclRowInd < numSameIDs; ++lclRowInd) {
5141 const GO srcGblRowInd = srcRowMap.getGlobalElement(lclRowInd);
5142 const GO tgtGblRowInd = tgtRowMap.getGlobalElement(lclRowInd);
5143 auto srcGblColInds = getRowGraphGlobalRow(
5144 srcGblColIndsScratch, source, srcGblRowInd);
5145 auto tgtGblColInds = getRowGraphGlobalRow(
5146 tgtGblColIndsScratch, *
this, tgtGblRowInd);
5147 padding.update_same(lclRowInd, tgtGblColInds.getRawPtr(),
5148 tgtGblColInds.size(), tgt_is_unique,
5149 srcGblColInds.getRawPtr(),
5150 srcGblColInds.size(), src_is_unique);
5153 std::ostringstream os;
5154 os << *prefix <<
"Done" << endl;
5155 std::cerr << os.str();
5159 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
5161 CrsGraph<LocalOrdinal, GlobalOrdinal, Node>::
5162 computeCrsPaddingForPermutedIDs(
5163 padding_type& padding,
5164 const RowGraph<local_ordinal_type, global_ordinal_type,
5166 const Kokkos::DualView<
const local_ordinal_type*,
5167 buffer_device_type>& permuteToLIDs,
5168 const Kokkos::DualView<
const local_ordinal_type*,
5169 buffer_device_type>& permuteFromLIDs)
const
5172 using GO = global_ordinal_type;
5173 using Details::Impl::getRowGraphGlobalRow;
5175 const char tfecfFuncName[] =
"computeCrsPaddingForPermutedIds";
5177 std::unique_ptr<std::string> prefix;
5178 const bool verbose = verbose_;
5180 prefix = this->
createPrefix(
"CrsGraph", tfecfFuncName);
5181 std::ostringstream os;
5182 os << *prefix <<
"permuteToLIDs.extent(0): "
5183 << permuteToLIDs.extent(0)
5184 <<
", permuteFromLIDs.extent(0): "
5185 << permuteFromLIDs.extent(0) << endl;
5186 std::cerr << os.str();
5189 if (permuteToLIDs.extent(0) == 0) {
5193 const map_type& srcRowMap = *(source.getRowMap());
5194 const map_type& tgtRowMap = *rowMap_;
5195 using this_CRS_type = CrsGraph<LocalOrdinal, GlobalOrdinal, Node>;
5196 const this_CRS_type* srcCrs =
dynamic_cast<const this_CRS_type*
>(&source);
5197 const bool src_is_unique =
5198 srcCrs ==
nullptr ? false : srcCrs->isMerged();
5199 const bool tgt_is_unique = this->isMerged();
5201 TEUCHOS_ASSERT( ! permuteToLIDs.need_sync_host() );
5202 auto permuteToLIDs_h = permuteToLIDs.view_host();
5203 TEUCHOS_ASSERT( ! permuteFromLIDs.need_sync_host() );
5204 auto permuteFromLIDs_h = permuteFromLIDs.view_host();
5206 std::vector<GO> srcGblColIndsScratch;
5207 std::vector<GO> tgtGblColIndsScratch;
5208 const LO numPermutes =
static_cast<LO
>(permuteToLIDs_h.extent(0));
5210 execute_sync_host_uvm_access();
5211 for (LO whichPermute = 0; whichPermute < numPermutes; ++whichPermute) {
5212 const LO srcLclRowInd = permuteFromLIDs_h[whichPermute];
5213 const GO srcGblRowInd = srcRowMap.getGlobalElement(srcLclRowInd);
5214 auto srcGblColInds = getRowGraphGlobalRow(
5215 srcGblColIndsScratch, source, srcGblRowInd);
5216 const LO tgtLclRowInd = permuteToLIDs_h[whichPermute];
5217 const GO tgtGblRowInd = tgtRowMap.getGlobalElement(tgtLclRowInd);
5218 auto tgtGblColInds = getRowGraphGlobalRow(
5219 tgtGblColIndsScratch, *
this, tgtGblRowInd);
5220 padding.update_permute(whichPermute, tgtLclRowInd,
5221 tgtGblColInds.getRawPtr(),
5222 tgtGblColInds.size(), tgt_is_unique,
5223 srcGblColInds.getRawPtr(),
5224 srcGblColInds.size(), src_is_unique);
5228 std::ostringstream os;
5229 os << *prefix <<
"Done" << endl;
5230 std::cerr << os.str();
5234 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
5236 typename CrsGraph<LocalOrdinal, GlobalOrdinal, Node>::padding_type
5238 CrsGraph<LocalOrdinal, GlobalOrdinal, Node>::
5239 computeCrsPaddingForImports(
5240 const Kokkos::DualView<
const local_ordinal_type*,
5241 buffer_device_type>& importLIDs,
5242 Kokkos::DualView<packet_type*, buffer_device_type> imports,
5243 Kokkos::DualView<size_t*, buffer_device_type> numPacketsPerLID,
5244 const bool verbose)
const
5246 using Details::Impl::getRowGraphGlobalRow;
5249 using GO = global_ordinal_type;
5250 const char tfecfFuncName[] =
"computeCrsPaddingForImports";
5252 std::unique_ptr<std::string> prefix;
5254 prefix = this->
createPrefix(
"CrsGraph", tfecfFuncName);
5255 std::ostringstream os;
5256 os << *prefix <<
"importLIDs.extent(0): "
5257 << importLIDs.extent(0)
5258 <<
", imports.extent(0): "
5259 << imports.extent(0)
5260 <<
", numPacketsPerLID.extent(0): "
5261 << numPacketsPerLID.extent(0) << endl;
5262 std::cerr << os.str();
5265 const LO numImports =
static_cast<LO
>(importLIDs.extent(0));
5266 const int myRank = [&] () {
5267 auto comm = rowMap_.is_null() ? Teuchos::null :
5269 return comm.is_null() ? -1 : comm->getRank();
5271 std::unique_ptr<padding_type> padding(
5272 new padding_type(myRank, numImports));
5274 if (imports.need_sync_host()) {
5275 imports.sync_host();
5277 auto imports_h = imports.view_host();
5278 if (numPacketsPerLID.need_sync_host ()) {
5279 numPacketsPerLID.sync_host();
5281 auto numPacketsPerLID_h = numPacketsPerLID.view_host();
5283 TEUCHOS_ASSERT( ! importLIDs.need_sync_host() );
5284 auto importLIDs_h = importLIDs.view_host();
5286 const map_type& tgtRowMap = *rowMap_;
5290 constexpr bool src_is_unique =
false;
5291 const bool tgt_is_unique = isMerged();
5293 std::vector<GO> tgtGblColIndsScratch;
5295 execute_sync_host_uvm_access();
5296 for (LO whichImport = 0; whichImport < numImports; ++whichImport) {
5301 const LO origSrcNumEnt =
5302 static_cast<LO
>(numPacketsPerLID_h[whichImport]);
5303 GO*
const srcGblColInds = imports_h.data() + offset;
5305 const LO tgtLclRowInd = importLIDs_h[whichImport];
5306 const GO tgtGblRowInd =
5307 tgtRowMap.getGlobalElement(tgtLclRowInd);
5308 auto tgtGblColInds = getRowGraphGlobalRow(
5309 tgtGblColIndsScratch, *
this, tgtGblRowInd);
5310 const size_t origTgtNumEnt(tgtGblColInds.size());
5312 padding->update_import(whichImport, tgtLclRowInd,
5313 tgtGblColInds.getRawPtr(),
5314 origTgtNumEnt, tgt_is_unique,
5316 origSrcNumEnt, src_is_unique);
5317 offset += origSrcNumEnt;
5321 std::ostringstream os;
5322 os << *prefix <<
"Done" << endl;
5323 std::cerr << os.str();
5328 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
5330 typename CrsGraph<LocalOrdinal, GlobalOrdinal, Node>::padding_type
5332 CrsGraph<LocalOrdinal, GlobalOrdinal, Node>::
5333 computePaddingForCrsMatrixUnpack(
5334 const Kokkos::DualView<
const local_ordinal_type*,
5335 buffer_device_type>& importLIDs,
5336 Kokkos::DualView<char*, buffer_device_type> imports,
5337 Kokkos::DualView<size_t*, buffer_device_type> numPacketsPerLID,
5338 const bool verbose)
const
5340 using Details::Impl::getRowGraphGlobalRow;
5341 using Details::PackTraits;
5344 using GO = global_ordinal_type;
5345 const char tfecfFuncName[] =
"computePaddingForCrsMatrixUnpack";
5347 std::unique_ptr<std::string> prefix;
5349 prefix = this->
createPrefix(
"CrsGraph", tfecfFuncName);
5350 std::ostringstream os;
5351 os << *prefix <<
"importLIDs.extent(0): "
5352 << importLIDs.extent(0)
5353 <<
", imports.extent(0): "
5354 << imports.extent(0)
5355 <<
", numPacketsPerLID.extent(0): "
5356 << numPacketsPerLID.extent(0) << endl;
5357 std::cerr << os.str();
5359 const bool extraVerbose =
5362 const LO numImports =
static_cast<LO
>(importLIDs.extent(0));
5363 TEUCHOS_ASSERT( LO(numPacketsPerLID.extent(0)) >= numImports );
5364 const int myRank = [&] () {
5365 auto comm = rowMap_.is_null() ? Teuchos::null :
5367 return comm.is_null() ? -1 : comm->getRank();
5369 std::unique_ptr<padding_type> padding(
5370 new padding_type(myRank, numImports));
5372 if (imports.need_sync_host()) {
5373 imports.sync_host();
5375 auto imports_h = imports.view_host();
5376 if (numPacketsPerLID.need_sync_host ()) {
5377 numPacketsPerLID.sync_host();
5379 auto numPacketsPerLID_h = numPacketsPerLID.view_host();
5381 TEUCHOS_ASSERT( ! importLIDs.need_sync_host() );
5382 auto importLIDs_h = importLIDs.view_host();
5384 const map_type& tgtRowMap = *rowMap_;
5388 constexpr bool src_is_unique =
false;
5389 const bool tgt_is_unique = isMerged();
5391 std::vector<GO> srcGblColIndsScratch;
5392 std::vector<GO> tgtGblColIndsScratch;
5394 execute_sync_host_uvm_access();
5395 for (LO whichImport = 0; whichImport < numImports; ++whichImport) {
5400 const size_t numBytes = numPacketsPerLID_h[whichImport];
5402 std::ostringstream os;
5403 os << *prefix <<
"whichImport=" << whichImport
5404 <<
", numImports=" << numImports
5405 <<
", numBytes=" << numBytes << endl;
5406 std::cerr << os.str();
5408 if (numBytes == 0) {
5411 LO origSrcNumEnt = 0;
5412 const size_t numEntBeg = offset;
5413 const size_t numEntLen =
5414 PackTraits<LO>::packValueCount(origSrcNumEnt);
5415 TEUCHOS_ASSERT( numBytes >= numEntLen );
5416 TEUCHOS_ASSERT( imports_h.extent(0) >= numEntBeg + numEntLen );
5417 PackTraits<LO>::unpackValue(origSrcNumEnt,
5418 imports_h.data() + numEntBeg);
5420 std::ostringstream os;
5421 os << *prefix <<
"whichImport=" << whichImport
5422 <<
", numImports=" << numImports
5423 <<
", origSrcNumEnt=" << origSrcNumEnt << endl;
5424 std::cerr << os.str();
5426 TEUCHOS_ASSERT( origSrcNumEnt >= LO(0) );
5427 TEUCHOS_ASSERT( numBytes >=
size_t(numEntLen + origSrcNumEnt *
sizeof(GO)) );
5428 const size_t gidsBeg = numEntBeg + numEntLen;
5429 if (srcGblColIndsScratch.size() <
size_t(origSrcNumEnt)) {
5430 srcGblColIndsScratch.resize(origSrcNumEnt);
5432 GO*
const srcGblColInds = srcGblColIndsScratch.data();
5433 PackTraits<GO>::unpackArray(srcGblColInds,
5434 imports_h.data() + gidsBeg,
5436 const LO tgtLclRowInd = importLIDs_h[whichImport];
5437 const GO tgtGblRowInd =
5438 tgtRowMap.getGlobalElement(tgtLclRowInd);
5439 auto tgtGblColInds = getRowGraphGlobalRow(
5440 tgtGblColIndsScratch, *
this, tgtGblRowInd);
5441 const size_t origNumTgtEnt(tgtGblColInds.size());
5444 std::ostringstream os;
5445 os << *prefix <<
"whichImport=" << whichImport
5446 <<
", numImports=" << numImports
5447 <<
": Call padding->update_import" << endl;
5448 std::cerr << os.str();
5450 padding->update_import(whichImport, tgtLclRowInd,
5451 tgtGblColInds.getRawPtr(),
5452 origNumTgtEnt, tgt_is_unique,
5454 origSrcNumEnt, src_is_unique);
5459 std::ostringstream os;
5460 os << *prefix <<
"Done" << endl;
5461 std::cerr << os.str();
5466 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
5468 CrsGraph<LocalOrdinal, GlobalOrdinal, Node>::
5470 (
const SrcDistObject& source,
5471 const Kokkos::DualView<
const local_ordinal_type*,
5472 buffer_device_type>& exportLIDs,
5473 Kokkos::DualView<packet_type*,
5474 buffer_device_type>& exports,
5475 Kokkos::DualView<
size_t*,
5476 buffer_device_type> numPacketsPerLID,
5477 size_t& constantNumPackets)
5480 using GO = global_ordinal_type;
5482 using crs_graph_type =
5483 CrsGraph<local_ordinal_type, global_ordinal_type, node_type>;
5484 const char tfecfFuncName[] =
"packAndPrepare: ";
5485 ProfilingRegion region_papn (
"Tpetra::CrsGraph::packAndPrepare");
5487 const bool verbose = verbose_;
5488 std::unique_ptr<std::string> prefix;
5490 prefix = this->
createPrefix(
"CrsGraph",
"packAndPrepare");
5491 std::ostringstream os;
5492 os << *prefix <<
"Start" << endl;
5493 std::cerr << os.str();
5496 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC
5497 (exportLIDs.extent (0) != numPacketsPerLID.extent (0),
5499 "exportLIDs.extent(0) = " << exportLIDs.extent (0)
5500 <<
" != numPacketsPerLID.extent(0) = " << numPacketsPerLID.extent (0)
5502 const row_graph_type* srcRowGraphPtr =
5503 dynamic_cast<const row_graph_type*
> (&source);
5504 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC
5505 (srcRowGraphPtr ==
nullptr, std::invalid_argument,
"Source of an Export "
5506 "or Import operation to a CrsGraph must be a RowGraph with the same "
5507 "template parameters.");
5511 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC
5512 (this->isFillComplete (), std::runtime_error,
5513 "The target graph of an Import or Export must not be fill complete.");
5515 const crs_graph_type* srcCrsGraphPtr =
5516 dynamic_cast<const crs_graph_type*
> (&source);
5518 if (srcCrsGraphPtr ==
nullptr) {
5519 using Teuchos::ArrayView;
5523 std::ostringstream os;
5524 os << *prefix <<
"Source is a RowGraph but not a CrsGraph"
5526 std::cerr << os.str();
5533 TEUCHOS_ASSERT( ! exportLIDs.need_sync_host () );
5534 auto exportLIDs_h = exportLIDs.view_host ();
5535 ArrayView<const LO> exportLIDs_av (exportLIDs_h.data (),
5536 exportLIDs_h.extent (0));
5537 Teuchos::Array<GO> exports_a;
5539 numPacketsPerLID.clear_sync_state ();
5540 numPacketsPerLID.modify_host ();
5541 auto numPacketsPerLID_h = numPacketsPerLID.view_host ();
5542 ArrayView<size_t> numPacketsPerLID_av (numPacketsPerLID_h.data (),
5543 numPacketsPerLID_h.extent (0));
5544 srcRowGraphPtr->pack (exportLIDs_av, exports_a, numPacketsPerLID_av,
5545 constantNumPackets);
5546 const size_t newSize =
static_cast<size_t> (exports_a.size ());
5547 if (
static_cast<size_t> (exports.extent (0)) != newSize) {
5548 using exports_dv_type = Kokkos::DualView<packet_type*, buffer_device_type>;
5549 exports = exports_dv_type (
"exports", newSize);
5551 Kokkos::View<
const packet_type*, Kokkos::HostSpace,
5552 Kokkos::MemoryUnmanaged> exports_a_h (exports_a.getRawPtr (), newSize);
5553 exports.clear_sync_state ();
5554 exports.modify_host ();
5556 Kokkos::deep_copy (exports.view_host (), exports_a_h);
5559 else if (! getColMap ().is_null () &&
5560 (this->getRowPtrsPackedDevice().extent (0) != 0 ||
5561 getRowMap ()->getLocalNumElements () == 0)) {
5563 std::ostringstream os;
5564 os << *prefix <<
"packCrsGraphNew path" << endl;
5565 std::cerr << os.str();
5567 using export_pids_type =
5568 Kokkos::DualView<const int*, buffer_device_type>;
5569 export_pids_type exportPIDs;
5571 using NT = node_type;
5573 packCrsGraphNew<LO,GO,NT> (*srcCrsGraphPtr, exportLIDs, exportPIDs,
5574 exports, numPacketsPerLID,
5575 constantNumPackets,
false);
5578 srcCrsGraphPtr->packFillActiveNew (exportLIDs, exports, numPacketsPerLID,
5579 constantNumPackets);
5583 std::ostringstream os;
5584 os << *prefix <<
"Done" << endl;
5585 std::cerr << os.str();
5589 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
5593 Teuchos::Array<GlobalOrdinal>& exports,
5597 auto col_map = this->getColMap();
5599 if( !
col_map.is_null() && (
this->getRowPtrsPackedDevice().extent(0) != 0 || getRowMap()->getLocalNumElements() ==0)) {
5610 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
5614 Teuchos::Array<GlobalOrdinal>& exports,
5621 using host_execution_space =
5622 typename Kokkos::View<size_t*, device_type>::
5623 HostMirror::execution_space;
5625 const bool verbose = verbose_;
5628 std::unique_ptr<std::string>
prefix;
5630 prefix = this->createPrefix(
"CrsGraph",
"allocateIndices");
5631 std::ostringstream
os;
5633 std::cerr <<
os.str();
5635 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC
5636 (numExportLIDs != numPacketsPerLID.size (), std::runtime_error,
5637 "exportLIDs.size() = " << numExportLIDs <<
" != numPacketsPerLID.size()"
5638 " = " << numPacketsPerLID.size () <<
".");
5640 const map_type&
rowMap = * (this->getRowMap ());
5641 const map_type*
const colMapPtr = this->colMap_.getRawPtr ();
5642 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC
5643 (this->isLocallyIndexed () && colMapPtr ==
nullptr, std::logic_error,
5644 "This graph claims to be locally indexed, but its column Map is nullptr. "
5645 "This should never happen. Please report this bug to the Tpetra "
5649 constantNumPackets = 0;
5653 size_t*
const numPacketsPerLID_raw = numPacketsPerLID.getRawPtr ();
5654 const LO*
const exportLIDs_raw = exportLIDs.getRawPtr ();
5661 Kokkos::RangePolicy<host_execution_space, LO> inputRange (0, numExportLIDs);
5662 size_t totalNumPackets = 0;
5663 size_t errCount = 0;
5666 typedef Kokkos::Device<host_execution_space, Kokkos::HostSpace>
5668 Kokkos::View<size_t, host_device_type> errCountView (&errCount);
5669 constexpr size_t ONE = 1;
5671 execute_sync_host_uvm_access();
5672 Kokkos::parallel_reduce (
"Tpetra::CrsGraph::pack: totalNumPackets",
5674 [=] (
const LO& i,
size_t& curTotalNumPackets) {
5675 const GO gblRow =
rowMap.getGlobalElement (exportLIDs_raw[i]);
5676 if (gblRow == Tpetra::Details::OrdinalTraits<GO>::invalid ()) {
5677 Kokkos::atomic_add (&errCountView(), ONE);
5678 numPacketsPerLID_raw[i] = 0;
5681 const size_t numEnt = this->getNumEntriesInGlobalRow (gblRow);
5682 numPacketsPerLID_raw[i] = numEnt;
5683 curTotalNumPackets += numEnt;
5689 std::ostringstream os;
5690 os << *prefix <<
"totalNumPackets=" << totalNumPackets << endl;
5691 std::cerr << os.str();
5693 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC
5694 (errCount != 0, std::logic_error,
"totalNumPackets count encountered "
5695 "one or more errors! errCount = " << errCount
5696 <<
", totalNumPackets = " << totalNumPackets <<
".");
5700 exports.resize (totalNumPackets);
5702 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC
5703 (! this->supportsRowViews (), std::logic_error,
5704 "this->supportsRowViews() returns false; this should never happen. "
5705 "Please report this bug to the Tpetra developers.");
5711 std::ostringstream os;
5712 os << *prefix <<
"Pack into exports" << endl;
5713 std::cerr << os.str();
5718 GO*
const exports_raw = exports.getRawPtr ();
5720 Kokkos::parallel_scan (
"Tpetra::CrsGraph::pack: pack from views",
5721 inputRange, [=, &prefix]
5722 (
const LO i,
size_t& exportsOffset,
const bool final) {
5723 const size_t curOffset = exportsOffset;
5724 const GO gblRow =
rowMap.getGlobalElement (exportLIDs_raw[i]);
5725 const RowInfo rowInfo =
5726 this->getRowInfoFromGlobalRowIndex (gblRow);
5728 using TDO = Tpetra::Details::OrdinalTraits<size_t>;
5729 if (rowInfo.localRow == TDO::invalid ()) {
5731 std::ostringstream os;
5732 os << *prefix <<
": INVALID rowInfo: i=" << i
5733 <<
", lclRow=" << exportLIDs_raw[i] << endl;
5734 std::cerr << os.str();
5736 Kokkos::atomic_add (&errCountView(), ONE);
5738 else if (curOffset + rowInfo.numEntries > totalNumPackets) {
5740 std::ostringstream os;
5741 os << *prefix <<
": UH OH! For i=" << i <<
", lclRow="
5742 << exportLIDs_raw[i] <<
", gblRow=" << gblRow <<
", curOffset "
5743 "(= " << curOffset <<
") + numEnt (= " << rowInfo.numEntries
5744 <<
") > totalNumPackets (= " << totalNumPackets <<
")."
5746 std::cerr << os.str();
5748 Kokkos::atomic_add (&errCountView(), ONE);
5751 const LO numEnt =
static_cast<LO
> (rowInfo.numEntries);
5752 if (this->isLocallyIndexed ()) {
5753 auto lclColInds = getLocalIndsViewHost (rowInfo);
5755 for (LO k = 0; k < numEnt; ++k) {
5756 const LO lclColInd = lclColInds(k);
5757 const GO gblColInd = colMapPtr->getGlobalElement (lclColInd);
5761 exports_raw[curOffset + k] = gblColInd;
5764 exportsOffset = curOffset + numEnt;
5766 else if (this->isGloballyIndexed ()) {
5767 auto gblColInds = getGlobalIndsViewHost (rowInfo);
5769 for (LO k = 0; k < numEnt; ++k) {
5770 const GO gblColInd = gblColInds(k);
5774 exports_raw[curOffset + k] = gblColInd;
5777 exportsOffset = curOffset + numEnt;
5785 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC
5786 (errCount != 0, std::logic_error,
"Packing encountered "
5787 "one or more errors! errCount = " << errCount
5788 <<
", totalNumPackets = " << totalNumPackets <<
".");
5791 std::ostringstream os;
5792 os << *prefix <<
"Done" << endl;
5793 std::cerr << os.str();
5797 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
5799 CrsGraph<LocalOrdinal, GlobalOrdinal, Node>::
5800 packFillActiveNew (
const Kokkos::DualView<
const local_ordinal_type*,
5801 buffer_device_type>& exportLIDs,
5802 Kokkos::DualView<packet_type*,
5803 buffer_device_type>& exports,
5804 Kokkos::DualView<
size_t*,
5805 buffer_device_type> numPacketsPerLID,
5806 size_t& constantNumPackets)
const
5810 using GO = global_ordinal_type;
5811 using host_execution_space =
typename Kokkos::View<
size_t*,
5812 device_type>::HostMirror::execution_space;
5813 using host_device_type =
5814 Kokkos::Device<host_execution_space, Kokkos::HostSpace>;
5815 using exports_dv_type =
5816 Kokkos::DualView<packet_type*, buffer_device_type>;
5817 const char tfecfFuncName[] =
"packFillActiveNew: ";
5818 const bool verbose = verbose_;
5820 const auto numExportLIDs = exportLIDs.extent (0);
5821 std::unique_ptr<std::string> prefix;
5823 prefix = this->
createPrefix(
"CrsGraph",
"packFillActiveNew");
5824 std::ostringstream os;
5825 os << *prefix <<
"numExportLIDs: " << numExportLIDs
5826 <<
", numPacketsPerLID.extent(0): "
5827 << numPacketsPerLID.extent(0) << endl;
5828 std::cerr << os.str();
5830 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC
5831 (numExportLIDs != numPacketsPerLID.extent (0), std::runtime_error,
5832 "exportLIDs.extent(0) = " << numExportLIDs
5833 <<
" != numPacketsPerLID.extent(0) = "
5834 << numPacketsPerLID.extent (0) <<
".");
5835 TEUCHOS_ASSERT( ! exportLIDs.need_sync_host () );
5836 auto exportLIDs_h = exportLIDs.view_host ();
5838 const map_type&
rowMap = * (this->getRowMap ());
5839 const map_type*
const colMapPtr = this->colMap_.getRawPtr ();
5840 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC
5841 (this->isLocallyIndexed () && colMapPtr ==
nullptr, std::logic_error,
5842 "This graph claims to be locally indexed, but its column Map is nullptr. "
5843 "This should never happen. Please report this bug to the Tpetra "
5847 constantNumPackets = 0;
5849 numPacketsPerLID.clear_sync_state ();
5850 numPacketsPerLID.modify_host ();
5851 auto numPacketsPerLID_h = numPacketsPerLID.view_host ();
5858 using range_type = Kokkos::RangePolicy<host_execution_space, LO>;
5859 range_type inputRange (0, numExportLIDs);
5860 size_t totalNumPackets = 0;
5861 size_t errCount = 0;
5864 Kokkos::View<size_t, host_device_type> errCountView (&errCount);
5865 constexpr size_t ONE = 1;
5868 std::ostringstream os;
5869 os << *prefix <<
"Compute totalNumPackets" << endl;
5870 std::cerr << os.str ();
5873 execute_sync_host_uvm_access();
5874 totalNumPackets = 0;
5875 for (
size_t i=0; i<numExportLIDs; ++i) {
5876 const LO lclRow = exportLIDs_h[i];
5877 const GO gblRow =
rowMap.getGlobalElement (lclRow);
5878 if (gblRow == Tpetra::Details::OrdinalTraits<GO>::invalid ()) {
5880 std::ostringstream os;
5881 os << *prefix <<
"For i=" << i <<
", lclRow=" << lclRow
5882 <<
" not in row Map on this process" << endl;
5883 std::cerr << os.str();
5885 Kokkos::atomic_add (&errCountView(), ONE);
5886 numPacketsPerLID_h(i) = 0;
5889 const size_t numEnt = this->getNumEntriesInGlobalRow (gblRow);
5890 numPacketsPerLID_h(i) = numEnt;
5891 totalNumPackets += numEnt;
5896 std::ostringstream os;
5897 os << *prefix <<
"totalNumPackets: " << totalNumPackets
5898 <<
", errCount: " << errCount << endl;
5899 std::cerr << os.str ();
5901 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC
5902 (errCount != 0, std::logic_error,
"totalNumPackets count encountered "
5903 "one or more errors! totalNumPackets: " << totalNumPackets
5904 <<
", errCount: " << errCount <<
".");
5907 if (
size_t(exports.extent (0)) < totalNumPackets) {
5909 exports = exports_dv_type (
"exports", totalNumPackets);
5912 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC
5913 (! this->supportsRowViews (), std::logic_error,
5914 "this->supportsRowViews() returns false; this should never happen. "
5915 "Please report this bug to the Tpetra developers.");
5921 std::ostringstream os;
5922 os << *prefix <<
"Pack into exports buffer" << endl;
5923 std::cerr << os.str();
5926 exports.clear_sync_state ();
5927 exports.modify_host ();
5928 auto exports_h = exports.view_host ();
5934 if(isLocallyIndexed())
5935 lclIndsUnpacked_wdv.getHostView(Access::ReadOnly);
5936 else if(isGloballyIndexed())
5937 gblInds_wdv.getHostView(Access::ReadOnly);
5940 Kokkos::parallel_scan
5941 (
"Tpetra::CrsGraph::packFillActiveNew: Pack exports",
5942 inputRange, [=, &prefix]
5943 (
const LO i,
size_t& exportsOffset,
const bool final) {
5944 const size_t curOffset = exportsOffset;
5945 const LO lclRow = exportLIDs_h(i);
5946 const GO gblRow =
rowMap.getGlobalElement (lclRow);
5947 if (gblRow == Details::OrdinalTraits<GO>::invalid ()) {
5949 std::ostringstream os;
5950 os << *prefix <<
"For i=" << i <<
", lclRow=" << lclRow
5951 <<
" not in row Map on this process" << endl;
5952 std::cerr << os.str();
5954 Kokkos::atomic_add (&errCountView(), ONE);
5958 const RowInfo rowInfo = this->getRowInfoFromGlobalRowIndex (gblRow);
5959 if (rowInfo.localRow == Details::OrdinalTraits<size_t>::invalid ()) {
5961 std::ostringstream os;
5962 os << *prefix <<
"For i=" << i <<
", lclRow=" << lclRow
5963 <<
", gblRow=" << gblRow <<
": invalid rowInfo"
5965 std::cerr << os.str();
5967 Kokkos::atomic_add (&errCountView(), ONE);
5971 if (curOffset + rowInfo.numEntries > totalNumPackets) {
5973 std::ostringstream os;
5974 os << *prefix <<
"For i=" << i <<
", lclRow=" << lclRow
5975 <<
", gblRow=" << gblRow <<
", curOffset (= "
5976 << curOffset <<
") + numEnt (= " << rowInfo.numEntries
5977 <<
") > totalNumPackets (= " << totalNumPackets
5979 std::cerr << os.str();
5981 Kokkos::atomic_add (&errCountView(), ONE);
5985 const LO numEnt =
static_cast<LO
> (rowInfo.numEntries);
5986 if (this->isLocallyIndexed ()) {
5987 auto lclColInds = getLocalIndsViewHost(rowInfo);
5989 for (LO k = 0; k < numEnt; ++k) {
5990 const LO lclColInd = lclColInds(k);
5991 const GO gblColInd = colMapPtr->getGlobalElement (lclColInd);
5995 exports_h(curOffset + k) = gblColInd;
5998 exportsOffset = curOffset + numEnt;
6000 else if (this->isGloballyIndexed ()) {
6001 auto gblColInds = getGlobalIndsViewHost(rowInfo);
6003 for (LO k = 0; k < numEnt; ++k) {
6004 const GO gblColInd = gblColInds(k);
6008 exports_h(curOffset + k) = gblColInd;
6011 exportsOffset = curOffset + numEnt;
6025 std::ostringstream os;
6026 os << *prefix <<
"errCount=" << errCount <<
"; Done" << endl;
6027 std::cerr << os.str();
6031 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
6039 Kokkos::DualView<
size_t*,
6050 ProfilingRegion
regionCGC(
"Tpetra::CrsGraph::unpackAndCombine");
6051 const bool verbose = verbose_;
6053 std::unique_ptr<std::string>
prefix;
6056 std::ostringstream
os;
6058 std::cerr <<
os.str ();
6061 auto padding = computeCrsPaddingForImports(
6063 applyCrsPadding(*
padding, verbose);
6065 std::ostringstream
os;
6066 os << *
prefix <<
"Done computing & applying padding" <<
endl;
6067 std::cerr <<
os.str ();
6090 std::runtime_error,
": importLIDs.extent(0) = "
6091 <<
importLIDs.extent (0) <<
" != numPacketsPerLID.extent(0) = "
6094 (isFillComplete (), std::runtime_error,
6095 ": Import or Export operations are not allowed on a target "
6096 "CrsGraph that is fillComplete.");
6103 if (imports.need_sync_host()) {
6104 imports.sync_host();
6112 if (isLocallyIndexed()) {
6114 std::ostringstream
os;
6115 os << *
prefix <<
"Preallocate local indices scratch" <<
endl;
6116 std::cerr <<
os.str();
6123 std::ostringstream
os;
6124 os << *
prefix <<
"Local indices scratch size: "
6126 std::cerr <<
os.str();
6132 std::ostringstream
os;
6134 if (isGloballyIndexed()) {
6135 os <<
"Graph is globally indexed";
6138 os <<
"Graph is neither locally nor globally indexed";
6141 std::cerr <<
os.str();
6152 std::ostringstream
os;
6153 os << *
prefix <<
"i=" <<
i <<
", numImportLIDs="
6155 std::cerr <<
os.str();
6162 (
gblRow == Teuchos::OrdinalTraits<GO>::invalid(),
6163 std::logic_error,
"importLIDs[i=" <<
i <<
"]="
6164 <<
lclRow <<
" is not in the row Map on the calling "
6169 if (! isLocallyIndexed()) {
6183 catch (std::exception&
e) {
6185 (
true, std::runtime_error,
6186 "Tpetra::CrsGraph::unpackAndCombine: Insert loop threw an "
6187 "exception: " <<
endl <<
e.what());
6191 std::ostringstream
os;
6193 std::cerr <<
os.str();
6197 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
6202 using Teuchos::Comm;
6203 using Teuchos::null;
6204 using Teuchos::ParameterList;
6218 if (! domainMap_.is_null ()) {
6219 if (domainMap_.getRawPtr () == rowMap_.getRawPtr ()) {
6229 if (! rangeMap_.is_null ()) {
6230 if (rangeMap_.getRawPtr () == rowMap_.getRawPtr ()) {
6240 if (! colMap_.is_null ()) {
6254 if (! rangeMap_.is_null () &&
6257 if (
params.is_null () || !
params->isSublist (
"Export")) {
6266 if (! domainMap_.is_null () &&
6269 if (
params.is_null () || !
params->isSublist (
"Import")) {
6295 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
6298 getLocalDiagOffsets (
const Kokkos::View<size_t*, device_type, Kokkos::MemoryUnmanaged>& offsets)
const
6304 const bool verbose = verbose_;
6306 std::unique_ptr<std::string>
prefix;
6308 prefix = this->createPrefix(
"CrsGraph",
"getLocalDiagOffsets");
6309 std::ostringstream
os;
6310 os << *
prefix <<
"offsets.extent(0)=" << offsets.extent(0)
6312 std::cerr <<
os.str();
6316 (! hasColMap (), std::runtime_error,
"The graph must have a column Map.");
6317 const LO
lclNumRows =
static_cast<LO
> (this->getLocalNumRows ());
6319 (
static_cast<LO
> (offsets.extent (0)) <
lclNumRows,
6320 std::invalid_argument,
"offsets.extent(0) = " <<
6321 offsets.extent (0) <<
" < getLocalNumRows() = " <<
lclNumRows <<
".");
6346 const bool sorted = this->isSorted ();
6347 if (isFillComplete ()) {
6348 auto lclGraph = this->getLocalGraphDevice ();
6357 auto offsets_h = Kokkos::create_mirror_view (offsets);
6367 if (
lclColInd == Tpetra::Details::OrdinalTraits<LO>::invalid ()) {
6377 const size_t hint = 0;
6388 typename local_inds_dualv_type::t_host::const_type
lclColInds;
6425 std::ostringstream
os;
6426 os << *
prefix <<
"Wrong offsets: [";
6435 std::cerr <<
os.str();
6439 using Teuchos::reduceAll;
6441 Teuchos::RCP<const Teuchos::Comm<int> > comm = this->getComm ();
6465 std::ostringstream
os;
6466 os <<
"Issue(s) that we noticed (on Process " <<
gblResults[4] <<
", "
6467 "possibly among others): " <<
endl;
6469 os <<
" - The column Map does not contain at least one diagonal entry "
6470 "of the graph." <<
endl;
6473 os <<
" - On one or more processes, some row does not contain a "
6474 "diagonal entry." <<
endl;
6477 os <<
" - On one or more processes, some offsets are incorrect."
6481 os <<
" - One or more processes had some other error."
6489 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
6496 const bool verbose = verbose_;
6498 std::unique_ptr<std::string>
prefix;
6500 prefix = this->createPrefix(
"CrsGraph",
"getLocalOffRankOffsets");
6501 std::ostringstream
os;
6502 os << *
prefix <<
"offsets.extent(0)=" << offsets.extent(0)
6504 std::cerr <<
os.str();
6508 (! hasColMap (), std::runtime_error,
"The graph must have a column Map.");
6511 const size_t lclNumRows = this->getLocalNumRows ();
6513 if (haveLocalOffRankOffsets_ && k_offRankOffsets_.extent(0) ==
lclNumRows+1) {
6514 offsets = k_offRankOffsets_;
6517 haveLocalOffRankOffsets_ =
false;
6532 if (isFillComplete ()) {
6533 k_offRankOffsets_ = offset_device_view_type(Kokkos::ViewAllocateWithoutInitializing(
"offRankOffset"),
lclNumRows+1);
6534 auto lclGraph = this->getLocalGraphDevice ();
6535 ::Tpetra::Details::getGraphOffRankOffsets (k_offRankOffsets_,
6538 offsets = k_offRankOffsets_;
6539 haveLocalOffRankOffsets_ =
true;
6542 (
true, std::logic_error,
"Can't get off-rank offsets for non-fill-complete graph");
6564 template<
class DeviceType,
6566 std::is_same<
typename DeviceType::memory_space,
6567 Kokkos::HostSpace>::value>
6568 struct HelpGetLocalDiagOffsets {};
6570 template<
class DeviceType>
6571 struct HelpGetLocalDiagOffsets<DeviceType, true> {
6572 typedef DeviceType device_type;
6573 typedef Kokkos::View<
size_t*, Kokkos::HostSpace,
6574 Kokkos::MemoryUnmanaged> device_offsets_type;
6575 typedef Kokkos::View<
size_t*, Kokkos::HostSpace,
6576 Kokkos::MemoryUnmanaged> host_offsets_type;
6578 static device_offsets_type
6579 getDeviceOffsets (
const host_offsets_type& hostOffsets)
6587 copyBackIfNeeded (
const host_offsets_type& ,
6588 const device_offsets_type& )
6592 template<
class DeviceType>
6593 struct HelpGetLocalDiagOffsets<DeviceType, false> {
6594 typedef DeviceType device_type;
6598 typedef Kokkos::View<size_t*, device_type> device_offsets_type;
6599 typedef Kokkos::View<
size_t*, Kokkos::HostSpace,
6600 Kokkos::MemoryUnmanaged> host_offsets_type;
6602 static device_offsets_type
6603 getDeviceOffsets (
const host_offsets_type& hostOffsets)
6607 return device_offsets_type (
"offsets", hostOffsets.extent (0));
6611 copyBackIfNeeded (
const host_offsets_type& hostOffsets,
6612 const device_offsets_type& deviceOffsets)
6615 Kokkos::deep_copy (hostOffsets, deviceOffsets);
6621 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
6629 (! this->hasColMap (), std::runtime_error,
6630 "The graph does not yet have a column Map.");
6631 const LO
myNumRows =
static_cast<LO
> (this->getLocalNumRows ());
6632 if (
static_cast<LO
> (offsets.size ()) !=
myNumRows) {
6649 typedef typename helper_type::host_offsets_type host_offsets_type;
6659 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
6666 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
6670 const ::Tpetra::Details::Transfer<LocalOrdinal, GlobalOrdinal, Node>&
rowTransfer,
6671 const Teuchos::RCP<const ::Tpetra::Details::Transfer<LocalOrdinal, GlobalOrdinal, Node> > &
domainTransfer,
6672 const Teuchos::RCP<const map_type>& domainMap,
6673 const Teuchos::RCP<const map_type>&
rangeMap,
6674 const Teuchos::RCP<Teuchos::ParameterList>&
params)
const
6680 using Teuchos::ArrayRCP;
6681 using Teuchos::ArrayView;
6682 using Teuchos::Comm;
6683 using Teuchos::ParameterList;
6686#ifdef HAVE_TPETRA_MMM_TIMINGS
6688 using Teuchos::TimeMonitor;
6693 using NT = node_type;
6697 const char*
prefix =
"Tpetra::CrsGraph::transferAndFillComplete: ";
6699#ifdef HAVE_TPETRA_MMM_TIMINGS
6701 if(!
params.is_null()) label =
params->get(
"Timer Label", label);
6702 string prefix2 =
string(
"Tpetra ")+ label + std::string(
": CrsGraph TAFC ");
6716 prefix <<
"The 'rowTransfer' input argument must be either an Import or "
6717 "an Export, and its template parameters must match the corresponding "
6718 "template parameters of the CrsGraph.");
6734 prefix <<
"The 'domainTransfer' input argument must be either an "
6735 "Import or an Export, and its template parameters must match the "
6736 "corresponding template parameters of the CrsGraph.");
6742 prefix <<
"The 'rowTransfer' and 'domainTransfer' input arguments "
6743 "must be of the same type (either Import or Export).");
6749 prefix <<
"The 'rowTransfer' and 'domainTransfer' input arguments "
6750 "must be of the same type (either Import or Export).");
6757 const bool communication_needed = rowTransfer.getSourceMap()->isDistributed();
6763 bool reverseMode =
false;
6764 bool restrictComm =
false;
6765 RCP<ParameterList> graphparams;
6766 if (! params.is_null()) {
6767 reverseMode = params->get(
"Reverse Mode", reverseMode);
6768 restrictComm = params->get(
"Restrict Communicator", restrictComm);
6769 graphparams = sublist(params,
"CrsGraph");
6774 RCP<const map_type> MyRowMap = reverseMode ?
6775 rowTransfer.getSourceMap() : rowTransfer.getTargetMap();
6776 RCP<const map_type> MyColMap;
6777 RCP<const map_type> MyDomainMap = !
domainMap.is_null() ?
domainMap : getDomainMap();
6778 RCP<const map_type> MyRangeMap = ! rangeMap.is_null() ? rangeMap : getRangeMap();
6779 RCP<const map_type> BaseRowMap = MyRowMap;
6780 RCP<const map_type> BaseDomainMap = MyDomainMap;
6788 if (! destGraph.is_null()) {
6799 const bool NewFlag =
6800 ! destGraph->isLocallyIndexed() && ! destGraph->isGloballyIndexed();
6801 TEUCHOS_TEST_FOR_EXCEPTION(! NewFlag, std::invalid_argument,
6802 prefix <<
"The input argument 'destGraph' is only allowed to be nonnull, "
6803 "if its graph is empty (neither locally nor globally indexed).");
6812 TEUCHOS_TEST_FOR_EXCEPTION(
6813 ! destGraph->getRowMap()->isSameAs(*MyRowMap), std::invalid_argument,
6814 prefix <<
"The (row) Map of the input argument 'destGraph' is not the "
6815 "same as the (row) Map specified by the input argument 'rowTransfer'.");
6817 TEUCHOS_TEST_FOR_EXCEPTION(
6818 ! destGraph->checkSizes(*
this), std::invalid_argument,
6819 prefix <<
"You provided a nonnull destination graph, but checkSizes() "
6820 "indicates that it is not a legal legal target for redistribution from "
6821 "the source graph (*this). This may mean that they do not have the "
6822 "same dimensions.");
6836 TEUCHOS_TEST_FOR_EXCEPTION(
6837 ! (reverseMode || getRowMap()->isSameAs(*rowTransfer.getSourceMap())),
6838 std::invalid_argument, prefix <<
6839 "rowTransfer->getSourceMap() must match this->getRowMap() in forward mode.");
6841 TEUCHOS_TEST_FOR_EXCEPTION(
6842 ! (! reverseMode || getRowMap()->isSameAs(*rowTransfer.getTargetMap())),
6843 std::invalid_argument, prefix <<
6844 "rowTransfer->getTargetMap() must match this->getRowMap() in reverse mode.");
6847 TEUCHOS_TEST_FOR_EXCEPTION(
6848 ! xferDomainAsImport.is_null() && ! xferDomainAsImport->getTargetMap()->isSameAs(*
domainMap),
6849 std::invalid_argument,
6850 prefix <<
"The target map of the 'domainTransfer' input argument must be "
6851 "the same as the rebalanced domain map 'domainMap'");
6853 TEUCHOS_TEST_FOR_EXCEPTION(
6854 ! xferDomainAsExport.is_null() && ! xferDomainAsExport->getSourceMap()->isSameAs(*
domainMap),
6855 std::invalid_argument,
6856 prefix <<
"The source map of the 'domainTransfer' input argument must be "
6857 "the same as the rebalanced domain map 'domainMap'");
6870 const size_t NumSameIDs = rowTransfer.getNumSameIDs();
6871 ArrayView<const LO> ExportLIDs = reverseMode ?
6872 rowTransfer.getRemoteLIDs() : rowTransfer.getExportLIDs();
6873 ArrayView<const LO> RemoteLIDs = reverseMode ?
6874 rowTransfer.getExportLIDs() : rowTransfer.getRemoteLIDs();
6875 ArrayView<const LO> PermuteToLIDs = reverseMode ?
6876 rowTransfer.getPermuteFromLIDs() : rowTransfer.getPermuteToLIDs();
6877 ArrayView<const LO> PermuteFromLIDs = reverseMode ?
6878 rowTransfer.getPermuteToLIDs() : rowTransfer.getPermuteFromLIDs();
6879 Distributor& Distor = rowTransfer.getDistributor();
6882 Teuchos::Array<int> SourcePids;
6883 Teuchos::Array<int> TargetPids;
6884 int MyPID = getComm()->getRank();
6887 RCP<const map_type> ReducedRowMap, ReducedColMap,
6888 ReducedDomainMap, ReducedRangeMap;
6889 RCP<const Comm<int> > ReducedComm;
6893 if (destGraph.is_null()) {
6894 destGraph = rcp(
new this_CRS_type(MyRowMap, 0, graphparams));
6901 ReducedRowMap = MyRowMap->removeEmptyProcesses();
6902 ReducedComm = ReducedRowMap.is_null() ?
6904 ReducedRowMap->getComm();
6905 destGraph->removeEmptyProcessesInPlace(ReducedRowMap);
6907 ReducedDomainMap = MyRowMap.getRawPtr() == MyDomainMap.getRawPtr() ?
6909 MyDomainMap->replaceCommWithSubset(ReducedComm);
6910 ReducedRangeMap = MyRowMap.getRawPtr() == MyRangeMap.getRawPtr() ?
6912 MyRangeMap->replaceCommWithSubset(ReducedComm);
6915 MyRowMap = ReducedRowMap;
6916 MyDomainMap = ReducedDomainMap;
6917 MyRangeMap = ReducedRangeMap;
6920 if (! ReducedComm.is_null()) {
6921 MyPID = ReducedComm->getRank();
6928 ReducedComm = MyRowMap->getComm();
6934#ifdef HAVE_TPETRA_MMM_TIMINGS
6936 MM = rcp(
new TimeMonitor(*TimeMonitor::getNewTimer(prefix2+
string(
"ImportSetup"))));
6939 RCP<const import_type> MyImporter = getImporter();
6942 bool bSameDomainMap = BaseDomainMap->isSameAs(*getDomainMap());
6944 if (! restrictComm && ! MyImporter.is_null() && bSameDomainMap ) {
6951 Import_Util::getPids(*MyImporter, SourcePids,
false);
6953 else if (restrictComm && ! MyImporter.is_null() && bSameDomainMap) {
6956 ivector_type SourceDomain_pids(getDomainMap(),
true);
6957 ivector_type SourceCol_pids(getColMap());
6959 SourceDomain_pids.putScalar(MyPID);
6961 SourceCol_pids.doImport(SourceDomain_pids, *MyImporter,
INSERT);
6962 SourcePids.resize(getColMap()->getLocalNumElements());
6963 SourceCol_pids.get1dCopy(SourcePids());
6965 else if (MyImporter.is_null() && bSameDomainMap) {
6967 SourcePids.resize(getColMap()->getLocalNumElements());
6968 SourcePids.assign(getColMap()->getLocalNumElements(), MyPID);
6970 else if ( ! MyImporter.is_null() &&
6971 ! domainTransfer.is_null() ) {
6978 ivector_type TargetDomain_pids(
domainMap);
6979 TargetDomain_pids.putScalar(MyPID);
6982 ivector_type SourceDomain_pids(getDomainMap());
6985 ivector_type SourceCol_pids(getColMap());
6987 if (! reverseMode && ! xferDomainAsImport.is_null() ) {
6988 SourceDomain_pids.doExport(TargetDomain_pids, *xferDomainAsImport,
INSERT);
6990 else if (reverseMode && ! xferDomainAsExport.is_null() ) {
6991 SourceDomain_pids.doExport(TargetDomain_pids, *xferDomainAsExport,
INSERT);
6993 else if (! reverseMode && ! xferDomainAsExport.is_null() ) {
6994 SourceDomain_pids.doImport(TargetDomain_pids, *xferDomainAsExport,
INSERT);
6996 else if (reverseMode && ! xferDomainAsImport.is_null() ) {
6997 SourceDomain_pids.doImport(TargetDomain_pids, *xferDomainAsImport,
INSERT);
7000 TEUCHOS_TEST_FOR_EXCEPTION(
7001 true, std::logic_error,
7002 prefix <<
"Should never get here! Please report this bug to a Tpetra developer.");
7004 SourceCol_pids.doImport(SourceDomain_pids, *MyImporter,
INSERT);
7005 SourcePids.resize(getColMap()->getLocalNumElements());
7006 SourceCol_pids.get1dCopy(SourcePids());
7008 else if (BaseDomainMap->isSameAs(*BaseRowMap) &&
7009 getDomainMap()->isSameAs(*getRowMap())) {
7012 ivector_type SourceRow_pids(getRowMap());
7013 ivector_type SourceCol_pids(getColMap());
7015 TargetRow_pids.putScalar(MyPID);
7016 if (! reverseMode && xferAsImport !=
nullptr) {
7017 SourceRow_pids.doExport(TargetRow_pids, *xferAsImport,
INSERT);
7019 else if (reverseMode && xferAsExport !=
nullptr) {
7020 SourceRow_pids.doExport(TargetRow_pids, *xferAsExport,
INSERT);
7022 else if (! reverseMode && xferAsExport !=
nullptr) {
7023 SourceRow_pids.doImport(TargetRow_pids, *xferAsExport,
INSERT);
7025 else if (reverseMode && xferAsImport !=
nullptr) {
7026 SourceRow_pids.doImport(TargetRow_pids, *xferAsImport,
INSERT);
7029 TEUCHOS_TEST_FOR_EXCEPTION(
7030 true, std::logic_error,
7031 prefix <<
"Should never get here! Please report this bug to a Tpetra developer.");
7033 SourceCol_pids.doImport(SourceRow_pids, *MyImporter,
INSERT);
7034 SourcePids.resize(getColMap()->getLocalNumElements());
7035 SourceCol_pids.get1dCopy(SourcePids());
7038 TEUCHOS_TEST_FOR_EXCEPTION(
7039 true, std::invalid_argument,
7040 prefix <<
"This method only allows either domainMap == getDomainMap(), "
7041 "or (domainMap == rowTransfer.getTargetMap() and getDomainMap() == getRowMap()).");
7045 size_t constantNumPackets = destGraph->constantNumberOfPackets();
7046 if (constantNumPackets == 0) {
7047 destGraph->reallocArraysForNumPacketsPerLid(ExportLIDs.size(),
7055 const size_t rbufLen = RemoteLIDs.size() * constantNumPackets;
7056 destGraph->reallocImportsIfNeeded(rbufLen,
false,
nullptr);
7061 destGraph->numExportPacketsPerLID_.modify_host();
7062 Teuchos::ArrayView<size_t> numExportPacketsPerLID =
7067 numExportPacketsPerLID, ExportLIDs,
7068 SourcePids, constantNumPackets);
7072#ifdef HAVE_TPETRA_MMM_TIMINGS
7074 MM = rcp(
new TimeMonitor(*TimeMonitor::getNewTimer(prefix2+
string(
"Transfer"))));
7077 if (communication_needed) {
7079 if (constantNumPackets == 0) {
7083 destGraph->numExportPacketsPerLID_.sync_host();
7084 Teuchos::ArrayView<const size_t> numExportPacketsPerLID =
7086 destGraph->numImportPacketsPerLID_.sync_host();
7087 Teuchos::ArrayView<size_t> numImportPacketsPerLID =
7090 Distor.doReversePostsAndWaits(destGraph->numExportPacketsPerLID_.view_host(), 1,
7091 destGraph->numImportPacketsPerLID_.view_host());
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 Distor.doReversePostsAndWaits(hostExports,
7107 numExportPacketsPerLID,
7109 numImportPacketsPerLID);
7112 destGraph->imports_.modify_host();
7113 auto hostImports = destGraph->imports_.view_host();
7116 destGraph->exports_.sync_host();
7117 auto hostExports = destGraph->exports_.view_host();
7118 Distor.doReversePostsAndWaits(hostExports,
7124 if (constantNumPackets == 0) {
7128 destGraph->numExportPacketsPerLID_.sync_host();
7129 destGraph->numImportPacketsPerLID_.sync_host();
7130 Distor.doPostsAndWaits(destGraph->numExportPacketsPerLID_.view_host(), 1,
7131 destGraph->numImportPacketsPerLID_.view_host());
7133 Teuchos::ArrayView<const size_t> numImportPacketsPerLID =
7135 size_t totalImportPackets = 0;
7137 totalImportPackets += numImportPacketsPerLID[i];
7142 destGraph->reallocImportsIfNeeded(totalImportPackets,
false,
nullptr);
7143 destGraph->imports_.modify_host();
7144 auto hostImports = destGraph->imports_.view_host();
7147 destGraph->exports_.sync_host();
7148 auto hostExports = destGraph->exports_.view_host();
7149 Teuchos::ArrayView<const size_t> numExportPacketsPerLID =
7151 Distor.doPostsAndWaits(hostExports, numExportPacketsPerLID, hostImports, numImportPacketsPerLID);
7154 destGraph->imports_.modify_host();
7155 auto hostImports = destGraph->imports_.view_host();
7158 destGraph->exports_.sync_host();
7159 auto hostExports = destGraph->exports_.view_host();
7160 Distor.doPostsAndWaits(hostExports, constantNumPackets, hostImports);
7169#ifdef HAVE_TPETRA_MMM_TIMINGS
7171 MM = rcp(
new TimeMonitor(*TimeMonitor::getNewTimer(prefix2+
string(
"Unpack-1"))));
7175 destGraph->numImportPacketsPerLID_.sync_host();
7176 Teuchos::ArrayView<const size_t> numImportPacketsPerLID =
7178 destGraph->imports_.sync_host();
7179 Teuchos::ArrayView<const packet_type> hostImports =
7183 numImportPacketsPerLID,
7184 constantNumPackets,
INSERT,
7185 NumSameIDs, PermuteToLIDs, PermuteFromLIDs);
7186 size_t N = BaseRowMap->getLocalNumElements();
7189 ArrayRCP<size_t> CSR_rowptr(N+1);
7190 ArrayRCP<GO> CSR_colind_GID;
7191 ArrayRCP<LO> CSR_colind_LID;
7192 CSR_colind_GID.resize(mynnz);
7196 if (
typeid(LO) ==
typeid(GO)) {
7197 CSR_colind_LID = Teuchos::arcp_reinterpret_cast<LO>(CSR_colind_GID);
7200 CSR_colind_LID.resize(mynnz);
7209 numImportPacketsPerLID, constantNumPackets,
7210 INSERT, NumSameIDs, PermuteToLIDs,
7211 PermuteFromLIDs, N, mynnz, MyPID,
7212 CSR_rowptr(), CSR_colind_GID(),
7213 SourcePids(), TargetPids);
7218#ifdef HAVE_TPETRA_MMM_TIMINGS
7220 MM = rcp(
new TimeMonitor(*TimeMonitor::getNewTimer(prefix2+
string(
"Unpack-2"))));
7225 Teuchos::Array<int> RemotePids;
7226 Import_Util::lowCommunicationMakeColMapAndReindex(CSR_rowptr(),
7230 TargetPids, RemotePids,
7237 ReducedColMap = (MyRowMap.getRawPtr() == MyColMap.getRawPtr()) ?
7239 MyColMap->replaceCommWithSubset(ReducedComm);
7240 MyColMap = ReducedColMap;
7244 destGraph->replaceColMap(MyColMap);
7251 if (ReducedComm.is_null()) {
7258 if ((! reverseMode && xferAsImport !=
nullptr) ||
7259 (reverseMode && xferAsExport !=
nullptr)) {
7260 Import_Util::sortCrsEntries(CSR_rowptr(),
7263 else if ((! reverseMode && xferAsExport !=
nullptr) ||
7264 (reverseMode && xferAsImport !=
nullptr)) {
7265 Import_Util::sortAndMergeCrsEntries(CSR_rowptr(),
7267 if (CSR_rowptr[N] != mynnz) {
7268 CSR_colind_LID.resize(CSR_rowptr[N]);
7272 TEUCHOS_TEST_FOR_EXCEPTION(
7273 true, std::logic_error,
7274 prefix <<
"Should never get here! Please report this bug to a Tpetra developer.");
7282 destGraph->setAllIndices(CSR_rowptr, CSR_colind_LID);
7288 Teuchos::ParameterList esfc_params;
7289#ifdef HAVE_TPETRA_MMM_TIMINGS
7291 MM = rcp(
new TimeMonitor(*TimeMonitor::getNewTimer(prefix2+
string(
"CreateImporter"))));
7293 RCP<import_type> MyImport = rcp(
new import_type(MyDomainMap, MyColMap, RemotePids));
7294#ifdef HAVE_TPETRA_MMM_TIMINGS
7296 MM = rcp(
new TimeMonitor(*TimeMonitor::getNewTimer(prefix2+
string(
"ESFC"))));
7298 esfc_params.set(
"Timer Label",prefix + std::string(
"TAFC"));
7300 if(!params.is_null())
7301 esfc_params.set(
"compute global constants",params->get(
"compute global constants",
true));
7303 destGraph->expertStaticFillComplete(MyDomainMap, MyRangeMap,
7304 MyImport, Teuchos::null, rcp(&esfc_params,
false));
7308 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
7313 const Teuchos::RCP<const map_type>& domainMap,
7314 const Teuchos::RCP<const map_type>&
rangeMap,
7315 const Teuchos::RCP<Teuchos::ParameterList>&
params)
const
7320 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
7326 const Teuchos::RCP<const map_type>& domainMap,
7327 const Teuchos::RCP<const map_type>&
rangeMap,
7328 const Teuchos::RCP<Teuchos::ParameterList>&
params)
const
7333 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
7338 const Teuchos::RCP<const map_type>& domainMap,
7339 const Teuchos::RCP<const map_type>&
rangeMap,
7340 const Teuchos::RCP<Teuchos::ParameterList>&
params)
const
7345 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
7351 const Teuchos::RCP<const map_type>& domainMap,
7352 const Teuchos::RCP<const map_type>&
rangeMap,
7353 const Teuchos::RCP<Teuchos::ParameterList>&
params)
const
7359 template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
7364 std::swap(
graph.need_sync_host_uvm_access,
this->need_sync_host_uvm_access);
7366 std::swap(
graph.rowMap_,
this->rowMap_);
7367 std::swap(
graph.colMap_,
this->colMap_);
7368 std::swap(
graph.rangeMap_,
this->rangeMap_);
7369 std::swap(
graph.domainMap_,
this->domainMap_);
7371 std::swap(
graph.importer_,
this->importer_);
7372 std::swap(
graph.exporter_,
this->exporter_);
7374 std::swap(
graph.nodeMaxNumRowEntries_,
this->nodeMaxNumRowEntries_);
7376 std::swap(
graph.globalNumEntries_,
this->globalNumEntries_);
7377 std::swap(
graph.globalMaxNumRowEntries_,
this->globalMaxNumRowEntries_);
7379 std::swap(
graph.numAllocForAllRows_,
this->numAllocForAllRows_);
7381 std::swap(
graph.rowPtrsPacked_dev_,
this->rowPtrsPacked_dev_);
7382 std::swap(
graph.rowPtrsPacked_host_,
this->rowPtrsPacked_host_);
7384 std::swap(
graph.rowPtrsUnpacked_dev_,
this->rowPtrsUnpacked_dev_);
7385 std::swap(
graph.rowPtrsUnpacked_host_,
this->rowPtrsUnpacked_host_);
7386 std::swap(
graph.packedUnpackedRowPtrsMatch_,
this->packedUnpackedRowPtrsMatch_);
7388 std::swap(
graph.k_offRankOffsets_,
this->k_offRankOffsets_);
7390 std::swap(
graph.lclIndsUnpacked_wdv,
this->lclIndsUnpacked_wdv);
7391 std::swap(
graph.gblInds_wdv,
this->gblInds_wdv);
7392 std::swap(
graph.lclIndsPacked_wdv,
this->lclIndsPacked_wdv);
7394 std::swap(
graph.storageStatus_,
this->storageStatus_);
7396 std::swap(
graph.indicesAreAllocated_,
this->indicesAreAllocated_);
7397 std::swap(
graph.indicesAreLocal_,
this->indicesAreLocal_);
7398 std::swap(
graph.indicesAreGlobal_,
this->indicesAreGlobal_);
7399 std::swap(
graph.fillComplete_,
this->fillComplete_);
7400 std::swap(
graph.indicesAreSorted_,
this->indicesAreSorted_);
7401 std::swap(
graph.noRedundancies_,
this->noRedundancies_);
7402 std::swap(
graph.haveLocalConstants_,
this->haveLocalConstants_);
7403 std::swap(
graph.haveGlobalConstants_,
this->haveGlobalConstants_);
7404 std::swap(
graph.haveLocalOffRankOffsets_,
this->haveLocalOffRankOffsets_);
7406 std::swap(
graph.sortGhostsAssociatedWithEachProcessor_,
this->sortGhostsAssociatedWithEachProcessor_);
7408 std::swap(
graph.k_numAllocPerRow_,
this->k_numAllocPerRow_);
7409 std::swap(
graph.k_numRowEntries_,
this->k_numRowEntries_);
7410 std::swap(
graph.nonlocals_,
this->nonlocals_);
7414 template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
7428 auto v1 =
m1.find(
key)->second;
7429 auto v2 =
m2.find(
key)->second;
7430 std::sort(
v1.begin(),
v1.end());
7431 std::sort(
v2.begin(),
v2.end());
7450 output = this->nodeMaxNumRowEntries_ ==
graph.nodeMaxNumRowEntries_ ?
output :
false;
7453 output = this->globalMaxNumRowEntries_ ==
graph.globalMaxNumRowEntries_ ?
output :
false;
7455 output = this->numAllocForAllRows_ ==
graph.numAllocForAllRows_ ?
output :
false;
7459 output = this->indicesAreAllocated_ ==
graph.indicesAreAllocated_ ?
output :
false;
7465 output = this->haveLocalConstants_ ==
graph.haveLocalConstants_ ?
output :
false;
7466 output = this->haveGlobalConstants_ ==
graph.haveGlobalConstants_ ?
output :
false;
7467 output = this->haveLocalOffRankOffsets_ ==
graph.haveLocalOffRankOffsets_ ?
output :
false;
7468 output = this->sortGhostsAssociatedWithEachProcessor_ ==
graph.sortGhostsAssociatedWithEachProcessor_ ?
output :
false;
7476 output = this->k_numAllocPerRow_.extent(0) ==
graph.k_numAllocPerRow_.extent(0) ?
output :
false;
7477 if(
output && this->k_numAllocPerRow_.extent(0) > 0)
7479 for(
size_t i=0;
output &&
i<this->k_numAllocPerRow_.extent(0);
i++)
7485 output = this->k_numRowEntries_.extent(0) ==
graph.k_numRowEntries_.extent(0) ?
output :
false;
7486 if(
output && this->k_numRowEntries_.extent(0) > 0)
7488 for(
size_t i = 0;
output &&
i < this->k_numRowEntries_.extent(0);
i++)
7494 auto rowPtrsThis = this->getRowPtrsUnpackedHost();
7502 output = this->lclIndsUnpacked_wdv.extent(0) ==
graph.lclIndsUnpacked_wdv.extent(0) ?
output :
false;
7503 if(
output && this->lclIndsUnpacked_wdv.extent(0) > 0)
7505 auto indThis = this->lclIndsUnpacked_wdv.getHostView(Access::ReadOnly);
7506 auto indGraph =
graph.lclIndsUnpacked_wdv.getHostView(Access::ReadOnly);
7512 output = this->gblInds_wdv.extent(0) ==
graph.gblInds_wdv.extent(0) ?
output :
false;
7513 if(
output && this->gblInds_wdv.extent(0) > 0)
7515 auto indtThis = this->gblInds_wdv.getHostView(Access::ReadOnly);
7516 auto indtGraph =
graph.gblInds_wdv.getHostView(Access::ReadOnly);
7589#define TPETRA_CRSGRAPH_IMPORT_AND_FILL_COMPLETE_INSTANT(LO,GO,NODE) \
7591 Teuchos::RCP<CrsGraph<LO,GO,NODE> > \
7592 importAndFillCompleteCrsGraph(const Teuchos::RCP<const CrsGraph<LO,GO,NODE> >& sourceGraph, \
7593 const Import<CrsGraph<LO,GO,NODE>::local_ordinal_type, \
7594 CrsGraph<LO,GO,NODE>::global_ordinal_type, \
7595 CrsGraph<LO,GO,NODE>::node_type>& importer, \
7596 const Teuchos::RCP<const Map<CrsGraph<LO,GO,NODE>::local_ordinal_type, \
7597 CrsGraph<LO,GO,NODE>::global_ordinal_type, \
7598 CrsGraph<LO,GO,NODE>::node_type> >& domainMap, \
7599 const Teuchos::RCP<const Map<CrsGraph<LO,GO,NODE>::local_ordinal_type, \
7600 CrsGraph<LO,GO,NODE>::global_ordinal_type, \
7601 CrsGraph<LO,GO,NODE>::node_type> >& rangeMap, \
7602 const Teuchos::RCP<Teuchos::ParameterList>& params);
7604#define TPETRA_CRSGRAPH_IMPORT_AND_FILL_COMPLETE_INSTANT_TWO(LO,GO,NODE) \
7606 Teuchos::RCP<CrsGraph<LO,GO,NODE> > \
7607 importAndFillCompleteCrsGraph(const Teuchos::RCP<const CrsGraph<LO,GO,NODE> >& sourceGraph, \
7608 const Import<CrsGraph<LO,GO,NODE>::local_ordinal_type, \
7609 CrsGraph<LO,GO,NODE>::global_ordinal_type, \
7610 CrsGraph<LO,GO,NODE>::node_type>& rowImporter, \
7611 const Import<CrsGraph<LO,GO,NODE>::local_ordinal_type, \
7612 CrsGraph<LO,GO,NODE>::global_ordinal_type, \
7613 CrsGraph<LO,GO,NODE>::node_type>& domainImporter, \
7614 const Teuchos::RCP<const Map<CrsGraph<LO,GO,NODE>::local_ordinal_type, \
7615 CrsGraph<LO,GO,NODE>::global_ordinal_type, \
7616 CrsGraph<LO,GO,NODE>::node_type> >& domainMap, \
7617 const Teuchos::RCP<const Map<CrsGraph<LO,GO,NODE>::local_ordinal_type, \
7618 CrsGraph<LO,GO,NODE>::global_ordinal_type, \
7619 CrsGraph<LO,GO,NODE>::node_type> >& rangeMap, \
7620 const Teuchos::RCP<Teuchos::ParameterList>& params);
7623#define TPETRA_CRSGRAPH_EXPORT_AND_FILL_COMPLETE_INSTANT(LO,GO,NODE) \
7625 Teuchos::RCP<CrsGraph<LO,GO,NODE> > \
7626 exportAndFillCompleteCrsGraph(const Teuchos::RCP<const CrsGraph<LO,GO,NODE> >& sourceGraph, \
7627 const Export<CrsGraph<LO,GO,NODE>::local_ordinal_type, \
7628 CrsGraph<LO,GO,NODE>::global_ordinal_type, \
7629 CrsGraph<LO,GO,NODE>::node_type>& exporter, \
7630 const Teuchos::RCP<const Map<CrsGraph<LO,GO,NODE>::local_ordinal_type, \
7631 CrsGraph<LO,GO,NODE>::global_ordinal_type, \
7632 CrsGraph<LO,GO,NODE>::node_type> >& domainMap, \
7633 const Teuchos::RCP<const Map<CrsGraph<LO,GO,NODE>::local_ordinal_type, \
7634 CrsGraph<LO,GO,NODE>::global_ordinal_type, \
7635 CrsGraph<LO,GO,NODE>::node_type> >& rangeMap, \
7636 const Teuchos::RCP<Teuchos::ParameterList>& params);
7638#define TPETRA_CRSGRAPH_EXPORT_AND_FILL_COMPLETE_INSTANT_TWO(LO,GO,NODE) \
7640 Teuchos::RCP<CrsGraph<LO,GO,NODE> > \
7641 exportAndFillCompleteCrsGraph(const Teuchos::RCP<const CrsGraph<LO,GO,NODE> >& sourceGraph, \
7642 const Export<CrsGraph<LO,GO,NODE>::local_ordinal_type, \
7643 CrsGraph<LO,GO,NODE>::global_ordinal_type, \
7644 CrsGraph<LO,GO,NODE>::node_type>& rowExporter, \
7645 const Export<CrsGraph<LO,GO,NODE>::local_ordinal_type, \
7646 CrsGraph<LO,GO,NODE>::global_ordinal_type, \
7647 CrsGraph<LO,GO,NODE>::node_type>& domainExporter, \
7648 const Teuchos::RCP<const Map<CrsGraph<LO,GO,NODE>::local_ordinal_type, \
7649 CrsGraph<LO,GO,NODE>::global_ordinal_type, \
7650 CrsGraph<LO,GO,NODE>::node_type> >& domainMap, \
7651 const Teuchos::RCP<const Map<CrsGraph<LO,GO,NODE>::local_ordinal_type, \
7652 CrsGraph<LO,GO,NODE>::global_ordinal_type, \
7653 CrsGraph<LO,GO,NODE>::node_type> >& rangeMap, \
7654 const Teuchos::RCP<Teuchos::ParameterList>& params);
7657#define TPETRA_CRSGRAPH_INSTANT( LO, GO, NODE ) \
7658 template class CrsGraph<LO, GO, NODE>; \
7659 TPETRA_CRSGRAPH_IMPORT_AND_FILL_COMPLETE_INSTANT(LO,GO,NODE) \
7660 TPETRA_CRSGRAPH_EXPORT_AND_FILL_COMPLETE_INSTANT(LO,GO,NODE) \
7661 TPETRA_CRSGRAPH_IMPORT_AND_FILL_COMPLETE_INSTANT_TWO(LO,GO,NODE) \
7662 TPETRA_CRSGRAPH_EXPORT_AND_FILL_COMPLETE_INSTANT_TWO(LO,GO,NODE)