1#ifndef TPETRA_DETAILS_MAKECOLMAP_DEF_HPP
2#define TPETRA_DETAILS_MAKECOLMAP_DEF_HPP
56#include "Tpetra_RowGraph.hpp"
58#include "Teuchos_Array.hpp"
59#include "Kokkos_Bitset.hpp"
66template <
class LO,
class GO,
class NT>
69 Teuchos::Array<int>& remotePIDs,
71 size_t numLocalColGIDs,
72 size_t numRemoteColGIDs,
73 std::set<GO>& RemoteGIDSet,
74 std::vector<GO>& RemoteGIDUnorderedVector,
75 std::vector<bool>& GIDisLocal,
76 const bool sortEachProcsGids,
77 std::ostream* errStrm)
80 using Teuchos::ArrayView;
84 const char prefix[] =
"Tpetra::Details::makeColMapImpl: ";
85 typedef ::Tpetra::Map<LO, GO, NT> map_type;
115 if (domMap->getComm ()->getSize () == 1) {
116 if (numRemoteColGIDs != 0) {
118 if (errStrm != NULL) {
119 *errStrm << prefix <<
"The domain Map only has one process, but "
120 << numRemoteColGIDs <<
" column "
121 << (numRemoteColGIDs != 1 ?
"indices are" :
"index is")
122 <<
" not in the domain Map. Either these indices are "
123 "invalid or the domain Map is invalid. Remember that nonsquare "
124 "matrices, or matrices where the row and range Maps differ, "
125 "require calling the version of fillComplete that takes the "
126 "domain and range Maps as input." << endl;
129 if (numLocalColGIDs == domMap->getLocalNumElements ()) {
139 Array<GO> myColumns(numLocalColGIDs + numRemoteColGIDs);
141 ArrayView<GO> LocalColGIDs = myColumns (0, numLocalColGIDs);
142 ArrayView<GO> remoteColGIDs = myColumns (numLocalColGIDs, numRemoteColGIDs);
145 if (sortEachProcsGids) {
147 std::copy (RemoteGIDSet.begin(), RemoteGIDSet.end(),
148 remoteColGIDs.begin());
152 std::copy (RemoteGIDUnorderedVector.begin(),
153 RemoteGIDUnorderedVector.end(), remoteColGIDs.begin());
159 if (
static_cast<size_t> (remotePIDs.size ()) != numRemoteColGIDs) {
160 remotePIDs.resize (numRemoteColGIDs);
165 domMap->getRemoteIndexList (remoteColGIDs, remotePIDs ());
175 if (errStrm != NULL) {
176 *errStrm << prefix <<
"Some column indices are not in the domain Map."
177 "Either these column indices are invalid or the domain Map is "
178 "invalid. Likely cause: For a nonsquare matrix, you must give the "
179 "domain and range Maps as input to fillComplete." << endl;
198 sort2 (remotePIDs.begin (), remotePIDs.end (), remoteColGIDs.begin ());
210 const size_t numDomainElts = domMap->getLocalNumElements ();
211 if (numLocalColGIDs == numDomainElts) {
215 if (domMap->isContiguous ()) {
220 GO curColMapGid = domMap->getMinGlobalIndex ();
221 for (
size_t k = 0; k < numLocalColGIDs; ++k, ++curColMapGid) {
222 LocalColGIDs[k] = curColMapGid;
226 ArrayView<const GO> domainElts = domMap->getLocalElementList ();
227 std::copy (domainElts.begin(), domainElts.end(), LocalColGIDs.begin());
233 size_t numLocalCount = 0;
234 if (domMap->isContiguous ()) {
239 GO curColMapGid = domMap->getMinGlobalIndex ();
240 for (
size_t i = 0; i < numDomainElts; ++i, ++curColMapGid) {
242 LocalColGIDs[numLocalCount++] = curColMapGid;
247 ArrayView<const GO> domainElts = domMap->getLocalElementList ();
248 for (
size_t i = 0; i < numDomainElts; ++i) {
250 LocalColGIDs[numLocalCount++] = domainElts[i];
254 if (numLocalCount != numLocalColGIDs) {
255 if (errStrm != NULL) {
256 *errStrm << prefix <<
"numLocalCount = " << numLocalCount
257 <<
" != numLocalColGIDs = " << numLocalColGIDs
258 <<
". This should never happen. "
259 "Please report this bug to the Tpetra developers." << endl;
315 Tpetra::Details::OrdinalTraits<global_size_t>::invalid ();
320 const GO indexBase = domMap->getIndexBase ();
321 colMap = rcp (
new map_type (INV, myColumns, indexBase, domMap->getComm ()));
325template <
class LO,
class GO,
class NT>
328 Teuchos::Array<int>& remotePIDs,
334 using Teuchos::Array;
335 using Teuchos::ArrayView;
338 typedef ::Tpetra::Map<LO, GO, NT> map_type;
339 const char prefix[] =
"Tpetra::Details::makeColMap: ";
349 if (
domMap.is_null () ||
domMap->getComm ().is_null ()) {
350 colMap = Teuchos::null;
355 if (
graph.isLocallyIndexed ()) {
356 colMap =
graph.getColMap ();
359 if (colMap.is_null () || !
graph.hasColMap ()) {
362 *
errStrm <<
prefix <<
"The graph is locally indexed on the calling "
363 "process, but has no column Map (either getColMap() returns null, "
364 "or hasColMap() returns false)." <<
endl;
376 if (colMap->isContiguous ()) {
378 const LO
numCurGids =
static_cast<LO
> (colMap->getLocalNumElements ());
396 else if (
graph.isGloballyIndexed ()) {
420 const LO
LINV = Tpetra::Details::OrdinalTraits<LO>::invalid ();
432 if (!
graph.getRowMap ().is_null ()) {
434 const LO
lclNumRows = rowMap.getLocalNumElements ();
437 typename RowGraph<LO,GO,NT>::global_inds_host_view_type
rowGids;
489 Tpetra::Details::OrdinalTraits<global_size_t>::invalid ();
499template<
typename GOView,
typename bitset_t>
500struct GatherPresentEntries
502 using GO =
typename GOView::non_const_value_type;
508 KOKKOS_INLINE_FUNCTION
void operator()(
const GO i)
const
510 present.set(gids(i) - minGID);
518template<
typename LO,
typename GO,
typename device_t,
typename LocalMapType,
typename const_bitset_t,
bool doingRemotes>
521 using mem_space =
typename device_t::memory_space;
522 using GOView = Kokkos::View<GO*, mem_space>;
523 using SingleView = Kokkos::View<GO, mem_space>;
525 ListGIDs(GO minGID_, GOView& gidList_, SingleView& numElems_, const_bitset_t& present_,
const LocalMapType& localDomainMap_)
526 : minGID(minGID_), gidList(gidList_), numElems(numElems_), present(present_), localDomainMap(localDomainMap_)
529 KOKKOS_INLINE_FUNCTION
void operator()(
const GO i, GO& lcount,
const bool finalPass)
const
531 bool isRemote = localDomainMap.getLocalElement(i + minGID) == ::Tpetra::Details::OrdinalTraits<LO>::invalid();
532 if(present.test(i) && doingRemotes == isRemote)
537 gidList(lcount) = minGID + i;
541 if((i ==
static_cast<GO
>(present.size() - 1)) && finalPass)
551 const_bitset_t present;
552 const LocalMapType localDomainMap;
555template<
typename GO,
typename mem_space>
556struct MinMaxReduceFunctor
558 using MinMaxValue =
typename Kokkos::MinMax<GO>::value_type;
559 using GOView = Kokkos::View<GO*, mem_space>;
561 MinMaxReduceFunctor(
const GOView& gids_)
565 KOKKOS_INLINE_FUNCTION
void operator()(
const GO i, MinMaxValue& lminmax)
const
568 if(gid < lminmax.min_val)
569 lminmax.min_val = gid;
570 if(gid > lminmax.max_val)
571 lminmax.max_val = gid;
577template <
class LO,
class GO,
class NT>
581 Kokkos::View<GO*, typename NT::memory_space> gids,
585 using Teuchos::Array;
586 using Kokkos::RangePolicy;
587 using device_t =
typename NT::device_type;
588 using exec_space =
typename device_t::execution_space;
589 using memory_space =
typename device_t::memory_space;
595 using bitset_t = Kokkos::Bitset<typename exec_space::memory_space>;
596 using const_bitset_t = Kokkos::ConstBitset<typename exec_space::memory_space>;
597 using GOView = Kokkos::View<GO*, memory_space>;
598 using SingleView = Kokkos::View<GO, memory_space>;
600 using LocalMap =
typename map_type::local_map_type;
602 GO minGID = Teuchos::OrdinalTraits<GO>::max();
604 using MinMaxValue =
typename Kokkos::MinMax<GO>::value_type;
687#define TPETRA_DETAILS_MAKECOLMAP_INSTANT(LO,GO,NT) \
688 namespace Details { \
690 makeColMap (Teuchos::RCP<const Tpetra::Map<LO, GO, NT> >&, \
691 Teuchos::Array<int>&, \
692 const Teuchos::RCP<const Tpetra::Map<LO, GO, NT> >&, \
693 const RowGraph<LO, GO, NT>&, \
697 makeColMap (Teuchos::RCP<const Tpetra::Map<LO, GO, NT> >&, \
698 const Teuchos::RCP<const Tpetra::Map<LO, GO, NT> >&, \
699 Kokkos::View<GO*, typename NT::memory_space>, \
Stand-alone utility functions and macros.
Struct that holds views of the contents of a CrsMatrix.
"Local" part of Map suitable for Kokkos kernels.
Implementation details of Tpetra.
int makeColMap(Teuchos::RCP< const Tpetra::Map< LO, GO, NT > > &colMap, Teuchos::Array< int > &remotePIDs, const Teuchos::RCP< const Tpetra::Map< LO, GO, NT > > &domMap, const RowGraph< LO, GO, NT > &graph, const bool sortEachProcsGids=true, std::ostream *errStrm=NULL)
Make the graph's column Map.
Namespace Tpetra contains the class and methods constituting the Tpetra library.
void sort2(const IT1 &first1, const IT1 &last1, const IT2 &first2)
Sort the first array, and apply the resulting permutation to the second array.
LookupStatus
Return status of Map remote index lookup (getRemoteIndexList()).
size_t global_size_t
Global size_t object.