Xpetra_StridedMap.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_HPP
50 #define XPETRA_STRIDEDMAP_HPP
51 
52 /* this file is automatically generated - do not edit (see script/interfaces.py) */
53 
54 #include <Kokkos_DefaultNode.hpp>
55 
56 #include <Teuchos_Describable.hpp>
58 
59 #include "Xpetra_ConfigDefs.hpp"
60 #include "Xpetra_Exceptions.hpp"
61 
62 #include "Xpetra_Map.hpp"
63 #include "Xpetra_MapFactory.hpp"
64 
65 namespace Xpetra {
66 
95  template <class LocalOrdinal = Map<>::local_ordinal_type,
96  class GlobalOrdinal = typename Map<LocalOrdinal>::global_ordinal_type,
97  class Node = typename Map<LocalOrdinal,GlobalOrdinal>::node_type>
98  class StridedMap : public virtual Map<LocalOrdinal, GlobalOrdinal, Node> {
99  public:
100  typedef LocalOrdinal local_ordinal_type;
101  typedef GlobalOrdinal global_ordinal_type;
102  typedef Node node_type;
103 
104  private:
105 
107 #undef XPETRA_STRIDEDMAP_SHORT
109 
110  public:
111 
113 
114 
135  global_size_t numGlobalElements,
136  GlobalOrdinal indexBase,
137  std::vector<size_t>& stridingInfo,
138  const Teuchos::RCP< const Teuchos::Comm< int > >& comm,
139  LocalOrdinal stridedBlockId = -1, // FIXME (mfh 03 Sep 2014) This breaks for unsigned LocalOrdinal
140  GlobalOrdinal offset = 0,
142  const Teuchos::RCP< Node >& node = Teuchos::rcp(new Node))
143  : stridingInfo_ (stridingInfo),
144  stridedBlockId_ (stridedBlockId),
145  offset_ (offset),
146  indexBase_ (indexBase)
147  {
148  size_t blkSize = getFixedBlockSize ();
150  stridingInfo.size() == 0, Exceptions::RuntimeError,
151  "StridedMap::StridedMap: stridingInfo not valid: stridingInfo.size() = 0?");
153  numGlobalElements == Teuchos::OrdinalTraits<global_size_t>::invalid (),
154  std::invalid_argument,
155  "StridedMap::StridedMap: numGlobalElements is invalid");
156  TEUCHOS_TEST_FOR_EXCEPTION(
157  numGlobalElements % blkSize != 0, Exceptions::RuntimeError,
158  "StridedMap::StridedMap: stridingInfo not valid: getFixedBlockSize "
159  "is not an integer multiple of numGlobalElements.");
160  if (stridedBlockId != -1)
161  TEUCHOS_TEST_FOR_EXCEPTION(
162  stridingInfo.size() < static_cast<size_t> (stridedBlockId),
163  Exceptions::RuntimeError, "StridedTpetraMap::StridedTpetraMap: "
164  "stridedBlockId > stridingInfo.size()");
165 
166  // Try to create a shortcut
167  if (blkSize != 1 || offset_ != 0) {
168  // check input data and reorganize map
169  global_size_t numGlobalNodes = numGlobalElements / blkSize;
170 
171  // build an equally distributed node map
172  RCP<Map> nodeMap = MapFactory_t::Build(xlib, numGlobalNodes, indexBase, comm, lg, node);
173  global_size_t numLocalNodes = nodeMap->getNodeNumElements();
174 
175  // translate local node ids to local dofs
176  size_t nStridedOffset = 0;
177  size_t nDofsPerNode = blkSize; // dofs per node for local striding block
178  if (stridedBlockId > -1) {
179  for (int j = 0; j < stridedBlockId; j++)
180  nStridedOffset += stridingInfo_[j];
181 
182  nDofsPerNode = stridingInfo_[stridedBlockId];
183  numGlobalElements = numGlobalNodes * Teuchos::as<global_size_t>(nDofsPerNode);
184  }
185  size_t numLocalElements = numLocalNodes * Teuchos::as<size_t>(nDofsPerNode);
186 
187  std::vector<GlobalOrdinal> dofgids(numLocalElements);
188  for (LocalOrdinal i = 0; i < Teuchos::as<LocalOrdinal>(numLocalNodes); i++) {
189  GlobalOrdinal nodeGID = nodeMap->getGlobalElement(i);
190 
191  for (size_t j = 0; j < nDofsPerNode; j++)
192  dofgids[i*nDofsPerNode + j] = indexBase_ + offset_ + (nodeGID - indexBase_)*Teuchos::as<GlobalOrdinal>(blkSize) + Teuchos::as<GlobalOrdinal>(nStridedOffset + j);
193  }
194 
195  map_ = MapFactory_t::Build(xlib, numGlobalElements, dofgids, indexBase, comm, node);
196 
197  if (stridedBlockId == -1) {
198  TEUCHOS_TEST_FOR_EXCEPTION(getNodeNumElements() != Teuchos::as<size_t>(nodeMap->getNodeNumElements()*nDofsPerNode), Exceptions::RuntimeError,
199  "StridedTpetraMap::StridedTpetraMap: wrong distribution of dofs among processors.");
200  TEUCHOS_TEST_FOR_EXCEPTION(getGlobalNumElements() != Teuchos::as<size_t>(nodeMap->getGlobalNumElements()*nDofsPerNode), Exceptions::RuntimeError,
201  "StridedTpetraMap::StridedTpetraMap: wrong distribution of dofs among processors.");
202 
203  } else {
204  size_t nDofsInStridedBlock = stridingInfo[stridedBlockId];
205  TEUCHOS_TEST_FOR_EXCEPTION(getNodeNumElements() != Teuchos::as<size_t>(nodeMap->getNodeNumElements()*nDofsInStridedBlock), Exceptions::RuntimeError,
206  "StridedTpetraMap::StridedTpetraMap: wrong distribution of dofs among processors.");
207  TEUCHOS_TEST_FOR_EXCEPTION(getGlobalNumElements() != Teuchos::as<size_t>(nodeMap->getGlobalNumElements()*nDofsInStridedBlock), Exceptions::RuntimeError,
208  "StridedTpetraMap::StridedTpetraMap: wrong distribution of dofs among processors.");
209  }
210  } else {
211  map_ = MapFactory_t::Build(xlib, numGlobalElements, indexBase, comm, lg, node);
212  }
213 
214  TEUCHOS_TEST_FOR_EXCEPTION(CheckConsistency() == false, Exceptions::RuntimeError, "StridedTpetraMap::StridedTpetraMap: CheckConsistency() == false");
215  }
216 
218 
238  StridedMap(UnderlyingLib xlib, global_size_t numGlobalElements, size_t numLocalElements, GlobalOrdinal indexBase, std::vector<size_t>& stridingInfo,
239  const Teuchos::RCP< const Teuchos::Comm< int > > &comm, LocalOrdinal stridedBlockId = -1, GlobalOrdinal offset = 0,
240  const Teuchos::RCP< Node > &node = Teuchos::rcp(new Node))
241  : stridingInfo_(stridingInfo), stridedBlockId_(stridedBlockId), offset_(offset), indexBase_(indexBase)
242  {
243  size_t blkSize = getFixedBlockSize();
244  TEUCHOS_TEST_FOR_EXCEPTION(stridingInfo.size() == 0, Exceptions::RuntimeError,
245  "StridedMap::StridedMap: stridingInfo not valid: stridingInfo.size() = 0?");
246  if (numGlobalElements != Teuchos::OrdinalTraits<global_size_t>::invalid()) {
247  TEUCHOS_TEST_FOR_EXCEPTION(numGlobalElements % blkSize != 0, Exceptions::RuntimeError,
248  "StridedMap::StridedMap: stridingInfo not valid: getFixedBlockSize is not an integer multiple of numGlobalElements.");
249 #ifdef HAVE_XPETRA_DEBUG
250  // We have to do this check ourselves, as we don't necessarily construct the full Tpetra map
251  global_size_t sumLocalElements;
252  Teuchos::reduceAll(*comm, Teuchos::REDUCE_SUM, Teuchos::as<global_size_t>(numLocalElements), Teuchos::outArg(sumLocalElements));
253  TEUCHOS_TEST_FOR_EXCEPTION(sumLocalElements != numGlobalElements, std::invalid_argument,
254  "StridedMap::StridedMap: sum of numbers of local elements is different from the provided number of global elements.");
255 #endif
256  }
257  TEUCHOS_TEST_FOR_EXCEPTION(numLocalElements % blkSize != 0, Exceptions::RuntimeError,
258  "StridedMap::StridedMap: stridingInfo not valid: getFixedBlockSize is not an integer multiple of numLocalElements.");
259  if (stridedBlockId != -1)
260  TEUCHOS_TEST_FOR_EXCEPTION(stridingInfo.size() < Teuchos::as<size_t>(stridedBlockId), Exceptions::RuntimeError,
261  "StridedTpetraMap::StridedTpetraMap: stridedBlockId > stridingInfo.size()");
262 
263  // Try to create a shortcut
264  if (blkSize != 1 || offset_ != 0) {
265  // check input data and reorganize map
267  if (numGlobalElements != Teuchos::OrdinalTraits<global_size_t>::invalid())
268  numGlobalNodes = numGlobalElements / blkSize;
269  global_size_t numLocalNodes = numLocalElements / blkSize;
270 
271  // build an equally distributed node map
272  RCP<Map> nodeMap = MapFactory_t::Build(xlib, numGlobalNodes, numLocalNodes, indexBase, comm, node);
273 
274  // translate local node ids to local dofs
275  size_t nStridedOffset = 0;
276  size_t nDofsPerNode = blkSize; // dofs per node for local striding block
277  if (stridedBlockId > -1) {
278  for (int j = 0; j < stridedBlockId; j++)
279  nStridedOffset += stridingInfo_[j];
280 
281  nDofsPerNode = stridingInfo_[stridedBlockId];
282  numGlobalElements = nodeMap->getGlobalNumElements() * Teuchos::as<global_size_t>(nDofsPerNode);
283  }
284  numLocalElements = numLocalNodes * Teuchos::as<size_t>(nDofsPerNode);
285 
286  std::vector<GlobalOrdinal> dofgids(numLocalElements);
287  for (LocalOrdinal i = 0; i < Teuchos::as<LocalOrdinal>(numLocalNodes); i++) {
288  GlobalOrdinal nodeGID = nodeMap->getGlobalElement(i);
289 
290  for (size_t j = 0; j < nDofsPerNode; j++)
291  dofgids[i*nDofsPerNode + j] = indexBase_ + offset_ + (nodeGID - indexBase_)*Teuchos::as<GlobalOrdinal>(blkSize) + Teuchos::as<GlobalOrdinal>(nStridedOffset + j);
292  }
293 
294  map_ = MapFactory_t::Build(xlib, numGlobalElements, dofgids, indexBase, comm, node);
295 
296  if (stridedBlockId == -1) {
297  TEUCHOS_TEST_FOR_EXCEPTION(getNodeNumElements() != Teuchos::as<size_t>(nodeMap->getNodeNumElements()*nDofsPerNode), Exceptions::RuntimeError,
298  "StridedTpetraMap::StridedTpetraMap: wrong distribution of dofs among processors.");
299  TEUCHOS_TEST_FOR_EXCEPTION(getGlobalNumElements() != Teuchos::as<size_t>(nodeMap->getGlobalNumElements()*nDofsPerNode), Exceptions::RuntimeError,
300  "StridedTpetraMap::StridedTpetraMap: wrong distribution of dofs among processors.");
301 
302  } else {
303  int nDofsInStridedBlock = stridingInfo[stridedBlockId];
304  TEUCHOS_TEST_FOR_EXCEPTION(getNodeNumElements() != Teuchos::as<size_t>(nodeMap->getNodeNumElements()*nDofsInStridedBlock), Exceptions::RuntimeError,
305  "StridedTpetraMap::StridedTpetraMap: wrong distribution of dofs among processors.");
306  TEUCHOS_TEST_FOR_EXCEPTION(getGlobalNumElements() != Teuchos::as<size_t>(nodeMap->getGlobalNumElements()*nDofsInStridedBlock), Exceptions::RuntimeError,
307  "StridedTpetraMap::StridedTpetraMap: wrong distribution of dofs among processors.");
308  }
309 
310  } else {
311  map_ = MapFactory_t::Build(xlib, numGlobalElements, numLocalElements, indexBase, comm, node);
312  }
313 
314  TEUCHOS_TEST_FOR_EXCEPTION(CheckConsistency() == false, Exceptions::RuntimeError, "StridedTpetraMap::StridedTpetraMap: CheckConsistency() == false");
315  }
316 
327  StridedMap(UnderlyingLib xlib, global_size_t numGlobalElements, const Teuchos::ArrayView< const GlobalOrdinal > &elementList, GlobalOrdinal indexBase,
328  std::vector<size_t>& stridingInfo, const Teuchos::RCP< const Teuchos::Comm< int > > &comm, LocalOrdinal stridedBlockId = -1,
329  const Teuchos::RCP< Node > &node = Teuchos::rcp(new Node))
330  : stridingInfo_(stridingInfo), stridedBlockId_(stridedBlockId), indexBase_(indexBase)
331  {
332  size_t blkSize = getFixedBlockSize();
333 
334  TEUCHOS_TEST_FOR_EXCEPTION(stridingInfo.size() == 0, Exceptions::RuntimeError,
335  "StridedMap::StridedMap: stridingInfo not valid: stridingInfo.size() = 0?");
336  if (stridedBlockId != -1)
337  TEUCHOS_TEST_FOR_EXCEPTION(stridingInfo.size() < Teuchos::as<size_t>(stridedBlockId), Exceptions::RuntimeError,
338  "StridedTpetraMap::StridedTpetraMap: stridedBlockId > stridingInfo.size()");
339  if (numGlobalElements != Teuchos::OrdinalTraits<global_size_t>::invalid()) {
340  TEUCHOS_TEST_FOR_EXCEPTION(numGlobalElements % blkSize != 0, Exceptions::RuntimeError,
341  "StridedMap::StridedMap: stridingInfo not valid: getFixedBlockSize is not an integer multiple of numGlobalElements.");
342 #ifdef HAVE_XPETRA_DEBUG
343  // We have to do this check ourselves, as we don't necessarily construct the full Tpetra map
344  global_size_t sumLocalElements, numLocalElements = elementList.size();
345  Teuchos::reduceAll(*comm, Teuchos::REDUCE_SUM, numLocalElements, Teuchos::outArg(sumLocalElements));
346  TEUCHOS_TEST_FOR_EXCEPTION(sumLocalElements != numGlobalElements, std::invalid_argument,
347  "StridedMap::StridedMap: sum of numbers of local elements is different from the provided number of global elements.");
348 #endif
349  }
350 
351  if (stridedBlockId == -1) {
352  // numGlobalElements can be -1! FIXME
353  // TEUCHOS_TEST_FOR_EXCEPTION(numGlobalElements % blkSize != 0, Exceptions::RuntimeError,
354  // "StridedMap::StridedMap: stridingInfo not valid: getFixedBlockSize is not an integer multiple of numGlobalElements.");
355  TEUCHOS_TEST_FOR_EXCEPTION(elementList.size() % blkSize != 0, Exceptions::RuntimeError,
356  "StridedMap::StridedMap: stridingInfo not valid: getFixedBlockSize is not an integer multiple of elementList.size().");
357 
358  } else {
359  // numGlobalElements can be -1! FIXME
360  // TEUCHOS_TEST_FOR_EXCEPTION(numGlobalElements % stridingInfo[stridedBlockId] != 0, Exceptions::RuntimeError,
361  // "StridedMap::StridedMap: stridingInfo not valid: stridingBlockInfo[stridedBlockId] is not an integer multiple of numGlobalElements.");
362  TEUCHOS_TEST_FOR_EXCEPTION(elementList.size() % stridingInfo[stridedBlockId] != 0, Exceptions::RuntimeError,
363  "StridedMap::StridedMap: stridingInfo not valid: stridingBlockInfo[stridedBlockId] is not an integer multiple of elementList.size().");
364  }
365 
366  map_ = MapFactory_t::Build(xlib, numGlobalElements, elementList, indexBase, comm, node);
367 
368  // calculate offset_
369 
370  // find minimum GID over all procs
371  GlobalOrdinal minGidOnCurProc = Teuchos::OrdinalTraits<GlobalOrdinal>::max();
372  for (Teuchos_Ordinal k = 0; k < elementList.size(); k++) // TODO fix occurence of Teuchos_Ordinal
373  if (elementList[k] < minGidOnCurProc)
374  minGidOnCurProc = elementList[k];
375 
376  Teuchos::reduceAll(*comm, Teuchos::REDUCE_MIN, minGidOnCurProc, Teuchos::outArg(offset_));
377 
378  // calculate striding index
379  size_t nStridedOffset = 0;
380  for (int j = 0; j < stridedBlockId; j++)
381  nStridedOffset += stridingInfo[j];
382  const GlobalOrdinal goStridedOffset = Teuchos::as<GlobalOrdinal>(nStridedOffset);
383 
384  // adapt offset_
385  offset_ -= goStridedOffset + indexBase_;
386 
387  TEUCHOS_TEST_FOR_EXCEPTION(CheckConsistency() == false, Exceptions::RuntimeError, "StridedTpetraMap::StridedTpetraMap: CheckConsistency() == false");
388  }
389 
390  StridedMap(const RCP<const Map>& map, std::vector<size_t>& stridingInfo, GlobalOrdinal indexBase, LocalOrdinal stridedBlockId = -1, GlobalOrdinal offset = 0)
391  : stridingInfo_(stridingInfo), stridedBlockId_(stridedBlockId), offset_(offset), indexBase_(map->getIndexBase())
392  {
393  // TAW: 11/24/15
394  // A strided map never can be built from a strided map. getMap always returns the underlying
395  // Xpetra::Map object which contains the data (either in a Xpetra::EpetraMapT or Xpetra::TpetraMap
396  // object)
397  if(Teuchos::rcp_dynamic_cast<const StridedMap>(map) == Teuchos::null)
398  map_ = map; // if map is not a strided map, just store it (standard case)
399  else
400  map_ = map->getMap(); // if map is also a strided map, store the underlying plain Epetra/Tpetra Xpetra map object
401  }
402 
403 
405  virtual ~StridedMap() { }
406 
408 
410 
411 
412  std::vector<size_t> getStridingData() const { return stridingInfo_; }
413 
414  void setStridingData(std::vector<size_t> stridingInfo) { stridingInfo_ = stridingInfo; }
415 
416  size_t getFixedBlockSize() const {
417  size_t blkSize = 0;
418  for (std::vector<size_t>::const_iterator it = stridingInfo_.begin(); it != stridingInfo_.end(); ++it)
419  blkSize += *it;
420  return blkSize;
421  }
422 
425  LocalOrdinal getStridedBlockId() const { return stridedBlockId_; }
426 
428  bool isStrided() const { return stridingInfo_.size() > 1 ? true : false; }
429 
432  bool isBlocked() const { return getFixedBlockSize() > 1 ? true : false; }
433 
434  GlobalOrdinal getOffset() const { return offset_; }
435 
436  void setOffset(GlobalOrdinal offset) { offset_ = offset; }
437 
438  // returns number of strided block id which gid belongs to.
439  size_t GID2StridingBlockId(GlobalOrdinal gid) const {
440  GlobalOrdinal tgid = gid - offset_ - indexBase_;
441  tgid = tgid % getFixedBlockSize();
442 
443  size_t nStridedOffset = 0;
444  size_t stridedBlockId = 0;
445  for (size_t j = 0; j < stridingInfo_.size(); j++) {
446  nStridedOffset += stridingInfo_[j];
447  if (Teuchos::as<size_t>(tgid) < nStridedOffset) {
448  stridedBlockId = j;
449  break;
450  }
451  }
452  return stridedBlockId;
453  }
454 
456 
457 
459 
460 #ifdef HAVE_XPETRA_KOKKOS_REFACTOR
461 #ifdef HAVE_XPETRA_TPETRA
464  local_map_type getLocalMap () const {
465  return map_->getLocalMap();
466  }
467 #else
468 #ifdef __GNUC__
469 #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."
470 #endif
471 #endif
472 #endif
473 
475 
476  /* // function currently not needed but maybe useful
477  std::vector<GlobalOrdinal> NodeId2GlobalDofIds(GlobalOrdinal nodeId) const {
478  TEUCHOS_TEST_FOR_EXCEPTION(stridingInfo_.size() == 0, Exceptions::RuntimeError, "StridedMap::NodeId2GlobalDofIds: stridingInfo not valid: stridingInfo.size() = 0?");
479  std::vector<GlobalOrdinal> dofs;
480  if(stridedBlockId_ > -1) {
481  TEUCHOS_TEST_FOR_EXCEPTION(stridingInfo_[stridedBlockId_] == 0, Exceptions::RuntimeError, "StridedMap::NodeId2GlobalDofIds: stridingInfo not valid: stridingInfo[stridedBlockId] = 0?");
482 
483  // determine nStridedOffset
484  size_t nStridedOffset = 0;
485  for(int j=0; j<stridedBlockId_; j++) {
486  nStridedOffset += stridingInfo_[j];
487  }
488 
489  for(size_t i = 0; i<stridingInfo_[stridedBlockId_]; i++) {
490  GlobalOrdinal gid =
491  nodeId * Teuchos::as<GlobalOrdinal>(getFixedBlockSize()) +
492  offset_ +
493  Teuchos::as<GlobalOrdinal>(nStridedOffset) +
494  Teuchos::as<GlobalOrdinal>(i);
495  dofs.push_back(gid);
496  }
497  } else {
498  for(size_t i = 0; i<getFixedBlockSize(); i++) {
499  GlobalOrdinal gid =
500  nodeId * Teuchos::as<GlobalOrdinal>(getFixedBlockSize()) +
501  offset_ +
502  Teuchos::as<GlobalOrdinal>(i);
503  dofs.push_back(gid);
504  }
505  }
506  return dofs;
507  }*/
509 
510  private:
511  virtual bool CheckConsistency() {
512 #ifndef HAVE_XPETRA_DEBUG
513  return true;
514 #else
515  if (getStridedBlockId() == -1) {
516  // Strided map contains the full map
517  if (getNodeNumElements() % getFixedBlockSize() != 0 || // number of local elements is not a multiple of block size
518  getGlobalNumElements() % getFixedBlockSize() != 0) // number of global -//-
519  return false;
520 
521  } else {
522  // Strided map contains only the partial map
524  // std::sort(dofGids.begin(), dofGids.end());
525 
526  if (dofGids.size() == 0) // special treatment for empty processors
527  return true;
528 
529  if (dofGids.size() % stridingInfo_[stridedBlockId_] != 0)
530  return false;
531 
532 
533  // Calculate nStridedOffset
534  size_t nStridedOffset = 0;
535  for (int j = 0; j < stridedBlockId_; j++)
536  nStridedOffset += stridingInfo_[j];
537 
538  const GlobalOrdinal goStridedOffset = Teuchos::as<GlobalOrdinal>(nStridedOffset);
539  const GlobalOrdinal goZeroOffset = (dofGids[0] - nStridedOffset - offset_ - indexBase_) / Teuchos::as<GlobalOrdinal>(getFixedBlockSize());
540 
541  GlobalOrdinal cnt = 0;
542  for (size_t i = 0; i < Teuchos::as<size_t>(dofGids.size())/stridingInfo_[stridedBlockId_]; i += stridingInfo_[stridedBlockId_]) {
543  const GlobalOrdinal first_gid = dofGids[i];
544 
545  // We expect this to be the same for all DOFs of the same node
546  cnt = (first_gid - goStridedOffset - offset_ - indexBase_) / Teuchos::as<GlobalOrdinal>(getFixedBlockSize()) - goZeroOffset;
547 
548  // Loop over all DOFs that belong to current node
549  for (size_t j = 0; j < stridingInfo_[stridedBlockId_]; j++) {
550  const GlobalOrdinal gid = dofGids[i+j];
551  const GlobalOrdinal r = (gid - Teuchos::as<GlobalOrdinal>(j) - goStridedOffset - offset_ - indexBase_) /
552  Teuchos::as<GlobalOrdinal>(getFixedBlockSize()) - goZeroOffset - cnt;
553  // TAW 1/18/2016: We cannot use Teuchos::OrdinalTraits<GlobalOrdinal>::zero() ) here,
554  // If, e.g., GO=long long is disabled, OrdinalTraits<long long> is not available.
555  // But we instantiate stubs on GO=long long which might contain StridedMaps.
556  // These lead to compilation errors, then.
557  if (r != 0 ) {
558  std::cout << "goZeroOffset : " << goZeroOffset << std::endl
559  << "dofGids[0] : " << dofGids[0] << std::endl
560  << "stridedOffset : " << nStridedOffset << std::endl
561  << "offset_ : " << offset_ << std::endl
562  << "goStridedOffset: " << goStridedOffset << std::endl
563  << "getFixedBlkSize: " << getFixedBlockSize() << std::endl
564  << "gid: " << gid << " GID: " << r << std::endl;
565 
566  return false;
567  }
568  }
569  }
570  }
571 
572  return true;
573 #endif
574  }
575 
576  private:
578 
579  std::vector<size_t> stridingInfo_;
580  LocalOrdinal stridedBlockId_;
581  // stridedBlock == -1: the full map (with all strided block dofs)
582  // stridedBlock > -1: only dofs of strided block with index "stridedBlockId" are stored in this map
583  GlobalOrdinal offset_;
584  GlobalOrdinal indexBase_;
585 
586  public:
587 
589 
590 
592  global_size_t getGlobalNumElements() const { return map_->getGlobalNumElements(); }
593 
595  size_t getNodeNumElements() const { return map_->getNodeNumElements(); }
596 
598  GlobalOrdinal getIndexBase() const { return map_->getIndexBase(); }
599 
601  LocalOrdinal getMinLocalIndex() const { return map_->getMinLocalIndex(); }
602 
604  LocalOrdinal getMaxLocalIndex() const { return map_->getMaxLocalIndex(); }
605 
607  GlobalOrdinal getMinGlobalIndex() const { return map_->getMinGlobalIndex(); }
608 
610  GlobalOrdinal getMaxGlobalIndex() const { return map_->getMaxGlobalIndex(); }
611 
613  GlobalOrdinal getMinAllGlobalIndex() const { return map_->getMinAllGlobalIndex(); }
614 
616  GlobalOrdinal getMaxAllGlobalIndex() const { return map_->getMaxAllGlobalIndex(); }
617 
619  LocalOrdinal getLocalElement(GlobalOrdinal globalIndex) const { return map_->getLocalElement(globalIndex); }
620 
622  GlobalOrdinal getGlobalElement(LocalOrdinal localIndex) const { return map_->getGlobalElement(localIndex); }
623 
626  return map_->getRemoteIndexList(GIDList, nodeIDList, LIDList);
627  }
628 
631  return map_->getRemoteIndexList(GIDList, nodeIDList);
632  }
633 
635  Teuchos::ArrayView< const GlobalOrdinal > getNodeElementList() const { return map_->getNodeElementList(); }
636 
638  bool isNodeLocalElement(LocalOrdinal localIndex) const { return map_->isNodeLocalElement(localIndex); }
639 
641  bool isNodeGlobalElement(GlobalOrdinal globalIndex) const { return map_->isNodeGlobalElement(globalIndex); }
642 
644  bool isContiguous() const { return map_->isContiguous(); }
645 
647  bool isDistributed() const { return map_->isDistributed(); }
648 
650 
652  bool isCompatible(const Map& map) const { return map_->isCompatible(map); }
653 
655  bool isSameAs(const Map& map) const { return map_->isSameAs(map); }
656 
658  Teuchos::RCP< const Teuchos::Comm< int > > getComm() const { return map_->getComm(); }
659 
661  Teuchos::RCP<Node> getNode() const { return map_->getNode(); }
662 
663  RCP<const Map> removeEmptyProcesses () const { return map_->removeEmptyProcesses(); }
664  RCP<const Map> replaceCommWithSubset (const Teuchos::RCP<const Teuchos::Comm<int> >& newComm) const { return map_->replaceCommWithSubset(newComm); }
665 
667  std::string description() const { return map_->description(); }
668 
670  void describe(Teuchos::FancyOStream& out, const Teuchos::EVerbosityLevel verbLevel = Teuchos::Describable::verbLevel_default) const { map_->describe(out, verbLevel); }
671 
673  UnderlyingLib lib() const { return map_->lib(); }
674 
675  }; // StridedMap class
676 
677 } // Xpetra namespace
678 
679 #define XPETRA_STRIDEDMAP_SHORT
680 #endif // XPETRA_STRIDEDMAP_HPP
StridedMap(UnderlyingLib xlib, global_size_t numGlobalElements, const Teuchos::ArrayView< const GlobalOrdinal > &elementList, GlobalOrdinal indexBase, std::vector< size_t > &stridingInfo, const Teuchos::RCP< const Teuchos::Comm< int > > &comm, LocalOrdinal stridedBlockId=-1, const Teuchos::RCP< Node > &node=Teuchos::rcp(new Node))
Map constructor with user-defined non-contiguous (arbitrary) distribution.
StridedMap(UnderlyingLib xlib, global_size_t numGlobalElements, size_t numLocalElements, GlobalOrdinal indexBase, std::vector< size_t > &stridingInfo, const Teuchos::RCP< const Teuchos::Comm< int > > &comm, LocalOrdinal stridedBlockId=-1, GlobalOrdinal offset=0, const Teuchos::RCP< Node > &node=Teuchos::rcp(new Node))
Map constructor with a user-defined contiguous distribution.
bool isStrided() const
returns true, if this is a strided map (i.e. more than 1 strided blocks)
std::vector< size_t > getStridingData() const
Xpetra::MapFactory< LocalOrdinal, GlobalOrdinal, Node > MapFactory_t
LocalOrdinal local_ordinal_type
GlobalOrdinal global_ordinal_type
Definition: Xpetra_Map.hpp:95
GlobalOrdinal global_ordinal_type
GlobalOrdinal getOffset() const
bool isSameAs(const Map &map) const
Returns true if map is identical to this Map.
LocalOrdinal getMinLocalIndex() const
Returns minimum local index.
void setStridingData(std::vector< size_t > stridingInfo)
Node node_type
Definition: Xpetra_Map.hpp:96
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
GlobalOrdinal getIndexBase() const
Returns the index base for this Map.
GlobalOrdinal indexBase_
index base for the strided map (default = 0)
Xpetra namespace
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.
LocalOrdinal getMaxLocalIndex() const
Returns maximum local index.
Exception throws to report errors in the internal logical of the program.
GlobalOrdinal getMinAllGlobalIndex() const
Return the minimum global index over all nodes.
size_type size() const
std::string description() const
Return a simple one-line description of this object.
Teuchos::RCP< Node > getNode() const
Get the Node object for this Map.
LocalOrdinal stridedBlockId_
member variable denoting which dofs are stored in map
RCP< const Map > replaceCommWithSubset(const Teuchos::RCP< const Teuchos::Comm< int > > &newComm) const
Replace this Map&#39;s communicator with a subset communicator.
GlobalOrdinal getMaxAllGlobalIndex() const
Return the maximum global index over all nodes.
GlobalOrdinal getGlobalElement(LocalOrdinal localIndex) const
Return the global index for a given local index.
StridedMap(const RCP< const Map > &map, std::vector< size_t > &stridingInfo, GlobalOrdinal indexBase, LocalOrdinal stridedBlockId=-1, GlobalOrdinal offset=0)
global_size_t getGlobalNumElements() const
Returns the number of elements in this Map.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
std::vector< size_t > stridingInfo_
vector with size of strided blocks (dofs)
LocalOrdinal getLocalElement(GlobalOrdinal globalIndex) const
Return the local index for a given global index.
virtual ~StridedMap()
Destructor.
LocalOrdinal getStridedBlockId() const
RCP< const Map > removeEmptyProcesses() const
Return a new Map with processes with zero elements removed.
GlobalOrdinal offset_
offset for gids in map (default = 0)
TEUCHOS_DEPRECATED void reduceAll(const Comm< Ordinal > &comm, const EReductionType reductType, const Packet &send, Packet *globalReduct)
LookupStatus getRemoteIndexList(const Teuchos::ArrayView< const GlobalOrdinal > &GIDList, const Teuchos::ArrayView< int > &nodeIDList) const
Returns the node IDs for a given list of global indices.
UnderlyingLib lib() const
Get the library used by this object (Tpetra or Epetra?)
size_t global_size_t
Global size_t object.
static const EVerbosityLevel verbLevel_default
Teuchos::RCP< const Teuchos::Comm< int > > getComm() const
Get the Comm object for this Map.
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.
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...
virtual bool CheckConsistency()
size_t getFixedBlockSize() const
Create an Xpetra::Map instance.
bool isDistributed() const
Returns true if this Map is distributed across more than one node; returns false otherwise.
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...
GlobalOrdinal getMaxGlobalIndex() const
Returns maximum global index owned by this node.
bool isCompatible(const Map &map) const
Returns true if map is compatible with this Map.
bool isContiguous() const
Returns true if this Map is distributed contiguously; returns false otherwise.
RCP< const Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > getMap() const
static Teuchos::RCP< Map< LocalOrdinal, GlobalOrdinal, Node > > Build(UnderlyingLib lib, global_size_t numGlobalElements, GlobalOrdinal indexBase, const Teuchos::RCP< const Teuchos::Comm< int > > &comm, LocalGlobal lg=Xpetra::GloballyDistributed, const Teuchos::RCP< Node > &=Teuchos::null)
Map constructor with Xpetra-defined contiguous uniform distribution.
Teuchos::ArrayView< const GlobalOrdinal > getNodeElementList() const
Return a list of the global indices owned by this node.
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, const Teuchos::RCP< Node > &node=Teuchos::rcp(new Node))
Map constructor with contiguous uniform distribution.
size_t GID2StridingBlockId(GlobalOrdinal gid) const
void setOffset(GlobalOrdinal offset)
RCP< const Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > map_
GlobalOrdinal getMinGlobalIndex() const
Returns minimum global index owned by this node.
size_t getNodeNumElements() const
Returns the number of elements belonging to the calling node.