All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Xpetra_StridedMapFactory_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_STRIDEDMAPFACTORY_DEF_HPP
50 #define XPETRA_STRIDEDMAPFACTORY_DEF_HPP
51 
53 
54 #include "Xpetra_Exceptions.hpp"
55 
56 // This factory creates Xpetra::Map. User have to specify the exact class of
57 // object that he want to create (ie: a Xpetra::TpetraMap or a Xpetra::EpetraMap).
58 
59 
60 
61 namespace Xpetra {
62 
63 
64 
65 template<class LocalOrdinal, class GlobalOrdinal, class Node>
68 {
69 }
70 
71 
72 #ifdef TPETRA_ENABLE_DEPRECATED_CODE
73 template<class LocalOrdinal, class GlobalOrdinal, class Node>
74 TPETRA_DEPRECATED
78  global_size_t numGlobalElements,
79  GlobalOrdinal indexBase,
80  std::vector<size_t>& stridingInfo,
81  const Teuchos::RCP<const Teuchos::Comm<int>>& comm,
82  LocalOrdinal stridedBlockId,
83  GlobalOrdinal offset,
84  LocalGlobal lg,
85  const Teuchos::RCP<Node>& /* node */)
86 {
87  return Build(lib, numGlobalElements, indexBase, stridingInfo, comm, stridedBlockId, offset, lg);
88 }
89 #endif // TPETRA_ENABLE_DEPRECATED_CODE
90 
91 
92 template<class LocalOrdinal, class GlobalOrdinal, class Node>
93 RCP<Xpetra::StridedMap<LocalOrdinal, GlobalOrdinal, Node>>
96  global_size_t numGlobalElements,
97  GlobalOrdinal indexBase,
98  std::vector<size_t>& stridingInfo,
99  const Teuchos::RCP<const Teuchos::Comm<int>>& comm,
100  LocalOrdinal stridedBlockId,
101  GlobalOrdinal offset,
102  LocalGlobal lg)
103 {
104  return rcp(new Xpetra::StridedMap<LocalOrdinal, GlobalOrdinal, Node>(lib, numGlobalElements, indexBase, stridingInfo, comm, stridedBlockId, offset, lg));
105 }
106 
107 
108 #ifdef TPETRA_ENABLE_DEPRECATED_CODE
109 template<class LocalOrdinal, class GlobalOrdinal, class Node>
110 TPETRA_DEPRECATED
113 Build(UnderlyingLib lib,
114  global_size_t numGlobalElements,
115  size_t numLocalElements,
116  GlobalOrdinal indexBase,
117  std::vector<size_t>& stridingInfo,
118  const Teuchos::RCP<const Teuchos::Comm<int>>& comm,
119  LocalOrdinal stridedBlockId,
120  GlobalOrdinal offset,
121  const Teuchos::RCP<Node>& /* node */)
122 {
123  return Build(lib, numGlobalElements, numLocalElements, indexBase, stridingInfo, comm, stridedBlockId, offset);
124 }
125 #endif // TPETRA_ENABLE_DEPRECATED_CODE
126 
127 
128 template<class LocalOrdinal, class GlobalOrdinal, class Node>
129 RCP<Xpetra::StridedMap<LocalOrdinal,GlobalOrdinal,Node>>
132  global_size_t numGlobalElements,
133  size_t numLocalElements,
134  GlobalOrdinal indexBase,
135  std::vector<size_t>& stridingInfo,
136  const Teuchos::RCP<const Teuchos::Comm<int>>& comm,
137  LocalOrdinal stridedBlockId,
138  GlobalOrdinal offset)
139 {
140  return rcp(new StridedMap(lib, numGlobalElements, numLocalElements, indexBase, stridingInfo, comm, stridedBlockId, offset));
141 }
142 
143 
144 template<class LocalOrdinal, class GlobalOrdinal, class Node>
148  std::vector<size_t>& stridingInfo,
149  LocalOrdinal stridedBlockId,
150  GlobalOrdinal offset)
151 {
152  return rcp(new StridedMap(map, stridingInfo, map->getIndexBase(), stridedBlockId, offset));
153 }
154 
155 
156 template<class LocalOrdinal, class GlobalOrdinal, class Node>
159 Build(const RCP<const StridedMap>& map, LocalOrdinal stridedBlockId)
160 {
161  TEUCHOS_TEST_FOR_EXCEPTION(stridedBlockId < 0,
163  "Xpetra::StridedMapFactory::Build: constructor expects stridedBlockId > -1.");
164 
167  "Xpetra::StridedMapFactory::Build: constructor expects a full map (stridedBlockId == -1).");
168 
169  std::vector<size_t> stridingInfo = map->getStridingData();
170 
172  // std::sort(dofGids.begin(),dofGids.end()); // TODO: do we need this?
173 
174  // determine nStridedOffset
175  size_t nStridedOffset = 0;
176  for(int j = 0; j < map->getStridedBlockId(); j++)
177  {
178  nStridedOffset += stridingInfo[ j ];
179  }
180 
181  size_t numMyBlockDofs = (stridingInfo[ stridedBlockId ] * map->getNodeNumElements()) / map->getFixedBlockSize();
182 
183  std::vector<GlobalOrdinal> subBlockDofGids(numMyBlockDofs);
184 
185  // TODO fill vector with dofs
186  LocalOrdinal ind = 0;
187  for(typename Teuchos::ArrayView<const GlobalOrdinal>::iterator it = dofGids.begin(); it != dofGids.end(); ++it)
188  {
189  if(map->GID2StridingBlockId(*it) == Teuchos::as<size_t>(stridedBlockId))
190  {
191  subBlockDofGids[ ind++ ] = *it;
192  }
193  }
194 
195  const Teuchos::ArrayView<const GlobalOrdinal> subBlockDofGids_view(&subBlockDofGids[ 0 ], subBlockDofGids.size());
196 
197  return rcp(new StridedMap(map->lib(),
199  subBlockDofGids_view,
200  map->getIndexBase(),
201  stridingInfo,
202  map->getComm(),
203  stridedBlockId));
204 }
205 
206 
207 template<class LocalOrdinal, class GlobalOrdinal, class Node>
210 Build(const StridedMap& map)
211 {
212  XPETRA_MONITOR("MapFactory::Build");
213 
214  LocalOrdinal N = map.getNodeNumElements();
217 
218  for(LocalOrdinal i = 0; i < N; i++)
219  {
220  newElements[ i ] = oldElements[ i ];
221  }
222 
223  std::vector<size_t> strData = map.getStridingData();
224  return rcp(new StridedMap(map.lib(), map.getGlobalNumElements(), newElements, map.getIndexBase(), strData, map.getComm(), map.getStridedBlockId()));
225 
226  // XPETRA_FACTORY_END;
227 }
228 
229 
230 #ifdef TPETRA_ENABLE_DEPRECATED_CODE
231 template<class LocalOrdinal, class GlobalOrdinal, class Node>
232 TPETRA_DEPRECATED
235 Build(UnderlyingLib lib,
236  global_size_t numGlobalElements,
237  const Teuchos::ArrayView<const GlobalOrdinal>& elementList,
238  GlobalOrdinal indexBase,
239  std::vector<size_t>& stridingInfo,
240  const Teuchos::RCP<const Teuchos::Comm<int>>& comm,
241  LocalOrdinal stridedBlockId, // FIXME (mfh 03 Sep 2014) This breaks if LocalOrdinal is unsigned
242  GlobalOrdinal offset,
243  const Teuchos::RCP<Node>& /* node */)
244 {
245  return Build(lib, numGlobalElements, elementList, indexBase, stridingInfo, comm, stridedBlockId, offset);
246 }
247 #endif // TPETRA_ENABLE_DEPRECATED_CODE
248 
249 
250 template<class LocalOrdinal, class GlobalOrdinal, class Node>
251 RCP<Xpetra::StridedMap<LocalOrdinal,GlobalOrdinal,Node>>
254  global_size_t numGlobalElements,
255  const Teuchos::ArrayView<const GlobalOrdinal>& elementList,
256  GlobalOrdinal indexBase,
257  std::vector<size_t>& stridingInfo,
258  const Teuchos::RCP<const Teuchos::Comm<int>>& comm,
259  LocalOrdinal stridedBlockId, // FIXME (mfh 03 Sep 2014) This breaks if LocalOrdinal is unsigned
260  GlobalOrdinal /* offset */)
261 {
262  return rcp(new StridedMap(lib, numGlobalElements, elementList, indexBase, stridingInfo, comm, stridedBlockId));
263 }
264 
265 
266 
267 } // namespace Xpetra
268 
269 
270 
271 #endif // __XPETRA_STRIDEDMAPFACTORY_DEF_HPP__
272 
273 // TODO: removed unused methods
LocalOrdinal getStridedBlockId() const
size_t GID2StridingBlockId(GlobalOrdinal gid) const
iterator begin() const
#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.
Exception throws to report errors in the internal logical of the program.
virtual GlobalOrdinal getIndexBase() const =0
The index base for this Map.
Teuchos::RCP< const Teuchos::Comm< int > > getComm() const
Get the Comm object for this Map.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
size_t getFixedBlockSize() const
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.
global_size_t getGlobalNumElements() const
Returns the number of elements in this Map.
std::vector< size_t > getStridingData() const
UnderlyingLib lib() const
Get the library used by this object (Tpetra or Epetra?)
iterator end() const
StridedMapFactory()
Private constructor. This is a static class.
#define XPETRA_MONITOR(funcName)
static RCP< Xpetra::StridedMap< LocalOrdinal, GlobalOrdinal, Node > > 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)
Map constructor with Xpetra-defined contiguous uniform distribution.
Class that stores a strided map.