All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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 
49 
51 
52 #include "Xpetra_Map.hpp"
53 
54 #include <Epetra_Map.h>
55 #include <Epetra_BlockMap.h>
56 
57 #include "Xpetra_Utils.hpp"
58 #include "Xpetra_EpetraUtils.hpp"
60 
61 #include "Xpetra_ConfigDefs.hpp"
62 
63 namespace Xpetra {
64 
65  // TODO: move that elsewhere
66  template<class GlobalOrdinal, class Node>
67  const Epetra_Map & toEpetra(const Map<int,GlobalOrdinal, Node> &);
68 
69  template<class GlobalOrdinal, class Node>
70  const Epetra_Map & toEpetra(const RCP< const Map<int, GlobalOrdinal, Node> > &);
71 
72  //template<class GlobalOrdinal>
73  //const RCP< const Map<int, GlobalOrdinal> > toXpetra(const RCP< const Epetra_Map > &);
74 
75  template<class GlobalOrdinal, class Node>
76  const RCP< const Map<int, GlobalOrdinal, Node> > toXpetra(const Epetra_BlockMap &);
77 
78  // stub implementation for EpetraMapT
79  template<class GlobalOrdinal, class Node>
80  class EpetraMapT
81  : public virtual Map<int, GlobalOrdinal, Node>
82  {
83  typedef int LocalOrdinal;
84 
85  public:
86  typedef int local_ordinal_type;
87  typedef GlobalOrdinal global_ordinal_type;
88  typedef Node node_type;
89 
91 
92 
94 #ifdef TPETRA_ENABLE_DEPRECATED_CODE
95  TPETRA_DEPRECATED
96  EpetraMapT(global_size_t numGlobalElements,
97  GlobalOrdinal indexBase,
98  const Teuchos::RCP< const Teuchos::Comm< int > > &comm,
99  LocalGlobal lg,
100  const Teuchos::RCP< Node > &/*node*/)
101  : EpetraMapT(numGlobalElements, indexBase, comm, lg)
102  {}
103 #endif // TPETRA_ENABLE_DEPRECATED_CODE
104  EpetraMapT(global_size_t numGlobalElements,
105  GlobalOrdinal indexBase,
106  const Teuchos::RCP< const Teuchos::Comm< int > > &comm,
108  {
110  "Xpetra::EpetraMap only available for GO=int or GO=long long with EpetraNode (Serial or OpenMP depending on configuration)");
111  }
112 
114 #ifdef TPETRA_ENABLE_DEPRECATED_CODE
115  TPETRA_DEPRECATED
116  EpetraMapT(global_size_t numGlobalElements, size_t numLocalElements, GlobalOrdinal indexBase, const Teuchos::RCP< const Teuchos::Comm< int > > &comm, const Teuchos::RCP< Node > &node)
117  : EpetraMapT(numGlobalElements, numLocalElements, indexBase, comm)
118  {}
119 #endif // TPETRA_ENABLE_DEPRECATED_CODE
120  EpetraMapT(global_size_t numGlobalElements, size_t numLocalElements, GlobalOrdinal indexBase, const Teuchos::RCP< const Teuchos::Comm< int > > &comm) {
122  "Xpetra::EpetraMap only available for GO=int or GO=long long with EpetraNode (Serial or OpenMP depending on configuration)");
123  }
124 
126 #ifdef TPETRA_ENABLE_DEPRECATED_CODE
127  TPETRA_DEPRECATED
128  EpetraMapT(global_size_t numGlobalElements,
130  GlobalOrdinal indexBase,
131  const Teuchos::RCP< const Teuchos::Comm< int > > &comm,
132  const Teuchos::RCP< Node > &node)
133  : EpetraMapT(numGlobalElements, elementList, indexBase, comm)
134  {}
135 #endif // TPETRA_ENABLE_DEPRECATED_CODE
136  EpetraMapT(global_size_t numGlobalElements,
138  GlobalOrdinal indexBase,
139  const Teuchos::RCP< const Teuchos::Comm< int > > &comm) {
141  "Xpetra::EpetraMap only available for GO=int or GO=long long with EpetraNode (Serial or OpenMP depending on configuration)");
142  }
143 
145 
147 
148 
150  global_size_t getGlobalNumElements() const { return 0; }
151 
153  size_t getNodeNumElements() const { return 0; }
154 
156  GlobalOrdinal getIndexBase() const { return 0; }
157 
159  LocalOrdinal getMinLocalIndex() const { return 0; }
160 
162  LocalOrdinal getMaxLocalIndex() const { return 0; }
163 
165  GlobalOrdinal getMinGlobalIndex() const { return 0; }
166 
168  GlobalOrdinal getMaxGlobalIndex() const { return 0; }
169 
171  GlobalOrdinal getMinAllGlobalIndex() const { return 0; }
172 
174  GlobalOrdinal getMaxAllGlobalIndex() const { return 0; }
175 
177  LocalOrdinal getLocalElement(GlobalOrdinal /* globalIndex */) const { return 0; }
178 
181 
184 
186  //Teuchos::ArrayView< const GlobalOrdinal > getNodeElementList() const;
187 
190 
192 
193 
195  bool isNodeLocalElement(LocalOrdinal /* localIndex */) const { return false; }
196 
198  bool isNodeGlobalElement(GlobalOrdinal /* globalIndex */) const { return false; }
199 
201  bool isContiguous() const { return false; }
202 
204  bool isDistributed() const { return false; }
205 
207  bool isCompatible(const Map< LocalOrdinal, GlobalOrdinal, Node > &/* map */) const { return false; }
208 
210  bool isSameAs(const Map< LocalOrdinal, GlobalOrdinal, Node > &/* map */) const { return false; }
211 
213 
215 
216 
218  Teuchos::RCP< const Teuchos::Comm< int > > getComm() const { return Teuchos::null; }
219 
220 #ifdef TPETRA_ENABLE_DEPRECATED_CODE
221  Teuchos::RCP< Node > getNode() const {
223  XPETRA_MONITOR("EpetraMapT<GlobalOrdinal>::getNode");
224  return Teuchos::rcp (new Node);
225  }
226 #endif // TPETRA_ENABLE_DEPRECATED_CODE
227 
229 
231 
232 
234  std::string description() const { return std::string(""); }
235 
238 
240 
242 
243 
246 
248  RCP<const Map<int,GlobalOrdinal,Node> > replaceCommWithSubset(const Teuchos::RCP< const Teuchos::Comm< int > > &/* newComm */) const { return Teuchos::null; }
249 
251 
253  GlobalOrdinal getGlobalElement(LocalOrdinal /* localIndex */) const { return -1; }
254 
256 
257 
259  virtual ~EpetraMapT() {}
260 
263  : map_(map) {
265  "Xpetra::EpetraMap only available for GO=int or GO=long long with EpetraNode (Serial or OpenMP depending on configuration)");
266  }
267 
269  UnderlyingLib lib() const { return Xpetra::UseEpetra; }
270 
272  //const RCP< const Epetra_Map > & getEpetra_Map() const { return map_; }
273  const Epetra_BlockMap& getEpetra_BlockMap() const { return *map_; }
274  const Epetra_Map& getEpetra_Map() const { return (Epetra_Map &)*map_; } // Ugly, but the same is done in Epetra_CrsMatrix.h to get the map.
275 
276 #ifdef HAVE_XPETRA_KOKKOS_REFACTOR
277 #ifdef HAVE_XPETRA_TPETRA
278  using local_map_type = typename Map<LocalOrdinal, GlobalOrdinal, Node>::local_map_type;
280  local_map_type getLocalMap () const {
281  throw std::runtime_error("Xpetra::EpetraMap::getLocalMap is not implemented.");
282  }
283 #else
284 #ifdef __GNUC__
285 #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."
286 #endif
287 #endif
288 #endif
289 
291 
292  protected:
293 
295  }; // EpetraMapT class
296 
297  // specialization on GO=int and EpetraNode
298 #ifndef XPETRA_EPETRA_NO_32BIT_GLOBAL_INDICES
299  template<>
300  class EpetraMapT<int, EpetraNode>
301  : public virtual Map<int, int, EpetraNode>
302  {
303  typedef int LocalOrdinal;
304  typedef int GlobalOrdinal;
305  typedef EpetraNode Node;
306 
307  public:
310  typedef Node node_type;
311 
313 
314 
316 #ifdef TPETRA_ENABLE_DEPRECATED_CODE
317  TPETRA_DEPRECATED
318  EpetraMapT(global_size_t numGlobalElements,
319  GlobalOrdinal indexBase,
320  const Teuchos::RCP< const Teuchos::Comm< int > > &comm,
321  LocalGlobal lg,
322  const Teuchos::RCP< Node > &/* node */)
323  : EpetraMapT(numGlobalElements, indexBase, comm, lg)
324  {}
325 #endif // TPETRA_ENABLE_DEPRECATED_CODE
326  EpetraMapT(global_size_t numGlobalElements,
327  GlobalOrdinal indexBase,
328  const Teuchos::RCP< const Teuchos::Comm< int > > &comm,
330  {
331  // This test come from Tpetra (Epetra doesn't check if numGlobalElements,indexBase are equivalent across images).
332  // 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.
333  std::string errPrefix;
334  errPrefix = Teuchos::typeName(*this) + "::constructor(numGlobal,indexBase,comm,lOrG): ";
335 
336  if (lg == GloballyDistributed) {
337  const int myImageID = comm->getRank();
338 
339  // check that numGlobalElements,indexBase is equivalent across images
340  global_size_t rootNGE = numGlobalElements;
341  GlobalOrdinal rootIB = indexBase;
342  Teuchos::broadcast<int,global_size_t>(*comm,0,&rootNGE);
343  Teuchos::broadcast<int,GlobalOrdinal>(*comm,0,&rootIB);
344  int localChecks[2], globalChecks[2];
345  localChecks[0] = -1; // fail or pass
346  localChecks[1] = 0; // fail reason
347  if (numGlobalElements != rootNGE) {
348  localChecks[0] = myImageID;
349  localChecks[1] = 1;
350  }
351  else if (indexBase != rootIB) {
352  localChecks[0] = myImageID;
353  localChecks[1] = 2;
354  }
355  // REDUCE_MAX will give us the image ID of the highest rank proc that DID NOT pass, as well as the reason
356  // these will be -1 and 0 if all procs passed
357  Teuchos::reduceAll<int,int>(*comm,Teuchos::REDUCE_MAX,2,localChecks,globalChecks);
358  if (globalChecks[0] != -1) {
359  if (globalChecks[1] == 1) {
360  TEUCHOS_TEST_FOR_EXCEPTION(true,std::invalid_argument,
361  errPrefix << "numGlobal must be the same on all nodes (examine node " << globalChecks[0] << ").");
362  }
363  else if (globalChecks[1] == 2) {
364  TEUCHOS_TEST_FOR_EXCEPTION(true,std::invalid_argument,
365  errPrefix << "indexBase must be the same on all nodes (examine node " << globalChecks[0] << ").");
366  }
367  else {
368  // logic error on our part
369  TEUCHOS_TEST_FOR_EXCEPTION(true,std::logic_error,
370  errPrefix << "logic error. Please contact the Tpetra team.");
371  }
372  }
373  }
374 
375  // Note: validity of numGlobalElements checked by Epetra.
376 
377  IF_EPETRA_EXCEPTION_THEN_THROW_GLOBAL_INVALID_ARG((map_ = (rcp(new Epetra_BlockMap(static_cast<GlobalOrdinal>(numGlobalElements), 1, indexBase, *toEpetra(comm))))));
378  }
379 
381 #ifdef TPETRA_ENABLE_DEPRECATED_CODE
382  TPETRA_DEPRECATED
383  EpetraMapT(global_size_t numGlobalElements, size_t numLocalElements, GlobalOrdinal indexBase, const Teuchos::RCP< const Teuchos::Comm< int > > &comm, const Teuchos::RCP< Node > &/* node */)
384  : EpetraMapT(numGlobalElements, numLocalElements, indexBase, comm)
385  {}
386 #endif // TPETRA_ENABLE_DEPRECATED_CODE
387  EpetraMapT(global_size_t numGlobalElements, size_t numLocalElements, GlobalOrdinal indexBase, const Teuchos::RCP< const Teuchos::Comm< int > > &comm)
388  {
389  // This test come from Tpetra
390  using Teuchos::outArg;
391 
392  const size_t L0 = Teuchos::OrdinalTraits<size_t>::zero();
393  const size_t L1 = Teuchos::OrdinalTraits<size_t>::one();
397 
398  std::string errPrefix;
399  errPrefix = Teuchos::typeName(*this) + "::constructor(numGlobal,numLocal,indexBase,platform): ";
400 
401  // get a internodal communicator from the Platform
402  const int myImageID = comm->getRank();
403 
404  global_size_t global_sum;
405  { // begin scoping block
406  // for communicating failures
407  int localChecks[2], globalChecks[2];
408  /* compute the global size
409  we are computing the number of global elements because exactly ONE of the following is true:
410  - the user didn't specify it, and we need it
411  - the user did specify it, but we need to
412  + validate it against the sum of the local sizes, and
413  + ensure that it is the same on all nodes
414  */
415  Teuchos::reduceAll<int,global_size_t>(*comm,Teuchos::REDUCE_SUM,
416  Teuchos::as<global_size_t>(numLocalElements),outArg(global_sum));
417  /* there are three errors we should be detecting:
418  - numGlobalElements != invalid() and it is incorrect/invalid
419  - numLocalElements invalid (<0)
420  */
421  localChecks[0] = -1;
422  localChecks[1] = 0;
423  if (numLocalElements < L1 && numLocalElements != L0) {
424  // invalid
425  localChecks[0] = myImageID;
426  localChecks[1] = 1;
427  }
428  else if (numGlobalElements < GST1 && numGlobalElements != GST0 && numGlobalElements != GSTI) {
429  // invalid
430  localChecks[0] = myImageID;
431  localChecks[1] = 2;
432  }
433  else if (numGlobalElements != GSTI && numGlobalElements != global_sum) {
434  // incorrect
435  localChecks[0] = myImageID;
436  localChecks[1] = 3;
437  }
438  // now check that indexBase is equivalent across images
439  GlobalOrdinal rootIB = indexBase;
440  Teuchos::broadcast<int,GlobalOrdinal>(*comm,0,&rootIB); // broadcast one ordinal from node 0
441  if (indexBase != rootIB) {
442  localChecks[0] = myImageID;
443  localChecks[1] = 4;
444  }
445  // REDUCE_MAX will give us the image ID of the highest rank proc that DID NOT pass
446  // this will be -1 if all procs passed
447  Teuchos::reduceAll<int,int>(*comm,Teuchos::REDUCE_MAX,2,localChecks,globalChecks);
448  if (globalChecks[0] != -1) {
449  if (globalChecks[1] == 1) {
450  TEUCHOS_TEST_FOR_EXCEPTION(true,std::invalid_argument,
451  errPrefix << "numLocal is not valid on at least one node (possibly node "
452  << globalChecks[0] << ").");
453  }
454  else if (globalChecks[1] == 2) {
455  TEUCHOS_TEST_FOR_EXCEPTION(true,std::invalid_argument,
456  errPrefix << "numGlobal is not valid on at least one node (possibly node "
457  << globalChecks[0] << ").");
458  }
459  else if (globalChecks[1] == 3) {
460  TEUCHOS_TEST_FOR_EXCEPTION(true,std::invalid_argument,
461  errPrefix << "numGlobal doesn't match sum of numLocal (== "
462  << global_sum << ") on at least one node (possibly node "
463  << globalChecks[0] << ").");
464  }
465  else if (globalChecks[1] == 4) {
466  TEUCHOS_TEST_FOR_EXCEPTION(true,std::invalid_argument,
467  errPrefix << "indexBase is not the same on all nodes (examine node "
468  << globalChecks[0] << ").");
469  }
470  else {
471  // logic error on my part
472  TEUCHOS_TEST_FOR_EXCEPTION(true,std::logic_error,
473  errPrefix << "logic error. Please contact the Tpetra team.");
474  }
475  }
476 
477  }
478 
479  // set numGlobalElements
480  if (numGlobalElements == GSTI) {
481  numGlobalElements = global_sum;}
482 
483  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))))));
484  }
485 
487 #ifdef TPETRA_ENABLE_DEPRECATED_CODE
488  TPETRA_DEPRECATED
489  EpetraMapT(global_size_t numGlobalElements,
491  GlobalOrdinal indexBase,
492  const Teuchos::RCP< const Teuchos::Comm< int > > &comm,
493  const Teuchos::RCP< Node > &/* node */)
494  : EpetraMapT(numGlobalElements, elementList, indexBase, comm)
495  {}
496 #endif // TPETRA_ENABLE_DEPRECATED_CODE
497  EpetraMapT(global_size_t numGlobalElements,
499  GlobalOrdinal indexBase,
500  const Teuchos::RCP< const Teuchos::Comm< int > > &comm)
501  {
502  if (numGlobalElements == Teuchos::OrdinalTraits<global_size_t>::invalid()) {
503  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))))));
504  } else {
505  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))))));
506  }
507  }
508 
510 
512 
513 
515  global_size_t getGlobalNumElements() const { XPETRA_MONITOR("EpetraMapT::getGlobalNumElements"); return map_->NumGlobalElements64(); }
516 
518  size_t getNodeNumElements() const { XPETRA_MONITOR("EpetraMapT::getNodeNumElements"); return map_->NumMyElements(); }
519 
521  GlobalOrdinal getIndexBase() const { XPETRA_MONITOR("EpetraMapT::getIndexBase"); return (GlobalOrdinal) map_->IndexBase64(); }
522 
524  LocalOrdinal getMinLocalIndex() const { XPETRA_MONITOR("EpetraMapT::getMinLocalIndex"); return map_->MinLID(); }
525 
527  LocalOrdinal getMaxLocalIndex() const { XPETRA_MONITOR("EpetraMapT::getMaxLocalIndex"); return map_->MaxLID(); }
528 
530  GlobalOrdinal getMinGlobalIndex() const { XPETRA_MONITOR("EpetraMapT::getMinGlobalIndex"); return (GlobalOrdinal) map_->MinMyGID64(); }
531 
533  GlobalOrdinal getMaxGlobalIndex() const { XPETRA_MONITOR("EpetraMapT::getMaxGlobalIndex"); return (GlobalOrdinal) map_->MaxMyGID64(); }
534 
536  GlobalOrdinal getMinAllGlobalIndex() const { XPETRA_MONITOR("EpetraMapT::getMinAllGlobalIndex"); return (GlobalOrdinal) map_->MinAllGID64(); }
537 
539  GlobalOrdinal getMaxAllGlobalIndex() const { XPETRA_MONITOR("EpetraMapT::getMaxAllGlobalIndex"); return (GlobalOrdinal) map_->MaxAllGID64(); }
540 
542  LocalOrdinal getLocalElement(GlobalOrdinal globalIndex) const { XPETRA_MONITOR("EpetraMapT::getLocalElement"); return map_->LID(globalIndex); }
543 
544 
547  const Teuchos::ArrayView< int > &nodeIDList,
548  const Teuchos::ArrayView< LocalOrdinal > &LIDList) const
549  {
550  XPETRA_MONITOR("EpetraMapT::getRemoteIndexList");
551  return toXpetra(map_->RemoteIDList(static_cast<int>(GIDList.size()), GIDList.getRawPtr(), nodeIDList.getRawPtr(), LIDList.getRawPtr()));
552  }
553 
554 
557  const Teuchos::ArrayView< int > &nodeIDList) const
558  {
559  XPETRA_MONITOR("EpetraMapT::getRemoteIndexList");
560  return toXpetra(map_->RemoteIDList(static_cast<int>(GIDList.size()), GIDList.getRawPtr(), nodeIDList.getRawPtr(), 0));
561  }
562 
563 
567 
569 
570 
572  bool isNodeLocalElement(LocalOrdinal localIndex) const { XPETRA_MONITOR("EpetraMapT::isNodeLocalElement"); return map_->MyLID(localIndex); }
573 
575  bool isNodeGlobalElement(GlobalOrdinal globalIndex) const { XPETRA_MONITOR("EpetraMapT::isNodeGlobalElement"); return map_->MyGID(globalIndex); }
576 
578  bool isContiguous() const { XPETRA_MONITOR("EpetraMapT::isContiguous"); return map_->LinearMap(); }
579 
581  bool isDistributed() const { XPETRA_MONITOR("EpetraMapT::isDistributed"); return map_->DistributedGlobal(); }
582 
584  bool isCompatible(const Map< LocalOrdinal, GlobalOrdinal, Node > &map) const { XPETRA_MONITOR("EpetraMapT::isCompatible"); return map_->PointSameAs(toEpetra<GlobalOrdinal,Node>(map)); }
585 
587  bool isSameAs(const Map< LocalOrdinal, GlobalOrdinal, Node > &map) const { XPETRA_MONITOR("EpetraMapT::isSameAs"); return map_->SameAs(toEpetra<GlobalOrdinal,Node>(map)); }
588 
590 
592 
593 
596  {
597  XPETRA_MONITOR("EpetraMapT::getComm");
598  return toXpetra(map_->Comm());
599  }
600 
601 #ifdef TPETRA_ENABLE_DEPRECATED_CODE
602  Teuchos::RCP< Node > getNode() const {
604  XPETRA_MONITOR("EpetraMapT<GlobalOrdinal>::getNode");
605  return Teuchos::rcp (new Node);
606  }
607 #endif // TPETRA_ENABLE_DEPRECATED_CODE
608 
610 
612 
613 
615  std::string description() const {
616  XPETRA_MONITOR("EpetraMapT::description");
617 
618  // This implementation come from Tpetra_Map_def.hpp (without modification)
619  std::ostringstream oss;
621  oss << "{getGlobalNumElements() = " << getGlobalNumElements()
622  << ", getNodeNumElements() = " << getNodeNumElements()
623  << ", isContiguous() = " << isContiguous()
624  << ", isDistributed() = " << isDistributed()
625  << "}";
626  return oss.str();
627  }
628 
631  XPETRA_MONITOR("EpetraMapT::describe");
632 
634 
635  // This implementation come from Tpetra_Map_def.hpp (without modification)
636  using std::endl;
637  using std::setw;
638  using Teuchos::VERB_DEFAULT;
639  using Teuchos::VERB_NONE;
640  using Teuchos::VERB_LOW;
641  using Teuchos::VERB_MEDIUM;
642  using Teuchos::VERB_HIGH;
643  using Teuchos::VERB_EXTREME;
644 
645  const size_t nME = getNodeNumElements();
647  int myImageID = comm_->getRank();
648  int numImages = comm_->getSize();
649 
650  Teuchos::EVerbosityLevel vl = verbLevel;
651  if (vl == VERB_DEFAULT) vl = VERB_LOW;
652 
653  size_t width = 1;
654  for (size_t dec=10; dec<getGlobalNumElements(); dec *= 10) {
655  ++width;
656  }
657  width = ::std::max<size_t>(width, (size_t) 12) + 2; // casting to size_t to avoid ambiguity error when compiling Sacado.
658 
659  Teuchos::OSTab tab(out);
660 
661  if (vl == VERB_NONE) {
662  // do nothing
663  }
664  else if (vl == VERB_LOW) {
665  out << this->description() << endl;
666  }
667  else { // MEDIUM, HIGH or EXTREME
668  for (int imageCtr = 0; imageCtr < numImages; ++imageCtr) {
669  if (myImageID == imageCtr) {
670  if (myImageID == 0) { // this is the root node (only output this info once)
671  out << endl
672  << "Number of Global Entries = " << getGlobalNumElements() << endl
673  << "Maximum of all GIDs = " << getMaxAllGlobalIndex() << endl
674  << "Minimum of all GIDs = " << getMinAllGlobalIndex() << endl
675  << "Index Base = " << getIndexBase() << endl;
676  }
677  out << endl;
678  if (vl == VERB_HIGH || vl == VERB_EXTREME) {
679  out << "Number of Local Elements = " << nME << endl
680  << "Maximum of my GIDs = " << getMaxGlobalIndex() << endl
681  << "Minimum of my GIDs = " << getMinGlobalIndex() << endl;
682  out << endl;
683  }
684  if (vl == VERB_EXTREME) {
685  out << std::setw(width) << "Node ID"
686  << std::setw(width) << "Local Index"
687  << std::setw(width) << "Global Index"
688  << endl;
689  for (size_t i=0; i < nME; i++) {
690  out << std::setw(width) << myImageID
691  << std::setw(width) << i
692  << std::setw(width) << myEntries[i]
693  << endl;
694  }
695  out << std::flush;
696  }
697  }
698  // Do a few global ops to give I/O a chance to complete
699  comm_->barrier();
700  comm_->barrier();
701  comm_->barrier();
702  }
703  }
704  }
705 
707 
709 
710 
713  const Epetra_BlockMap * NewMap = map_->RemoveEmptyProcesses();
714  if (!NewMap) {
715  return Teuchos::null;
716  } else {
717  const RCP< const Map<int, GlobalOrdinal, Node> > NewMapX = toXpetra<GlobalOrdinal, Node>(*NewMap);
718  delete NewMap; // NOTE: toXpetra *copys* the epetra map rather than wrapping it, so we have to delete NewMap to avoid a memory leak.
719  return NewMapX;
720  }
721  }
722 
725  throw std::runtime_error("Xpetra::EpetraMapT::replaceCommWithSubset has not yet been implemented.");
726  TEUCHOS_UNREACHABLE_RETURN(Teuchos::null);
727  }
728 
730 
733  XPETRA_MONITOR("EpetraMapT::getGlobalElement");
734 
735  GlobalOrdinal gid = (GlobalOrdinal) map_->GID64(localIndex);
736  if (gid == map_->IndexBase64()-1) return (-1);
737  else return (gid);
738  }
739 
741 
742 
744  virtual ~EpetraMapT() {}
745 
748  : map_(map) {
749  TEUCHOS_TEST_FOR_EXCEPTION(!map->GlobalIndicesIsType<GlobalOrdinal>(), std::runtime_error, "Xpetra::EpetraMapT: GlobalOrdinal mismatch.");
750  }
751 
753  UnderlyingLib lib() const { return Xpetra::UseEpetra; }
754 
756  //const RCP< const Epetra_Map > & getEpetra_Map() const { return map_; }
757  const Epetra_BlockMap& getEpetra_BlockMap() const { return *map_; }
758  const Epetra_Map& getEpetra_Map() const { return (Epetra_Map &)*map_; } // Ugly, but the same is done in Epetra_CrsMatrix.h to get the map.
759 
761 
762 #ifdef HAVE_XPETRA_KOKKOS_REFACTOR
763 #ifdef HAVE_XPETRA_TPETRA
764  using local_map_type = typename Map<LocalOrdinal, GlobalOrdinal, Node>::local_map_type;
766  local_map_type getLocalMap () const {
767  throw std::runtime_error("Xpetra::EpetraMap::getLocalMap is not implemented.");
768  }
769 
770  private:
771  mutable local_map_type localMap_;
772 #else
773 #ifdef __GNUC__
774 #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."
775 #endif
776 #endif
777 #endif
778 
779  protected:
780 
782 }; // EpetraMapT class
783 #endif // #ifndef XPETRA_EPETRA_NO_32BIT_GLOBAL_INDICES
784 
785 // specialization on GO=long long and EpetraNode
786 #ifndef XPETRA_EPETRA_NO_64BIT_GLOBAL_INDICES
787  template<>
788  class EpetraMapT<long long, EpetraNode>
789  : public virtual Map<int, long long, EpetraNode>
790  {
791  typedef int LocalOrdinal;
792  typedef long long GlobalOrdinal;
793  typedef EpetraNode Node;
794 
795  public:
798  typedef Node node_type;
799 
801 
802 
804 #ifdef TPETRA_ENABLE_DEPRECATED_CODE
805  TPETRA_DEPRECATED
806  EpetraMapT(global_size_t numGlobalElements,
807  GlobalOrdinal indexBase,
808  const Teuchos::RCP< const Teuchos::Comm< int > > &comm,
809  LocalGlobal lg,
810  const Teuchos::RCP< Node > &/* node */)
811  : EpetraMapT(numGlobalElements, indexBase, comm, lg)
812  {}
813 #endif // TPETRA_ENABLE_DEPRECATED_CODE
814  EpetraMapT(global_size_t numGlobalElements,
815  GlobalOrdinal indexBase,
816  const Teuchos::RCP< const Teuchos::Comm< int > > &comm,
818  {
819  // This test come from Tpetra (Epetra doesn't check if numGlobalElements,indexBase are equivalent across images).
820  // 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.
821  std::string errPrefix;
822  errPrefix = Teuchos::typeName(*this) + "::constructor(numGlobal,indexBase,comm,lOrG): ";
823 
824  if (lg == GloballyDistributed) {
825  const int myImageID = comm->getRank();
826 
827  // check that numGlobalElements,indexBase is equivalent across images
828  global_size_t rootNGE = numGlobalElements;
829  GlobalOrdinal rootIB = indexBase;
830  Teuchos::broadcast<int,global_size_t>(*comm,0,&rootNGE);
831  Teuchos::broadcast<int,GlobalOrdinal>(*comm,0,&rootIB);
832  int localChecks[2], globalChecks[2];
833  localChecks[0] = -1; // fail or pass
834  localChecks[1] = 0; // fail reason
835  if (numGlobalElements != rootNGE) {
836  localChecks[0] = myImageID;
837  localChecks[1] = 1;
838  }
839  else if (indexBase != rootIB) {
840  localChecks[0] = myImageID;
841  localChecks[1] = 2;
842  }
843  // REDUCE_MAX will give us the image ID of the highest rank proc that DID NOT pass, as well as the reason
844  // these will be -1 and 0 if all procs passed
845  Teuchos::reduceAll<int,int>(*comm,Teuchos::REDUCE_MAX,2,localChecks,globalChecks);
846  if (globalChecks[0] != -1) {
847  if (globalChecks[1] == 1) {
848  TEUCHOS_TEST_FOR_EXCEPTION(true,std::invalid_argument,
849  errPrefix << "numGlobal must be the same on all nodes (examine node " << globalChecks[0] << ").");
850  }
851  else if (globalChecks[1] == 2) {
852  TEUCHOS_TEST_FOR_EXCEPTION(true,std::invalid_argument,
853  errPrefix << "indexBase must be the same on all nodes (examine node " << globalChecks[0] << ").");
854  }
855  else {
856  // logic error on our part
857  TEUCHOS_TEST_FOR_EXCEPTION(true,std::logic_error,
858  errPrefix << "logic error. Please contact the Tpetra team.");
859  }
860  }
861  }
862 
863  // Note: validity of numGlobalElements checked by Epetra.
864 
865  IF_EPETRA_EXCEPTION_THEN_THROW_GLOBAL_INVALID_ARG((map_ = (rcp(new Epetra_BlockMap(static_cast<GlobalOrdinal>(numGlobalElements), 1, indexBase, *toEpetra(comm))))));
866  }
867 
869 #ifdef TPETRA_ENABLE_DEPRECATED_CODE
870  TPETRA_DEPRECATED
871  EpetraMapT(global_size_t numGlobalElements, size_t numLocalElements, GlobalOrdinal indexBase, const Teuchos::RCP< const Teuchos::Comm< int > > &comm, const Teuchos::RCP< Node > &/* node */)
872  : EpetraMapT(numGlobalElements, numLocalElements, indexBase, comm)
873  {}
874 #endif // TPETRA_ENABLE_DEPRECATED_CODE
875  EpetraMapT(global_size_t numGlobalElements, size_t numLocalElements, GlobalOrdinal indexBase, const Teuchos::RCP< const Teuchos::Comm< int > > &comm) {
876  // This test come from Tpetra
877  using Teuchos::outArg;
878 
879  const size_t L0 = Teuchos::OrdinalTraits<size_t>::zero();
880  const size_t L1 = Teuchos::OrdinalTraits<size_t>::one();
884 
885  std::string errPrefix;
886  errPrefix = Teuchos::typeName(*this) + "::constructor(numGlobal,numLocal,indexBase,platform): ";
887 
888  // get a internodal communicator from the Platform
889  const int myImageID = comm->getRank();
890 
891  global_size_t global_sum;
892  { // begin scoping block
893  // for communicating failures
894  int localChecks[2], globalChecks[2];
895  /* compute the global size
896  we are computing the number of global elements because exactly ONE of the following is true:
897  - the user didn't specify it, and we need it
898  - the user did specify it, but we need to
899  + validate it against the sum of the local sizes, and
900  + ensure that it is the same on all nodes
901  */
902  Teuchos::reduceAll<int,global_size_t>(*comm,Teuchos::REDUCE_SUM,
903  Teuchos::as<global_size_t>(numLocalElements),outArg(global_sum));
904  /* there are three errors we should be detecting:
905  - numGlobalElements != invalid() and it is incorrect/invalid
906  - numLocalElements invalid (<0)
907  */
908  localChecks[0] = -1;
909  localChecks[1] = 0;
910  if (numLocalElements < L1 && numLocalElements != L0) {
911  // invalid
912  localChecks[0] = myImageID;
913  localChecks[1] = 1;
914  }
915  else if (numGlobalElements < GST1 && numGlobalElements != GST0 && numGlobalElements != GSTI) {
916  // invalid
917  localChecks[0] = myImageID;
918  localChecks[1] = 2;
919  }
920  else if (numGlobalElements != GSTI && numGlobalElements != global_sum) {
921  // incorrect
922  localChecks[0] = myImageID;
923  localChecks[1] = 3;
924  }
925  // now check that indexBase is equivalent across images
926  GlobalOrdinal rootIB = indexBase;
927  Teuchos::broadcast<int,GlobalOrdinal>(*comm,0,&rootIB); // broadcast one ordinal from node 0
928  if (indexBase != rootIB) {
929  localChecks[0] = myImageID;
930  localChecks[1] = 4;
931  }
932  // REDUCE_MAX will give us the image ID of the highest rank proc that DID NOT pass
933  // this will be -1 if all procs passed
934  Teuchos::reduceAll<int,int>(*comm,Teuchos::REDUCE_MAX,2,localChecks,globalChecks);
935  if (globalChecks[0] != -1) {
936  if (globalChecks[1] == 1) {
937  TEUCHOS_TEST_FOR_EXCEPTION(true,std::invalid_argument,
938  errPrefix << "numLocal is not valid on at least one node (possibly node "
939  << globalChecks[0] << ").");
940  }
941  else if (globalChecks[1] == 2) {
942  TEUCHOS_TEST_FOR_EXCEPTION(true,std::invalid_argument,
943  errPrefix << "numGlobal is not valid on at least one node (possibly node "
944  << globalChecks[0] << ").");
945  }
946  else if (globalChecks[1] == 3) {
947  TEUCHOS_TEST_FOR_EXCEPTION(true,std::invalid_argument,
948  errPrefix << "numGlobal doesn't match sum of numLocal (== "
949  << global_sum << ") on at least one node (possibly node "
950  << globalChecks[0] << ").");
951  }
952  else if (globalChecks[1] == 4) {
953  TEUCHOS_TEST_FOR_EXCEPTION(true,std::invalid_argument,
954  errPrefix << "indexBase is not the same on all nodes (examine node "
955  << globalChecks[0] << ").");
956  }
957  else {
958  // logic error on my part
959  TEUCHOS_TEST_FOR_EXCEPTION(true,std::logic_error,
960  errPrefix << "logic error. Please contact the Tpetra team.");
961  }
962  }
963 
964  }
965 
966  // set numGlobalElements
967  if (numGlobalElements == GSTI) {
968  numGlobalElements = global_sum;}
969 
970  IF_EPETRA_EXCEPTION_THEN_THROW_GLOBAL_INVALID_ARG((map_ = (rcp(new Epetra_BlockMap(static_cast<GlobalOrdinal>(numGlobalElements), numLocalElements, 1, indexBase, *toEpetra(comm))))));
971  }
972 
974 #ifdef TPETRA_ENABLE_DEPRECATED_CODE
975  TPETRA_DEPRECATED
976  EpetraMapT(global_size_t numGlobalElements,
978  GlobalOrdinal indexBase,
979  const Teuchos::RCP< const Teuchos::Comm< int > > &comm,
980  const Teuchos::RCP< Node > &/* node */)
981  : EpetraMapT(numGlobalElements, elementList, indexBase, comm)
982  {}
983 #endif // TPETRA_ENABLE_DEPRECATED_CODE
984  EpetraMapT(global_size_t numGlobalElements,
986  GlobalOrdinal indexBase,
987  const Teuchos::RCP< const Teuchos::Comm< int > > &comm)
988  {
989  if (numGlobalElements == Teuchos::OrdinalTraits<global_size_t>::invalid()) {
990  IF_EPETRA_EXCEPTION_THEN_THROW_GLOBAL_INVALID_ARG((map_ = (rcp(new Epetra_BlockMap(-1, elementList.size(), elementList.getRawPtr(), 1, indexBase, *toEpetra(comm))))));
991  } else {
992  IF_EPETRA_EXCEPTION_THEN_THROW_GLOBAL_INVALID_ARG((map_ = (rcp(new Epetra_BlockMap(numGlobalElements, elementList.size(), elementList.getRawPtr(), 1, indexBase, *toEpetra(comm))))));
993  }
994  }
995 
997 
999 
1000 
1002  global_size_t getGlobalNumElements() const { XPETRA_MONITOR("EpetraMapT::getGlobalNumElements"); return map_->NumGlobalElements64(); }
1003 
1005  size_t getNodeNumElements() const { XPETRA_MONITOR("EpetraMapT::getNodeNumElements"); return map_->NumMyElements(); }
1006 
1008  GlobalOrdinal getIndexBase() const { XPETRA_MONITOR("EpetraMapT::getIndexBase"); return (GlobalOrdinal) map_->IndexBase64(); }
1009 
1011  LocalOrdinal getMinLocalIndex() const { XPETRA_MONITOR("EpetraMapT::getMinLocalIndex"); return map_->MinLID(); }
1012 
1014  LocalOrdinal getMaxLocalIndex() const { XPETRA_MONITOR("EpetraMapT::getMaxLocalIndex"); return map_->MaxLID(); }
1015 
1017  GlobalOrdinal getMinGlobalIndex() const { XPETRA_MONITOR("EpetraMapT::getMinGlobalIndex"); return (GlobalOrdinal) map_->MinMyGID64(); }
1018 
1020  GlobalOrdinal getMaxGlobalIndex() const { XPETRA_MONITOR("EpetraMapT::getMaxGlobalIndex"); return (GlobalOrdinal) map_->MaxMyGID64(); }
1021 
1023  GlobalOrdinal getMinAllGlobalIndex() const { XPETRA_MONITOR("EpetraMapT::getMinAllGlobalIndex"); return (GlobalOrdinal) map_->MinAllGID64(); }
1024 
1026  GlobalOrdinal getMaxAllGlobalIndex() const { XPETRA_MONITOR("EpetraMapT::getMaxAllGlobalIndex"); return (GlobalOrdinal) map_->MaxAllGID64(); }
1027 
1029  LocalOrdinal getLocalElement(GlobalOrdinal globalIndex) const { XPETRA_MONITOR("EpetraMapT::getLocalElement"); return map_->LID(globalIndex); }
1030 
1032  LookupStatus getRemoteIndexList(const Teuchos::ArrayView< const GlobalOrdinal > &GIDList, const Teuchos::ArrayView< int > &nodeIDList, const Teuchos::ArrayView< LocalOrdinal > &LIDList) const { XPETRA_MONITOR("EpetraMapT::getRemoteIndexList"); return toXpetra(map_->RemoteIDList(GIDList.size(), GIDList.getRawPtr(), nodeIDList.getRawPtr(), LIDList.getRawPtr())); }
1033 
1035  LookupStatus getRemoteIndexList(const Teuchos::ArrayView< const GlobalOrdinal > &GIDList, const Teuchos::ArrayView< int > &nodeIDList) const { XPETRA_MONITOR("EpetraMapT::getRemoteIndexList"); return toXpetra(map_->RemoteIDList(GIDList.size(), GIDList.getRawPtr(), nodeIDList.getRawPtr(), 0)); }
1036 
1038  Teuchos::ArrayView< const GlobalOrdinal > getNodeElementList() const { XPETRA_MONITOR("EpetraMapT::getNodeElementList"); return ArrayView< const long long >(map_->MyGlobalElements64(), map_->NumMyElements()); }
1040 
1042 
1043 
1045  bool isNodeLocalElement(LocalOrdinal localIndex) const { XPETRA_MONITOR("EpetraMapT::isNodeLocalElement"); return map_->MyLID(localIndex); }
1046 
1048  bool isNodeGlobalElement(GlobalOrdinal globalIndex) const { XPETRA_MONITOR("EpetraMapT::isNodeGlobalElement"); return map_->MyGID(globalIndex); }
1049 
1051  bool isContiguous() const { XPETRA_MONITOR("EpetraMapT::isContiguous"); return map_->LinearMap(); }
1052 
1054  bool isDistributed() const { XPETRA_MONITOR("EpetraMapT::isDistributed"); return map_->DistributedGlobal(); }
1055 
1057  bool isCompatible(const Map< LocalOrdinal, GlobalOrdinal, Node > &map) const { XPETRA_MONITOR("EpetraMapT::isCompatible"); return map_->PointSameAs(toEpetra<GlobalOrdinal,Node>(map)); }
1058 
1060  bool isSameAs(const Map< LocalOrdinal, GlobalOrdinal, Node > &map) const { XPETRA_MONITOR("EpetraMapT::isSameAs"); return map_->SameAs(toEpetra<GlobalOrdinal,Node>(map)); }
1061 
1063 
1065 
1066 
1068  Teuchos::RCP< const Teuchos::Comm< int > > getComm() const { XPETRA_MONITOR("EpetraMapT::getComm"); return toXpetra(map_->Comm()); }
1069 
1070 #ifdef TPETRA_ENABLE_DEPRECATED_CODE
1071  Teuchos::RCP< Node > getNode() const {
1073  XPETRA_MONITOR("EpetraMapT<GlobalOrdinal>::getNode");
1074  return Teuchos::rcp (new Node);
1075  }
1076 #endif // TPETRA_ENABLE_DEPRECATED_CODE
1077 
1079 
1081 
1082 
1084  std::string description() const {
1085  XPETRA_MONITOR("EpetraMapT::description");
1086 
1087  // This implementation come from Tpetra_Map_def.hpp (without modification)
1088  std::ostringstream oss;
1090  oss << "{getGlobalNumElements() = " << getGlobalNumElements()
1091  << ", getNodeNumElements() = " << getNodeNumElements()
1092  << ", isContiguous() = " << isContiguous()
1093  << ", isDistributed() = " << isDistributed()
1094  << "}";
1095  return oss.str();
1096  }
1097 
1100  XPETRA_MONITOR("EpetraMapT::describe");
1101 
1103 
1104  // This implementation come from Tpetra_Map_def.hpp (without modification)
1105  using std::endl;
1106  using std::setw;
1107  using Teuchos::VERB_DEFAULT;
1108  using Teuchos::VERB_NONE;
1109  using Teuchos::VERB_LOW;
1110  using Teuchos::VERB_MEDIUM;
1111  using Teuchos::VERB_HIGH;
1112  using Teuchos::VERB_EXTREME;
1113 
1114  const size_t nME = getNodeNumElements();
1116  int myImageID = comm_->getRank();
1117  int numImages = comm_->getSize();
1118 
1119  Teuchos::EVerbosityLevel vl = verbLevel;
1120  if (vl == VERB_DEFAULT) vl = VERB_LOW;
1121 
1122  size_t width = 1;
1123  for (size_t dec=10; dec<getGlobalNumElements(); dec *= 10) {
1124  ++width;
1125  }
1126  width = ::std::max<size_t>(width, (size_t) 12) + 2; // casting to size_t to avoid ambiguity error when compiling Sacado.
1127 
1128  Teuchos::OSTab tab(out);
1129 
1130  if (vl == VERB_NONE) {
1131  // do nothing
1132  }
1133  else if (vl == VERB_LOW) {
1134  out << this->description() << endl;
1135  }
1136  else { // MEDIUM, HIGH or EXTREME
1137  for (int imageCtr = 0; imageCtr < numImages; ++imageCtr) {
1138  if (myImageID == imageCtr) {
1139  if (myImageID == 0) { // this is the root node (only output this info once)
1140  out << endl
1141  << "Number of Global Entries = " << getGlobalNumElements() << endl
1142  << "Maximum of all GIDs = " << getMaxAllGlobalIndex() << endl
1143  << "Minimum of all GIDs = " << getMinAllGlobalIndex() << endl
1144  << "Index Base = " << getIndexBase() << endl;
1145  }
1146  out << endl;
1147  if (vl == VERB_HIGH || vl == VERB_EXTREME) {
1148  out << "Number of Local Elements = " << nME << endl
1149  << "Maximum of my GIDs = " << getMaxGlobalIndex() << endl
1150  << "Minimum of my GIDs = " << getMinGlobalIndex() << endl;
1151  out << endl;
1152  }
1153  if (vl == VERB_EXTREME) {
1154  out << std::setw(width) << "Node ID"
1155  << std::setw(width) << "Local Index"
1156  << std::setw(width) << "Global Index"
1157  << endl;
1158  for (size_t i=0; i < nME; i++) {
1159  out << std::setw(width) << myImageID
1160  << std::setw(width) << i
1161  << std::setw(width) << myEntries[i]
1162  << endl;
1163  }
1164  out << std::flush;
1165  }
1166  }
1167  // Do a few global ops to give I/O a chance to complete
1168  comm_->barrier();
1169  comm_->barrier();
1170  comm_->barrier();
1171  }
1172  }
1173  }
1174 
1176 
1178 
1179 
1182  const Epetra_BlockMap * NewMap = map_->RemoveEmptyProcesses();
1183  if (!NewMap) {
1184  return Teuchos::null;
1185  } else {
1186  const RCP< const Map<int, GlobalOrdinal, Node> > NewMapX = toXpetra<GlobalOrdinal, Node>(*NewMap);
1187  delete NewMap; // NOTE: toXpetra *copys* the epetra map rather than wrapping it, so we have to delete NewMap to avoid a memory leak.
1188  return NewMapX;
1189  }
1190  }
1191 
1194  throw std::runtime_error("Xpetra::EpetraMapT::replaceCommWithSubset has not yet been implemented.");
1195  // return Teuchos::null; // unreachable
1196  }
1197 
1199 
1202  XPETRA_MONITOR("EpetraMapT::getGlobalElement");
1203 
1204  GlobalOrdinal gid = (GlobalOrdinal) map_->GID64(localIndex);
1205  if (gid == map_->IndexBase64()-1) return (-1);
1206  else return (gid);
1207  }
1208 
1210 
1211 
1213  virtual ~EpetraMapT() {}
1214 
1217  : map_(map) {
1218  TEUCHOS_TEST_FOR_EXCEPTION(!map->GlobalIndicesIsType<GlobalOrdinal>(), std::runtime_error, "Xpetra::EpetraMapT: GlobalOrdinal mismatch.");
1219  }
1220 
1223 
1225  //const RCP< const Epetra_Map > & getEpetra_Map() const { return map_; }
1226  const Epetra_BlockMap& getEpetra_BlockMap() const { return *map_; }
1227  const Epetra_Map& getEpetra_Map() const { return (Epetra_Map &)*map_; } // Ugly, but the same is done in Epetra_CrsMatrix.h to get the map.
1228 
1229 #ifdef HAVE_XPETRA_KOKKOS_REFACTOR
1230 #ifdef HAVE_XPETRA_TPETRA
1231  using local_map_type = typename Map<LocalOrdinal, GlobalOrdinal, Node>::local_map_type;
1233  local_map_type getLocalMap () const {
1234  throw std::runtime_error("Xpetra::EpetraMap::getLocalMap is not implemented.");
1235  }
1236 
1237  private:
1238  mutable local_map_type localMap_;
1239 #else
1240 #ifdef __GNUC__
1241 #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."
1242 #endif
1243 #endif
1244 #endif
1245 
1247 
1248  protected:
1249 
1251 }; // EpetraMapT class
1252 #endif // #ifndef XPETRA_EPETRA_NO_64BIT_GLOBAL_INDICES
1253 
1254 } // Xpetra namespace
1255 
1256 #endif // XPETRA_EPETRAMAP_HPP
bool isDistributed() const
Whether this Map is globally distributed or locally replicated.
bool PointSameAs(const Epetra_BlockMap &Map) const
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
Teuchos::ArrayView< const GlobalOrdinal > getNodeElementList() const
Return a view of the global indices owned by this process.
bool DistributedGlobal() const
GlobalOrdinal getIndexBase() const
The index base for this Map.
size_t getNodeNumElements() const
The number of elements belonging to the calling process.
size_t getNodeNumElements() const
The number of elements belonging to the calling process.
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.
size_t getNodeNumElements() const
The number of elements belonging to the calling 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.
RCP< const Map< int, GlobalOrdinal, Node > > removeEmptyProcesses() const
Return a new Map with processes with zero elements removed.
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.
bool isNodeGlobalElement(GlobalOrdinal globalIndex) const
Whether the given global index is valid for this Map on this process.
int MaxLID() const
RCP< const Map< int, GlobalOrdinal, Node > > removeEmptyProcesses() const
Return a new Map with processes with zero elements removed.
const Epetra_BlockMap & getEpetra_BlockMap() const
Get the underlying Epetra map.
bool SameAs(const Epetra_BlockMap &Map) 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.
int MyGlobalElements(int *MyGlobalElementList) const
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.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
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
Get the underlying Epetra map.
GlobalOrdinal getMaxAllGlobalIndex() const
The maximum global index over all processes in the communicator.
size_type size() const
LocalOrdinal getMaxLocalIndex() const
The maximum local index on the calling process.
Exception throws to report errors in the internal logical of the program.
const Epetra_CrsGraph & toEpetra(const RCP< const CrsGraph< int, GlobalOrdinal, Node > > &graph)
bool isSameAs(const Map< LocalOrdinal, GlobalOrdinal, Node > &map) const
True if and only if map is identical to 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.
bool isContiguous() const
True if this Map is distributed contiguously, else false.
RCP< const Map< int, GlobalOrdinal, Node > > removeEmptyProcesses() const
Return a new Map with processes with zero elements removed.
UnderlyingLib lib() const
Get the library used by this object (Epetra or Epetra?)
Teuchos::RCP< const Teuchos::Comm< int > > getComm() const
Get this Map&#39;s Comm object.
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.
int MinLID() const
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.
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.
LocalOrdinal getMinLocalIndex() const
The minimum local index.
Teuchos::ArrayView< const GlobalOrdinal > getNodeElementList() const
Return a view of the global indices owned by this process.
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.
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.
int NumMyElements() const
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.
bool isSameAs(const Map< LocalOrdinal, GlobalOrdinal, Node > &) const
True if and only if map is identical to this Map.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
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.
bool isSameAs(const Map< LocalOrdinal, GlobalOrdinal, Node > &map) const
True if and only if map is identical to this Map.
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.
Teuchos::RCP< const Teuchos::Comm< int > > getComm() const
Get this Map&#39;s Comm object.
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.
Teuchos::ArrayView< const GlobalOrdinal > getNodeElementList() const
Return a view of the global indices owned by this process.
const Epetra_Map & getEpetra_Map() const
RCP< const Epetra_BlockMap > map_
#define IF_EPETRA_EXCEPTION_THEN_THROW_GLOBAL_INVALID_ARG(sourceCode)
virtual std::string description() const
Teuchos::RCP< const Teuchos::Comm< int > > getComm() const
Get this Map&#39;s Comm object.
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
Get the underlying Epetra map.
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...
int LID(int GID) const
bool MyGID(int GID_in) const
LocalOrdinal getLocalElement(GlobalOrdinal globalIndex) const
The local index corresponding to the given global index.
T * getRawPtr() const
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.
const Epetra_Comm & Comm() const
RCP< const Epetra_BlockMap > map_
size_t global_size_t
Global size_t object.
bool LinearMap() const
global_size_t getGlobalNumElements() const
The number of elements in this Map.
static const EVerbosityLevel verbLevel_default
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_size_t getGlobalNumElements() const
The number of elements in this Map.
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?)
RCP< const CrsGraph< int, GlobalOrdinal, Node > > toXpetra(const Epetra_CrsGraph &g)
GlobalOrdinal getMinGlobalIndex() const
The minimum global index owned by the calling process.
#define TEUCHOS_UNREACHABLE_RETURN(dummyReturnVal)
const Epetra_Map & getEpetra_Map() const
bool isCompatible(const Map< LocalOrdinal, GlobalOrdinal, Node > &map) const
True if and only if map is compatible with this Map.
virtual ~EpetraMapT()
Destructor.
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.
bool MyLID(int lid) const
GlobalOrdinal getMaxGlobalIndex() const
The maximum global index owned by the calling process.
bool isCompatible(const Map< LocalOrdinal, GlobalOrdinal, Node > &map) const
True if and only if map is compatible with this Map.
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.
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.
LookupStatus getRemoteIndexList(const Teuchos::ArrayView< const GlobalOrdinal > &, const Teuchos::ArrayView< int > &) const
Return the process ranks for the given global indices.
std::string typeName(const T &t)
Epetra_BlockMap * RemoveEmptyProcesses() const
std::string description() const
Return a simple one-line description of this object.
int RemoteIDList(int NumIDs, const int *GIDList, int *PIDList, int *LIDList) const