All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 
134 #ifdef TPETRA_ENABLE_DEPRECATED_CODE
135  TPETRA_DEPRECATED
137  global_size_t numGlobalElements,
138  GlobalOrdinal indexBase,
139  std::vector<size_t>& stridingInfo,
140  const Teuchos::RCP< const Teuchos::Comm< int > >& comm,
141  LocalOrdinal stridedBlockId, // FIXME (mfh 03 Sep 2014) This breaks for unsigned LocalOrdinal
142  GlobalOrdinal offset,
143  LocalGlobal lg,
144  const Teuchos::RCP< Node >& /* node */)
145  : StridedMap(xlib, numGlobalElements, indexBase, stridingInfo, comm,
146  stridedBlockId, offset, lg)
147  {}
148 #endif // #ifdef TPETRA_ENABLE_DEPRECATED_CODE
150  global_size_t numGlobalElements,
151  GlobalOrdinal indexBase,
152  std::vector<size_t>& stridingInfo,
153  const Teuchos::RCP< const Teuchos::Comm< int > >& comm,
154  LocalOrdinal stridedBlockId = -1, // FIXME (mfh 03 Sep 2014) This breaks for unsigned LocalOrdinal
155  GlobalOrdinal offset = 0,
157  : stridingInfo_ (stridingInfo),
158  stridedBlockId_ (stridedBlockId),
159  offset_ (offset),
160  indexBase_ (indexBase)
161  {
162  size_t blkSize = getFixedBlockSize ();
164  stridingInfo.size() == 0, Exceptions::RuntimeError,
165  "StridedMap::StridedMap: stridingInfo not valid: stridingInfo.size() = 0?");
167  numGlobalElements == Teuchos::OrdinalTraits<global_size_t>::invalid (),
168  std::invalid_argument,
169  "StridedMap::StridedMap: numGlobalElements is invalid");
170  TEUCHOS_TEST_FOR_EXCEPTION(
171  numGlobalElements % blkSize != 0, Exceptions::RuntimeError,
172  "StridedMap::StridedMap: stridingInfo not valid: getFixedBlockSize "
173  "is not an integer multiple of numGlobalElements.");
174  if (stridedBlockId != -1)
175  TEUCHOS_TEST_FOR_EXCEPTION(
176  stridingInfo.size() < static_cast<size_t> (stridedBlockId),
177  Exceptions::RuntimeError, "StridedTpetraMap::StridedTpetraMap: "
178  "stridedBlockId > stridingInfo.size()");
179 
180  // Try to create a shortcut
181  if (blkSize != 1 || offset_ != 0) {
182  // check input data and reorganize map
183  global_size_t numGlobalNodes = numGlobalElements / blkSize;
184 
185  // build an equally distributed node map
186  RCP<Map> nodeMap = MapFactory_t::Build(xlib, numGlobalNodes, indexBase, comm, lg);
187  global_size_t numLocalNodes = nodeMap->getNodeNumElements();
188 
189  // translate local node ids to local dofs
190  size_t nStridedOffset = 0;
191  size_t nDofsPerNode = blkSize; // dofs per node for local striding block
192  if (stridedBlockId > -1) {
193  for (int j = 0; j < stridedBlockId; j++)
194  nStridedOffset += stridingInfo_[j];
195 
196  nDofsPerNode = stridingInfo_[stridedBlockId];
197  numGlobalElements = numGlobalNodes * Teuchos::as<global_size_t>(nDofsPerNode);
198  }
199  size_t numLocalElements = numLocalNodes * Teuchos::as<size_t>(nDofsPerNode);
200 
201  std::vector<GlobalOrdinal> dofgids(numLocalElements);
202  for (LocalOrdinal i = 0; i < Teuchos::as<LocalOrdinal>(numLocalNodes); i++) {
203  GlobalOrdinal nodeGID = nodeMap->getGlobalElement(i);
204 
205  for (size_t j = 0; j < nDofsPerNode; j++)
206  dofgids[i*nDofsPerNode + j] = indexBase_ + offset_ + (nodeGID - indexBase_)*Teuchos::as<GlobalOrdinal>(blkSize) + Teuchos::as<GlobalOrdinal>(nStridedOffset + j);
207  }
208 
209  map_ = MapFactory_t::Build(xlib, numGlobalElements, dofgids, indexBase, comm);
210 
211  if (stridedBlockId == -1) {
212  TEUCHOS_TEST_FOR_EXCEPTION(getNodeNumElements() != Teuchos::as<size_t>(nodeMap->getNodeNumElements()*nDofsPerNode), Exceptions::RuntimeError,
213  "StridedTpetraMap::StridedTpetraMap: wrong distribution of dofs among processors.");
214  TEUCHOS_TEST_FOR_EXCEPTION(getGlobalNumElements() != Teuchos::as<size_t>(nodeMap->getGlobalNumElements()*nDofsPerNode), Exceptions::RuntimeError,
215  "StridedTpetraMap::StridedTpetraMap: wrong distribution of dofs among processors.");
216 
217  } else {
218  size_t nDofsInStridedBlock = stridingInfo[stridedBlockId];
219  TEUCHOS_TEST_FOR_EXCEPTION(getNodeNumElements() != Teuchos::as<size_t>(nodeMap->getNodeNumElements()*nDofsInStridedBlock), Exceptions::RuntimeError,
220  "StridedTpetraMap::StridedTpetraMap: wrong distribution of dofs among processors.");
221  TEUCHOS_TEST_FOR_EXCEPTION(getGlobalNumElements() != Teuchos::as<size_t>(nodeMap->getGlobalNumElements()*nDofsInStridedBlock), Exceptions::RuntimeError,
222  "StridedTpetraMap::StridedTpetraMap: wrong distribution of dofs among processors.");
223  }
224  } else {
225  map_ = MapFactory_t::Build(xlib, numGlobalElements, indexBase, comm, lg);
226  }
227 
228  TEUCHOS_TEST_FOR_EXCEPTION(CheckConsistency() == false, Exceptions::RuntimeError, "StridedTpetraMap::StridedTpetraMap: CheckConsistency() == false");
229  }
230 
232 
252 #ifdef TPETRA_ENABLE_DEPRECATED_CODE
253  TPETRA_DEPRECATED
254  StridedMap(UnderlyingLib xlib, global_size_t numGlobalElements, size_t numLocalElements, GlobalOrdinal indexBase, std::vector<size_t>& stridingInfo,
255  const Teuchos::RCP< const Teuchos::Comm< int > > &comm, LocalOrdinal stridedBlockId, GlobalOrdinal offset,
256  const Teuchos::RCP< Node > & /* node */)
257  : StridedMap(xlib, numGlobalElements, numLocalElements, indexBase,
258  stridingInfo, comm, stridedBlockId, offset)
259  {}
260 #endif // TPETRA_ENABLE_DEPRECATED_CODE
261  StridedMap(UnderlyingLib xlib, global_size_t numGlobalElements, size_t numLocalElements, GlobalOrdinal indexBase, std::vector<size_t>& stridingInfo,
262  const Teuchos::RCP< const Teuchos::Comm< int > > &comm, LocalOrdinal stridedBlockId = -1, GlobalOrdinal offset = 0)
263  : stridingInfo_(stridingInfo), stridedBlockId_(stridedBlockId), offset_(offset), indexBase_(indexBase)
264  {
265  size_t blkSize = getFixedBlockSize();
266  TEUCHOS_TEST_FOR_EXCEPTION(stridingInfo.size() == 0, Exceptions::RuntimeError,
267  "StridedMap::StridedMap: stridingInfo not valid: stridingInfo.size() = 0?");
268  if (numGlobalElements != Teuchos::OrdinalTraits<global_size_t>::invalid()) {
269  TEUCHOS_TEST_FOR_EXCEPTION(numGlobalElements % blkSize != 0, Exceptions::RuntimeError,
270  "StridedMap::StridedMap: stridingInfo not valid: getFixedBlockSize is not an integer multiple of numGlobalElements.");
271 #ifdef HAVE_XPETRA_DEBUG
272  // We have to do this check ourselves, as we don't necessarily construct the full Tpetra map
273  global_size_t sumLocalElements;
274  Teuchos::reduceAll(*comm, Teuchos::REDUCE_SUM, Teuchos::as<global_size_t>(numLocalElements), Teuchos::outArg(sumLocalElements));
275  TEUCHOS_TEST_FOR_EXCEPTION(sumLocalElements != numGlobalElements, std::invalid_argument,
276  "StridedMap::StridedMap: sum of numbers of local elements is different from the provided number of global elements.");
277 #endif
278  }
279  TEUCHOS_TEST_FOR_EXCEPTION(numLocalElements % blkSize != 0, Exceptions::RuntimeError,
280  "StridedMap::StridedMap: stridingInfo not valid: getFixedBlockSize is not an integer multiple of numLocalElements.");
281  if (stridedBlockId != -1)
282  TEUCHOS_TEST_FOR_EXCEPTION(stridingInfo.size() < Teuchos::as<size_t>(stridedBlockId), Exceptions::RuntimeError,
283  "StridedTpetraMap::StridedTpetraMap: stridedBlockId > stridingInfo.size()");
284 
285  // Try to create a shortcut
286  if (blkSize != 1 || offset_ != 0) {
287  // check input data and reorganize map
289  if (numGlobalElements != Teuchos::OrdinalTraits<global_size_t>::invalid())
290  numGlobalNodes = numGlobalElements / blkSize;
291  global_size_t numLocalNodes = numLocalElements / blkSize;
292 
293  // build an equally distributed node map
294  RCP<Map> nodeMap = MapFactory_t::Build(xlib, numGlobalNodes, numLocalNodes, indexBase, comm);
295 
296  // translate local node ids to local dofs
297  size_t nStridedOffset = 0;
298  size_t nDofsPerNode = blkSize; // dofs per node for local striding block
299  if (stridedBlockId > -1) {
300  for (int j = 0; j < stridedBlockId; j++)
301  nStridedOffset += stridingInfo_[j];
302 
303  nDofsPerNode = stridingInfo_[stridedBlockId];
304  numGlobalElements = nodeMap->getGlobalNumElements() * Teuchos::as<global_size_t>(nDofsPerNode);
305  }
306  numLocalElements = numLocalNodes * Teuchos::as<size_t>(nDofsPerNode);
307 
308  std::vector<GlobalOrdinal> dofgids(numLocalElements);
309  for (LocalOrdinal i = 0; i < Teuchos::as<LocalOrdinal>(numLocalNodes); i++) {
310  GlobalOrdinal nodeGID = nodeMap->getGlobalElement(i);
311 
312  for (size_t j = 0; j < nDofsPerNode; j++)
313  dofgids[i*nDofsPerNode + j] = indexBase_ + offset_ + (nodeGID - indexBase_)*Teuchos::as<GlobalOrdinal>(blkSize) + Teuchos::as<GlobalOrdinal>(nStridedOffset + j);
314  }
315 
316  map_ = MapFactory_t::Build(xlib, numGlobalElements, dofgids, indexBase, comm);
317 
318  if (stridedBlockId == -1) {
319  TEUCHOS_TEST_FOR_EXCEPTION(getNodeNumElements() != Teuchos::as<size_t>(nodeMap->getNodeNumElements()*nDofsPerNode), Exceptions::RuntimeError,
320  "StridedTpetraMap::StridedTpetraMap: wrong distribution of dofs among processors.");
321  TEUCHOS_TEST_FOR_EXCEPTION(getGlobalNumElements() != Teuchos::as<size_t>(nodeMap->getGlobalNumElements()*nDofsPerNode), Exceptions::RuntimeError,
322  "StridedTpetraMap::StridedTpetraMap: wrong distribution of dofs among processors.");
323 
324  } else {
325  int nDofsInStridedBlock = stridingInfo[stridedBlockId];
326  TEUCHOS_TEST_FOR_EXCEPTION(getNodeNumElements() != Teuchos::as<size_t>(nodeMap->getNodeNumElements()*nDofsInStridedBlock), Exceptions::RuntimeError,
327  "StridedTpetraMap::StridedTpetraMap: wrong distribution of dofs among processors.");
328  TEUCHOS_TEST_FOR_EXCEPTION(getGlobalNumElements() != Teuchos::as<size_t>(nodeMap->getGlobalNumElements()*nDofsInStridedBlock), Exceptions::RuntimeError,
329  "StridedTpetraMap::StridedTpetraMap: wrong distribution of dofs among processors.");
330  }
331 
332  } else {
333  map_ = MapFactory_t::Build(xlib, numGlobalElements, numLocalElements, indexBase, comm);
334  }
335 
336  TEUCHOS_TEST_FOR_EXCEPTION(CheckConsistency() == false, Exceptions::RuntimeError, "StridedTpetraMap::StridedTpetraMap: CheckConsistency() == false");
337  }
338 
349 #ifdef TPETRA_ENABLE_DEPRECATED_CODE
350  TPETRA_DEPRECATED
351  StridedMap(UnderlyingLib xlib, global_size_t numGlobalElements, const Teuchos::ArrayView< const GlobalOrdinal > &elementList, GlobalOrdinal indexBase,
352  std::vector<size_t>& stridingInfo, const Teuchos::RCP< const Teuchos::Comm< int > > &comm, LocalOrdinal stridedBlockId,
353  const Teuchos::RCP< Node > & /* node */)
354  : StridedMap(xlib, numGlobalElements, elementList, indexBase,
355  stridingInfo, comm, stridedBlockId)
356  {}
357 #endif // TPETRA_ENABLE_DEPRECATED_CODE
358  StridedMap(UnderlyingLib xlib, global_size_t numGlobalElements, const Teuchos::ArrayView< const GlobalOrdinal > &elementList, GlobalOrdinal indexBase,
359  std::vector<size_t>& stridingInfo, const Teuchos::RCP< const Teuchos::Comm< int > > &comm, LocalOrdinal stridedBlockId = -1)
360  : stridingInfo_(stridingInfo), stridedBlockId_(stridedBlockId), indexBase_(indexBase)
361  {
362  size_t blkSize = getFixedBlockSize();
363 
364  TEUCHOS_TEST_FOR_EXCEPTION(stridingInfo.size() == 0, Exceptions::RuntimeError,
365  "StridedMap::StridedMap: stridingInfo not valid: stridingInfo.size() = 0?");
366  if (stridedBlockId != -1)
367  TEUCHOS_TEST_FOR_EXCEPTION(stridingInfo.size() < Teuchos::as<size_t>(stridedBlockId), Exceptions::RuntimeError,
368  "StridedTpetraMap::StridedTpetraMap: stridedBlockId > stridingInfo.size()");
369  if (numGlobalElements != Teuchos::OrdinalTraits<global_size_t>::invalid()) {
370  TEUCHOS_TEST_FOR_EXCEPTION(numGlobalElements % blkSize != 0, Exceptions::RuntimeError,
371  "StridedMap::StridedMap: stridingInfo not valid: getFixedBlockSize is not an integer multiple of numGlobalElements.");
372 #ifdef HAVE_XPETRA_DEBUG
373  // We have to do this check ourselves, as we don't necessarily construct the full Tpetra map
374  global_size_t sumLocalElements, numLocalElements = elementList.size();
375  Teuchos::reduceAll(*comm, Teuchos::REDUCE_SUM, numLocalElements, Teuchos::outArg(sumLocalElements));
376  TEUCHOS_TEST_FOR_EXCEPTION(sumLocalElements != numGlobalElements, std::invalid_argument,
377  "StridedMap::StridedMap: sum of numbers of local elements is different from the provided number of global elements.");
378 #endif
379  }
380 
381  if (stridedBlockId == -1) {
382  // numGlobalElements can be -1! FIXME
383  // TEUCHOS_TEST_FOR_EXCEPTION(numGlobalElements % blkSize != 0, Exceptions::RuntimeError,
384  // "StridedMap::StridedMap: stridingInfo not valid: getFixedBlockSize is not an integer multiple of numGlobalElements.");
385  TEUCHOS_TEST_FOR_EXCEPTION(elementList.size() % blkSize != 0, Exceptions::RuntimeError,
386  "StridedMap::StridedMap: stridingInfo not valid: getFixedBlockSize is not an integer multiple of elementList.size().");
387 
388  } else {
389  // numGlobalElements can be -1! FIXME
390  // TEUCHOS_TEST_FOR_EXCEPTION(numGlobalElements % stridingInfo[stridedBlockId] != 0, Exceptions::RuntimeError,
391  // "StridedMap::StridedMap: stridingInfo not valid: stridingBlockInfo[stridedBlockId] is not an integer multiple of numGlobalElements.");
392  TEUCHOS_TEST_FOR_EXCEPTION(elementList.size() % stridingInfo[stridedBlockId] != 0, Exceptions::RuntimeError,
393  "StridedMap::StridedMap: stridingInfo not valid: stridingBlockInfo[stridedBlockId] is not an integer multiple of elementList.size().");
394  }
395 
396  map_ = MapFactory_t::Build(xlib, numGlobalElements, elementList, indexBase, comm);
397 
398  // calculate offset_
399 
400  // find minimum GID over all procs
401  GlobalOrdinal minGidOnCurProc = Teuchos::OrdinalTraits<GlobalOrdinal>::max();
402  for (Teuchos_Ordinal k = 0; k < elementList.size(); k++) // TODO fix occurence of Teuchos_Ordinal
403  if (elementList[k] < minGidOnCurProc)
404  minGidOnCurProc = elementList[k];
405 
406  Teuchos::reduceAll(*comm, Teuchos::REDUCE_MIN, minGidOnCurProc, Teuchos::outArg(offset_));
407 
408  // calculate striding index
409  size_t nStridedOffset = 0;
410  for (int j = 0; j < stridedBlockId; j++)
411  nStridedOffset += stridingInfo[j];
412  const GlobalOrdinal goStridedOffset = Teuchos::as<GlobalOrdinal>(nStridedOffset);
413 
414  // adapt offset_
415  offset_ -= goStridedOffset + indexBase_;
416 
417  TEUCHOS_TEST_FOR_EXCEPTION(CheckConsistency() == false, Exceptions::RuntimeError, "StridedTpetraMap::StridedTpetraMap: CheckConsistency() == false");
418  }
419 
420  StridedMap(const RCP<const Map>& map, std::vector<size_t>& stridingInfo, GlobalOrdinal /* indexBase */, LocalOrdinal stridedBlockId = -1, GlobalOrdinal offset = 0)
421  : stridingInfo_(stridingInfo), stridedBlockId_(stridedBlockId), offset_(offset), indexBase_(map->getIndexBase())
422  {
423  // TAW: 11/24/15
424  // A strided map never can be built from a strided map. getMap always returns the underlying
425  // Xpetra::Map object which contains the data (either in a Xpetra::EpetraMapT or Xpetra::TpetraMap
426  // object)
427  if(Teuchos::rcp_dynamic_cast<const StridedMap>(map) == Teuchos::null)
428  map_ = map; // if map is not a strided map, just store it (standard case)
429  else
430  map_ = map->getMap(); // if map is also a strided map, store the underlying plain Epetra/Tpetra Xpetra map object
431  }
432 
433 
435  virtual ~StridedMap() { }
436 
438 
440 
441 
442  std::vector<size_t> getStridingData() const { return stridingInfo_; }
443 
444  void setStridingData(std::vector<size_t> stridingInfo) { stridingInfo_ = stridingInfo; }
445 
446  size_t getFixedBlockSize() const {
447  size_t blkSize = 0;
448  for (std::vector<size_t>::const_iterator it = stridingInfo_.begin(); it != stridingInfo_.end(); ++it)
449  blkSize += *it;
450  return blkSize;
451  }
452 
455  LocalOrdinal getStridedBlockId() const { return stridedBlockId_; }
456 
458  bool isStrided() const { return stridingInfo_.size() > 1 ? true : false; }
459 
462  bool isBlocked() const { return getFixedBlockSize() > 1 ? true : false; }
463 
464  GlobalOrdinal getOffset() const { return offset_; }
465 
466  void setOffset(GlobalOrdinal offset) { offset_ = offset; }
467 
468  // returns number of strided block id which gid belongs to.
469  size_t GID2StridingBlockId(GlobalOrdinal gid) const {
470  GlobalOrdinal tgid = gid - offset_ - indexBase_;
471  tgid = tgid % getFixedBlockSize();
472 
473  size_t nStridedOffset = 0;
474  size_t stridedBlockId = 0;
475  for (size_t j = 0; j < stridingInfo_.size(); j++) {
476  nStridedOffset += stridingInfo_[j];
477  if (Teuchos::as<size_t>(tgid) < nStridedOffset) {
478  stridedBlockId = j;
479  break;
480  }
481  }
482  return stridedBlockId;
483  }
484 
486 
487 
489 
490 #ifdef HAVE_XPETRA_KOKKOS_REFACTOR
491 #ifdef HAVE_XPETRA_TPETRA
494  local_map_type getLocalMap () const {
495  return map_->getLocalMap();
496  }
497 #else
498 #ifdef __GNUC__
499 #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."
500 #endif
501 #endif
502 #endif
503 
505 
506  /* // function currently not needed but maybe useful
507  std::vector<GlobalOrdinal> NodeId2GlobalDofIds(GlobalOrdinal nodeId) const {
508  TEUCHOS_TEST_FOR_EXCEPTION(stridingInfo_.size() == 0, Exceptions::RuntimeError, "StridedMap::NodeId2GlobalDofIds: stridingInfo not valid: stridingInfo.size() = 0?");
509  std::vector<GlobalOrdinal> dofs;
510  if(stridedBlockId_ > -1) {
511  TEUCHOS_TEST_FOR_EXCEPTION(stridingInfo_[stridedBlockId_] == 0, Exceptions::RuntimeError, "StridedMap::NodeId2GlobalDofIds: stridingInfo not valid: stridingInfo[stridedBlockId] = 0?");
512 
513  // determine nStridedOffset
514  size_t nStridedOffset = 0;
515  for(int j=0; j<stridedBlockId_; j++) {
516  nStridedOffset += stridingInfo_[j];
517  }
518 
519  for(size_t i = 0; i<stridingInfo_[stridedBlockId_]; i++) {
520  GlobalOrdinal gid =
521  nodeId * Teuchos::as<GlobalOrdinal>(getFixedBlockSize()) +
522  offset_ +
523  Teuchos::as<GlobalOrdinal>(nStridedOffset) +
524  Teuchos::as<GlobalOrdinal>(i);
525  dofs.push_back(gid);
526  }
527  } else {
528  for(size_t i = 0; i<getFixedBlockSize(); i++) {
529  GlobalOrdinal gid =
530  nodeId * Teuchos::as<GlobalOrdinal>(getFixedBlockSize()) +
531  offset_ +
532  Teuchos::as<GlobalOrdinal>(i);
533  dofs.push_back(gid);
534  }
535  }
536  return dofs;
537  }*/
539 
540  private:
541  virtual bool CheckConsistency() {
542 #ifndef HAVE_XPETRA_DEBUG
543  return true;
544 #else
545  if (getStridedBlockId() == -1) {
546  // Strided map contains the full map
547  if (getNodeNumElements() % getFixedBlockSize() != 0 || // number of local elements is not a multiple of block size
548  getGlobalNumElements() % getFixedBlockSize() != 0) // number of global -//-
549  return false;
550 
551  } else {
552  // Strided map contains only the partial map
554  // std::sort(dofGids.begin(), dofGids.end());
555 
556  if (dofGids.size() == 0) // special treatment for empty processors
557  return true;
558 
559  if (dofGids.size() % stridingInfo_[stridedBlockId_] != 0)
560  return false;
561 
562 
563  // Calculate nStridedOffset
564  size_t nStridedOffset = 0;
565  for (int j = 0; j < stridedBlockId_; j++)
566  nStridedOffset += stridingInfo_[j];
567 
568  const GlobalOrdinal goStridedOffset = Teuchos::as<GlobalOrdinal>(nStridedOffset);
569  const GlobalOrdinal goZeroOffset = (dofGids[0] - nStridedOffset - offset_ - indexBase_) / Teuchos::as<GlobalOrdinal>(getFixedBlockSize());
570 
571  GlobalOrdinal cnt = 0;
572  for (size_t i = 0; i < Teuchos::as<size_t>(dofGids.size())/stridingInfo_[stridedBlockId_]; i += stridingInfo_[stridedBlockId_]) {
573  const GlobalOrdinal first_gid = dofGids[i];
574 
575  // We expect this to be the same for all DOFs of the same node
576  cnt = (first_gid - goStridedOffset - offset_ - indexBase_) / Teuchos::as<GlobalOrdinal>(getFixedBlockSize()) - goZeroOffset;
577 
578  // Loop over all DOFs that belong to current node
579  for (size_t j = 0; j < stridingInfo_[stridedBlockId_]; j++) {
580  const GlobalOrdinal gid = dofGids[i+j];
581  const GlobalOrdinal r = (gid - Teuchos::as<GlobalOrdinal>(j) - goStridedOffset - offset_ - indexBase_) /
582  Teuchos::as<GlobalOrdinal>(getFixedBlockSize()) - goZeroOffset - cnt;
583  // TAW 1/18/2016: We cannot use Teuchos::OrdinalTraits<GlobalOrdinal>::zero() ) here,
584  // If, e.g., GO=long long is disabled, OrdinalTraits<long long> is not available.
585  // But we instantiate stubs on GO=long long which might contain StridedMaps.
586  // These lead to compilation errors, then.
587  if (r != 0 ) {
588  std::cout << "goZeroOffset : " << goZeroOffset << std::endl
589  << "dofGids[0] : " << dofGids[0] << std::endl
590  << "stridedOffset : " << nStridedOffset << std::endl
591  << "offset_ : " << offset_ << std::endl
592  << "goStridedOffset: " << goStridedOffset << std::endl
593  << "getFixedBlkSize: " << getFixedBlockSize() << std::endl
594  << "gid: " << gid << " GID: " << r << std::endl;
595 
596  return false;
597  }
598  }
599  }
600  }
601 
602  return true;
603 #endif
604  }
605 
606  private:
608 
609  std::vector<size_t> stridingInfo_;
610  LocalOrdinal stridedBlockId_;
611  // stridedBlock == -1: the full map (with all strided block dofs)
612  // stridedBlock > -1: only dofs of strided block with index "stridedBlockId" are stored in this map
613  GlobalOrdinal offset_;
614  GlobalOrdinal indexBase_;
615 
616  public:
617 
619 
620 
622  global_size_t getGlobalNumElements() const { return map_->getGlobalNumElements(); }
623 
625  size_t getNodeNumElements() const { return map_->getNodeNumElements(); }
626 
628  GlobalOrdinal getIndexBase() const { return map_->getIndexBase(); }
629 
631  LocalOrdinal getMinLocalIndex() const { return map_->getMinLocalIndex(); }
632 
634  LocalOrdinal getMaxLocalIndex() const { return map_->getMaxLocalIndex(); }
635 
637  GlobalOrdinal getMinGlobalIndex() const { return map_->getMinGlobalIndex(); }
638 
640  GlobalOrdinal getMaxGlobalIndex() const { return map_->getMaxGlobalIndex(); }
641 
643  GlobalOrdinal getMinAllGlobalIndex() const { return map_->getMinAllGlobalIndex(); }
644 
646  GlobalOrdinal getMaxAllGlobalIndex() const { return map_->getMaxAllGlobalIndex(); }
647 
649  LocalOrdinal getLocalElement(GlobalOrdinal globalIndex) const { return map_->getLocalElement(globalIndex); }
650 
652  GlobalOrdinal getGlobalElement(LocalOrdinal localIndex) const { return map_->getGlobalElement(localIndex); }
653 
656  return map_->getRemoteIndexList(GIDList, nodeIDList, LIDList);
657  }
658 
661  return map_->getRemoteIndexList(GIDList, nodeIDList);
662  }
663 
665  Teuchos::ArrayView< const GlobalOrdinal > getNodeElementList() const { return map_->getNodeElementList(); }
666 
668  bool isNodeLocalElement(LocalOrdinal localIndex) const { return map_->isNodeLocalElement(localIndex); }
669 
671  bool isNodeGlobalElement(GlobalOrdinal globalIndex) const { return map_->isNodeGlobalElement(globalIndex); }
672 
674  bool isContiguous() const { return map_->isContiguous(); }
675 
677  bool isDistributed() const { return map_->isDistributed(); }
678 
680 
682  bool isCompatible(const Map& map) const { return map_->isCompatible(map); }
683 
685  bool isSameAs(const Map& map) const { return map_->isSameAs(map); }
686 
688  Teuchos::RCP< const Teuchos::Comm< int > > getComm() const { return map_->getComm(); }
689 
690 #ifdef TPETRA_ENABLE_DEPRECATED_CODE
691  Teuchos::RCP<Node> getNode() const { return map_->getNode(); }
693 #endif // TPETRA_ENABLE_DEPRECATED_CODE
694 
695  RCP<const Map> removeEmptyProcesses () const { return map_->removeEmptyProcesses(); }
696  RCP<const Map> replaceCommWithSubset (const Teuchos::RCP<const Teuchos::Comm<int> >& newComm) const { return map_->replaceCommWithSubset(newComm); }
697 
699  std::string description() const { return map_->description(); }
700 
702  void describe(Teuchos::FancyOStream& out, const Teuchos::EVerbosityLevel verbLevel = Teuchos::Describable::verbLevel_default) const { map_->describe(out, verbLevel); }
703 
705  UnderlyingLib lib() const { return map_->lib(); }
706 
707  }; // StridedMap class
708 
709 } // Xpetra namespace
710 
711 #define XPETRA_STRIDEDMAP_SHORT
712 #endif // XPETRA_STRIDEDMAP_HPP
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.
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.
Xpetra::MapFactory< LocalOrdinal, GlobalOrdinal, Node > MapFactory_t
size_t GID2StridingBlockId(GlobalOrdinal gid) const
RCP< const Map > removeEmptyProcesses() const
Return a new Map with processes with zero elements removed.
LocalOrdinal local_ordinal_type
StridedMap(const RCP< const Map > &map, std::vector< size_t > &stridingInfo, GlobalOrdinal, LocalOrdinal stridedBlockId=-1, GlobalOrdinal offset=0)
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)
Map constructor with a user-defined contiguous distribution.
GlobalOrdinal global_ordinal_type
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)
Map constructor with user-defined non-contiguous (arbitrary) distribution.
bool isContiguous() const
Returns true if this Map is distributed contiguously; returns false otherwise.
void setStridingData(std::vector< size_t > stridingInfo)
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Teuchos::ArrayView< const GlobalOrdinal > getNodeElementList() const
Return a list of the global indices owned by this node.
GlobalOrdinal indexBase_
index base for the strided map (default = 0)
size_type size() const
GlobalOrdinal getOffset() const
Exception throws to report errors in the internal logical of the program.
LocalOrdinal getMaxLocalIndex() const
Returns maximum local index.
LocalOrdinal stridedBlockId_
member variable denoting which dofs are stored in map
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...
RCP< const Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > getMap() const
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)
virtual ~StridedMap()
Destructor.
bool isDistributed() const
Returns true if this Map is distributed across more than one node; returns false otherwise.
size_t getFixedBlockSize() const
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)
std::vector< size_t > getStridingData() const
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.
size_t global_size_t
Global size_t object.
GlobalOrdinal getIndexBase() const
Returns the index base for this Map.
static const EVerbosityLevel verbLevel_default
global_size_t getGlobalNumElements() const
Returns the number of elements in this Map.
LocalOrdinal getLocalElement(GlobalOrdinal globalIndex) const
Return the local index for a given global index.
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.
virtual bool CheckConsistency()
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.
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.
RCP< const Map > replaceCommWithSubset(const Teuchos::RCP< const Teuchos::Comm< int > > &newComm) const
Replace this Map&#39;s communicator with a subset communicator.
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)
Map constructor with Xpetra-defined contiguous uniform distribution.
void setOffset(GlobalOrdinal offset)
RCP< const Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > map_