1#ifndef TPETRA_DETAILS_MAKECOLMAP_DEF_HPP
2#define TPETRA_DETAILS_MAKECOLMAP_DEF_HPP
24#include "Tpetra_RowGraph.hpp"
26#include "Teuchos_Array.hpp"
27#include "Kokkos_Bitset.hpp"
34template <
class LO,
class GO,
class NT>
37 Teuchos::Array<int>& remotePIDs,
39 size_t numLocalColGIDs,
40 size_t numRemoteColGIDs,
41 std::set<GO>& RemoteGIDSet,
42 std::vector<GO>& RemoteGIDUnorderedVector,
43 std::vector<bool>& GIDisLocal,
44 const bool sortEachProcsGids,
45 std::ostream* errStrm)
48 using Teuchos::ArrayView;
52 const char prefix[] =
"Tpetra::Details::makeColMapImpl: ";
53 typedef ::Tpetra::Map<LO, GO, NT> map_type;
83 if (domMap->getComm ()->getSize () == 1) {
84 if (numRemoteColGIDs != 0) {
86 if (errStrm != NULL) {
87 *errStrm << prefix <<
"The domain Map only has one process, but "
88 << numRemoteColGIDs <<
" column "
89 << (numRemoteColGIDs != 1 ?
"indices are" :
"index is")
90 <<
" not in the domain Map. Either these indices are "
91 "invalid or the domain Map is invalid. Remember that nonsquare "
92 "matrices, or matrices where the row and range Maps differ, "
93 "require calling the version of fillComplete that takes the "
94 "domain and range Maps as input." << endl;
97 if (numLocalColGIDs == domMap->getLocalNumElements ()) {
107 Array<GO> myColumns(numLocalColGIDs + numRemoteColGIDs);
109 ArrayView<GO> LocalColGIDs = myColumns (0, numLocalColGIDs);
110 ArrayView<GO> remoteColGIDs = myColumns (numLocalColGIDs, numRemoteColGIDs);
113 if (sortEachProcsGids) {
115 std::copy (RemoteGIDSet.begin(), RemoteGIDSet.end(),
116 remoteColGIDs.begin());
120 std::copy (RemoteGIDUnorderedVector.begin(),
121 RemoteGIDUnorderedVector.end(), remoteColGIDs.begin());
127 if (
static_cast<size_t> (remotePIDs.size ()) != numRemoteColGIDs) {
128 remotePIDs.resize (numRemoteColGIDs);
133 domMap->getRemoteIndexList (remoteColGIDs, remotePIDs ());
143 if (errStrm != NULL) {
144 *errStrm << prefix <<
"Some column indices are not in the domain Map."
145 "Either these column indices are invalid or the domain Map is "
146 "invalid. Likely cause: For a nonsquare matrix, you must give the "
147 "domain and range Maps as input to fillComplete." << endl;
166 sort2 (remotePIDs.begin (), remotePIDs.end (), remoteColGIDs.begin (),
true);
178 const size_t numDomainElts = domMap->getLocalNumElements ();
179 if (numLocalColGIDs == numDomainElts) {
183 if (domMap->isContiguous ()) {
188 GO curColMapGid = domMap->getMinGlobalIndex ();
189 for (
size_t k = 0; k < numLocalColGIDs; ++k, ++curColMapGid) {
190 LocalColGIDs[k] = curColMapGid;
194 ArrayView<const GO> domainElts = domMap->getLocalElementList ();
195 std::copy (domainElts.begin(), domainElts.end(), LocalColGIDs.begin());
201 size_t numLocalCount = 0;
202 if (domMap->isContiguous ()) {
207 GO curColMapGid = domMap->getMinGlobalIndex ();
208 for (
size_t i = 0; i < numDomainElts; ++i, ++curColMapGid) {
210 LocalColGIDs[numLocalCount++] = curColMapGid;
215 ArrayView<const GO> domainElts = domMap->getLocalElementList ();
216 for (
size_t i = 0; i < numDomainElts; ++i) {
218 LocalColGIDs[numLocalCount++] = domainElts[i];
222 if (numLocalCount != numLocalColGIDs) {
223 if (errStrm != NULL) {
224 *errStrm << prefix <<
"numLocalCount = " << numLocalCount
225 <<
" != numLocalColGIDs = " << numLocalColGIDs
226 <<
". This should never happen. "
227 "Please report this bug to the Tpetra developers." << endl;
283 Tpetra::Details::OrdinalTraits<global_size_t>::invalid ();
288 const GO indexBase = domMap->getIndexBase ();
289 colMap = rcp (
new map_type (INV, myColumns, indexBase, domMap->getComm ()));
293template <
class LO,
class GO,
class NT>
296 Teuchos::Array<int>& remotePIDs,
302 using Teuchos::Array;
303 using Teuchos::ArrayView;
306 typedef ::Tpetra::Map<LO, GO, NT> map_type;
307 const char prefix[] =
"Tpetra::Details::makeColMap: ";
317 if (
domMap.is_null () ||
domMap->getComm ().is_null ()) {
318 colMap = Teuchos::null;
323 if (
graph.isLocallyIndexed ()) {
324 colMap =
graph.getColMap ();
327 if (colMap.is_null () || !
graph.hasColMap ()) {
330 *
errStrm <<
prefix <<
"The graph is locally indexed on the calling "
331 "process, but has no column Map (either getColMap() returns null, "
332 "or hasColMap() returns false)." <<
endl;
344 if (colMap->isContiguous ()) {
346 const LO
numCurGids =
static_cast<LO
> (colMap->getLocalNumElements ());
364 else if (
graph.isGloballyIndexed ()) {
388 const LO
LINV = Tpetra::Details::OrdinalTraits<LO>::invalid ();
400 if (!
graph.getRowMap ().is_null ()) {
402 const LO
lclNumRows = rowMap.getLocalNumElements ();
405 typename RowGraph<LO,GO,NT>::global_inds_host_view_type
rowGids;
457 Tpetra::Details::OrdinalTraits<global_size_t>::invalid ();
467template<
typename GOView,
typename bitset_t>
468struct GatherPresentEntries
470 using GO =
typename GOView::non_const_value_type;
476 KOKKOS_INLINE_FUNCTION
void operator()(
const GO i)
const
478 present.set(gids(i) - minGID);
486template<
typename LO,
typename GO,
typename device_t,
typename LocalMapType,
typename const_bitset_t,
bool doingRemotes>
489 using mem_space =
typename device_t::memory_space;
490 using GOView = Kokkos::View<GO*, mem_space>;
491 using SingleView = Kokkos::View<GO, mem_space>;
493 ListGIDs(GO minGID_, GOView& gidList_, SingleView& numElems_, const_bitset_t& present_,
const LocalMapType& localDomainMap_)
494 : minGID(minGID_), gidList(gidList_), numElems(numElems_), present(present_), localDomainMap(localDomainMap_)
497 KOKKOS_INLINE_FUNCTION
void operator()(
const GO i, GO& lcount,
const bool finalPass)
const
499 bool isRemote = localDomainMap.getLocalElement(i + minGID) == ::Tpetra::Details::OrdinalTraits<LO>::invalid();
500 if(present.test(i) && doingRemotes == isRemote)
505 gidList(lcount) = minGID + i;
509 if((i ==
static_cast<GO
>(present.size() - 1)) && finalPass)
519 const_bitset_t present;
520 const LocalMapType localDomainMap;
523template<
typename GO,
typename mem_space>
524struct MinMaxReduceFunctor
526 using MinMaxValue =
typename Kokkos::MinMax<GO>::value_type;
527 using GOView = Kokkos::View<GO*, mem_space>;
529 MinMaxReduceFunctor(
const GOView& gids_)
533 KOKKOS_INLINE_FUNCTION
void operator()(
const GO i, MinMaxValue& lminmax)
const
536 if(gid < lminmax.min_val)
537 lminmax.min_val = gid;
538 if(gid > lminmax.max_val)
539 lminmax.max_val = gid;
545template <
class LO,
class GO,
class NT>
549 Kokkos::View<GO*, typename NT::memory_space> gids,
553 using Teuchos::Array;
554 using Kokkos::RangePolicy;
555 using device_t =
typename NT::device_type;
556 using exec_space =
typename device_t::execution_space;
557 using memory_space =
typename device_t::memory_space;
563 using bitset_t = Kokkos::Bitset<typename exec_space::memory_space>;
564 using const_bitset_t = Kokkos::ConstBitset<typename exec_space::memory_space>;
565 using GOView = Kokkos::View<GO*, memory_space>;
566 using SingleView = Kokkos::View<GO, memory_space>;
568 using LocalMap =
typename map_type::local_map_type;
570 GO minGID = Teuchos::OrdinalTraits<GO>::max();
572 using MinMaxValue =
typename Kokkos::MinMax<GO>::value_type;
612 Kokkos::fence(
"Tpetra::makeColMap");
655#define TPETRA_DETAILS_MAKECOLMAP_INSTANT(LO,GO,NT) \
656 namespace Details { \
658 makeColMap (Teuchos::RCP<const Tpetra::Map<LO, GO, NT> >&, \
659 Teuchos::Array<int>&, \
660 const Teuchos::RCP<const Tpetra::Map<LO, GO, NT> >&, \
661 const RowGraph<LO, GO, NT>&, \
665 makeColMap (Teuchos::RCP<const Tpetra::Map<LO, GO, NT> >&, \
666 const Teuchos::RCP<const Tpetra::Map<LO, GO, NT> >&, \
667 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, const bool stableSort=false)
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.