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>
 
   36                   Teuchos::Array<int>& remotePIDs,
 
   38                   size_t numLocalColGIDs,
 
   39                   size_t numRemoteColGIDs,
 
   40                   std::set<GO>& RemoteGIDSet,
 
   41                   std::vector<GO>& RemoteGIDUnorderedVector,
 
   42                   std::vector<bool>& GIDisLocal,
 
   43                   const bool sortEachProcsGids,
 
   44                   std::ostream* errStrm) {
 
   47  using Teuchos::ArrayView;
 
   50  const char prefix[] = 
"Tpetra::Details::makeColMapImpl: ";
 
   51  typedef ::Tpetra::Map<LO, GO, NT> map_type;
 
   81  if (domMap->getComm()->getSize() == 1) {
 
   82    if (numRemoteColGIDs != 0) {
 
   84      if (errStrm != NULL) {
 
   85        *errStrm << prefix << 
"The domain Map only has one process, but " 
   86                 << numRemoteColGIDs << 
" column " 
   87                 << (numRemoteColGIDs != 1 ? 
"indices are" : 
"index is")
 
   88                 << 
" not in the domain Map.  Either these indices are " 
   89                    "invalid or the domain Map is invalid.  Remember that nonsquare " 
   90                    "matrices, or matrices where the row and range Maps differ, " 
   91                    "require calling the version of fillComplete that takes the " 
   92                    "domain and range Maps as input." 
   96    if (numLocalColGIDs == domMap->getLocalNumElements()) {
 
  106  Array<GO> myColumns(numLocalColGIDs + numRemoteColGIDs);
 
  108  ArrayView<GO> LocalColGIDs  = myColumns(0, numLocalColGIDs);
 
  109  ArrayView<GO> remoteColGIDs = myColumns(numLocalColGIDs, numRemoteColGIDs);
 
  112  if (sortEachProcsGids) {
 
  114    std::copy(RemoteGIDSet.begin(), RemoteGIDSet.end(),
 
  115              remoteColGIDs.begin());
 
  118    std::copy(RemoteGIDUnorderedVector.begin(),
 
  119              RemoteGIDUnorderedVector.end(), remoteColGIDs.begin());
 
  125  if (
static_cast<size_t>(remotePIDs.size()) != numRemoteColGIDs) {
 
  126    remotePIDs.resize(numRemoteColGIDs);
 
  131        domMap->getRemoteIndexList(remoteColGIDs, remotePIDs());
 
  141      if (errStrm != NULL) {
 
  142        *errStrm << prefix << 
"Some column indices are not in the domain Map." 
  143                              "Either these column indices are invalid or the domain Map is " 
  144                              "invalid.  Likely cause: For a nonsquare matrix, you must give the " 
  145                              "domain and range Maps as input to fillComplete." 
  165  sort2(remotePIDs.begin(), remotePIDs.end(), remoteColGIDs.begin(), 
true);
 
  177  const size_t numDomainElts = domMap->getLocalNumElements();
 
  178  if (numLocalColGIDs == numDomainElts) {
 
  182    if (domMap->isContiguous()) {
 
  187      GO curColMapGid = domMap->getMinGlobalIndex();
 
  188      for (
size_t k = 0; k < numLocalColGIDs; ++k, ++curColMapGid) {
 
  189        LocalColGIDs[k] = curColMapGid;
 
  192      ArrayView<const GO> domainElts = domMap->getLocalElementList();
 
  193      std::copy(domainElts.begin(), domainElts.end(), LocalColGIDs.begin());
 
  198    size_t numLocalCount = 0;
 
  199    if (domMap->isContiguous()) {
 
  204      GO curColMapGid = domMap->getMinGlobalIndex();
 
  205      for (
size_t i = 0; i < numDomainElts; ++i, ++curColMapGid) {
 
  207          LocalColGIDs[numLocalCount++] = curColMapGid;
 
  211      ArrayView<const GO> domainElts = domMap->getLocalElementList();
 
  212      for (
size_t i = 0; i < numDomainElts; ++i) {
 
  214          LocalColGIDs[numLocalCount++] = domainElts[i];
 
  218    if (numLocalCount != numLocalColGIDs) {
 
  219      if (errStrm != NULL) {
 
  220        *errStrm << prefix << 
"numLocalCount = " << numLocalCount
 
  221                 << 
" != numLocalColGIDs = " << numLocalColGIDs
 
  222                 << 
".  This should never happen.  " 
  223                    "Please report this bug to the Tpetra developers." 
  280      Tpetra::Details::OrdinalTraits<global_size_t>::invalid();
 
  285  const GO indexBase = domMap->getIndexBase();
 
  286  colMap             = rcp(
new map_type(INV, myColumns, indexBase, domMap->getComm()));
 
  290template <
class LO, 
class GO, 
class NT>
 
  292               Teuchos::Array<int>& remotePIDs,
 
  298  using Teuchos::Array;
 
  299  using Teuchos::ArrayView;
 
  301  typedef ::Tpetra::Map<LO, GO, NT> map_type;
 
  302  const char prefix[] = 
"Tpetra::Details::makeColMap: ";
 
  313    colMap = Teuchos::null;
 
  318  if (
graph.isLocallyIndexed()) {
 
  319    colMap = 
graph.getColMap();
 
  322    if (colMap.is_null() || !
graph.hasColMap()) {
 
  325        *
errStrm << 
prefix << 
"The graph is locally indexed on the calling " 
  326                              "process, but has no column Map (either getColMap() returns null, " 
  327                              "or hasColMap() returns false)." 
  339      if (colMap->isContiguous()) {
 
  341        const LO 
numCurGids = 
static_cast<LO
>(colMap->getLocalNumElements());
 
  357  } 
else if (
graph.isGloballyIndexed()) {
 
  381    const LO 
LINV           = Tpetra::Details::OrdinalTraits<LO>::invalid();
 
  393    if (!
graph.getRowMap().is_null()) {
 
  395      const LO 
lclNumRows                   = rowMap.getLocalNumElements();
 
  398        typename RowGraph<LO, GO, NT>::global_inds_host_view_type 
rowGids;
 
  449      Tpetra::Details::OrdinalTraits<global_size_t>::invalid();
 
 
  459template <
typename GOView, 
typename bitset_t>
 
  460struct GatherPresentEntries {
 
  461  using GO = 
typename GOView::non_const_value_type;
 
  468  KOKKOS_INLINE_FUNCTION 
void operator()(
const GO i)
 const {
 
  469    present.set(gids(i) - minGID);
 
  477template <
typename LO, 
typename GO, 
typename device_t, 
typename LocalMapType, 
typename const_bitset_t, 
bool doingRemotes>
 
  479  using mem_space  = 
typename device_t::memory_space;
 
  480  using GOView     = Kokkos::View<GO*, mem_space>;
 
  481  using SingleView = Kokkos::View<GO, mem_space>;
 
  483  ListGIDs(GO minGID_, GOView& gidList_, SingleView& numElems_, const_bitset_t& present_, 
const LocalMapType& localDomainMap_)
 
  486    , numElems(numElems_)
 
  488    , localDomainMap(localDomainMap_) {}
 
  490  KOKKOS_INLINE_FUNCTION 
void operator()(
const GO i, GO& lcount, 
const bool finalPass)
 const {
 
  491    bool isRemote = localDomainMap.getLocalElement(i + minGID) == ::Tpetra::Details::OrdinalTraits<LO>::invalid();
 
  492    if (present.test(i) && doingRemotes == isRemote) {
 
  495        gidList(lcount) = minGID + i;
 
  499    if ((i == 
static_cast<GO
>(present.size() - 1)) && finalPass) {
 
  508  const_bitset_t present;
 
  509  const LocalMapType localDomainMap;
 
  512template <
typename GO, 
typename mem_space>
 
  513struct MinMaxReduceFunctor {
 
  514  using MinMaxValue = 
typename Kokkos::MinMax<GO>::value_type;
 
  515  using GOView      = Kokkos::View<GO*, mem_space>;
 
  517  MinMaxReduceFunctor(
const GOView& gids_)
 
  520  KOKKOS_INLINE_FUNCTION 
void operator()(
const GO i, MinMaxValue& lminmax)
 const {
 
  522    if (gid < lminmax.min_val)
 
  523      lminmax.min_val = gid;
 
  524    if (gid > lminmax.max_val)
 
  525      lminmax.max_val = gid;
 
  531template <
class LO, 
class GO, 
class NT>
 
  534               Kokkos::View<GO*, typename NT::memory_space> gids,
 
  536  using Kokkos::RangePolicy;
 
  537  using Teuchos::Array;
 
  539  using device_t     = 
typename NT::device_type;
 
  540  using exec_space   = 
typename device_t::execution_space;
 
  541  using memory_space = 
typename device_t::memory_space;
 
  547  using bitset_t        = Kokkos::Bitset<typename exec_space::memory_space>;
 
  548  using const_bitset_t  = Kokkos::ConstBitset<typename exec_space::memory_space>;
 
  549  using GOView          = Kokkos::View<GO*, memory_space>;
 
  550  using SingleView      = Kokkos::View<GO, memory_space>;
 
  552  using LocalMap        = 
typename map_type::local_map_type;
 
  554  GO minGID             = Teuchos::OrdinalTraits<GO>::max();
 
  556  using MinMaxValue     = 
typename Kokkos::MinMax<GO>::value_type;
 
  595  Kokkos::fence(
"Tpetra::makeColMap");
 
 
  636#define TPETRA_DETAILS_MAKECOLMAP_INSTANT(LO, GO, NT)            \ 
  637  namespace Details {                                            \ 
  639  makeColMap(Teuchos::RCP<const Tpetra::Map<LO, GO, NT>>&,       \ 
  640             Teuchos::Array<int>&,                               \ 
  641             const Teuchos::RCP<const Tpetra::Map<LO, GO, NT>>&, \ 
  642             const RowGraph<LO, GO, NT>&,                        \ 
  646  makeColMap(Teuchos::RCP<const Tpetra::Map<LO, GO, NT>>&,       \ 
  647             const Teuchos::RCP<const Tpetra::Map<LO, GO, NT>>&, \ 
  648             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.