Xpetra  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Xpetra_StridedMap_def.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 
47 // WARNING: This code is experimental. Backwards compatibility should not be expected.
48 
49 #ifndef XPETRA_STRIDEDMAP_DEF_HPP
50 #define XPETRA_STRIDEDMAP_DEF_HPP
51 
52 #include "Xpetra_StridedMap.hpp"
53 
54 #include <Teuchos_OrdinalTraits.hpp>
55 
56 #include "Xpetra_Exceptions.hpp"
57 #include "Xpetra_MapFactory.hpp"
58 
59 namespace Xpetra {
60 
61 template <class LocalOrdinal, class GlobalOrdinal, class Node>
64  global_size_t numGlobalElements,
65  GlobalOrdinal indexBase,
66  std::vector<size_t>& stridingInfo,
67  const Teuchos::RCP<const Teuchos::Comm<int>>& comm,
68  LocalOrdinal stridedBlockId, // FIXME (mfh 03 Sep 2014) This breaks for unsigned LocalOrdinal
69  GlobalOrdinal offset,
70  LocalGlobal lg)
71  : stridingInfo_(stridingInfo)
72  , stridedBlockId_(stridedBlockId)
73  , offset_(offset)
74  , indexBase_(indexBase) {
76 
77  size_t blkSize = getFixedBlockSize();
78 
79  TEUCHOS_TEST_FOR_EXCEPTION(stridingInfo.size() == 0,
81  "StridedMap::StridedMap: stridingInfo not valid: stridingInfo.size() = 0?");
82 
83  TEUCHOS_TEST_FOR_EXCEPTION(numGlobalElements == Teuchos::OrdinalTraits<global_size_t>::invalid(),
84  std::invalid_argument,
85  "StridedMap::StridedMap: numGlobalElements is invalid");
86 
87  TEUCHOS_TEST_FOR_EXCEPTION(numGlobalElements % blkSize != 0,
89  "StridedMap::StridedMap: stridingInfo not valid: getFixedBlockSize "
90  "is not an integer multiple of numGlobalElements.");
91 
92  if (stridedBlockId != -1) {
93  TEUCHOS_TEST_FOR_EXCEPTION(stridingInfo.size() < static_cast<size_t>(stridedBlockId),
95  "StridedTpetraMap::StridedTpetraMap: "
96  "stridedBlockId > stridingInfo.size()");
97  }
98 
99  // Try to create a shortcut
100  if (blkSize != 1 || offset_ != 0) {
101  // check input data and reorganize map
102  global_size_t numGlobalNodes = numGlobalElements / blkSize;
103 
104  // build an equally distributed node map
105  RCP<Map> nodeMap = MapFactory_t::Build(xlib, numGlobalNodes, indexBase, comm, lg);
106  global_size_t numLocalNodes = nodeMap->getLocalNumElements();
107 
108  // translate local node ids to local dofs
109  size_t nStridedOffset = 0;
110  size_t nDofsPerNode = blkSize; // dofs per node for local striding block
111  if (stridedBlockId > -1) {
112  for (int j = 0; j < stridedBlockId; j++) {
113  nStridedOffset += stridingInfo_[j];
114  }
115 
116  nDofsPerNode = stridingInfo_[stridedBlockId];
117  numGlobalElements = numGlobalNodes * Teuchos::as<global_size_t>(nDofsPerNode);
118  }
119  size_t numLocalElements = numLocalNodes * Teuchos::as<size_t>(nDofsPerNode);
120 
121  std::vector<GlobalOrdinal> dofgids(numLocalElements);
122  for (LocalOrdinal i = 0; i < Teuchos::as<LocalOrdinal>(numLocalNodes); i++) {
123  GlobalOrdinal nodeGID = nodeMap->getGlobalElement(i);
124 
125  for (size_t j = 0; j < nDofsPerNode; j++) {
126  dofgids[i * nDofsPerNode + j] = indexBase_ + offset_ + (nodeGID - indexBase_) * Teuchos::as<GlobalOrdinal>(blkSize) + Teuchos::as<GlobalOrdinal>(nStridedOffset + j);
127  }
128  }
129 
130  map_ = MapFactory_t::Build(xlib, numGlobalElements, dofgids, indexBase, comm);
131 
132  if (stridedBlockId == -1) {
133  TEUCHOS_TEST_FOR_EXCEPTION(getLocalNumElements() != Teuchos::as<size_t>(nodeMap->getLocalNumElements() * nDofsPerNode),
135  "StridedTpetraMap::StridedTpetraMap: wrong distribution of dofs among processors.");
136 
137  TEUCHOS_TEST_FOR_EXCEPTION(getGlobalNumElements() != Teuchos::as<size_t>(nodeMap->getGlobalNumElements() * nDofsPerNode),
139  "StridedTpetraMap::StridedTpetraMap: wrong distribution of dofs among processors.");
140  } else {
141  size_t nDofsInStridedBlock = stridingInfo[stridedBlockId];
142  TEUCHOS_TEST_FOR_EXCEPTION(getLocalNumElements() != Teuchos::as<size_t>(nodeMap->getLocalNumElements() * nDofsInStridedBlock),
144  "StridedTpetraMap::StridedTpetraMap: wrong distribution of dofs among processors.");
145 
146  TEUCHOS_TEST_FOR_EXCEPTION(getGlobalNumElements() != Teuchos::as<size_t>(nodeMap->getGlobalNumElements() * nDofsInStridedBlock),
148  "StridedTpetraMap::StridedTpetraMap: wrong distribution of dofs among processors.");
149  }
150  } else {
151  map_ = MapFactory_t::Build(xlib, numGlobalElements, indexBase, comm, lg);
152  }
153 
154  TEUCHOS_TEST_FOR_EXCEPTION(CheckConsistency() == false, Exceptions::RuntimeError, "StridedTpetraMap::StridedTpetraMap: CheckConsistency() == false");
155 }
156 
157 template <class LocalOrdinal, class GlobalOrdinal, class Node>
160  global_size_t numGlobalElements,
161  size_t numLocalElements,
162  GlobalOrdinal indexBase,
163  std::vector<size_t>& stridingInfo,
164  const Teuchos::RCP<const Teuchos::Comm<int>>& comm,
165  LocalOrdinal stridedBlockId,
166  GlobalOrdinal offset)
167  : stridingInfo_(stridingInfo)
168  , stridedBlockId_(stridedBlockId)
169  , offset_(offset)
170  , indexBase_(indexBase) {
172 
173  size_t blkSize = getFixedBlockSize();
174  TEUCHOS_TEST_FOR_EXCEPTION(stridingInfo.size() == 0,
176  "StridedMap::StridedMap: stridingInfo not valid: stridingInfo.size() = 0?");
177  if (numGlobalElements != Teuchos::OrdinalTraits<global_size_t>::invalid()) {
178  TEUCHOS_TEST_FOR_EXCEPTION(numGlobalElements % blkSize != 0,
180  "StridedMap::StridedMap: stridingInfo not valid: getFixedBlockSize is not an integer "
181  "multiple of numGlobalElements.");
182 #ifdef HAVE_XPETRA_DEBUG
183  // We have to do this check ourselves, as we don't necessarily construct the full Tpetra map
184  global_size_t sumLocalElements;
185  Teuchos::reduceAll(*comm, Teuchos::REDUCE_SUM, Teuchos::as<global_size_t>(numLocalElements), Teuchos::outArg(sumLocalElements));
186 
187  TEUCHOS_TEST_FOR_EXCEPTION(sumLocalElements != numGlobalElements,
188  std::invalid_argument,
189  "StridedMap::StridedMap: sum of numbers of local elements is different from the provided "
190  "number of global elements.");
191 #endif
192  }
193 
194  TEUCHOS_TEST_FOR_EXCEPTION(
195  numLocalElements % blkSize != 0,
197  "StridedMap::StridedMap: stridingInfo not valid: getFixedBlockSize is not an integer multiple of numLocalElements.");
198 
199  if (stridedBlockId != -1) {
200  TEUCHOS_TEST_FOR_EXCEPTION(stridingInfo.size() < Teuchos::as<size_t>(stridedBlockId),
202  "StridedTpetraMap::StridedTpetraMap: stridedBlockId > stridingInfo.size()");
203  }
204 
205  // Try to create a shortcut
206  if (blkSize != 1 || offset_ != 0) {
207  // check input data and reorganize map
208  global_size_t numGlobalNodes = Teuchos::OrdinalTraits<global_size_t>::invalid();
209  if (numGlobalElements != Teuchos::OrdinalTraits<global_size_t>::invalid()) {
210  numGlobalNodes = numGlobalElements / blkSize;
211  }
212  global_size_t numLocalNodes = numLocalElements / blkSize;
213 
214  // build an equally distributed node map
215  RCP<Map> nodeMap = MapFactory_t::Build(xlib, numGlobalNodes, numLocalNodes, indexBase, comm);
216 
217  // translate local node ids to local dofs
218  size_t nStridedOffset = 0;
219  size_t nDofsPerNode = blkSize; // dofs per node for local striding block
220  if (stridedBlockId > -1) {
221  for (int j = 0; j < stridedBlockId; j++) {
222  nStridedOffset += stridingInfo_[j];
223  }
224 
225  nDofsPerNode = stridingInfo_[stridedBlockId];
226  numGlobalElements = nodeMap->getGlobalNumElements() * Teuchos::as<global_size_t>(nDofsPerNode);
227  }
228  numLocalElements = numLocalNodes * Teuchos::as<size_t>(nDofsPerNode);
229 
230  std::vector<GlobalOrdinal> dofgids(numLocalElements);
231  for (LocalOrdinal i = 0; i < Teuchos::as<LocalOrdinal>(numLocalNodes); i++) {
232  GlobalOrdinal nodeGID = nodeMap->getGlobalElement(i);
233 
234  for (size_t j = 0; j < nDofsPerNode; j++) {
235  dofgids[i * nDofsPerNode + j] = indexBase_ + offset_ + (nodeGID - indexBase_) * Teuchos::as<GlobalOrdinal>(blkSize) + Teuchos::as<GlobalOrdinal>(nStridedOffset + j);
236  }
237  }
238 
239  map_ = MapFactory_t::Build(xlib, numGlobalElements, dofgids, indexBase, comm);
240 
241  if (stridedBlockId == -1) {
242  TEUCHOS_TEST_FOR_EXCEPTION(getLocalNumElements() != Teuchos::as<size_t>(nodeMap->getLocalNumElements() * nDofsPerNode),
244  "StridedTpetraMap::StridedTpetraMap: wrong distribution of dofs among processors.");
245 
246  TEUCHOS_TEST_FOR_EXCEPTION(getGlobalNumElements() != Teuchos::as<size_t>(nodeMap->getGlobalNumElements() * nDofsPerNode),
248  "StridedTpetraMap::StridedTpetraMap: wrong distribution of dofs among processors.");
249  } else {
250  int nDofsInStridedBlock = stridingInfo[stridedBlockId];
251 
252  TEUCHOS_TEST_FOR_EXCEPTION(getLocalNumElements() != Teuchos::as<size_t>(nodeMap->getLocalNumElements() * nDofsInStridedBlock),
254  "StridedTpetraMap::StridedTpetraMap: wrong distribution of dofs among processors.");
255 
256  TEUCHOS_TEST_FOR_EXCEPTION(getGlobalNumElements() != Teuchos::as<size_t>(nodeMap->getGlobalNumElements() * nDofsInStridedBlock),
258  "StridedTpetraMap::StridedTpetraMap: wrong distribution of dofs among processors.");
259  }
260  } else {
261  map_ = MapFactory_t::Build(xlib, numGlobalElements, numLocalElements, indexBase, comm);
262  }
263 
264  TEUCHOS_TEST_FOR_EXCEPTION(CheckConsistency() == false, Exceptions::RuntimeError, "StridedTpetraMap::StridedTpetraMap: CheckConsistency() == false");
265 }
266 
267 template <class LocalOrdinal, class GlobalOrdinal, class Node>
270  global_size_t numGlobalElements,
271  const Teuchos::ArrayView<const GlobalOrdinal>& elementList,
272  GlobalOrdinal indexBase,
273  std::vector<size_t>& stridingInfo,
274  const Teuchos::RCP<const Teuchos::Comm<int>>& comm,
275  LocalOrdinal stridedBlockId)
276  : stridingInfo_(stridingInfo)
277  , stridedBlockId_(stridedBlockId)
278  , indexBase_(indexBase) {
280 
281  size_t blkSize = getFixedBlockSize();
282 
283  TEUCHOS_TEST_FOR_EXCEPTION(stridingInfo.size() == 0,
285  "StridedMap::StridedMap: stridingInfo not valid: stridingInfo.size() = 0?");
286  if (stridedBlockId != -1)
287  TEUCHOS_TEST_FOR_EXCEPTION(stridingInfo.size() < Teuchos::as<size_t>(stridedBlockId),
289  "StridedTpetraMap::StridedTpetraMap: stridedBlockId > stridingInfo.size()");
290  if (numGlobalElements != Teuchos::OrdinalTraits<global_size_t>::invalid()) {
291  TEUCHOS_TEST_FOR_EXCEPTION(numGlobalElements % blkSize != 0,
293  "StridedMap::StridedMap: stridingInfo not valid: getFixedBlockSize is not an integer "
294  "multiple of numGlobalElements.");
295 #ifdef HAVE_XPETRA_DEBUG
296  // We have to do this check ourselves, as we don't necessarily construct the full Tpetra map
297  global_size_t sumLocalElements, numLocalElements = elementList.size();
298  Teuchos::reduceAll(*comm, Teuchos::REDUCE_SUM, numLocalElements, Teuchos::outArg(sumLocalElements));
299  TEUCHOS_TEST_FOR_EXCEPTION(sumLocalElements != numGlobalElements,
300  std::invalid_argument,
301  "StridedMap::StridedMap: sum of numbers of local elements is different from the provided "
302  "number of global elements.");
303 #endif
304  }
305 
306  if (stridedBlockId == -1) {
307  // numGlobalElements can be -1! FIXME
308  // TEUCHOS_TEST_FOR_EXCEPTION(numGlobalElements % blkSize != 0, Exceptions::RuntimeError,
309  // "StridedMap::StridedMap: stridingInfo not valid: getFixedBlockSize is not an integer multiple of
310  // numGlobalElements.");
311  TEUCHOS_TEST_FOR_EXCEPTION(elementList.size() % blkSize != 0,
313  "StridedMap::StridedMap: stridingInfo not valid: getFixedBlockSize is not an integer "
314  "multiple of elementList.size().");
315  } else {
316  // numGlobalElements can be -1! FIXME
317  // TEUCHOS_TEST_FOR_EXCEPTION(numGlobalElements % stridingInfo[stridedBlockId] != 0, Exceptions::RuntimeError,
318  // "StridedMap::StridedMap: stridingInfo not valid: stridingBlockInfo[stridedBlockId] is not an integer multiple of
319  // numGlobalElements.");
320  TEUCHOS_TEST_FOR_EXCEPTION(elementList.size() % stridingInfo[stridedBlockId] != 0,
322  "StridedMap::StridedMap: stridingInfo not valid: stridingBlockInfo[stridedBlockId] is not "
323  "an integer multiple of elementList.size().");
324  }
325 
326  map_ = MapFactory_t::Build(xlib, numGlobalElements, elementList, indexBase, comm);
327 
328  // calculate offset_
329 
330  // find minimum GID over all procs
331  GlobalOrdinal minGidOnCurProc = Teuchos::OrdinalTraits<GlobalOrdinal>::max();
332  for (Teuchos_Ordinal k = 0; k < elementList.size(); k++) // TODO fix occurence of Teuchos_Ordinal
333  {
334  if (elementList[k] < minGidOnCurProc) {
335  minGidOnCurProc = elementList[k];
336  }
337  }
338 
339  Teuchos::reduceAll(*comm, Teuchos::REDUCE_MIN, minGidOnCurProc, Teuchos::outArg(offset_));
340 
341  // calculate striding index
342  size_t nStridedOffset = 0;
343  for (int j = 0; j < stridedBlockId; j++) {
344  nStridedOffset += stridingInfo[j];
345  }
346  const GlobalOrdinal goStridedOffset = Teuchos::as<GlobalOrdinal>(nStridedOffset);
347 
348  // adapt offset_
349  offset_ -= goStridedOffset + indexBase_;
350 
351  TEUCHOS_TEST_FOR_EXCEPTION(CheckConsistency() == false, Exceptions::RuntimeError, "StridedTpetraMap::StridedTpetraMap: CheckConsistency() == false");
352 }
353 
354 template <class LocalOrdinal, class GlobalOrdinal, class Node>
356  StridedMap(const RCP<const Map>& map,
357  std::vector<size_t>& stridingInfo,
358  GlobalOrdinal /* indexBase */,
359  LocalOrdinal stridedBlockId,
360  GlobalOrdinal offset)
361  : stridingInfo_(stridingInfo)
362  , stridedBlockId_(stridedBlockId)
363  , offset_(offset)
364  , indexBase_(map->getIndexBase()) {
365  // TAW: 11/24/15
366  // A strided map never can be built from a strided map. getMap always returns the underlying
367  // Xpetra::Map object which contains the data (either in a Xpetra::EpetraMapT or Xpetra::TpetraMap
368  // object)
369  if (Teuchos::rcp_dynamic_cast<const StridedMap>(map) == Teuchos::null) {
370  map_ = map; // if map is not a strided map, just store it (standard case)
371  } else {
372  map_ = map->getMap(); // if map is also a strided map, store the underlying plain Epetra/Tpetra Xpetra map object
373  }
374 }
375 
376 template <class LocalOrdinal, class GlobalOrdinal, class Node>
379 }
380 
381 template <class LocalOrdinal, class GlobalOrdinal, class Node>
382 std::vector<size_t>
385  return stridingInfo_;
386 }
387 
388 template <class LocalOrdinal, class GlobalOrdinal, class Node>
390  setStridingData(std::vector<size_t> stridingInfo) {
391  stridingInfo_ = stridingInfo;
392 }
393 
394 template <class LocalOrdinal, class GlobalOrdinal, class Node>
395 size_t
398  size_t blkSize = 0;
399  for (std::vector<size_t>::const_iterator it = stridingInfo_.begin(); it != stridingInfo_.end(); ++it) {
400  blkSize += *it;
401  }
402  return blkSize;
403 }
404 
405 template <class LocalOrdinal, class GlobalOrdinal, class Node>
406 LocalOrdinal
409  return stridedBlockId_;
410 }
411 
412 template <class LocalOrdinal, class GlobalOrdinal, class Node>
414  isStrided() const {
415  return stridingInfo_.size() > 1 ? true : false;
416 }
417 
418 template <class LocalOrdinal, class GlobalOrdinal, class Node>
420  isBlocked() const {
421  return getFixedBlockSize() > 1 ? true : false;
422 }
423 
424 template <class LocalOrdinal, class GlobalOrdinal, class Node>
425 GlobalOrdinal
427  getOffset() const {
428  return offset_;
429 }
430 
431 template <class LocalOrdinal, class GlobalOrdinal, class Node>
433  setOffset(GlobalOrdinal offset) {
434  offset_ = offset;
435 }
436 
437 template <class LocalOrdinal, class GlobalOrdinal, class Node>
438 size_t
440  GID2StridingBlockId(GlobalOrdinal gid) const {
441  GlobalOrdinal tgid = gid - offset_ - indexBase_;
442  tgid = tgid % getFixedBlockSize();
443 
444  size_t nStridedOffset = 0;
445  size_t stridedBlockId = 0;
446  for (size_t j = 0; j < stridingInfo_.size(); j++) {
447  nStridedOffset += stridingInfo_[j];
448  if (Teuchos::as<size_t>(tgid) < nStridedOffset) {
449  stridedBlockId = j;
450  break;
451  }
452  }
453  return stridedBlockId;
454 }
455 
456 template <class LocalOrdinal, class GlobalOrdinal, class Node>
457 RCP<const Xpetra::Map<LocalOrdinal, GlobalOrdinal, Node>>
459  getMap() const {
460  return map_;
461 }
462 
463 template <class LocalOrdinal, class GlobalOrdinal, class Node>
466 #ifndef HAVE_XPETRA_DEBUG
467  return true;
468 #else
469  if (getStridedBlockId() == -1) {
470  // Strided map contains the full map
471  if (getLocalNumElements() % getFixedBlockSize() != 0 || // number of local elements is not a multiple of block size
472  getGlobalNumElements() % getFixedBlockSize() != 0) // number of global -//-
473  return false;
474  } else {
475  // Strided map contains only the partial map
476  Teuchos::ArrayView<const GlobalOrdinal> dofGids = getLocalElementList();
477  // std::sort(dofGids.begin(), dofGids.end());
478 
479  if (dofGids.size() == 0) // special treatment for empty processors
480  {
481  return true;
482  }
483 
484  if (dofGids.size() % stridingInfo_[stridedBlockId_] != 0) {
485  return false;
486  }
487 
488  // Calculate nStridedOffset
489  size_t nStridedOffset = 0;
490  for (int j = 0; j < stridedBlockId_; j++) {
491  nStridedOffset += stridingInfo_[j];
492  }
493 
494  const GlobalOrdinal goStridedOffset = Teuchos::as<GlobalOrdinal>(nStridedOffset);
495  const GlobalOrdinal goZeroOffset = (dofGids[0] - nStridedOffset - offset_ - indexBase_) / Teuchos::as<GlobalOrdinal>(getFixedBlockSize());
496 
497  GlobalOrdinal cnt = 0;
498  for (size_t i = 0;
499  i < Teuchos::as<size_t>(dofGids.size()) / stridingInfo_[stridedBlockId_];
500  i += stridingInfo_[stridedBlockId_]) {
501  const GlobalOrdinal first_gid = dofGids[i];
502 
503  // We expect this to be the same for all DOFs of the same node
504  cnt = (first_gid - goStridedOffset - offset_ - indexBase_) / Teuchos::as<GlobalOrdinal>(getFixedBlockSize()) - goZeroOffset;
505 
506  // Loop over all DOFs that belong to current node
507  for (size_t j = 0; j < stridingInfo_[stridedBlockId_]; j++) {
508  const GlobalOrdinal gid = dofGids[i + j];
509  const GlobalOrdinal r = (gid - Teuchos::as<GlobalOrdinal>(j) - goStridedOffset - offset_ - indexBase_) / Teuchos::as<GlobalOrdinal>(getFixedBlockSize()) - goZeroOffset - cnt;
510  // TAW 1/18/2016: We cannot use Teuchos::OrdinalTraits<GlobalOrdinal>::zero() ) here,
511  // If, e.g., GO=long long is disabled, OrdinalTraits<long long> is not available.
512  // But we instantiate stubs on GO=long long which might contain StridedMaps.
513  // These lead to compilation errors, then.
514  if (0 != r) {
515  std::cout << "goZeroOffset : " << goZeroOffset << std::endl
516  << "dofGids[0] : " << dofGids[0] << std::endl
517  << "stridedOffset : " << nStridedOffset << std::endl
518  << "offset_ : " << offset_ << std::endl
519  << "goStridedOffset: " << goStridedOffset << std::endl
520  << "getFixedBlkSize: " << getFixedBlockSize() << std::endl
521  << "gid: " << gid << " GID: " << r << std::endl;
522 
523  return false;
524  }
525  }
526  }
527  }
528 
529  return true;
530 #endif
531 }
532 
533 template <class LocalOrdinal, class GlobalOrdinal, class Node>
537  return map_->getGlobalNumElements();
538 }
539 
540 template <class LocalOrdinal, class GlobalOrdinal, class Node>
541 size_t
544  return map_->getLocalNumElements();
545 }
546 
547 template <class LocalOrdinal, class GlobalOrdinal, class Node>
548 GlobalOrdinal
550  getIndexBase() const {
551  return map_->getIndexBase();
552 }
553 
554 template <class LocalOrdinal, class GlobalOrdinal, class Node>
555 LocalOrdinal
558  return map_->getMinLocalIndex();
559 }
560 
561 template <class LocalOrdinal, class GlobalOrdinal, class Node>
562 LocalOrdinal
565  return map_->getMaxLocalIndex();
566 }
567 
568 template <class LocalOrdinal, class GlobalOrdinal, class Node>
569 GlobalOrdinal
572  return map_->getMinGlobalIndex();
573 }
574 
575 template <class LocalOrdinal, class GlobalOrdinal, class Node>
576 GlobalOrdinal
579  return map_->getMaxGlobalIndex();
580 }
581 
582 template <class LocalOrdinal, class GlobalOrdinal, class Node>
583 GlobalOrdinal
586  return map_->getMinAllGlobalIndex();
587 }
588 
589 template <class LocalOrdinal, class GlobalOrdinal, class Node>
590 GlobalOrdinal
593  return map_->getMaxAllGlobalIndex();
594 }
595 
596 template <class LocalOrdinal, class GlobalOrdinal, class Node>
597 LocalOrdinal
599  getLocalElement(GlobalOrdinal globalIndex) const {
600  return map_->getLocalElement(globalIndex);
601 }
602 
603 template <class LocalOrdinal, class GlobalOrdinal, class Node>
604 GlobalOrdinal
606  getGlobalElement(LocalOrdinal localIndex) const {
607  return map_->getGlobalElement(localIndex);
608 }
609 
610 template <class LocalOrdinal, class GlobalOrdinal, class Node>
613  getRemoteIndexList(const Teuchos::ArrayView<const GlobalOrdinal>& GIDList,
614  const Teuchos::ArrayView<int>& nodeIDList,
615  const Teuchos::ArrayView<LocalOrdinal>& LIDList) const {
616  return map_->getRemoteIndexList(GIDList, nodeIDList, LIDList);
617 }
618 
619 template <class LocalOrdinal, class GlobalOrdinal, class Node>
622  getRemoteIndexList(const Teuchos::ArrayView<const GlobalOrdinal>& GIDList,
623  const Teuchos::ArrayView<int>& nodeIDList) const {
624  return map_->getRemoteIndexList(GIDList, nodeIDList);
625 }
626 
627 template <class LocalOrdinal, class GlobalOrdinal, class Node>
628 Teuchos::ArrayView<const GlobalOrdinal>
631  return map_->getLocalElementList();
632 }
633 
634 template <class LocalOrdinal, class GlobalOrdinal, class Node>
638  return map_->getMyGlobalIndicesDevice();
639 }
640 
641 template <class LocalOrdinal, class GlobalOrdinal, class Node>
643  isNodeLocalElement(LocalOrdinal localIndex) const {
644  return map_->isNodeLocalElement(localIndex);
645 }
646 
647 template <class LocalOrdinal, class GlobalOrdinal, class Node>
649  isNodeGlobalElement(GlobalOrdinal globalIndex) const {
650  return map_->isNodeGlobalElement(globalIndex);
651 }
652 
653 template <class LocalOrdinal, class GlobalOrdinal, class Node>
655  isContiguous() const {
656  return map_->isContiguous();
657 }
658 
659 template <class LocalOrdinal, class GlobalOrdinal, class Node>
661  isDistributed() const {
662  return map_->isDistributed();
663 }
664 
665 template <class LocalOrdinal, class GlobalOrdinal, class Node>
667  isCompatible(const Map& map) const {
668  return map_->isCompatible(map);
669 }
670 
671 template <class LocalOrdinal, class GlobalOrdinal, class Node>
673  isSameAs(const Map& map) const {
674  return map_->isSameAs(map);
675 }
676 
677 template <class LocalOrdinal, class GlobalOrdinal, class Node>
678 Teuchos::RCP<const Teuchos::Comm<int>>
680  getComm() const {
681  return map_->getComm();
682 }
683 
684 template <class LocalOrdinal, class GlobalOrdinal, class Node>
685 RCP<const Xpetra::Map<LocalOrdinal, GlobalOrdinal, Node>>
688  return map_->removeEmptyProcesses();
689 }
690 
691 template <class LocalOrdinal, class GlobalOrdinal, class Node>
692 RCP<const Xpetra::Map<LocalOrdinal, GlobalOrdinal, Node>>
694  replaceCommWithSubset(const Teuchos::RCP<const Teuchos::Comm<int>>& newComm) const {
695  return map_->replaceCommWithSubset(newComm);
696 }
697 
698 template <class LocalOrdinal, class GlobalOrdinal, class Node>
699 std::string
701  description() const {
702  return map_->description();
703 }
704 
705 template <class LocalOrdinal, class GlobalOrdinal, class Node>
707  describe(Teuchos::FancyOStream& out, const Teuchos::EVerbosityLevel verbLevel) const {
708  map_->describe(out, verbLevel);
709 }
710 
711 template <class LocalOrdinal, class GlobalOrdinal, class Node>
714  lib() const {
715  return map_->lib();
716 }
717 
718 } // namespace Xpetra
719 
720 #endif // XPETRA_STRIDEDMAP_DEF_HPP
Teuchos::ArrayView< const GlobalOrdinal > getLocalElementList() const
Return a list of the global indices owned by this node.
LookupStatus getRemoteIndexList(const Teuchos::ArrayView< const GlobalOrdinal > &GIDList, const Teuchos::ArrayView< int > &nodeIDList, const Teuchos::ArrayView< LocalOrdinal > &LIDList) const
Returns the node IDs and corresponding local indices for a given list of global indices.
LocalOrdinal getStridedBlockId() const
GlobalOrdinal getMaxGlobalIndex() const
Returns maximum global index owned by this node.
GlobalOrdinal getGlobalElement(LocalOrdinal localIndex) const
Return the global index for a given local index.
size_t GID2StridingBlockId(GlobalOrdinal gid) const
bool isContiguous() const
Returns true if this Map is distributed contiguously; returns false otherwise.
void setStridingData(std::vector< size_t > stridingInfo)
size_t getLocalNumElements() const
Returns the number of elements belonging to the calling node.
GlobalOrdinal indexBase_
Index base for the strided map (default = 0)
GlobalOrdinal getOffset() const
Exception throws to report errors in the internal logical of the program.
LocalOrdinal getMaxLocalIndex() const
Returns maximum local index.
Teuchos::RCP< const Teuchos::Comm< int > > getComm() const
Get the Comm object for this Map.
bool isCompatible(const Map &map) const
Returns true if map is compatible with this Map.
std::string description() const
Return a simple one-line description of this object.
GlobalOrdinal getMaxAllGlobalIndex() const
Return the maximum global index over all nodes.
bool isNodeGlobalElement(GlobalOrdinal globalIndex) const
Returns true if the global index is found in this Map on this node; returns false if it isn&#39;t...
bool isNodeLocalElement(LocalOrdinal localIndex) const
Returns true if the local index is valid for this Map on this node; returns false if it isn&#39;t...
bool isStrided() const
returns true, if this is a strided map (i.e. more than 1 strided blocks)
bool isSameAs(const Map &map) const
Returns true if map is identical to this Map.
std::vector< size_t > stridingInfo_
Vector with size of strided blocks (dofs)
RCP< const Map > removeEmptyProcesses() const
Return a new Map with processes with zero elements removed.
RCP< const Map > replaceCommWithSubset(const Teuchos::RCP< const Teuchos::Comm< int >> &newComm) const
bool isDistributed() const
Returns true if this Map is distributed across more than one node; returns false otherwise.
size_t getFixedBlockSize() const
global_indices_array_device_type getMyGlobalIndicesDevice() const
Return a view of the global indices owned by this process on the Map&#39;s device.
GlobalOrdinal offset_
Offset for gids in map (default = 0)
GlobalOrdinal getMinGlobalIndex() const
Returns minimum global index owned by this node.
size_t global_size_t
Global size_t object.
GlobalOrdinal getIndexBase() const
Returns the index base for this Map.
RCP< const Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > getMap() const
global_size_t getGlobalNumElements() const
Returns the number of elements in this Map.
Kokkos::View< const global_ordinal_type *, typename Node::device_type > global_indices_array_device_type
std::vector< size_t > getStridingData() const
LocalOrdinal getLocalElement(GlobalOrdinal globalIndex) const
Return the local index for a given global index.
StridedMap(UnderlyingLib xlib, global_size_t numGlobalElements, GlobalOrdinal indexBase, std::vector< size_t > &stridingInfo, const Teuchos::RCP< const Teuchos::Comm< int >> &comm, LocalOrdinal stridedBlockId=-1, GlobalOrdinal offset=0, LocalGlobal lg=GloballyDistributed)
Map constructor with contiguous uniform distribution.
LocalOrdinal getMinLocalIndex() const
Returns minimum local index.
UnderlyingLib lib() const
Get the library used by this object (Tpetra or Epetra?)
GlobalOrdinal getMinAllGlobalIndex() const
Return the minimum global index over all nodes.
Create an Xpetra::Map instance.
void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const
Print the object with some verbosity level to a FancyOStream object.
virtual ~StridedMap()
Destructor.
void setOffset(GlobalOrdinal offset)
RCP< const Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > map_