Xpetra  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Xpetra_EpetraMap.hpp
Go to the documentation of this file.
1 // @HEADER
2 //
3 // ***********************************************************************
4 //
5 // Xpetra: A linear algebra interface package
6 // Copyright 2012 Sandia Corporation
7 //
8 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
9 // the U.S. Government retains certain rights in this software.
10 //
11 // Redistribution and use in source and binary forms, with or without
12 // modification, are permitted provided that the following conditions are
13 // met:
14 //
15 // 1. Redistributions of source code must retain the above copyright
16 // notice, this list of conditions and the following disclaimer.
17 //
18 // 2. Redistributions in binary form must reproduce the above copyright
19 // notice, this list of conditions and the following disclaimer in the
20 // documentation and/or other materials provided with the distribution.
21 //
22 // 3. Neither the name of the Corporation nor the names of the
23 // contributors may be used to endorse or promote products derived from
24 // this software without specific prior written permission.
25 //
26 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 //
38 // Questions? Contact
39 // Jonathan Hu (jhu@sandia.gov)
40 // Andrey Prokopenko (aprokop@sandia.gov)
41 // Ray Tuminaro (rstumin@sandia.gov)
42 //
43 // ***********************************************************************
44 //
45 // @HEADER
46 #ifndef XPETRA_EPETRAMAP_HPP
47 #define XPETRA_EPETRAMAP_HPP
48 
50 
51 #include "Xpetra_Map.hpp"
52 
53 #include <Epetra_Map.h>
54 #include <Epetra_BlockMap.h>
55 
56 #include "Xpetra_Utils.hpp"
57 #include "Xpetra_EpetraUtils.hpp"
59 
60 #include "Xpetra_ConfigDefs.hpp"
61 
62 #if defined(XPETRA_ENABLE_DEPRECATED_CODE)
63 #ifdef __GNUC__
64 #warning "The header file Trilinos/packages/xpetra/src/Map/Xpetra_EpetraMap.hpp is deprecated."
65 #endif
66 #else
67 #error "The header file Trilinos/packages/xpetra/src/Map/Xpetra_EpetraMap.hpp is deprecated."
68 #endif
69 
70 namespace Xpetra {
71 
72 // TODO: move that elsewhere
73 template <class GlobalOrdinal, class Node>
74 XPETRA_DEPRECATED const Epetra_Map &toEpetra(const Map<int, GlobalOrdinal, Node> &);
75 
76 template <class GlobalOrdinal, class Node>
77 XPETRA_DEPRECATED const Epetra_Map &toEpetra(const RCP<const Map<int, GlobalOrdinal, Node> > &);
78 
79 // template<class GlobalOrdinal>
80 // const RCP< const Map<int, GlobalOrdinal> > toXpetra(const RCP< const Epetra_Map > &);
81 
82 template <class GlobalOrdinal, class Node>
83 XPETRA_DEPRECATED const RCP<const Map<int, GlobalOrdinal, Node> > toXpetra(const Epetra_BlockMap &);
84 
85 // stub implementation for EpetraMapT
86 template <class GlobalOrdinal, class Node>
87 class XPETRA_DEPRECATED EpetraMapT
88  : public virtual Map<int, GlobalOrdinal, Node> {
89  typedef int LocalOrdinal;
90 
91  public:
92  typedef int local_ordinal_type;
93  typedef GlobalOrdinal global_ordinal_type;
94  typedef Node node_type;
96 
98 
99 
101  EpetraMapT(global_size_t numGlobalElements,
102  GlobalOrdinal indexBase,
103  const Teuchos::RCP<const Teuchos::Comm<int> > &comm,
105  TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::RuntimeError,
106  "Xpetra::EpetraMap only available for GO=int or GO=long long with EpetraNode (Serial or OpenMP depending on configuration)");
107  }
108 
110  EpetraMapT(global_size_t numGlobalElements, size_t numLocalElements, GlobalOrdinal indexBase, const Teuchos::RCP<const Teuchos::Comm<int> > &comm) {
111  TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::RuntimeError,
112  "Xpetra::EpetraMap only available for GO=int or GO=long long with EpetraNode (Serial or OpenMP depending on configuration)");
113  }
114 
116  EpetraMapT(global_size_t numGlobalElements,
117  const Teuchos::ArrayView<const GlobalOrdinal> &elementList,
118  GlobalOrdinal indexBase,
119  const Teuchos::RCP<const Teuchos::Comm<int> > &comm) {
120  TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::RuntimeError,
121  "Xpetra::EpetraMap only available for GO=int or GO=long long with EpetraNode (Serial or OpenMP depending on configuration)");
122  }
123 
125 
127 
128 
130  global_size_t getGlobalNumElements() const { return 0; }
131 
133  size_t getLocalNumElements() const { return 0; }
134 
136  GlobalOrdinal getIndexBase() const { return 0; }
137 
139  LocalOrdinal getMinLocalIndex() const { return 0; }
140 
142  LocalOrdinal getMaxLocalIndex() const { return 0; }
143 
145  GlobalOrdinal getMinGlobalIndex() const { return 0; }
146 
148  GlobalOrdinal getMaxGlobalIndex() const { return 0; }
149 
151  GlobalOrdinal getMinAllGlobalIndex() const { return 0; }
152 
154  GlobalOrdinal getMaxAllGlobalIndex() const { return 0; }
155 
157  LocalOrdinal getLocalElement(GlobalOrdinal /* globalIndex */) const { return 0; }
158 
160  LookupStatus getRemoteIndexList(const Teuchos::ArrayView<const GlobalOrdinal> & /* GIDList */, const Teuchos::ArrayView<int> & /* nodeIDList */, const Teuchos::ArrayView<LocalOrdinal> & /* LIDList */) const { return Xpetra::IDNotPresent; }
161 
163  LookupStatus getRemoteIndexList(const Teuchos::ArrayView<const GlobalOrdinal> & /* GIDList */, const Teuchos::ArrayView<int> & /* nodeIDList */) const { return Xpetra::IDNotPresent; }
164 
166  Teuchos::ArrayView<const GlobalOrdinal> getLocalElementList() const { return ArrayView<const GlobalOrdinal>(); }
167 
170 
172 
174 
175 
177  bool isNodeLocalElement(LocalOrdinal /* localIndex */) const { return false; }
178 
180  bool isNodeGlobalElement(GlobalOrdinal /* globalIndex */) const { return false; }
181 
183  bool isContiguous() const { return false; }
184 
186  bool isDistributed() const { return false; }
187 
189  bool isCompatible(const Map<LocalOrdinal, GlobalOrdinal, Node> & /* map */) const { return false; }
190 
192  bool isSameAs(const Map<LocalOrdinal, GlobalOrdinal, Node> & /* map */) const { return false; }
193 
195 
197 
198 
200  Teuchos::RCP<const Teuchos::Comm<int> > getComm() const { return Teuchos::null; }
201 
203 
205 
206 
208  std::string description() const { return std::string(""); }
209 
211  void describe(Teuchos::FancyOStream & /* out */, const Teuchos::EVerbosityLevel /* verbLevel */ = Teuchos::Describable::verbLevel_default) const {}
212 
214 
216 
217 
219  RCP<const Map<int, GlobalOrdinal, Node> > removeEmptyProcesses() const { return Teuchos::null; }
220 
222  RCP<const Map<int, GlobalOrdinal, Node> > replaceCommWithSubset(const Teuchos::RCP<const Teuchos::Comm<int> > & /* newComm */) const { return Teuchos::null; }
223 
225 
227  GlobalOrdinal getGlobalElement(LocalOrdinal /* localIndex */) const { return -1; }
228 
230 
231 
233  virtual ~EpetraMapT() {}
234 
236  EpetraMapT(const Teuchos::RCP<const Epetra_BlockMap> &map)
237  : map_(map) {
238  TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::RuntimeError,
239  "Xpetra::EpetraMap only available for GO=int or GO=long long with EpetraNode (Serial or OpenMP depending on configuration)");
240  }
241 
243  UnderlyingLib lib() const { return Xpetra::UseEpetra; }
244 
246  const RCP<const Epetra_Map> &getEpetra_MapRCP() const { return Teuchos::rcp_static_cast<const Epetra_Map>(map_); }
247  const Epetra_BlockMap &getEpetra_BlockMap() const { return *map_; }
248  const Epetra_Map &getEpetra_Map() const { return (Epetra_Map &)*map_; } // Ugly, but the same is done in Epetra_CrsMatrix.h to get the map.
249 
250 #ifdef HAVE_XPETRA_TPETRA
254  throw std::runtime_error("Xpetra::EpetraMap::getLocalMap is not implemented in " + std::string(__FILE__) + ":" + std::to_string(__LINE__));
255  }
256 #else
257 #ifdef __GNUC__
258 #warning "Xpetra Kokkos interface for CrsMatrix is enabled (HAVE_XPETRA_KOKKOS_REFACTOR) but Tpetra is disabled. The Kokkos interface needs Tpetra to be enabled, too."
259 #endif
260 #endif
261 
263 
264  protected:
265  RCP<const Epetra_BlockMap> map_;
266 }; // EpetraMapT class
267 
268 // specialization on GO=int and EpetraNode
269 #ifndef XPETRA_EPETRA_NO_32BIT_GLOBAL_INDICES
270 template <>
272  : public virtual Map<int, int, EpetraNode> {
273  typedef int LocalOrdinal;
274  typedef int GlobalOrdinal;
275  typedef EpetraNode Node;
276 
277  public:
280  typedef Node node_type;
282 
284 
285 
287  EpetraMapT(global_size_t numGlobalElements,
288  GlobalOrdinal indexBase,
289  const Teuchos::RCP<const Teuchos::Comm<int> > &comm,
291  // This test come from Tpetra (Epetra doesn't check if numGlobalElements,indexBase are equivalent across images).
292  // In addition, for the test TEST_THROW(M map((myImageID == 0 ? GSTI : 0),0,comm), std::invalid_argument), only one node throw an exception and there is a dead lock.
293  std::string errPrefix;
294  errPrefix = Teuchos::typeName(*this) + "::constructor(numGlobal,indexBase,comm,lOrG): ";
295 
296  if (lg == GloballyDistributed) {
297  const int myImageID = comm->getRank();
298 
299  // check that numGlobalElements,indexBase is equivalent across images
300  global_size_t rootNGE = numGlobalElements;
301  GlobalOrdinal rootIB = indexBase;
302  Teuchos::broadcast<int, global_size_t>(*comm, 0, &rootNGE);
303  Teuchos::broadcast<int, GlobalOrdinal>(*comm, 0, &rootIB);
304  int localChecks[2], globalChecks[2];
305  localChecks[0] = -1; // fail or pass
306  localChecks[1] = 0; // fail reason
307  if (numGlobalElements != rootNGE) {
308  localChecks[0] = myImageID;
309  localChecks[1] = 1;
310  } else if (indexBase != rootIB) {
311  localChecks[0] = myImageID;
312  localChecks[1] = 2;
313  }
314  // REDUCE_MAX will give us the image ID of the highest rank proc that DID NOT pass, as well as the reason
315  // these will be -1 and 0 if all procs passed
316  Teuchos::reduceAll<int, int>(*comm, Teuchos::REDUCE_MAX, 2, localChecks, globalChecks);
317  if (globalChecks[0] != -1) {
318  if (globalChecks[1] == 1) {
319  TEUCHOS_TEST_FOR_EXCEPTION(true, std::invalid_argument,
320  errPrefix << "numGlobal must be the same on all nodes (examine node " << globalChecks[0] << ").");
321  } else if (globalChecks[1] == 2) {
322  TEUCHOS_TEST_FOR_EXCEPTION(true, std::invalid_argument,
323  errPrefix << "indexBase must be the same on all nodes (examine node " << globalChecks[0] << ").");
324  } else {
325  // logic error on our part
326  TEUCHOS_TEST_FOR_EXCEPTION(true, std::logic_error,
327  errPrefix << "logic error. Please contact the Tpetra team.");
328  }
329  }
330  }
331 
332  // Note: validity of numGlobalElements checked by Epetra.
333 
334  IF_EPETRA_EXCEPTION_THEN_THROW_GLOBAL_INVALID_ARG((map_ = (rcp(new Epetra_BlockMap(static_cast<GlobalOrdinal>(numGlobalElements), 1, indexBase, *toEpetra(comm))))));
335  }
336 
338  EpetraMapT(global_size_t numGlobalElements, size_t numLocalElements, GlobalOrdinal indexBase, const Teuchos::RCP<const Teuchos::Comm<int> > &comm) {
339  // This test come from Tpetra
340  using Teuchos::outArg;
341 
342  const size_t L0 = Teuchos::OrdinalTraits<size_t>::zero();
343  const size_t L1 = Teuchos::OrdinalTraits<size_t>::one();
344  const global_size_t GST0 = Teuchos::OrdinalTraits<global_size_t>::zero();
345  const global_size_t GST1 = Teuchos::OrdinalTraits<global_size_t>::one();
346  const global_size_t GSTI = Teuchos::OrdinalTraits<global_size_t>::invalid();
347 
348  std::string errPrefix;
349  errPrefix = Teuchos::typeName(*this) + "::constructor(numGlobal,numLocal,indexBase,platform): ";
350 
351  // get a internodal communicator from the Platform
352  const int myImageID = comm->getRank();
353 
354  global_size_t global_sum;
355  { // begin scoping block
356  // for communicating failures
357  int localChecks[2], globalChecks[2];
358  /* compute the global size
359  we are computing the number of global elements because exactly ONE of the following is true:
360  - the user didn't specify it, and we need it
361  - the user did specify it, but we need to
362  + validate it against the sum of the local sizes, and
363  + ensure that it is the same on all nodes
364  */
365  Teuchos::reduceAll<int, global_size_t>(*comm, Teuchos::REDUCE_SUM,
366  Teuchos::as<global_size_t>(numLocalElements), outArg(global_sum));
367  /* there are three errors we should be detecting:
368  - numGlobalElements != invalid() and it is incorrect/invalid
369  - numLocalElements invalid (<0)
370  */
371  localChecks[0] = -1;
372  localChecks[1] = 0;
373  if (numLocalElements < L1 && numLocalElements != L0) {
374  // invalid
375  localChecks[0] = myImageID;
376  localChecks[1] = 1;
377  } else if (numGlobalElements < GST1 && numGlobalElements != GST0 && numGlobalElements != GSTI) {
378  // invalid
379  localChecks[0] = myImageID;
380  localChecks[1] = 2;
381  } else if (numGlobalElements != GSTI && numGlobalElements != global_sum) {
382  // incorrect
383  localChecks[0] = myImageID;
384  localChecks[1] = 3;
385  }
386  // now check that indexBase is equivalent across images
387  GlobalOrdinal rootIB = indexBase;
388  Teuchos::broadcast<int, GlobalOrdinal>(*comm, 0, &rootIB); // broadcast one ordinal from node 0
389  if (indexBase != rootIB) {
390  localChecks[0] = myImageID;
391  localChecks[1] = 4;
392  }
393  // REDUCE_MAX will give us the image ID of the highest rank proc that DID NOT pass
394  // this will be -1 if all procs passed
395  Teuchos::reduceAll<int, int>(*comm, Teuchos::REDUCE_MAX, 2, localChecks, globalChecks);
396  if (globalChecks[0] != -1) {
397  if (globalChecks[1] == 1) {
398  TEUCHOS_TEST_FOR_EXCEPTION(true, std::invalid_argument,
399  errPrefix << "numLocal is not valid on at least one node (possibly node "
400  << globalChecks[0] << ").");
401  } else if (globalChecks[1] == 2) {
402  TEUCHOS_TEST_FOR_EXCEPTION(true, std::invalid_argument,
403  errPrefix << "numGlobal is not valid on at least one node (possibly node "
404  << globalChecks[0] << ").");
405  } else if (globalChecks[1] == 3) {
406  TEUCHOS_TEST_FOR_EXCEPTION(true, std::invalid_argument,
407  errPrefix << "numGlobal doesn't match sum of numLocal (== "
408  << global_sum << ") on at least one node (possibly node "
409  << globalChecks[0] << ").");
410  } else if (globalChecks[1] == 4) {
411  TEUCHOS_TEST_FOR_EXCEPTION(true, std::invalid_argument,
412  errPrefix << "indexBase is not the same on all nodes (examine node "
413  << globalChecks[0] << ").");
414  } else {
415  // logic error on my part
416  TEUCHOS_TEST_FOR_EXCEPTION(true, std::logic_error,
417  errPrefix << "logic error. Please contact the Tpetra team.");
418  }
419  }
420  }
421 
422  // set numGlobalElements
423  if (numGlobalElements == GSTI) {
424  numGlobalElements = global_sum;
425  }
426 
427  IF_EPETRA_EXCEPTION_THEN_THROW_GLOBAL_INVALID_ARG((map_ = (rcp(new Epetra_BlockMap(static_cast<GlobalOrdinal>(numGlobalElements), static_cast<int>(numLocalElements), 1, indexBase, *toEpetra(comm))))));
428  }
429 
431  EpetraMapT(global_size_t numGlobalElements,
432  const Teuchos::ArrayView<const GlobalOrdinal> &elementList,
433  GlobalOrdinal indexBase,
434  const Teuchos::RCP<const Teuchos::Comm<int> > &comm) {
435  if (numGlobalElements == Teuchos::OrdinalTraits<global_size_t>::invalid()) {
436  IF_EPETRA_EXCEPTION_THEN_THROW_GLOBAL_INVALID_ARG((map_ = (rcp(new Epetra_BlockMap(-1, static_cast<int>(elementList.size()), elementList.getRawPtr(), 1, indexBase, *toEpetra(comm))))));
437  } else {
438  IF_EPETRA_EXCEPTION_THEN_THROW_GLOBAL_INVALID_ARG((map_ = (rcp(new Epetra_BlockMap(static_cast<int>(numGlobalElements), static_cast<int>(elementList.size()), elementList.getRawPtr(), 1, indexBase, *toEpetra(comm))))));
439  }
440  }
441 
443 
445 
446 
449  XPETRA_MONITOR("EpetraMapT::getGlobalNumElements");
450  return map_->NumGlobalElements64();
451  }
452 
454  size_t getLocalNumElements() const {
455  XPETRA_MONITOR("EpetraMapT::getLocalNumElements");
456  return map_->NumMyElements();
457  }
458 
461  XPETRA_MONITOR("EpetraMapT::getIndexBase");
462  return (GlobalOrdinal)map_->IndexBase64();
463  }
464 
467  XPETRA_MONITOR("EpetraMapT::getMinLocalIndex");
468  return map_->MinLID();
469  }
470 
473  XPETRA_MONITOR("EpetraMapT::getMaxLocalIndex");
474  return map_->MaxLID();
475  }
476 
479  XPETRA_MONITOR("EpetraMapT::getMinGlobalIndex");
480  return (GlobalOrdinal)map_->MinMyGID64();
481  }
482 
485  XPETRA_MONITOR("EpetraMapT::getMaxGlobalIndex");
486  return (GlobalOrdinal)map_->MaxMyGID64();
487  }
488 
491  XPETRA_MONITOR("EpetraMapT::getMinAllGlobalIndex");
492  return (GlobalOrdinal)map_->MinAllGID64();
493  }
494 
497  XPETRA_MONITOR("EpetraMapT::getMaxAllGlobalIndex");
498  return (GlobalOrdinal)map_->MaxAllGID64();
499  }
500 
503  XPETRA_MONITOR("EpetraMapT::getLocalElement");
504  return map_->LID(globalIndex);
505  }
506 
508  LookupStatus getRemoteIndexList(const Teuchos::ArrayView<const GlobalOrdinal> &GIDList,
509  const Teuchos::ArrayView<int> &nodeIDList,
510  const Teuchos::ArrayView<LocalOrdinal> &LIDList) const {
511  XPETRA_MONITOR("EpetraMapT::getRemoteIndexList");
512  return toXpetra(map_->RemoteIDList(static_cast<int>(GIDList.size()), GIDList.getRawPtr(), nodeIDList.getRawPtr(), LIDList.getRawPtr()));
513  }
514 
516  LookupStatus getRemoteIndexList(const Teuchos::ArrayView<const GlobalOrdinal> &GIDList,
517  const Teuchos::ArrayView<int> &nodeIDList) const {
518  XPETRA_MONITOR("EpetraMapT::getRemoteIndexList");
519  return toXpetra(map_->RemoteIDList(static_cast<int>(GIDList.size()), GIDList.getRawPtr(), nodeIDList.getRawPtr(), 0));
520  }
521 
523  Teuchos::ArrayView<const GlobalOrdinal> getLocalElementList() const {
524  XPETRA_MONITOR("EpetraMapT::getLocalElementList");
525  return ArrayView<const int>(map_->MyGlobalElements(), map_->NumMyElements());
526  }
527 
530  XPETRA_MONITOR("EpetraMapT::getMyGlobalIndicesDevice");
531  Teuchos::ArrayView<const GlobalOrdinal> view = getLocalElementList();
532  if (view.size() == 0)
534  else
535  return Kokkos::View<const global_ordinal_type *, typename Node::device_type, Kokkos::MemoryUnmanaged>(view.data(), view.size());
536  }
537 
539 
541 
542 
544  bool isNodeLocalElement(LocalOrdinal localIndex) const {
545  XPETRA_MONITOR("EpetraMapT::isNodeLocalElement");
546  return map_->MyLID(localIndex);
547  }
548 
550  bool isNodeGlobalElement(GlobalOrdinal globalIndex) const {
551  XPETRA_MONITOR("EpetraMapT::isNodeGlobalElement");
552  return map_->MyGID(globalIndex);
553  }
554 
556  bool isContiguous() const {
557  XPETRA_MONITOR("EpetraMapT::isContiguous");
558  return map_->LinearMap();
559  }
560 
562  bool isDistributed() const {
563  XPETRA_MONITOR("EpetraMapT::isDistributed");
564  return map_->DistributedGlobal();
565  }
566 
569  XPETRA_MONITOR("EpetraMapT::isCompatible");
570  return map_->PointSameAs(toEpetra<GlobalOrdinal, Node>(map));
571  }
572 
575  XPETRA_MONITOR("EpetraMapT::isSameAs");
576  return map_->SameAs(toEpetra<GlobalOrdinal, Node>(map));
577  }
578 
580 
582 
583 
585  Teuchos::RCP<const Teuchos::Comm<int> > getComm() const {
586  XPETRA_MONITOR("EpetraMapT::getComm");
587  return toXpetra(map_->Comm());
588  }
589 
591 
593 
594 
596  std::string description() const {
597  XPETRA_MONITOR("EpetraMapT::description");
598 
599  // This implementation come from Tpetra_Map_def.hpp (without modification)
600  std::ostringstream oss;
601  oss << Teuchos::Describable::description();
602  oss << "{getGlobalNumElements() = " << getGlobalNumElements()
603  << ", getLocalNumElements() = " << getLocalNumElements()
604  << ", isContiguous() = " << isContiguous()
605  << ", isDistributed() = " << isDistributed()
606  << "}";
607  return oss.str();
608  }
609 
611  void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel = Teuchos::Describable::verbLevel_default) const {
612  XPETRA_MONITOR("EpetraMapT::describe");
613 
614  const Teuchos::RCP<const Teuchos::Comm<int> > comm_ = getComm();
615 
616  // This implementation come from Tpetra_Map_def.hpp (without modification)
617  using std::endl;
618  using std::setw;
619  using Teuchos::VERB_DEFAULT;
620  using Teuchos::VERB_EXTREME;
621  using Teuchos::VERB_HIGH;
622  using Teuchos::VERB_LOW;
623  using Teuchos::VERB_MEDIUM;
624  using Teuchos::VERB_NONE;
625 
626  const size_t nME = getLocalNumElements();
627  Teuchos::ArrayView<const GlobalOrdinal> myEntries = getLocalElementList();
628  int myImageID = comm_->getRank();
629  int numImages = comm_->getSize();
630 
631  Teuchos::EVerbosityLevel vl = verbLevel;
632  if (vl == VERB_DEFAULT) vl = VERB_LOW;
633 
634  size_t width = 1;
635  for (size_t dec = 10; dec < getGlobalNumElements(); dec *= 10) {
636  ++width;
637  }
638  width = ::std::max<size_t>(width, (size_t)12) + 2; // casting to size_t to avoid ambiguity error when compiling Sacado.
639 
640  Teuchos::OSTab tab(out);
641 
642  if (vl == VERB_NONE) {
643  // do nothing
644  } else if (vl == VERB_LOW) {
645  out << this->description() << endl;
646  } else { // MEDIUM, HIGH or EXTREME
647  for (int imageCtr = 0; imageCtr < numImages; ++imageCtr) {
648  if (myImageID == imageCtr) {
649  if (myImageID == 0) { // this is the root node (only output this info once)
650  out << endl
651  << "Number of Global Entries = " << getGlobalNumElements() << endl
652  << "Maximum of all GIDs = " << getMaxAllGlobalIndex() << endl
653  << "Minimum of all GIDs = " << getMinAllGlobalIndex() << endl
654  << "Index Base = " << getIndexBase() << endl;
655  }
656  out << endl;
657  if (vl == VERB_HIGH || vl == VERB_EXTREME) {
658  out << "Number of Local Elements = " << nME << endl
659  << "Maximum of my GIDs = " << getMaxGlobalIndex() << endl
660  << "Minimum of my GIDs = " << getMinGlobalIndex() << endl;
661  out << endl;
662  }
663  if (vl == VERB_EXTREME) {
664  out << std::setw(width) << "Node ID"
665  << std::setw(width) << "Local Index"
666  << std::setw(width) << "Global Index"
667  << endl;
668  for (size_t i = 0; i < nME; i++) {
669  out << std::setw(width) << myImageID
670  << std::setw(width) << i
671  << std::setw(width) << myEntries[i]
672  << endl;
673  }
674  out << std::flush;
675  }
676  }
677  // Do a few global ops to give I/O a chance to complete
678  comm_->barrier();
679  comm_->barrier();
680  comm_->barrier();
681  }
682  }
683  }
684 
686 
688 
689 
691  RCP<const Map<int, GlobalOrdinal, Node> > removeEmptyProcesses() const {
692  const Epetra_BlockMap *NewMap = map_->RemoveEmptyProcesses();
693  if (!NewMap) {
694  return Teuchos::null;
695  } else {
696  const RCP<const Map<int, GlobalOrdinal, Node> > NewMapX = toXpetra<GlobalOrdinal, Node>(*NewMap);
697  delete NewMap; // NOTE: toXpetra *copys* the epetra map rather than wrapping it, so we have to delete NewMap to avoid a memory leak.
698  return NewMapX;
699  }
700  }
701 
703  RCP<const Map<int, GlobalOrdinal, Node> > replaceCommWithSubset(const Teuchos::RCP<const Teuchos::Comm<int> > & /* newComm */) const {
704  throw std::runtime_error("Xpetra::EpetraMapT::replaceCommWithSubset has not yet been implemented in " + std::string(__FILE__) + ":" + std::to_string(__LINE__));
705  TEUCHOS_UNREACHABLE_RETURN(Teuchos::null);
706  }
707 
709 
712  XPETRA_MONITOR("EpetraMapT::getGlobalElement");
713 
714  GlobalOrdinal gid = (GlobalOrdinal)map_->GID64(localIndex);
715  if (gid == map_->IndexBase64() - 1)
716  return (-1);
717  else
718  return (gid);
719  }
720 
722 
723 
725  virtual ~EpetraMapT() {}
726 
728  EpetraMapT(const Teuchos::RCP<const Epetra_BlockMap> &map)
729  : map_(map) {
730  TEUCHOS_TEST_FOR_EXCEPTION(!map->GlobalIndicesIsType<GlobalOrdinal>(), std::runtime_error, "Xpetra::EpetraMapT: GlobalOrdinal mismatch.");
731  }
732 
734  UnderlyingLib lib() const { return Xpetra::UseEpetra; }
735 
737  const RCP<const Epetra_Map> getEpetra_MapRCP() const { return Teuchos::rcp_static_cast<const Epetra_Map>(map_); }
738  const Epetra_BlockMap &getEpetra_BlockMap() const { return *map_; }
739  const Epetra_Map &getEpetra_Map() const { return (Epetra_Map &)*map_; } // Ugly, but the same is done in Epetra_CrsMatrix.h to get the map.
740 
742 
743 #ifdef HAVE_XPETRA_TPETRA
747  throw std::runtime_error("Xpetra::EpetraMap::getLocalMap is not implemented in " + std::string(__FILE__) + ":" + std::to_string(__LINE__));
748  }
749 
750  private:
752 #else
753 #ifdef __GNUC__
754 #warning "Xpetra Kokkos interface for CrsMatrix is enabled (HAVE_XPETRA_KOKKOS_REFACTOR) but Tpetra is disabled. The Kokkos interface needs Tpetra to be enabled, too."
755 #endif
756 #endif
757 
758  protected:
759  RCP<const Epetra_BlockMap> map_;
760 }; // EpetraMapT class
761 #endif // #ifndef XPETRA_EPETRA_NO_32BIT_GLOBAL_INDICES
762 
763 // specialization on GO=long long and EpetraNode
764 #ifndef XPETRA_EPETRA_NO_64BIT_GLOBAL_INDICES
765 template <>
766 class EpetraMapT<long long, EpetraNode>
767  : public virtual Map<int, long long, EpetraNode> {
768  typedef int LocalOrdinal;
769  typedef long long GlobalOrdinal;
770  typedef EpetraNode Node;
771 
772  public:
775  typedef Node node_type;
777 
779 
780 
782  EpetraMapT(global_size_t numGlobalElements,
783  GlobalOrdinal indexBase,
784  const Teuchos::RCP<const Teuchos::Comm<int> > &comm,
786  // This test come from Tpetra (Epetra doesn't check if numGlobalElements,indexBase are equivalent across images).
787  // In addition, for the test TEST_THROW(M map((myImageID == 0 ? GSTI : 0),0,comm), std::invalid_argument), only one node throw an exception and there is a dead lock.
788  std::string errPrefix;
789  errPrefix = Teuchos::typeName(*this) + "::constructor(numGlobal,indexBase,comm,lOrG): ";
790 
791  if (lg == GloballyDistributed) {
792  const int myImageID = comm->getRank();
793 
794  // check that numGlobalElements,indexBase is equivalent across images
795  global_size_t rootNGE = numGlobalElements;
796  GlobalOrdinal rootIB = indexBase;
797  Teuchos::broadcast<int, global_size_t>(*comm, 0, &rootNGE);
798  Teuchos::broadcast<int, GlobalOrdinal>(*comm, 0, &rootIB);
799  int localChecks[2], globalChecks[2];
800  localChecks[0] = -1; // fail or pass
801  localChecks[1] = 0; // fail reason
802  if (numGlobalElements != rootNGE) {
803  localChecks[0] = myImageID;
804  localChecks[1] = 1;
805  } else if (indexBase != rootIB) {
806  localChecks[0] = myImageID;
807  localChecks[1] = 2;
808  }
809  // REDUCE_MAX will give us the image ID of the highest rank proc that DID NOT pass, as well as the reason
810  // these will be -1 and 0 if all procs passed
811  Teuchos::reduceAll<int, int>(*comm, Teuchos::REDUCE_MAX, 2, localChecks, globalChecks);
812  if (globalChecks[0] != -1) {
813  if (globalChecks[1] == 1) {
814  TEUCHOS_TEST_FOR_EXCEPTION(true, std::invalid_argument,
815  errPrefix << "numGlobal must be the same on all nodes (examine node " << globalChecks[0] << ").");
816  } else if (globalChecks[1] == 2) {
817  TEUCHOS_TEST_FOR_EXCEPTION(true, std::invalid_argument,
818  errPrefix << "indexBase must be the same on all nodes (examine node " << globalChecks[0] << ").");
819  } else {
820  // logic error on our part
821  TEUCHOS_TEST_FOR_EXCEPTION(true, std::logic_error,
822  errPrefix << "logic error. Please contact the Tpetra team.");
823  }
824  }
825  }
826 
827  // Note: validity of numGlobalElements checked by Epetra.
828 
829  IF_EPETRA_EXCEPTION_THEN_THROW_GLOBAL_INVALID_ARG((map_ = (rcp(new Epetra_BlockMap(static_cast<GlobalOrdinal>(numGlobalElements), 1, indexBase, *toEpetra(comm))))));
830  }
831 
833  EpetraMapT(global_size_t numGlobalElements, size_t numLocalElements, GlobalOrdinal indexBase, const Teuchos::RCP<const Teuchos::Comm<int> > &comm) {
834  // This test come from Tpetra
835  using Teuchos::outArg;
836 
837  const size_t L0 = Teuchos::OrdinalTraits<size_t>::zero();
838  const size_t L1 = Teuchos::OrdinalTraits<size_t>::one();
839  const global_size_t GST0 = Teuchos::OrdinalTraits<global_size_t>::zero();
840  const global_size_t GST1 = Teuchos::OrdinalTraits<global_size_t>::one();
841  const global_size_t GSTI = Teuchos::OrdinalTraits<global_size_t>::invalid();
842 
843  std::string errPrefix;
844  errPrefix = Teuchos::typeName(*this) + "::constructor(numGlobal,numLocal,indexBase,platform): ";
845 
846  // get a internodal communicator from the Platform
847  const int myImageID = comm->getRank();
848 
849  global_size_t global_sum;
850  { // begin scoping block
851  // for communicating failures
852  int localChecks[2], globalChecks[2];
853  /* compute the global size
854  we are computing the number of global elements because exactly ONE of the following is true:
855  - the user didn't specify it, and we need it
856  - the user did specify it, but we need to
857  + validate it against the sum of the local sizes, and
858  + ensure that it is the same on all nodes
859  */
860  Teuchos::reduceAll<int, global_size_t>(*comm, Teuchos::REDUCE_SUM,
861  Teuchos::as<global_size_t>(numLocalElements), outArg(global_sum));
862  /* there are three errors we should be detecting:
863  - numGlobalElements != invalid() and it is incorrect/invalid
864  - numLocalElements invalid (<0)
865  */
866  localChecks[0] = -1;
867  localChecks[1] = 0;
868  if (numLocalElements < L1 && numLocalElements != L0) {
869  // invalid
870  localChecks[0] = myImageID;
871  localChecks[1] = 1;
872  } else if (numGlobalElements < GST1 && numGlobalElements != GST0 && numGlobalElements != GSTI) {
873  // invalid
874  localChecks[0] = myImageID;
875  localChecks[1] = 2;
876  } else if (numGlobalElements != GSTI && numGlobalElements != global_sum) {
877  // incorrect
878  localChecks[0] = myImageID;
879  localChecks[1] = 3;
880  }
881  // now check that indexBase is equivalent across images
882  GlobalOrdinal rootIB = indexBase;
883  Teuchos::broadcast<int, GlobalOrdinal>(*comm, 0, &rootIB); // broadcast one ordinal from node 0
884  if (indexBase != rootIB) {
885  localChecks[0] = myImageID;
886  localChecks[1] = 4;
887  }
888  // REDUCE_MAX will give us the image ID of the highest rank proc that DID NOT pass
889  // this will be -1 if all procs passed
890  Teuchos::reduceAll<int, int>(*comm, Teuchos::REDUCE_MAX, 2, localChecks, globalChecks);
891  if (globalChecks[0] != -1) {
892  if (globalChecks[1] == 1) {
893  TEUCHOS_TEST_FOR_EXCEPTION(true, std::invalid_argument,
894  errPrefix << "numLocal is not valid on at least one node (possibly node "
895  << globalChecks[0] << ").");
896  } else if (globalChecks[1] == 2) {
897  TEUCHOS_TEST_FOR_EXCEPTION(true, std::invalid_argument,
898  errPrefix << "numGlobal is not valid on at least one node (possibly node "
899  << globalChecks[0] << ").");
900  } else if (globalChecks[1] == 3) {
901  TEUCHOS_TEST_FOR_EXCEPTION(true, std::invalid_argument,
902  errPrefix << "numGlobal doesn't match sum of numLocal (== "
903  << global_sum << ") on at least one node (possibly node "
904  << globalChecks[0] << ").");
905  } else if (globalChecks[1] == 4) {
906  TEUCHOS_TEST_FOR_EXCEPTION(true, std::invalid_argument,
907  errPrefix << "indexBase is not the same on all nodes (examine node "
908  << globalChecks[0] << ").");
909  } else {
910  // logic error on my part
911  TEUCHOS_TEST_FOR_EXCEPTION(true, std::logic_error,
912  errPrefix << "logic error. Please contact the Tpetra team.");
913  }
914  }
915  }
916 
917  // set numGlobalElements
918  if (numGlobalElements == GSTI) {
919  numGlobalElements = global_sum;
920  }
921 
922  IF_EPETRA_EXCEPTION_THEN_THROW_GLOBAL_INVALID_ARG((map_ = (rcp(new Epetra_BlockMap(static_cast<GlobalOrdinal>(numGlobalElements), numLocalElements, 1, indexBase, *toEpetra(comm))))));
923  }
924 
926  EpetraMapT(global_size_t numGlobalElements,
927  const Teuchos::ArrayView<const GlobalOrdinal> &elementList,
928  GlobalOrdinal indexBase,
929  const Teuchos::RCP<const Teuchos::Comm<int> > &comm) {
930  if (numGlobalElements == Teuchos::OrdinalTraits<global_size_t>::invalid()) {
931  IF_EPETRA_EXCEPTION_THEN_THROW_GLOBAL_INVALID_ARG((map_ = (rcp(new Epetra_BlockMap(-1, elementList.size(), elementList.getRawPtr(), 1, indexBase, *toEpetra(comm))))));
932  } else {
933  IF_EPETRA_EXCEPTION_THEN_THROW_GLOBAL_INVALID_ARG((map_ = (rcp(new Epetra_BlockMap(numGlobalElements, elementList.size(), elementList.getRawPtr(), 1, indexBase, *toEpetra(comm))))));
934  }
935  }
936 
938 
940 
941 
944  XPETRA_MONITOR("EpetraMapT::getGlobalNumElements");
945  return map_->NumGlobalElements64();
946  }
947 
949  size_t getLocalNumElements() const {
950  XPETRA_MONITOR("EpetraMapT::getLocalNumElements");
951  return map_->NumMyElements();
952  }
953 
956  XPETRA_MONITOR("EpetraMapT::getIndexBase");
957  return (GlobalOrdinal)map_->IndexBase64();
958  }
959 
962  XPETRA_MONITOR("EpetraMapT::getMinLocalIndex");
963  return map_->MinLID();
964  }
965 
968  XPETRA_MONITOR("EpetraMapT::getMaxLocalIndex");
969  return map_->MaxLID();
970  }
971 
974  XPETRA_MONITOR("EpetraMapT::getMinGlobalIndex");
975  return (GlobalOrdinal)map_->MinMyGID64();
976  }
977 
980  XPETRA_MONITOR("EpetraMapT::getMaxGlobalIndex");
981  return (GlobalOrdinal)map_->MaxMyGID64();
982  }
983 
986  XPETRA_MONITOR("EpetraMapT::getMinAllGlobalIndex");
987  return (GlobalOrdinal)map_->MinAllGID64();
988  }
989 
992  XPETRA_MONITOR("EpetraMapT::getMaxAllGlobalIndex");
993  return (GlobalOrdinal)map_->MaxAllGID64();
994  }
995 
998  XPETRA_MONITOR("EpetraMapT::getLocalElement");
999  return map_->LID(globalIndex);
1000  }
1001 
1003  LookupStatus getRemoteIndexList(const Teuchos::ArrayView<const GlobalOrdinal> &GIDList, const Teuchos::ArrayView<int> &nodeIDList, const Teuchos::ArrayView<LocalOrdinal> &LIDList) const {
1004  XPETRA_MONITOR("EpetraMapT::getRemoteIndexList");
1005  return toXpetra(map_->RemoteIDList(GIDList.size(), GIDList.getRawPtr(), nodeIDList.getRawPtr(), LIDList.getRawPtr()));
1006  }
1007 
1009  LookupStatus getRemoteIndexList(const Teuchos::ArrayView<const GlobalOrdinal> &GIDList, const Teuchos::ArrayView<int> &nodeIDList) const {
1010  XPETRA_MONITOR("EpetraMapT::getRemoteIndexList");
1011  return toXpetra(map_->RemoteIDList(GIDList.size(), GIDList.getRawPtr(), nodeIDList.getRawPtr(), 0));
1012  }
1013 
1015  Teuchos::ArrayView<const GlobalOrdinal> getLocalElementList() const {
1016  XPETRA_MONITOR("EpetraMapT::getLocalElementList");
1017  return ArrayView<const long long>(map_->MyGlobalElements64(), map_->NumMyElements());
1018  }
1019 
1022  XPETRA_MONITOR("EpetraMapT::getMyGlobalIndicesDevice");
1023  Teuchos::ArrayView<const GlobalOrdinal> view = getLocalElementList();
1024  if (view.size() == 0)
1026  else
1027  return Kokkos::View<const global_ordinal_type *, typename Node::device_type, Kokkos::MemoryUnmanaged>(view.data(), view.size());
1028  }
1029 
1031 
1033 
1034 
1036  bool isNodeLocalElement(LocalOrdinal localIndex) const {
1037  XPETRA_MONITOR("EpetraMapT::isNodeLocalElement");
1038  return map_->MyLID(localIndex);
1039  }
1040 
1042  bool isNodeGlobalElement(GlobalOrdinal globalIndex) const {
1043  XPETRA_MONITOR("EpetraMapT::isNodeGlobalElement");
1044  return map_->MyGID(globalIndex);
1045  }
1046 
1048  bool isContiguous() const {
1049  XPETRA_MONITOR("EpetraMapT::isContiguous");
1050  return map_->LinearMap();
1051  }
1052 
1054  bool isDistributed() const {
1055  XPETRA_MONITOR("EpetraMapT::isDistributed");
1056  return map_->DistributedGlobal();
1057  }
1058 
1061  XPETRA_MONITOR("EpetraMapT::isCompatible");
1062  return map_->PointSameAs(toEpetra<GlobalOrdinal, Node>(map));
1063  }
1064 
1067  XPETRA_MONITOR("EpetraMapT::isSameAs");
1068  return map_->SameAs(toEpetra<GlobalOrdinal, Node>(map));
1069  }
1070 
1072 
1074 
1075 
1077  Teuchos::RCP<const Teuchos::Comm<int> > getComm() const {
1078  XPETRA_MONITOR("EpetraMapT::getComm");
1079  return toXpetra(map_->Comm());
1080  }
1081 
1083 
1085 
1086 
1088  std::string description() const {
1089  XPETRA_MONITOR("EpetraMapT::description");
1090 
1091  // This implementation come from Tpetra_Map_def.hpp (without modification)
1092  std::ostringstream oss;
1093  oss << Teuchos::Describable::description();
1094  oss << "{getGlobalNumElements() = " << getGlobalNumElements()
1095  << ", getLocalNumElements() = " << getLocalNumElements()
1096  << ", isContiguous() = " << isContiguous()
1097  << ", isDistributed() = " << isDistributed()
1098  << "}";
1099  return oss.str();
1100  }
1101 
1103  void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel = Teuchos::Describable::verbLevel_default) const {
1104  XPETRA_MONITOR("EpetraMapT::describe");
1105 
1106  const Teuchos::RCP<const Teuchos::Comm<int> > comm_ = getComm();
1107 
1108  // This implementation come from Tpetra_Map_def.hpp (without modification)
1109  using std::endl;
1110  using std::setw;
1111  using Teuchos::VERB_DEFAULT;
1112  using Teuchos::VERB_EXTREME;
1113  using Teuchos::VERB_HIGH;
1114  using Teuchos::VERB_LOW;
1115  using Teuchos::VERB_MEDIUM;
1116  using Teuchos::VERB_NONE;
1117 
1118  const size_t nME = getLocalNumElements();
1119  Teuchos::ArrayView<const GlobalOrdinal> myEntries = getLocalElementList();
1120  int myImageID = comm_->getRank();
1121  int numImages = comm_->getSize();
1122 
1123  Teuchos::EVerbosityLevel vl = verbLevel;
1124  if (vl == VERB_DEFAULT) vl = VERB_LOW;
1125 
1126  size_t width = 1;
1127  for (size_t dec = 10; dec < getGlobalNumElements(); dec *= 10) {
1128  ++width;
1129  }
1130  width = ::std::max<size_t>(width, (size_t)12) + 2; // casting to size_t to avoid ambiguity error when compiling Sacado.
1131 
1132  Teuchos::OSTab tab(out);
1133 
1134  if (vl == VERB_NONE) {
1135  // do nothing
1136  } else if (vl == VERB_LOW) {
1137  out << this->description() << endl;
1138  } else { // MEDIUM, HIGH or EXTREME
1139  for (int imageCtr = 0; imageCtr < numImages; ++imageCtr) {
1140  if (myImageID == imageCtr) {
1141  if (myImageID == 0) { // this is the root node (only output this info once)
1142  out << endl
1143  << "Number of Global Entries = " << getGlobalNumElements() << endl
1144  << "Maximum of all GIDs = " << getMaxAllGlobalIndex() << endl
1145  << "Minimum of all GIDs = " << getMinAllGlobalIndex() << endl
1146  << "Index Base = " << getIndexBase() << endl;
1147  }
1148  out << endl;
1149  if (vl == VERB_HIGH || vl == VERB_EXTREME) {
1150  out << "Number of Local Elements = " << nME << endl
1151  << "Maximum of my GIDs = " << getMaxGlobalIndex() << endl
1152  << "Minimum of my GIDs = " << getMinGlobalIndex() << endl;
1153  out << endl;
1154  }
1155  if (vl == VERB_EXTREME) {
1156  out << std::setw(width) << "Node ID"
1157  << std::setw(width) << "Local Index"
1158  << std::setw(width) << "Global Index"
1159  << endl;
1160  for (size_t i = 0; i < nME; i++) {
1161  out << std::setw(width) << myImageID
1162  << std::setw(width) << i
1163  << std::setw(width) << myEntries[i]
1164  << endl;
1165  }
1166  out << std::flush;
1167  }
1168  }
1169  // Do a few global ops to give I/O a chance to complete
1170  comm_->barrier();
1171  comm_->barrier();
1172  comm_->barrier();
1173  }
1174  }
1175  }
1176 
1178 
1180 
1181 
1183  RCP<const Map<int, GlobalOrdinal, Node> > removeEmptyProcesses() const {
1184  const Epetra_BlockMap *NewMap = map_->RemoveEmptyProcesses();
1185  if (!NewMap) {
1186  return Teuchos::null;
1187  } else {
1188  const RCP<const Map<int, GlobalOrdinal, Node> > NewMapX = toXpetra<GlobalOrdinal, Node>(*NewMap);
1189  delete NewMap; // NOTE: toXpetra *copys* the epetra map rather than wrapping it, so we have to delete NewMap to avoid a memory leak.
1190  return NewMapX;
1191  }
1192  }
1193 
1195  RCP<const Map<int, GlobalOrdinal, Node> > replaceCommWithSubset(const Teuchos::RCP<const Teuchos::Comm<int> > & /* newComm */) const {
1196  throw std::runtime_error("Xpetra::EpetraMapT::replaceCommWithSubset has not yet been implemented in " + std::string(__FILE__) + ":" + std::to_string(__LINE__));
1197  // return Teuchos::null; // unreachable
1198  }
1199 
1201 
1204  XPETRA_MONITOR("EpetraMapT::getGlobalElement");
1205 
1206  GlobalOrdinal gid = (GlobalOrdinal)map_->GID64(localIndex);
1207  if (gid == map_->IndexBase64() - 1)
1208  return (-1);
1209  else
1210  return (gid);
1211  }
1212 
1214 
1215 
1217  virtual ~EpetraMapT() {}
1218 
1220  EpetraMapT(const Teuchos::RCP<const Epetra_BlockMap> &map)
1221  : map_(map) {
1222  TEUCHOS_TEST_FOR_EXCEPTION(!map->GlobalIndicesIsType<GlobalOrdinal>(), std::runtime_error, "Xpetra::EpetraMapT: GlobalOrdinal mismatch.");
1223  }
1224 
1227 
1229  const RCP<const Epetra_Map> &getEpetra_MapRCP() const { return Teuchos::rcp_static_cast<const Epetra_Map>(map_); }
1230  const Epetra_BlockMap &getEpetra_BlockMap() const { return *map_; }
1231  const Epetra_Map &getEpetra_Map() const { return (Epetra_Map &)*map_; } // Ugly, but the same is done in Epetra_CrsMatrix.h to get the map.
1232 
1233 #ifdef HAVE_XPETRA_TPETRA
1237  throw std::runtime_error("Xpetra::EpetraMap::getLocalMap is not implemented in " + std::string(__FILE__) + ":" + std::to_string(__LINE__));
1238  }
1239 
1240  private:
1242 #else
1243 #ifdef __GNUC__
1244 #warning "Xpetra Kokkos interface for CrsMatrix is enabled (HAVE_XPETRA_KOKKOS_REFACTOR) but Tpetra is disabled. The Kokkos interface needs Tpetra to be enabled, too."
1245 #endif
1246 #endif
1247 
1249 
1250  protected:
1251  RCP<const Epetra_BlockMap> map_;
1252 }; // EpetraMapT class
1253 #endif // #ifndef XPETRA_EPETRA_NO_64BIT_GLOBAL_INDICES
1254 
1255 } // namespace Xpetra
1256 
1257 #endif // XPETRA_EPETRAMAP_HPP
Map< LocalOrdinal, GlobalOrdinal, Node >::global_indices_array_device_type global_indices_array_device_type
bool isDistributed() const
Whether this Map is globally distributed or locally replicated.
LookupStatus getRemoteIndexList(const Teuchos::ArrayView< const GlobalOrdinal > &GIDList, const Teuchos::ArrayView< int > &nodeIDList) const
Return the process ranks for the given global indices.
GlobalOrdinal global_ordinal_type
GlobalOrdinal getIndexBase() const
The index base for this Map.
GlobalOrdinal getIndexBase() const
The index base for this Map.
std::string description() const
Return a simple one-line description of this object.
bool isDistributed() const
Whether this Map is globally distributed or locally replicated.
void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const
Print this object with the given verbosity level to the given Teuchos::FancyOStream.
typename Map< LocalOrdinal, GlobalOrdinal, Node >::local_map_type local_map_type
const RCP< const Epetra_Map > & getEpetra_MapRCP() const
Get the underlying Epetra map.
bool isNodeGlobalElement(GlobalOrdinal globalIndex) const
Whether the given global index is valid for this Map on this process.
Tpetra::Map< LocalOrdinal, GlobalOrdinal, Node >::local_map_type local_map_type
const Epetra_BlockMap & getEpetra_BlockMap() const
GlobalOrdinal getMaxGlobalIndex() const
The maximum global index owned by the calling process.
GlobalOrdinal getMinGlobalIndex() const
The minimum global index owned by the calling process.
GlobalOrdinal getMinGlobalIndex() const
The minimum global index owned by the calling process.
Teuchos::ArrayView< const GlobalOrdinal > getLocalElementList() const
Return a view of the global indices owned by this process.
Teuchos::RCP< const Teuchos::Comm< int > > getComm() const
Get this Map&#39;s Comm object.
EpetraMapT(const Teuchos::RCP< const Epetra_BlockMap > &map)
EpetraMapT constructor to wrap a Epetra_Map object.
GlobalOrdinal getMinAllGlobalIndex() const
The minimum global index over all processes in the communicator.
std::string description() const
Return a simple one-line description of this object.
UnderlyingLib lib() const
Get the library used by this object (Epetra or Epetra?)
GlobalOrdinal getIndexBase() const
The index base for this Map.
bool isContiguous() const
True if this Map is distributed contiguously, else false.
LocalOrdinal getMaxLocalIndex() const
The maximum local index on the calling process.
const Epetra_BlockMap & getEpetra_BlockMap() const
GlobalOrdinal getMaxAllGlobalIndex() const
The maximum global index over all processes in the communicator.
LocalOrdinal getMaxLocalIndex() const
The maximum local index on the calling process.
Exception throws to report errors in the internal logical of the program.
bool isSameAs(const Map< LocalOrdinal, GlobalOrdinal, Node > &map) const
True if and only if map is identical to this Map.
bool isContiguous() const
True if this Map is distributed contiguously, else false.
UnderlyingLib lib() const
Get the library used by this object (Epetra or Epetra?)
GlobalOrdinal getMinAllGlobalIndex() const
The minimum global index over all processes in the communicator.
bool isNodeGlobalElement(GlobalOrdinal) const
Whether the given global index is valid for this Map on this process.
EpetraMapT(const Teuchos::RCP< const Epetra_BlockMap > &map)
EpetraMapT constructor to wrap a Epetra_Map object.
bool isNodeGlobalElement(GlobalOrdinal globalIndex) const
Whether the given global index is valid for this Map on this process.
LookupStatus getRemoteIndexList(const Teuchos::ArrayView< const GlobalOrdinal > &GIDList, const Teuchos::ArrayView< int > &nodeIDList) const
Return the process ranks for the given global indices.
LocalOrdinal getMaxLocalIndex() const
The maximum local index on the calling process.
LocalOrdinal getMinLocalIndex() const
The minimum local index.
Teuchos::ArrayView< const GlobalOrdinal > getLocalElementList() const
Return a view of the global indices owned by this process.
LookupStatus getRemoteIndexList(const Teuchos::ArrayView< const GlobalOrdinal > &GIDList, const Teuchos::ArrayView< int > &nodeIDList, const Teuchos::ArrayView< LocalOrdinal > &LIDList) const
Return the process ranks and corresponding local indices for the given global indices.
void describe(Teuchos::FancyOStream &, const Teuchos::EVerbosityLevel=Teuchos::Describable::verbLevel_default) const
Print this object with the given verbosity level to the given Teuchos::FancyOStream.
EpetraMapT(global_size_t numGlobalElements, const Teuchos::ArrayView< const GlobalOrdinal > &elementList, GlobalOrdinal indexBase, const Teuchos::RCP< const Teuchos::Comm< int > > &comm)
Constructor with user-defined arbitrary (possibly noncontiguous) distribution.
Map< LocalOrdinal, GlobalOrdinal, Node >::global_indices_array_type global_indices_array_type
LocalOrdinal getMinLocalIndex() const
The minimum local index.
RCP< const Map< int, GlobalOrdinal, Node > > removeEmptyProcesses() const
Return a new Map with processes with zero elements removed.
bool isDistributed() const
Whether this Map is globally distributed or locally replicated.
bool isContiguous() const
True if this Map is distributed contiguously, else false.
bool isNodeLocalElement(LocalOrdinal localIndex) const
Whether the given local index is valid for this Map on this process.
void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const
Print this object with the given verbosity level to the given Teuchos::FancyOStream.
EpetraMapT(global_size_t numGlobalElements, const Teuchos::ArrayView< const GlobalOrdinal > &elementList, GlobalOrdinal indexBase, const Teuchos::RCP< const Teuchos::Comm< int > > &comm)
Constructor with user-defined arbitrary (possibly noncontiguous) distribution.
typename Map< LocalOrdinal, GlobalOrdinal, Node >::local_map_type local_map_type
bool isSameAs(const Map< LocalOrdinal, GlobalOrdinal, Node > &) const
True if and only if map is identical to this Map.
typename Map< LocalOrdinal, GlobalOrdinal, Node >::local_map_type local_map_type
EpetraMapT(global_size_t numGlobalElements, size_t numLocalElements, GlobalOrdinal indexBase, const Teuchos::RCP< const Teuchos::Comm< int > > &comm)
Constructor with a user-defined contiguous distribution.
size_t getLocalNumElements() const
The number of elements belonging to the calling process.
bool isSameAs(const Map< LocalOrdinal, GlobalOrdinal, Node > &map) const
True if and only if map is identical to this Map.
Teuchos::RCP< const Teuchos::Comm< int > > getComm() const
Get this Map&#39;s Comm object.
Teuchos::RCP< const Teuchos::Comm< int > > getComm() const
Get this Map&#39;s Comm object.
bool isNodeLocalElement(LocalOrdinal localIndex) const
Whether the given local index is valid for this Map on this process.
LocalOrdinal getMinLocalIndex() const
The minimum local index.
LookupStatus getRemoteIndexList(const Teuchos::ArrayView< const GlobalOrdinal > &GIDList, const Teuchos::ArrayView< int > &nodeIDList, const Teuchos::ArrayView< LocalOrdinal > &LIDList) const
Return the process ranks and corresponding local indices for the given global indices.
const Epetra_Map & getEpetra_Map() const
RCP< const Epetra_BlockMap > map_
#define IF_EPETRA_EXCEPTION_THEN_THROW_GLOBAL_INVALID_ARG(sourceCode)
EpetraMapT(global_size_t numGlobalElements, GlobalOrdinal indexBase, const Teuchos::RCP< const Teuchos::Comm< int > > &comm, LocalGlobal lg=GloballyDistributed)
Constructor with Tpetra-defined contiguous uniform distribution.
const Epetra_BlockMap & getEpetra_BlockMap() const
GlobalOrdinal getGlobalElement(LocalOrdinal localIndex) const
Return the global index for a given local index. Note that this returns -1 if not found on this proce...
LocalOrdinal getLocalElement(GlobalOrdinal globalIndex) const
The local index corresponding to the given global index.
global_size_t getGlobalNumElements() const
The number of elements in this Map.
GlobalOrdinal getMaxGlobalIndex() const
The maximum global index owned by the calling process.
GlobalOrdinal getMaxAllGlobalIndex() const
The maximum global index over all processes in the communicator.
LookupStatus getRemoteIndexList(const Teuchos::ArrayView< const GlobalOrdinal > &, const Teuchos::ArrayView< int > &, const Teuchos::ArrayView< LocalOrdinal > &) const
Return the process ranks and corresponding local indices for the given global indices.
RCP< const Map< int, GlobalOrdinal, Node > > replaceCommWithSubset(const Teuchos::RCP< const Teuchos::Comm< int > > &) const
Replace this Map&#39;s communicator with a subset communicator.
RCP< const Epetra_BlockMap > map_
size_t global_size_t
Global size_t object.
global_size_t getGlobalNumElements() const
The number of elements in this Map.
size_t getLocalNumElements() const
The number of elements belonging to the calling process.
EpetraMapT(global_size_t numGlobalElements, size_t numLocalElements, GlobalOrdinal indexBase, const Teuchos::RCP< const Teuchos::Comm< int > > &comm)
Constructor with a user-defined contiguous distribution.
Kokkos::View< const global_ordinal_type *, typename Node::device_type > global_indices_array_device_type
Map< LocalOrdinal, GlobalOrdinal, Node >::global_indices_array_device_type global_indices_array_device_type
global_size_t getGlobalNumElements() const
The number of elements in this Map.
RCP< const Map< int, GlobalOrdinal, Node > > removeEmptyProcesses() const
Return a new Map with processes with zero elements removed.
local_map_type getLocalMap() const
Get the local Map for Kokkos kernels.
EpetraMapT(const Teuchos::RCP< const Epetra_BlockMap > &map)
EpetraMapT constructor to wrap a Epetra_Map object.
GlobalOrdinal getGlobalElement(LocalOrdinal localIndex) const
Return the global index for a given local index. Note that this returns -1 if not found on this proce...
UnderlyingLib lib() const
Get the library used by this object (Epetra or Epetra?)
Tpetra::KokkosCompat::KokkosSerialWrapperNode EpetraNode
GlobalOrdinal getMinGlobalIndex() const
The minimum global index owned by the calling process.
const Epetra_Map & getEpetra_Map() const
RCP< const Map< int, GlobalOrdinal, Node > > removeEmptyProcesses() const
Return a new Map with processes with zero elements removed.
bool isCompatible(const Map< LocalOrdinal, GlobalOrdinal, Node > &map) const
True if and only if map is compatible with this Map.
virtual ~EpetraMapT()
Destructor.
const RCP< const Epetra_Map > & getEpetra_MapRCP() const
Get the underlying Epetra map.
size_t getLocalNumElements() const
The number of elements belonging to the calling process.
bool isNodeLocalElement(LocalOrdinal) const
Whether the given local index is valid for this Map on this process.
LocalOrdinal getLocalElement(GlobalOrdinal) const
The local index corresponding to the given global index.
#define XPETRA_MONITOR(funcName)
LocalOrdinal getLocalElement(GlobalOrdinal globalIndex) const
The local index corresponding to the given global index.
const RCP< const Epetra_Map > getEpetra_MapRCP() const
Get the underlying Epetra map.
local_map_type getLocalMap() const
Get the local Map for Kokkos kernels.
GlobalOrdinal getMaxGlobalIndex() const
The maximum global index owned by the calling process.
global_indices_array_device_type getMyGlobalIndicesDevice() const
Return a view of the global indices owned by this process.
bool isCompatible(const Map< LocalOrdinal, GlobalOrdinal, Node > &map) const
True if and only if map is compatible with this Map.
RCP< const Map< int, GlobalOrdinal, Node > > replaceCommWithSubset(const Teuchos::RCP< const Teuchos::Comm< int > > &) const
Replace this Map&#39;s communicator with a subset communicator.
EpetraMapT(global_size_t numGlobalElements, GlobalOrdinal indexBase, const Teuchos::RCP< const Teuchos::Comm< int > > &comm, LocalGlobal lg=GloballyDistributed)
Constructor with Tpetra-defined contiguous uniform distribution.
EpetraMapT(global_size_t numGlobalElements, const Teuchos::ArrayView< const GlobalOrdinal > &elementList, GlobalOrdinal indexBase, const Teuchos::RCP< const Teuchos::Comm< int > > &comm)
Constructor with user-defined arbitrary (possibly noncontiguous) distribution.
GlobalOrdinal getMinAllGlobalIndex() const
The minimum global index over all processes in the communicator.
GlobalOrdinal getGlobalElement(LocalOrdinal) const
Return the global index for a given local index. Note that this returns -1 if not found on this proce...
EpetraMapT(global_size_t numGlobalElements, size_t numLocalElements, GlobalOrdinal indexBase, const Teuchos::RCP< const Teuchos::Comm< int > > &comm)
Constructor with a user-defined contiguous distribution.
global_indices_array_device_type getMyGlobalIndicesDevice() const
Return a view of the global indices owned by this process.
EpetraMapT(global_size_t numGlobalElements, GlobalOrdinal indexBase, const Teuchos::RCP< const Teuchos::Comm< int > > &comm, LocalGlobal lg=GloballyDistributed)
Constructor with Tpetra-defined contiguous uniform distribution.
GlobalOrdinal getMaxAllGlobalIndex() const
The maximum global index over all processes in the communicator.
bool isCompatible(const Map< LocalOrdinal, GlobalOrdinal, Node > &) const
True if and only if map is compatible with this Map.
RCP< const Map< int, GlobalOrdinal, Node > > replaceCommWithSubset(const Teuchos::RCP< const Teuchos::Comm< int > > &) const
Replace this Map&#39;s communicator with a subset communicator.
Teuchos::ArrayView< const GlobalOrdinal > getLocalElementList() const
Return a view of the global indices owned by this process.
LookupStatus getRemoteIndexList(const Teuchos::ArrayView< const GlobalOrdinal > &, const Teuchos::ArrayView< int > &) const
Return the process ranks for the given global indices.
const Epetra_CrsGraph & toEpetra(const RCP< const CrsGraph< int, GlobalOrdinal, Node > > &graph)
std::string description() const
Return a simple one-line description of this object.
local_map_type getLocalMap() const
Get the local Map for Kokkos kernels.
global_indices_array_device_type getMyGlobalIndicesDevice() const
Return a view of the global indices owned by this process.
RCP< const CrsGraph< int, GlobalOrdinal, Node > > toXpetra(const Epetra_CrsGraph &g)