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  template<class GlobalOrdinal, class Node>
69  const Epetra_Map & toEpetra(const RCP< const Map<int, GlobalOrdinal, Node> > &);
70  //template<class GlobalOrdinal>
71  //const RCP< const Map<int, GlobalOrdinal> > toXpetra(const RCP< const Epetra_Map > &);
72  template<class GlobalOrdinal, class Node>
73  const RCP< const Map<int, GlobalOrdinal, Node> > toXpetra(const Epetra_BlockMap &);
74 
75  // stub implementation for EpetraMapT
76  template<class GlobalOrdinal, class Node>
77  class EpetraMapT
78  : public virtual Map<int, GlobalOrdinal, Node>
79  {
80  typedef int LocalOrdinal;
81 
82  public:
83  typedef int local_ordinal_type;
84  typedef GlobalOrdinal global_ordinal_type;
85  typedef Node node_type;
86 
88 
89 
91 #ifdef TPETRA_ENABLE_DEPRECATED_CODE
92  TPETRA_DEPRECATED
93  EpetraMapT(global_size_t numGlobalElements,
94  GlobalOrdinal indexBase,
95  const Teuchos::RCP< const Teuchos::Comm< int > > &comm,
96  LocalGlobal lg,
97  const Teuchos::RCP< Node > &/*node*/)
98  : EpetraMapT(numGlobalElements, indexBase, comm, lg)
99  {}
100 #endif // TPETRA_ENABLE_DEPRECATED_CODE
101  EpetraMapT(global_size_t numGlobalElements,
102  GlobalOrdinal indexBase,
103  const Teuchos::RCP< const Teuchos::Comm< int > > &comm,
105  {
107  "Xpetra::EpetraMap only available for GO=int or GO=long long with EpetraNode (Serial or OpenMP depending on configuration)");
108  }
109 
111 #ifdef TPETRA_ENABLE_DEPRECATED_CODE
112  TPETRA_DEPRECATED
113  EpetraMapT(global_size_t numGlobalElements, size_t numLocalElements, GlobalOrdinal indexBase, const Teuchos::RCP< const Teuchos::Comm< int > > &comm, const Teuchos::RCP< Node > &node)
114  : EpetraMapT(numGlobalElements, numLocalElements, indexBase, comm)
115  {}
116 #endif // TPETRA_ENABLE_DEPRECATED_CODE
117  EpetraMapT(global_size_t numGlobalElements, size_t numLocalElements, GlobalOrdinal indexBase, const Teuchos::RCP< const Teuchos::Comm< int > > &comm) {
119  "Xpetra::EpetraMap only available for GO=int or GO=long long with EpetraNode (Serial or OpenMP depending on configuration)");
120  }
121 
123 #ifdef TPETRA_ENABLE_DEPRECATED_CODE
124  TPETRA_DEPRECATED
125  EpetraMapT(global_size_t numGlobalElements,
127  GlobalOrdinal indexBase,
128  const Teuchos::RCP< const Teuchos::Comm< int > > &comm,
129  const Teuchos::RCP< Node > &node)
130  : EpetraMapT(numGlobalElements, elementList, indexBase, comm)
131  {}
132 #endif // TPETRA_ENABLE_DEPRECATED_CODE
133  EpetraMapT(global_size_t numGlobalElements,
135  GlobalOrdinal indexBase,
136  const Teuchos::RCP< const Teuchos::Comm< int > > &comm) {
138  "Xpetra::EpetraMap only available for GO=int or GO=long long with EpetraNode (Serial or OpenMP depending on configuration)");
139  }
140 
142 
144 
145 
147  global_size_t getGlobalNumElements() const { return 0; }
148 
150  size_t getNodeNumElements() const { return 0; }
151 
153  GlobalOrdinal getIndexBase() const { return 0; }
154 
156  LocalOrdinal getMinLocalIndex() const { return 0; }
157 
159  LocalOrdinal getMaxLocalIndex() const { return 0; }
160 
162  GlobalOrdinal getMinGlobalIndex() const { return 0; }
163 
165  GlobalOrdinal getMaxGlobalIndex() const { return 0; }
166 
168  GlobalOrdinal getMinAllGlobalIndex() const { return 0; }
169 
171  GlobalOrdinal getMaxAllGlobalIndex() const { return 0; }
172 
174  LocalOrdinal getLocalElement(GlobalOrdinal /* globalIndex */) const { return 0; }
175 
178 
181 
183  //Teuchos::ArrayView< const GlobalOrdinal > getNodeElementList() const;
184 
187 
189 
190 
192  bool isNodeLocalElement(LocalOrdinal /* localIndex */) const { return false; }
193 
195  bool isNodeGlobalElement(GlobalOrdinal /* globalIndex */) const { return false; }
196 
198  bool isContiguous() const { return false; }
199 
201  bool isDistributed() const { return false; }
202 
204  bool isCompatible(const Map< LocalOrdinal, GlobalOrdinal, Node > &/* map */) const { return false; }
205 
207  bool isSameAs(const Map< LocalOrdinal, GlobalOrdinal, Node > &/* map */) const { return false; }
208 
210 
212 
213 
215  Teuchos::RCP< const Teuchos::Comm< int > > getComm() const { return Teuchos::null; }
216 
217 #ifdef TPETRA_ENABLE_DEPRECATED_CODE
218  Teuchos::RCP< Node > getNode() const {
220  XPETRA_MONITOR("EpetraMapT<GlobalOrdinal>::getNode");
221  return Teuchos::rcp (new Node);
222  }
223 #endif // TPETRA_ENABLE_DEPRECATED_CODE
224 
226 
228 
229 
231  std::string description() const { return std::string(""); }
232 
235 
237 
239 
240 
243 
245  RCP<const Map<int,GlobalOrdinal,Node> > replaceCommWithSubset(const Teuchos::RCP< const Teuchos::Comm< int > > &/* newComm */) const { return Teuchos::null; }
246 
248 
250  GlobalOrdinal getGlobalElement(LocalOrdinal /* localIndex */) const { return -1; }
251 
253 
254 
256  virtual ~EpetraMapT() {}
257 
260  : map_(map) {
262  "Xpetra::EpetraMap only available for GO=int or GO=long long with EpetraNode (Serial or OpenMP depending on configuration)");
263  }
264 
266  UnderlyingLib lib() const { return Xpetra::UseEpetra; }
267 
269  //const RCP< const Epetra_Map > & getEpetra_Map() const { return map_; }
270  const Epetra_BlockMap& getEpetra_BlockMap() const { return *map_; }
271  const Epetra_Map& getEpetra_Map() const { return (Epetra_Map &)*map_; } // Ugly, but the same is done in Epetra_CrsMatrix.h to get the map.
272 
273 #ifdef HAVE_XPETRA_KOKKOS_REFACTOR
274 #ifdef HAVE_XPETRA_TPETRA
275  using local_map_type = typename Map<LocalOrdinal, GlobalOrdinal, Node>::local_map_type;
277  local_map_type getLocalMap () const {
278  throw std::runtime_error("Xpetra::EpetraMap::getLocalMap is not implemented.");
279  }
280 #else
281 #ifdef __GNUC__
282 #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."
283 #endif
284 #endif
285 #endif
286 
288 
289  protected:
290 
292  }; // EpetraMapT class
293 
294  // specialization on GO=int and EpetraNode
295 #ifndef XPETRA_EPETRA_NO_32BIT_GLOBAL_INDICES
296  template<>
297  class EpetraMapT<int, EpetraNode>
298  : public virtual Map<int, int, EpetraNode>
299  {
300  typedef int LocalOrdinal;
301  typedef int GlobalOrdinal;
302  typedef EpetraNode Node;
303 
304  public:
307  typedef Node node_type;
308 
310 
311 
313 #ifdef TPETRA_ENABLE_DEPRECATED_CODE
314  TPETRA_DEPRECATED
315  EpetraMapT(global_size_t numGlobalElements,
316  GlobalOrdinal indexBase,
317  const Teuchos::RCP< const Teuchos::Comm< int > > &comm,
318  LocalGlobal lg,
319  const Teuchos::RCP< Node > &/* node */)
320  : EpetraMapT(numGlobalElements, indexBase, comm, lg)
321  {}
322 #endif // TPETRA_ENABLE_DEPRECATED_CODE
323  EpetraMapT(global_size_t numGlobalElements,
324  GlobalOrdinal indexBase,
325  const Teuchos::RCP< const Teuchos::Comm< int > > &comm,
327  {
328  // This test come from Tpetra (Epetra doesn't check if numGlobalElements,indexBase are equivalent across images).
329  // 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.
330  std::string errPrefix;
331  errPrefix = Teuchos::typeName(*this) + "::constructor(numGlobal,indexBase,comm,lOrG): ";
332 
333  if (lg == GloballyDistributed) {
334  const int myImageID = comm->getRank();
335 
336  // check that numGlobalElements,indexBase is equivalent across images
337  global_size_t rootNGE = numGlobalElements;
338  GlobalOrdinal rootIB = indexBase;
339  Teuchos::broadcast<int,global_size_t>(*comm,0,&rootNGE);
340  Teuchos::broadcast<int,GlobalOrdinal>(*comm,0,&rootIB);
341  int localChecks[2], globalChecks[2];
342  localChecks[0] = -1; // fail or pass
343  localChecks[1] = 0; // fail reason
344  if (numGlobalElements != rootNGE) {
345  localChecks[0] = myImageID;
346  localChecks[1] = 1;
347  }
348  else if (indexBase != rootIB) {
349  localChecks[0] = myImageID;
350  localChecks[1] = 2;
351  }
352  // REDUCE_MAX will give us the image ID of the highest rank proc that DID NOT pass, as well as the reason
353  // these will be -1 and 0 if all procs passed
354  Teuchos::reduceAll<int,int>(*comm,Teuchos::REDUCE_MAX,2,localChecks,globalChecks);
355  if (globalChecks[0] != -1) {
356  if (globalChecks[1] == 1) {
357  TEUCHOS_TEST_FOR_EXCEPTION(true,std::invalid_argument,
358  errPrefix << "numGlobal must be the same on all nodes (examine node " << globalChecks[0] << ").");
359  }
360  else if (globalChecks[1] == 2) {
361  TEUCHOS_TEST_FOR_EXCEPTION(true,std::invalid_argument,
362  errPrefix << "indexBase must be the same on all nodes (examine node " << globalChecks[0] << ").");
363  }
364  else {
365  // logic error on our part
366  TEUCHOS_TEST_FOR_EXCEPTION(true,std::logic_error,
367  errPrefix << "logic error. Please contact the Tpetra team.");
368  }
369  }
370  }
371 
372  // Note: validity of numGlobalElements checked by Epetra.
373 
374  IF_EPETRA_EXCEPTION_THEN_THROW_GLOBAL_INVALID_ARG((map_ = (rcp(new Epetra_BlockMap(static_cast<GlobalOrdinal>(numGlobalElements), 1, indexBase, *toEpetra(comm))))));
375  }
376 
378 #ifdef TPETRA_ENABLE_DEPRECATED_CODE
379  TPETRA_DEPRECATED
380  EpetraMapT(global_size_t numGlobalElements, size_t numLocalElements, GlobalOrdinal indexBase, const Teuchos::RCP< const Teuchos::Comm< int > > &comm, const Teuchos::RCP< Node > &/* node */)
381  : EpetraMapT(numGlobalElements, numLocalElements, indexBase, comm)
382  {}
383 #endif // TPETRA_ENABLE_DEPRECATED_CODE
384  EpetraMapT(global_size_t numGlobalElements, size_t numLocalElements, GlobalOrdinal indexBase, const Teuchos::RCP< const Teuchos::Comm< int > > &comm)
385  {
386  // This test come from Tpetra
387  using Teuchos::outArg;
388 
389  const size_t L0 = Teuchos::OrdinalTraits<size_t>::zero();
390  const size_t L1 = Teuchos::OrdinalTraits<size_t>::one();
394 
395  std::string errPrefix;
396  errPrefix = Teuchos::typeName(*this) + "::constructor(numGlobal,numLocal,indexBase,platform): ";
397 
398  // get a internodal communicator from the Platform
399  const int myImageID = comm->getRank();
400 
401  global_size_t global_sum;
402  { // begin scoping block
403  // for communicating failures
404  int localChecks[2], globalChecks[2];
405  /* compute the global size
406  we are computing the number of global elements because exactly ONE of the following is true:
407  - the user didn't specify it, and we need it
408  - the user did specify it, but we need to
409  + validate it against the sum of the local sizes, and
410  + ensure that it is the same on all nodes
411  */
412  Teuchos::reduceAll<int,global_size_t>(*comm,Teuchos::REDUCE_SUM,
413  Teuchos::as<global_size_t>(numLocalElements),outArg(global_sum));
414  /* there are three errors we should be detecting:
415  - numGlobalElements != invalid() and it is incorrect/invalid
416  - numLocalElements invalid (<0)
417  */
418  localChecks[0] = -1;
419  localChecks[1] = 0;
420  if (numLocalElements < L1 && numLocalElements != L0) {
421  // invalid
422  localChecks[0] = myImageID;
423  localChecks[1] = 1;
424  }
425  else if (numGlobalElements < GST1 && numGlobalElements != GST0 && numGlobalElements != GSTI) {
426  // invalid
427  localChecks[0] = myImageID;
428  localChecks[1] = 2;
429  }
430  else if (numGlobalElements != GSTI && numGlobalElements != global_sum) {
431  // incorrect
432  localChecks[0] = myImageID;
433  localChecks[1] = 3;
434  }
435  // now check that indexBase is equivalent across images
436  GlobalOrdinal rootIB = indexBase;
437  Teuchos::broadcast<int,GlobalOrdinal>(*comm,0,&rootIB); // broadcast one ordinal from node 0
438  if (indexBase != rootIB) {
439  localChecks[0] = myImageID;
440  localChecks[1] = 4;
441  }
442  // REDUCE_MAX will give us the image ID of the highest rank proc that DID NOT pass
443  // this will be -1 if all procs passed
444  Teuchos::reduceAll<int,int>(*comm,Teuchos::REDUCE_MAX,2,localChecks,globalChecks);
445  if (globalChecks[0] != -1) {
446  if (globalChecks[1] == 1) {
447  TEUCHOS_TEST_FOR_EXCEPTION(true,std::invalid_argument,
448  errPrefix << "numLocal is not valid on at least one node (possibly node "
449  << globalChecks[0] << ").");
450  }
451  else if (globalChecks[1] == 2) {
452  TEUCHOS_TEST_FOR_EXCEPTION(true,std::invalid_argument,
453  errPrefix << "numGlobal is not valid on at least one node (possibly node "
454  << globalChecks[0] << ").");
455  }
456  else if (globalChecks[1] == 3) {
457  TEUCHOS_TEST_FOR_EXCEPTION(true,std::invalid_argument,
458  errPrefix << "numGlobal doesn't match sum of numLocal (== "
459  << global_sum << ") on at least one node (possibly node "
460  << globalChecks[0] << ").");
461  }
462  else if (globalChecks[1] == 4) {
463  TEUCHOS_TEST_FOR_EXCEPTION(true,std::invalid_argument,
464  errPrefix << "indexBase is not the same on all nodes (examine node "
465  << globalChecks[0] << ").");
466  }
467  else {
468  // logic error on my part
469  TEUCHOS_TEST_FOR_EXCEPTION(true,std::logic_error,
470  errPrefix << "logic error. Please contact the Tpetra team.");
471  }
472  }
473 
474  }
475 
476  // set numGlobalElements
477  if (numGlobalElements == GSTI) {
478  numGlobalElements = global_sum;}
479 
480  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))))));
481  }
482 
484 #ifdef TPETRA_ENABLE_DEPRECATED_CODE
485  TPETRA_DEPRECATED
486  EpetraMapT(global_size_t numGlobalElements,
488  GlobalOrdinal indexBase,
489  const Teuchos::RCP< const Teuchos::Comm< int > > &comm,
490  const Teuchos::RCP< Node > &/* node */)
491  : EpetraMapT(numGlobalElements, elementList, indexBase, comm)
492  {}
493 #endif // TPETRA_ENABLE_DEPRECATED_CODE
494  EpetraMapT(global_size_t numGlobalElements,
496  GlobalOrdinal indexBase,
497  const Teuchos::RCP< const Teuchos::Comm< int > > &comm)
498  {
499  if (numGlobalElements == Teuchos::OrdinalTraits<global_size_t>::invalid()) {
500  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))))));
501  } else {
502  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))))));
503  }
504  }
505 
507 
509 
510 
512  global_size_t getGlobalNumElements() const { XPETRA_MONITOR("EpetraMapT::getGlobalNumElements"); return map_->NumGlobalElements64(); }
513 
515  size_t getNodeNumElements() const { XPETRA_MONITOR("EpetraMapT::getNodeNumElements"); return map_->NumMyElements(); }
516 
518  GlobalOrdinal getIndexBase() const { XPETRA_MONITOR("EpetraMapT::getIndexBase"); return (GlobalOrdinal) map_->IndexBase64(); }
519 
521  LocalOrdinal getMinLocalIndex() const { XPETRA_MONITOR("EpetraMapT::getMinLocalIndex"); return map_->MinLID(); }
522 
524  LocalOrdinal getMaxLocalIndex() const { XPETRA_MONITOR("EpetraMapT::getMaxLocalIndex"); return map_->MaxLID(); }
525 
527  GlobalOrdinal getMinGlobalIndex() const { XPETRA_MONITOR("EpetraMapT::getMinGlobalIndex"); return (GlobalOrdinal) map_->MinMyGID64(); }
528 
530  GlobalOrdinal getMaxGlobalIndex() const { XPETRA_MONITOR("EpetraMapT::getMaxGlobalIndex"); return (GlobalOrdinal) map_->MaxMyGID64(); }
531 
533  GlobalOrdinal getMinAllGlobalIndex() const { XPETRA_MONITOR("EpetraMapT::getMinAllGlobalIndex"); return (GlobalOrdinal) map_->MinAllGID64(); }
534 
536  GlobalOrdinal getMaxAllGlobalIndex() const { XPETRA_MONITOR("EpetraMapT::getMaxAllGlobalIndex"); return (GlobalOrdinal) map_->MaxAllGID64(); }
537 
539  LocalOrdinal getLocalElement(GlobalOrdinal globalIndex) const { XPETRA_MONITOR("EpetraMapT::getLocalElement"); return map_->LID(globalIndex); }
540 
542  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(static_cast<int>(GIDList.size()), GIDList.getRawPtr(), nodeIDList.getRawPtr(), LIDList.getRawPtr())); }
543 
545  LookupStatus getRemoteIndexList(const Teuchos::ArrayView< const GlobalOrdinal > &GIDList, const Teuchos::ArrayView< int > &nodeIDList) const { XPETRA_MONITOR("EpetraMapT::getRemoteIndexList"); return toXpetra(map_->RemoteIDList(static_cast<int>(GIDList.size()), GIDList.getRawPtr(), nodeIDList.getRawPtr(), 0)); }
546 
550 
552 
553 
555  bool isNodeLocalElement(LocalOrdinal localIndex) const { XPETRA_MONITOR("EpetraMapT::isNodeLocalElement"); return map_->MyLID(localIndex); }
556 
558  bool isNodeGlobalElement(GlobalOrdinal globalIndex) const { XPETRA_MONITOR("EpetraMapT::isNodeGlobalElement"); return map_->MyGID(globalIndex); }
559 
561  bool isContiguous() const { XPETRA_MONITOR("EpetraMapT::isContiguous"); return map_->LinearMap(); }
562 
564  bool isDistributed() const { XPETRA_MONITOR("EpetraMapT::isDistributed"); return map_->DistributedGlobal(); }
565 
567  bool isCompatible(const Map< LocalOrdinal, GlobalOrdinal, Node > &map) const { XPETRA_MONITOR("EpetraMapT::isCompatible"); return map_->PointSameAs(toEpetra<GlobalOrdinal,Node>(map)); }
568 
570  bool isSameAs(const Map< LocalOrdinal, GlobalOrdinal, Node > &map) const { XPETRA_MONITOR("EpetraMapT::isSameAs"); return map_->SameAs(toEpetra<GlobalOrdinal,Node>(map)); }
571 
573 
575 
576 
578  Teuchos::RCP< const Teuchos::Comm< int > > getComm() const { XPETRA_MONITOR("EpetraMapT::getComm"); return toXpetra(map_->Comm()); }
579 
580 #ifdef TPETRA_ENABLE_DEPRECATED_CODE
581  Teuchos::RCP< Node > getNode() const {
583  XPETRA_MONITOR("EpetraMapT<GlobalOrdinal>::getNode");
584  return Teuchos::rcp (new Node);
585  }
586 #endif // TPETRA_ENABLE_DEPRECATED_CODE
587 
589 
591 
592 
594  std::string description() const {
595  XPETRA_MONITOR("EpetraMapT::description");
596 
597  // This implementation come from Tpetra_Map_def.hpp (without modification)
598  std::ostringstream oss;
600  oss << "{getGlobalNumElements() = " << getGlobalNumElements()
601  << ", getNodeNumElements() = " << getNodeNumElements()
602  << ", isContiguous() = " << isContiguous()
603  << ", isDistributed() = " << isDistributed()
604  << "}";
605  return oss.str();
606  }
607 
610  XPETRA_MONITOR("EpetraMapT::describe");
611 
613 
614  // This implementation come from Tpetra_Map_def.hpp (without modification)
615  using std::endl;
616  using std::setw;
617  using Teuchos::VERB_DEFAULT;
618  using Teuchos::VERB_NONE;
619  using Teuchos::VERB_LOW;
620  using Teuchos::VERB_MEDIUM;
621  using Teuchos::VERB_HIGH;
622  using Teuchos::VERB_EXTREME;
623 
624  const size_t nME = getNodeNumElements();
626  int myImageID = comm_->getRank();
627  int numImages = comm_->getSize();
628 
629  Teuchos::EVerbosityLevel vl = verbLevel;
630  if (vl == VERB_DEFAULT) vl = VERB_LOW;
631 
632  size_t width = 1;
633  for (size_t dec=10; dec<getGlobalNumElements(); dec *= 10) {
634  ++width;
635  }
636  width = ::std::max<size_t>(width, (size_t) 12) + 2; // casting to size_t to avoid ambiguity error when compiling Sacado.
637 
638  Teuchos::OSTab tab(out);
639 
640  if (vl == VERB_NONE) {
641  // do nothing
642  }
643  else if (vl == VERB_LOW) {
644  out << this->description() << endl;
645  }
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 
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 
704  throw std::runtime_error("Xpetra::EpetraMapT::replaceCommWithSubset has not yet been implemented.");
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) return (-1);
716  else return (gid);
717  }
718 
720 
721 
723  virtual ~EpetraMapT() {}
724 
727  : map_(map) {
728  TEUCHOS_TEST_FOR_EXCEPTION(!map->GlobalIndicesIsType<GlobalOrdinal>(), std::runtime_error, "Xpetra::EpetraMapT: GlobalOrdinal mismatch.");
729  }
730 
732  UnderlyingLib lib() const { return Xpetra::UseEpetra; }
733 
735  //const RCP< const Epetra_Map > & getEpetra_Map() const { return map_; }
736  const Epetra_BlockMap& getEpetra_BlockMap() const { return *map_; }
737  const Epetra_Map& getEpetra_Map() const { return (Epetra_Map &)*map_; } // Ugly, but the same is done in Epetra_CrsMatrix.h to get the map.
738 
740 
741 #ifdef HAVE_XPETRA_KOKKOS_REFACTOR
742 #ifdef HAVE_XPETRA_TPETRA
743  using local_map_type = typename Map<LocalOrdinal, GlobalOrdinal, Node>::local_map_type;
745  local_map_type getLocalMap () const {
746  throw std::runtime_error("Xpetra::EpetraMap::getLocalMap is not implemented.");
747  }
748 
749  private:
750  mutable local_map_type localMap_;
751 #else
752 #ifdef __GNUC__
753 #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."
754 #endif
755 #endif
756 #endif
757 
758  protected:
759 
761 }; // EpetraMapT class
762 #endif // #ifndef XPETRA_EPETRA_NO_32BIT_GLOBAL_INDICES
763 
764 // specialization on GO=long long and EpetraNode
765 #ifndef XPETRA_EPETRA_NO_64BIT_GLOBAL_INDICES
766  template<>
767  class EpetraMapT<long long, EpetraNode>
768  : public virtual Map<int, long long, EpetraNode>
769  {
770  typedef int LocalOrdinal;
771  typedef long long GlobalOrdinal;
772  typedef EpetraNode Node;
773 
774  public:
777  typedef Node node_type;
778 
780 
781 
783 #ifdef TPETRA_ENABLE_DEPRECATED_CODE
784  TPETRA_DEPRECATED
785  EpetraMapT(global_size_t numGlobalElements,
786  GlobalOrdinal indexBase,
787  const Teuchos::RCP< const Teuchos::Comm< int > > &comm,
788  LocalGlobal lg,
789  const Teuchos::RCP< Node > &/* node */)
790  : EpetraMapT(numGlobalElements, indexBase, comm, lg)
791  {}
792 #endif // TPETRA_ENABLE_DEPRECATED_CODE
793  EpetraMapT(global_size_t numGlobalElements,
794  GlobalOrdinal indexBase,
795  const Teuchos::RCP< const Teuchos::Comm< int > > &comm,
797  {
798  // This test come from Tpetra (Epetra doesn't check if numGlobalElements,indexBase are equivalent across images).
799  // 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.
800  std::string errPrefix;
801  errPrefix = Teuchos::typeName(*this) + "::constructor(numGlobal,indexBase,comm,lOrG): ";
802 
803  if (lg == GloballyDistributed) {
804  const int myImageID = comm->getRank();
805 
806  // check that numGlobalElements,indexBase is equivalent across images
807  global_size_t rootNGE = numGlobalElements;
808  GlobalOrdinal rootIB = indexBase;
809  Teuchos::broadcast<int,global_size_t>(*comm,0,&rootNGE);
810  Teuchos::broadcast<int,GlobalOrdinal>(*comm,0,&rootIB);
811  int localChecks[2], globalChecks[2];
812  localChecks[0] = -1; // fail or pass
813  localChecks[1] = 0; // fail reason
814  if (numGlobalElements != rootNGE) {
815  localChecks[0] = myImageID;
816  localChecks[1] = 1;
817  }
818  else if (indexBase != rootIB) {
819  localChecks[0] = myImageID;
820  localChecks[1] = 2;
821  }
822  // REDUCE_MAX will give us the image ID of the highest rank proc that DID NOT pass, as well as the reason
823  // these will be -1 and 0 if all procs passed
824  Teuchos::reduceAll<int,int>(*comm,Teuchos::REDUCE_MAX,2,localChecks,globalChecks);
825  if (globalChecks[0] != -1) {
826  if (globalChecks[1] == 1) {
827  TEUCHOS_TEST_FOR_EXCEPTION(true,std::invalid_argument,
828  errPrefix << "numGlobal must be the same on all nodes (examine node " << globalChecks[0] << ").");
829  }
830  else if (globalChecks[1] == 2) {
831  TEUCHOS_TEST_FOR_EXCEPTION(true,std::invalid_argument,
832  errPrefix << "indexBase must be the same on all nodes (examine node " << globalChecks[0] << ").");
833  }
834  else {
835  // logic error on our part
836  TEUCHOS_TEST_FOR_EXCEPTION(true,std::logic_error,
837  errPrefix << "logic error. Please contact the Tpetra team.");
838  }
839  }
840  }
841 
842  // Note: validity of numGlobalElements checked by Epetra.
843 
844  IF_EPETRA_EXCEPTION_THEN_THROW_GLOBAL_INVALID_ARG((map_ = (rcp(new Epetra_BlockMap(static_cast<GlobalOrdinal>(numGlobalElements), 1, indexBase, *toEpetra(comm))))));
845  }
846 
848 #ifdef TPETRA_ENABLE_DEPRECATED_CODE
849  TPETRA_DEPRECATED
850  EpetraMapT(global_size_t numGlobalElements, size_t numLocalElements, GlobalOrdinal indexBase, const Teuchos::RCP< const Teuchos::Comm< int > > &comm, const Teuchos::RCP< Node > &/* node */)
851  : EpetraMapT(numGlobalElements, numLocalElements, indexBase, comm)
852  {}
853 #endif // TPETRA_ENABLE_DEPRECATED_CODE
854  EpetraMapT(global_size_t numGlobalElements, size_t numLocalElements, GlobalOrdinal indexBase, const Teuchos::RCP< const Teuchos::Comm< int > > &comm) {
855  // This test come from Tpetra
856  using Teuchos::outArg;
857 
858  const size_t L0 = Teuchos::OrdinalTraits<size_t>::zero();
859  const size_t L1 = Teuchos::OrdinalTraits<size_t>::one();
863 
864  std::string errPrefix;
865  errPrefix = Teuchos::typeName(*this) + "::constructor(numGlobal,numLocal,indexBase,platform): ";
866 
867  // get a internodal communicator from the Platform
868  const int myImageID = comm->getRank();
869 
870  global_size_t global_sum;
871  { // begin scoping block
872  // for communicating failures
873  int localChecks[2], globalChecks[2];
874  /* compute the global size
875  we are computing the number of global elements because exactly ONE of the following is true:
876  - the user didn't specify it, and we need it
877  - the user did specify it, but we need to
878  + validate it against the sum of the local sizes, and
879  + ensure that it is the same on all nodes
880  */
881  Teuchos::reduceAll<int,global_size_t>(*comm,Teuchos::REDUCE_SUM,
882  Teuchos::as<global_size_t>(numLocalElements),outArg(global_sum));
883  /* there are three errors we should be detecting:
884  - numGlobalElements != invalid() and it is incorrect/invalid
885  - numLocalElements invalid (<0)
886  */
887  localChecks[0] = -1;
888  localChecks[1] = 0;
889  if (numLocalElements < L1 && numLocalElements != L0) {
890  // invalid
891  localChecks[0] = myImageID;
892  localChecks[1] = 1;
893  }
894  else if (numGlobalElements < GST1 && numGlobalElements != GST0 && numGlobalElements != GSTI) {
895  // invalid
896  localChecks[0] = myImageID;
897  localChecks[1] = 2;
898  }
899  else if (numGlobalElements != GSTI && numGlobalElements != global_sum) {
900  // incorrect
901  localChecks[0] = myImageID;
902  localChecks[1] = 3;
903  }
904  // now check that indexBase is equivalent across images
905  GlobalOrdinal rootIB = indexBase;
906  Teuchos::broadcast<int,GlobalOrdinal>(*comm,0,&rootIB); // broadcast one ordinal from node 0
907  if (indexBase != rootIB) {
908  localChecks[0] = myImageID;
909  localChecks[1] = 4;
910  }
911  // REDUCE_MAX will give us the image ID of the highest rank proc that DID NOT pass
912  // this will be -1 if all procs passed
913  Teuchos::reduceAll<int,int>(*comm,Teuchos::REDUCE_MAX,2,localChecks,globalChecks);
914  if (globalChecks[0] != -1) {
915  if (globalChecks[1] == 1) {
916  TEUCHOS_TEST_FOR_EXCEPTION(true,std::invalid_argument,
917  errPrefix << "numLocal is not valid on at least one node (possibly node "
918  << globalChecks[0] << ").");
919  }
920  else if (globalChecks[1] == 2) {
921  TEUCHOS_TEST_FOR_EXCEPTION(true,std::invalid_argument,
922  errPrefix << "numGlobal is not valid on at least one node (possibly node "
923  << globalChecks[0] << ").");
924  }
925  else if (globalChecks[1] == 3) {
926  TEUCHOS_TEST_FOR_EXCEPTION(true,std::invalid_argument,
927  errPrefix << "numGlobal doesn't match sum of numLocal (== "
928  << global_sum << ") on at least one node (possibly node "
929  << globalChecks[0] << ").");
930  }
931  else if (globalChecks[1] == 4) {
932  TEUCHOS_TEST_FOR_EXCEPTION(true,std::invalid_argument,
933  errPrefix << "indexBase is not the same on all nodes (examine node "
934  << globalChecks[0] << ").");
935  }
936  else {
937  // logic error on my part
938  TEUCHOS_TEST_FOR_EXCEPTION(true,std::logic_error,
939  errPrefix << "logic error. Please contact the Tpetra team.");
940  }
941  }
942 
943  }
944 
945  // set numGlobalElements
946  if (numGlobalElements == GSTI) {
947  numGlobalElements = global_sum;}
948 
949  IF_EPETRA_EXCEPTION_THEN_THROW_GLOBAL_INVALID_ARG((map_ = (rcp(new Epetra_BlockMap(static_cast<GlobalOrdinal>(numGlobalElements), numLocalElements, 1, indexBase, *toEpetra(comm))))));
950  }
951 
953 #ifdef TPETRA_ENABLE_DEPRECATED_CODE
954  TPETRA_DEPRECATED
955  EpetraMapT(global_size_t numGlobalElements,
957  GlobalOrdinal indexBase,
958  const Teuchos::RCP< const Teuchos::Comm< int > > &comm,
959  const Teuchos::RCP< Node > &/* node */)
960  : EpetraMapT(numGlobalElements, elementList, indexBase, comm)
961  {}
962 #endif // TPETRA_ENABLE_DEPRECATED_CODE
963  EpetraMapT(global_size_t numGlobalElements,
965  GlobalOrdinal indexBase,
966  const Teuchos::RCP< const Teuchos::Comm< int > > &comm)
967  {
968  if (numGlobalElements == Teuchos::OrdinalTraits<global_size_t>::invalid()) {
969  IF_EPETRA_EXCEPTION_THEN_THROW_GLOBAL_INVALID_ARG((map_ = (rcp(new Epetra_BlockMap(-1, elementList.size(), elementList.getRawPtr(), 1, indexBase, *toEpetra(comm))))));
970  } else {
971  IF_EPETRA_EXCEPTION_THEN_THROW_GLOBAL_INVALID_ARG((map_ = (rcp(new Epetra_BlockMap(numGlobalElements, elementList.size(), elementList.getRawPtr(), 1, indexBase, *toEpetra(comm))))));
972  }
973  }
974 
976 
978 
979 
981  global_size_t getGlobalNumElements() const { XPETRA_MONITOR("EpetraMapT::getGlobalNumElements"); return map_->NumGlobalElements64(); }
982 
984  size_t getNodeNumElements() const { XPETRA_MONITOR("EpetraMapT::getNodeNumElements"); return map_->NumMyElements(); }
985 
987  GlobalOrdinal getIndexBase() const { XPETRA_MONITOR("EpetraMapT::getIndexBase"); return (GlobalOrdinal) map_->IndexBase64(); }
988 
990  LocalOrdinal getMinLocalIndex() const { XPETRA_MONITOR("EpetraMapT::getMinLocalIndex"); return map_->MinLID(); }
991 
993  LocalOrdinal getMaxLocalIndex() const { XPETRA_MONITOR("EpetraMapT::getMaxLocalIndex"); return map_->MaxLID(); }
994 
996  GlobalOrdinal getMinGlobalIndex() const { XPETRA_MONITOR("EpetraMapT::getMinGlobalIndex"); return (GlobalOrdinal) map_->MinMyGID64(); }
997 
999  GlobalOrdinal getMaxGlobalIndex() const { XPETRA_MONITOR("EpetraMapT::getMaxGlobalIndex"); return (GlobalOrdinal) map_->MaxMyGID64(); }
1000 
1002  GlobalOrdinal getMinAllGlobalIndex() const { XPETRA_MONITOR("EpetraMapT::getMinAllGlobalIndex"); return (GlobalOrdinal) map_->MinAllGID64(); }
1003 
1005  GlobalOrdinal getMaxAllGlobalIndex() const { XPETRA_MONITOR("EpetraMapT::getMaxAllGlobalIndex"); return (GlobalOrdinal) map_->MaxAllGID64(); }
1006 
1008  LocalOrdinal getLocalElement(GlobalOrdinal globalIndex) const { XPETRA_MONITOR("EpetraMapT::getLocalElement"); return map_->LID(globalIndex); }
1009 
1011  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())); }
1012 
1014  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)); }
1015 
1017  Teuchos::ArrayView< const GlobalOrdinal > getNodeElementList() const { XPETRA_MONITOR("EpetraMapT::getNodeElementList"); return ArrayView< const long long >(map_->MyGlobalElements64(), map_->NumMyElements()); }
1019 
1021 
1022 
1024  bool isNodeLocalElement(LocalOrdinal localIndex) const { XPETRA_MONITOR("EpetraMapT::isNodeLocalElement"); return map_->MyLID(localIndex); }
1025 
1027  bool isNodeGlobalElement(GlobalOrdinal globalIndex) const { XPETRA_MONITOR("EpetraMapT::isNodeGlobalElement"); return map_->MyGID(globalIndex); }
1028 
1030  bool isContiguous() const { XPETRA_MONITOR("EpetraMapT::isContiguous"); return map_->LinearMap(); }
1031 
1033  bool isDistributed() const { XPETRA_MONITOR("EpetraMapT::isDistributed"); return map_->DistributedGlobal(); }
1034 
1036  bool isCompatible(const Map< LocalOrdinal, GlobalOrdinal, Node > &map) const { XPETRA_MONITOR("EpetraMapT::isCompatible"); return map_->PointSameAs(toEpetra<GlobalOrdinal,Node>(map)); }
1037 
1039  bool isSameAs(const Map< LocalOrdinal, GlobalOrdinal, Node > &map) const { XPETRA_MONITOR("EpetraMapT::isSameAs"); return map_->SameAs(toEpetra<GlobalOrdinal,Node>(map)); }
1040 
1042 
1044 
1045 
1047  Teuchos::RCP< const Teuchos::Comm< int > > getComm() const { XPETRA_MONITOR("EpetraMapT::getComm"); return toXpetra(map_->Comm()); }
1048 
1049 #ifdef TPETRA_ENABLE_DEPRECATED_CODE
1050  Teuchos::RCP< Node > getNode() const {
1052  XPETRA_MONITOR("EpetraMapT<GlobalOrdinal>::getNode");
1053  return Teuchos::rcp (new Node);
1054  }
1055 #endif // TPETRA_ENABLE_DEPRECATED_CODE
1056 
1058 
1060 
1061 
1063  std::string description() const {
1064  XPETRA_MONITOR("EpetraMapT::description");
1065 
1066  // This implementation come from Tpetra_Map_def.hpp (without modification)
1067  std::ostringstream oss;
1069  oss << "{getGlobalNumElements() = " << getGlobalNumElements()
1070  << ", getNodeNumElements() = " << getNodeNumElements()
1071  << ", isContiguous() = " << isContiguous()
1072  << ", isDistributed() = " << isDistributed()
1073  << "}";
1074  return oss.str();
1075  }
1076 
1079  XPETRA_MONITOR("EpetraMapT::describe");
1080 
1082 
1083  // This implementation come from Tpetra_Map_def.hpp (without modification)
1084  using std::endl;
1085  using std::setw;
1086  using Teuchos::VERB_DEFAULT;
1087  using Teuchos::VERB_NONE;
1088  using Teuchos::VERB_LOW;
1089  using Teuchos::VERB_MEDIUM;
1090  using Teuchos::VERB_HIGH;
1091  using Teuchos::VERB_EXTREME;
1092 
1093  const size_t nME = getNodeNumElements();
1095  int myImageID = comm_->getRank();
1096  int numImages = comm_->getSize();
1097 
1098  Teuchos::EVerbosityLevel vl = verbLevel;
1099  if (vl == VERB_DEFAULT) vl = VERB_LOW;
1100 
1101  size_t width = 1;
1102  for (size_t dec=10; dec<getGlobalNumElements(); dec *= 10) {
1103  ++width;
1104  }
1105  width = ::std::max<size_t>(width, (size_t) 12) + 2; // casting to size_t to avoid ambiguity error when compiling Sacado.
1106 
1107  Teuchos::OSTab tab(out);
1108 
1109  if (vl == VERB_NONE) {
1110  // do nothing
1111  }
1112  else if (vl == VERB_LOW) {
1113  out << this->description() << endl;
1114  }
1115  else { // MEDIUM, HIGH or EXTREME
1116  for (int imageCtr = 0; imageCtr < numImages; ++imageCtr) {
1117  if (myImageID == imageCtr) {
1118  if (myImageID == 0) { // this is the root node (only output this info once)
1119  out << endl
1120  << "Number of Global Entries = " << getGlobalNumElements() << endl
1121  << "Maximum of all GIDs = " << getMaxAllGlobalIndex() << endl
1122  << "Minimum of all GIDs = " << getMinAllGlobalIndex() << endl
1123  << "Index Base = " << getIndexBase() << endl;
1124  }
1125  out << endl;
1126  if (vl == VERB_HIGH || vl == VERB_EXTREME) {
1127  out << "Number of Local Elements = " << nME << endl
1128  << "Maximum of my GIDs = " << getMaxGlobalIndex() << endl
1129  << "Minimum of my GIDs = " << getMinGlobalIndex() << endl;
1130  out << endl;
1131  }
1132  if (vl == VERB_EXTREME) {
1133  out << std::setw(width) << "Node ID"
1134  << std::setw(width) << "Local Index"
1135  << std::setw(width) << "Global Index"
1136  << endl;
1137  for (size_t i=0; i < nME; i++) {
1138  out << std::setw(width) << myImageID
1139  << std::setw(width) << i
1140  << std::setw(width) << myEntries[i]
1141  << endl;
1142  }
1143  out << std::flush;
1144  }
1145  }
1146  // Do a few global ops to give I/O a chance to complete
1147  comm_->barrier();
1148  comm_->barrier();
1149  comm_->barrier();
1150  }
1151  }
1152  }
1153 
1155 
1157 
1158 
1161  const Epetra_BlockMap * NewMap = map_->RemoveEmptyProcesses();
1162  if (!NewMap) {
1163  return Teuchos::null;
1164  } else {
1165  const RCP< const Map<int, GlobalOrdinal, Node> > NewMapX = toXpetra<GlobalOrdinal, Node>(*NewMap);
1166  delete NewMap; // NOTE: toXpetra *copys* the epetra map rather than wrapping it, so we have to delete NewMap to avoid a memory leak.
1167  return NewMapX;
1168  }
1169  }
1170 
1173  throw std::runtime_error("Xpetra::EpetraMapT::replaceCommWithSubset has not yet been implemented.");
1174  // return Teuchos::null; // unreachable
1175  }
1176 
1178 
1181  XPETRA_MONITOR("EpetraMapT::getGlobalElement");
1182 
1183  GlobalOrdinal gid = (GlobalOrdinal) map_->GID64(localIndex);
1184  if (gid == map_->IndexBase64()-1) return (-1);
1185  else return (gid);
1186  }
1187 
1189 
1190 
1192  virtual ~EpetraMapT() {}
1193 
1196  : map_(map) {
1197  TEUCHOS_TEST_FOR_EXCEPTION(!map->GlobalIndicesIsType<GlobalOrdinal>(), std::runtime_error, "Xpetra::EpetraMapT: GlobalOrdinal mismatch.");
1198  }
1199 
1202 
1204  //const RCP< const Epetra_Map > & getEpetra_Map() const { return map_; }
1205  const Epetra_BlockMap& getEpetra_BlockMap() const { return *map_; }
1206  const Epetra_Map& getEpetra_Map() const { return (Epetra_Map &)*map_; } // Ugly, but the same is done in Epetra_CrsMatrix.h to get the map.
1207 
1208 #ifdef HAVE_XPETRA_KOKKOS_REFACTOR
1209 #ifdef HAVE_XPETRA_TPETRA
1210  using local_map_type = typename Map<LocalOrdinal, GlobalOrdinal, Node>::local_map_type;
1212  local_map_type getLocalMap () const {
1213  throw std::runtime_error("Xpetra::EpetraMap::getLocalMap is not implemented.");
1214  }
1215 
1216  private:
1217  mutable local_map_type localMap_;
1218 #else
1219 #ifdef __GNUC__
1220 #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."
1221 #endif
1222 #endif
1223 #endif
1224 
1226 
1227  protected:
1228 
1230 }; // EpetraMapT class
1231 #endif // #ifndef XPETRA_EPETRA_NO_64BIT_GLOBAL_INDICES
1232 
1233 } // Xpetra namespace
1234 
1235 #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