Xpetra_StridedMapFactory.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_STRIDEDMAPFACTORY_HPP
50 #define XPETRA_STRIDEDMAPFACTORY_HPP
51 
52 #include <Kokkos_DefaultNode.hpp>
53 
54 #include "Xpetra_ConfigDefs.hpp"
55 #include "Xpetra_Exceptions.hpp"
56 
57 #include "Xpetra_StridedMap.hpp"
58 
59 // This factory creates Xpetra::Map. User have to specify the exact class of object that he want to create (ie: a Xpetra::TpetraMap or a Xpetra::EpetraMap).
60 
61 namespace Xpetra {
62 
63  template <class LocalOrdinal = StridedMap<>::local_ordinal_type,
64  class GlobalOrdinal =
66  class Node =
68  class StridedMapFactory {
69 #undef XPETRA_STRIDEDMAPFACTORY_SHORT
71 
72  private:
75 
76  public:
77 
79  static RCP<StridedMap> Build(UnderlyingLib lib, global_size_t numGlobalElements, GlobalOrdinal indexBase,
80  std::vector<size_t>& stridingInfo, const Teuchos::RCP<const Teuchos::Comm<int> > &comm,
81  LocalOrdinal stridedBlockId = -1, GlobalOrdinal offset = 0, LocalGlobal lg = Xpetra::GloballyDistributed,
82  const Teuchos::RCP<Node> &node = Teuchos::rcp(new Node)) {
83 
84  return rcp(new StridedMap(lib, numGlobalElements, indexBase, stridingInfo, comm, stridedBlockId, offset, lg, node));
85  }
86 
88  static RCP<StridedMap> Build(UnderlyingLib lib, global_size_t numGlobalElements, size_t numLocalElements, GlobalOrdinal indexBase,
89  std::vector<size_t>& stridingInfo, const Teuchos::RCP<const Teuchos::Comm<int> > &comm,
90  LocalOrdinal stridedBlockId = -1, GlobalOrdinal offset = 0,
91  const Teuchos::RCP<Node> &node = Teuchos::rcp(new Node)) {
92 
93  return rcp(new StridedMap(lib, numGlobalElements, numLocalElements, indexBase, stridingInfo, comm, stridedBlockId, offset, node));
94  }
95 
96  static RCP<StridedMap> Build(const RCP<const Map>& map, std::vector<size_t>& stridingInfo, LocalOrdinal stridedBlockId = -1, GlobalOrdinal offset = 0) {
97  return rcp(new StridedMap(map, stridingInfo, map->getIndexBase(), stridedBlockId, offset));
98  }
99 
100  // special constructor for generating a given subblock of a strided map
101  static RCP<StridedMap> Build(const RCP<const StridedMap>& map, LocalOrdinal stridedBlockId) {
103  "Xpetra::StridedMapFactory::Build: constructor expects stridedBlockId > -1.");
104  TEUCHOS_TEST_FOR_EXCEPTION(map->getStridedBlockId() != -1, Exceptions::RuntimeError,
105  "Xpetra::StridedMapFactory::Build: constructor expects a full map (stridedBlockId == -1).");
106 
107  std::vector<size_t> stridingInfo = map->getStridingData();
108 
109  Teuchos::ArrayView<const GlobalOrdinal> dofGids = map->getNodeElementList();
110  // std::sort(dofGids.begin(),dofGids.end()); // TODO: do we need this?
111 
112  // determine nStridedOffset
113  size_t nStridedOffset = 0;
114  for (int j = 0; j < map->getStridedBlockId(); j++)
115  nStridedOffset += stridingInfo[j];
116 
117  size_t numMyBlockDofs = (stridingInfo[stridedBlockId] * map->getNodeNumElements()) / map->getFixedBlockSize();
118  std::vector<GlobalOrdinal> subBlockDofGids(numMyBlockDofs);
119 
120  // TODO fill vector with dofs
121  LocalOrdinal ind = 0;
122  for (typename Teuchos::ArrayView< const GlobalOrdinal >::iterator it = dofGids.begin(); it!=dofGids.end(); ++it)
123  if (map->GID2StridingBlockId(*it) == Teuchos::as<size_t>(stridedBlockId))
124  subBlockDofGids[ind++] = *it;
125 
126  const Teuchos::ArrayView<const GlobalOrdinal> subBlockDofGids_view(&subBlockDofGids[0],subBlockDofGids.size());
127 
128  return rcp(new StridedMap(map->lib(), Teuchos::OrdinalTraits<global_size_t>::invalid(), subBlockDofGids_view, map->getIndexBase(), stridingInfo, map->getComm(), stridedBlockId, map->getNode()));
129  }
130 
132  static RCP<StridedMap> Build(const StridedMap& map) {
133  XPETRA_MONITOR("MapFactory::Build");
134 
135  LocalOrdinal N = map.getNodeNumElements();
138  for (LocalOrdinal i = 0; i < N; i++)
139  newElements[i] = oldElements[i];
140 
141  std::vector<size_t> strData = map.getStridingData();
142  return rcp(new StridedMap(map.lib(), map.getGlobalNumElements(), newElements, map.getIndexBase(), strData, map.getComm(), map.getStridedBlockId(), map.getNode()));
143 
144  //XPETRA_FACTORY_END;
145  }
146 
148  static RCP<StridedMap>
150  global_size_t numGlobalElements,
151  const Teuchos::ArrayView<const GlobalOrdinal> &elementList,
152  GlobalOrdinal indexBase,
153  std::vector<size_t>& stridingInfo,
154  const Teuchos::RCP<const Teuchos::Comm<int> > &comm,
155  LocalOrdinal stridedBlockId = -1, // FIXME (mfh 03 Sep 2014) This breaks if LocalOrdinal is unsigned
156  GlobalOrdinal offset = 0,
157  const Teuchos::RCP<Node> &node = Teuchos::rcp(new Node))
158  {
159  return rcp (new StridedMap (lib, numGlobalElements, elementList,
160  indexBase, stridingInfo, comm,
161  stridedBlockId, node));
162  }
163  };
164 }
165 
166 #define XPETRA_STRIDEDMAPFACTORY_SHORT
167 #endif
168 //TODO: removed unused methods
Xpetra::StridedMap::getGlobalNumElements
global_size_t getGlobalNumElements() const
Returns the number of elements in this Map.
Definition: Xpetra_StridedMap.hpp:592
Xpetra::LocalGlobal
LocalGlobal
Definition: Xpetra_ConfigDefs.hpp:173
Xpetra
Xpetra namespace
Definition: Xpetra_BlockedCrsMatrix.hpp:86
Xpetra::StridedMap::getComm
Teuchos::RCP< const Teuchos::Comm< int > > getComm() const
Get the Comm object for this Map.
Definition: Xpetra_StridedMap.hpp:658
Teuchos::ArrayView::iterator
pointer iterator
Xpetra::global_size_t
size_t global_size_t
Global size_t object.
Definition: Xpetra_ConfigDefs.hpp:170
Xpetra::StridedMapFactory::Build
static RCP< StridedMap > Build(UnderlyingLib lib, 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, GlobalOrdinal offset=0, const Teuchos::RCP< Node > &node=Teuchos::rcp(new Node))
Map constructor with a user-defined contiguous distribution. (for experts only. There is no special c...
Definition: Xpetra_StridedMapFactory.hpp:149
Xpetra::StridedMap::getNode
Teuchos::RCP< Node > getNode() const
Get the Node object for this Map.
Definition: Xpetra_StridedMap.hpp:661
Xpetra::StridedMap::getIndexBase
GlobalOrdinal getIndexBase() const
Returns the index base for this Map.
Definition: Xpetra_StridedMap.hpp:598
Xpetra::StridedMapFactory::Build
static RCP< StridedMap > Build(const RCP< const Map > &map, std::vector< size_t > &stridingInfo, LocalOrdinal stridedBlockId=-1, GlobalOrdinal offset=0)
Definition: Xpetra_StridedMapFactory.hpp:96
Teuchos::rcp
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Xpetra::StridedMap::global_ordinal_type
GlobalOrdinal global_ordinal_type
Definition: Xpetra_StridedMap.hpp:101
Xpetra::GloballyDistributed
Definition: Xpetra_ConfigDefs.hpp:175
Xpetra::StridedMap::getStridingData
std::vector< size_t > getStridingData() const
Definition: Xpetra_StridedMap.hpp:412
Teuchos::ArrayView
Xpetra::StridedMapFactory::Build
static RCP< StridedMap > Build(const RCP< const StridedMap > &map, LocalOrdinal stridedBlockId)
Definition: Xpetra_StridedMapFactory.hpp:101
Teuchos::RCP
Xpetra_StridedMap.hpp
Xpetra::StridedMap
Class that stores a strided map.
Definition: Xpetra_StridedMap_fwd.hpp:51
Teuchos::Array
Teuchos::ArrayView::begin
iterator begin() const
Xpetra::Exceptions::RuntimeError
Exception throws to report errors in the internal logical of the program.
Definition: Xpetra_Exceptions.hpp:101
Kokkos_DefaultNode.hpp
Xpetra::StridedMap::getNodeElementList
Teuchos::ArrayView< const GlobalOrdinal > getNodeElementList() const
Return a list of the global indices owned by this node.
Definition: Xpetra_StridedMap.hpp:635
Xpetra::StridedMap::node_type
Node node_type
Definition: Xpetra_StridedMap.hpp:102
Xpetra::StridedMapFactory::Build
static RCP< StridedMap > Build(UnderlyingLib lib, 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=Xpetra::GloballyDistributed, const Teuchos::RCP< Node > &node=Teuchos::rcp(new Node))
Map constructor with Xpetra-defined contiguous uniform distribution.
Definition: Xpetra_StridedMapFactory.hpp:79
Xpetra::StridedMapFactory::Build
static RCP< StridedMap > Build(UnderlyingLib lib, 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.
Definition: Xpetra_StridedMapFactory.hpp:88
Xpetra_ConfigDefs.hpp
Xpetra_UseShortNamesOrdinal.hpp
Teuchos::ArrayView::end
iterator end() const
Xpetra::StridedMap::getNodeNumElements
size_t getNodeNumElements() const
Returns the number of elements belonging to the calling node.
Definition: Xpetra_StridedMap.hpp:595
Xpetra::StridedMap::lib
UnderlyingLib lib() const
Get the library used by this object (Tpetra or Epetra?)
Definition: Xpetra_StridedMap.hpp:673
Xpetra_Exceptions.hpp
Xpetra::StridedMap::getStridedBlockId
LocalOrdinal getStridedBlockId() const
Definition: Xpetra_StridedMap.hpp:425
Xpetra::UnderlyingLib
UnderlyingLib
Definition: Xpetra_Map.hpp:81
Xpetra::StridedMapFactory::Build
static RCP< StridedMap > Build(const StridedMap &map)
Create copy of existing map (this just creates a copy of your map, it's not a clone in the sense of T...
Definition: Xpetra_StridedMapFactory.hpp:132
Xpetra::StridedMapFactory::StridedMapFactory
StridedMapFactory()
Private constructor. This is a static class.
Definition: Xpetra_StridedMapFactory.hpp:74
Teuchos::OrdinalTraits::invalid
static T invalid()
Teuchos::Comm
TEUCHOS_TEST_FOR_EXCEPTION
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
XPETRA_MONITOR
#define XPETRA_MONITOR(funcName)
Definition: Xpetra_ConfigDefs.hpp:128