Xpetra  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Xpetra_MapFactory_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 #ifndef XPETRA_MAPFACTORY_DEF_HPP
47 #define XPETRA_MAPFACTORY_DEF_HPP
48 
50 
51 #ifdef HAVE_XPETRA_TPETRA
52 # include "Xpetra_TpetraMap.hpp"
53 #endif
54 #ifdef HAVE_XPETRA_EPETRA
55 # include "Xpetra_EpetraMap.hpp"
56 #endif
57 
58 #include "Xpetra_BlockedMap.hpp"
59 
60 namespace Xpetra {
61 
62 #if 0
63 template<class LocalOrdinal, class GlobalOrdinal, class Node>
65 MapFactory()
66 {
67 }
68 #endif
69 
70 
71 
72 
73 
74 
75 template<class LocalOrdinal, class GlobalOrdinal, class Node>
76 Teuchos::RCP<Map<LocalOrdinal, GlobalOrdinal, Node>>
79  global_size_t numGlobalElements,
80  GlobalOrdinal indexBase,
81  const Teuchos::RCP<const Teuchos::Comm<int>>& comm,
82  LocalGlobal lg)
83 {
84  XPETRA_MONITOR("MapFactory::Build");
85 
86 #ifdef HAVE_XPETRA_TPETRA
87  if(lib == UseTpetra)
88  return Teuchos::rcp(new TpetraMap<LocalOrdinal, GlobalOrdinal, Node>(numGlobalElements, indexBase, comm, lg));
89 #endif
90 
93 }
94 
95 
96 
97 
98 
99 
100 template<class LocalOrdinal, class GlobalOrdinal, class Node>
101 Teuchos::RCP<Map<LocalOrdinal, GlobalOrdinal, Node>>
104  global_size_t numGlobalElements,
105  size_t numLocalElements,
106  GlobalOrdinal indexBase,
107  const Teuchos::RCP<const Teuchos::Comm<int>>& comm)
108 {
109  XPETRA_MONITOR("MapFactory::Build");
110 
111 #ifdef HAVE_XPETRA_TPETRA
112  if(lib == UseTpetra)
113  return rcp(new TpetraMap<LocalOrdinal, GlobalOrdinal, Node>(numGlobalElements, numLocalElements, indexBase, comm));
114 #endif
115 
118 }
119 
120 
121 
122 
123 
124 
125 template<class LocalOrdinal, class GlobalOrdinal, class Node>
126 Teuchos::RCP<Map<LocalOrdinal, GlobalOrdinal, Node>>
129  global_size_t numGlobalElements,
130  const Teuchos::ArrayView<const GlobalOrdinal>& elementList,
131  GlobalOrdinal indexBase,
132  const Teuchos::RCP<const Teuchos::Comm<int>>& comm)
133 {
134  XPETRA_MONITOR("MapFactory::Build");
135 
136 #ifdef HAVE_XPETRA_TPETRA
137  if(lib == UseTpetra)
138  return rcp(new TpetraMap<LocalOrdinal, GlobalOrdinal, Node>(numGlobalElements, elementList, indexBase, comm));
139 #endif
140 
143 }
144 
145 
146 
147 template<class LocalOrdinal, class GlobalOrdinal, class Node>
148 Teuchos::RCP<Map<LocalOrdinal, GlobalOrdinal, Node>>
150 Build(const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node>>& map,
151  LocalOrdinal numDofPerNode)
152 {
153  XPETRA_MONITOR("MapFactory::Build");
154 
155  RCP<const BlockedMap<LocalOrdinal, GlobalOrdinal, Node>> bmap =
156  Teuchos::rcp_dynamic_cast<const BlockedMap<LocalOrdinal, GlobalOrdinal, Node>>(map);
157  if(!bmap.is_null())
158  {
159  TEUCHOS_TEST_FOR_EXCEPTION(numDofPerNode != 1,
161  "Xpetra::MapFactory::Build: When provided a BlockedMap numDofPerNode must set to be one. It is set to "
162  << numDofPerNode << ".");
164  }
165 
166 #ifdef HAVE_XPETRA_TPETRA
167  LocalOrdinal N = map->getNodeNumElements();
168  Teuchos::ArrayView<const GlobalOrdinal> oldElements = map->getNodeElementList();
169  Teuchos::Array<GlobalOrdinal> newElements(map->getNodeNumElements() * numDofPerNode);
170  for(LocalOrdinal i = 0; i < N; i++)
171  {
172  for(LocalOrdinal j = 0; j < numDofPerNode; j++)
173  {
174  newElements[ i * numDofPerNode + j ] = oldElements[ i ] * numDofPerNode + j;
175  }
176  }
177  if(map->lib() == UseTpetra)
178  {
179  return rcp(new TpetraMap<LocalOrdinal, GlobalOrdinal, Node>
180  (map->getGlobalNumElements() * numDofPerNode, newElements, map->getIndexBase(), map->getComm())
181  );
182  }
183 #endif
184 
185  XPETRA_FACTORY_ERROR_IF_EPETRA(map->lib());
187 }
188 
189 
190 
191 #ifdef HAVE_XPETRA_KOKKOS_REFACTOR
192 #ifdef HAVE_XPETRA_TPETRA
193 template<class LocalOrdinal, class GlobalOrdinal, class Node>
194 Teuchos::RCP<Map<LocalOrdinal, GlobalOrdinal, Node>>
196 Build(UnderlyingLib lib,
197  global_size_t numGlobalElements,
198  const Kokkos::View<const GlobalOrdinal*, typename Node::device_type>& indexList,
199  GlobalOrdinal indexBase,
200  const Teuchos::RCP<const Teuchos::Comm<int>>& comm)
201 {
202  XPETRA_MONITOR("MapFactory::Build");
203  if(lib == UseTpetra)
204  return rcp(new TpetraMap<LocalOrdinal, GlobalOrdinal, Node>(numGlobalElements, indexList, indexBase, comm));
207 }
208 #endif // HAVE_XPETRA_TPETRA
209 #endif // HAVE_XPETRA_KOKKOS_REFACTOR
210 
211 
212 
213 template<class LocalOrdinal, class GlobalOrdinal, class Node>
214 Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node>>
217  size_t numElements,
218  const Teuchos::RCP<const Teuchos::Comm<int>>& comm)
219 {
220  XPETRA_MONITOR("MapFactory::Build");
221 
222 #ifdef HAVE_XPETRA_TPETRA
223  if(lib == UseTpetra)
224  {
225  // Pre-ETI code called Tpetra::createLocalMap() but this can result in compile erros
226  // when Trilinos is built with multiple node-types, specifically the GCC 4.8.4 PR
227  // build generates an error because it would try to match Tpetra::Map objects where
228  // Node is Serial in one and OpenMP in the other. See Issue #5672 / PR #5723 for more
229  // information.
230  //return rcp(new Xpetra::TpetraMap<LocalOrdinal,GlobalOrdinal,Node>(Tpetra::createLocalMapWithNode<LocalOrdinal,GlobalOrdinal,Node>(numElements, comm))); // (old version)
231  return rcp(new TpetraMap<LocalOrdinal,GlobalOrdinal,Node>(Tpetra::createLocalMapWithNode<LocalOrdinal,GlobalOrdinal,Node>(numElements, comm)));
232  }
233 #endif // HAVE_XPETRA_TPETRA
234 
237 }
238 
239 
240 
241 
242 
243 template<class LocalOrdinal, class GlobalOrdinal, class Node>
244 Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node>>
247  size_t numElements,
248  const Teuchos::RCP<const Teuchos::Comm<int>>& comm)
249 {
250  XPETRA_MONITOR("MapFactory::Build");
251 
252 #ifdef HAVE_XPETRA_TPETRA
253  if(lib == UseTpetra)
254  {
255  return rcp(new TpetraMap<LocalOrdinal,GlobalOrdinal,Node>(Tpetra::createLocalMapWithNode<LocalOrdinal,GlobalOrdinal,Node>(numElements, comm)));
256  }
257 #endif // HAVE_XPETRA_TPETRA
258 
261 }
262 
263 
264 
265 
266 
267 
268 template<class LocalOrdinal, class GlobalOrdinal, class Node>
269 Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node>>
272  global_size_t numElements,
273  const Teuchos::RCP<const Teuchos::Comm<int>>& comm)
274 {
275  XPETRA_MONITOR("MapFactory::Build");
276 
277 #ifdef HAVE_XPETRA_TPETRA
278  if(lib == UseTpetra)
280  Tpetra::createUniformContigMapWithNode<LocalOrdinal, GlobalOrdinal, Node>(numElements, comm)));
281 #endif // HAVE_XPETRA_TPETRA
282 
285 }
286 
287 
288 
289 template<class LocalOrdinal, class GlobalOrdinal, class Node>
290 Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node>>
293  global_size_t numElements,
294  const Teuchos::RCP<const Teuchos::Comm<int>>& comm)
295 {
296  XPETRA_MONITOR("MapFactory::Build");
297 
298 #ifdef HAVE_XPETRA_TPETRA
299  if(lib == UseTpetra)
301  Tpetra::createUniformContigMapWithNode<LocalOrdinal, GlobalOrdinal, Node>(numElements, comm)));
302 #endif // HAVE_XPETRA_TPETRA
303 
306 }
307 
308 
309 template<class LocalOrdinal, class GlobalOrdinal, class Node>
310 Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node>>
313  global_size_t numElements,
314  size_t localNumElements,
315  const Teuchos::RCP<const Teuchos::Comm<int>>& comm)
316 {
317  XPETRA_MONITOR("MapFactory::Build");
318 
319 #ifdef HAVE_XPETRA_TPETRA
320  if(lib == UseTpetra)
322  Tpetra::createContigMapWithNode<LocalOrdinal, GlobalOrdinal, Node>(numElements, localNumElements, comm)));
323 #endif // HAVE_XPETRA_TPETRA
324 
327 }
328 
329 
330 
331 
332 
333 
334 template<class LocalOrdinal, class GlobalOrdinal, class Node>
335 Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node>>
338  global_size_t numElements,
339  size_t localNumElements,
340  const Teuchos::RCP<const Teuchos::Comm<int>>& comm)
341 {
342  XPETRA_MONITOR("MapFactory::Build");
343 
344 #ifdef HAVE_XPETRA_TPETRA
345  if(lib == UseTpetra)
346  {
348  Tpetra::createContigMapWithNode<LocalOrdinal, GlobalOrdinal, Node>(numElements, localNumElements, comm)));
349  }
350 #endif // HAVE_XPETRA_TPETRA
351 
354 }
355 
356 
357 } // namespace Xpetra
358 
359 
360 #endif // XPETRA_MAPFACTORY_DEF_HPP
361 
362 
363 //TODO: remove unused methods
364 
365 
static Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > createLocalMap(UnderlyingLib lib, size_t numElements, const Teuchos::RCP< const Teuchos::Comm< int >> &comm)
Create a locally replicated Map with the default node.
static Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > createContigMap(UnderlyingLib lib, global_size_t numElements, size_t localNumElements, const Teuchos::RCP< const Teuchos::Comm< int >> &comm)
Create a (potentially) non-uniform, contiguous Map with the default node.
Exception throws to report errors in the internal logical of the program.
#define XPETRA_FACTORY_ERROR_IF_EPETRA(lib)
MapFactory()
Private constructor. This is a static class.
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.
static Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > createContigMapWithNode(UnderlyingLib lib, global_size_t numElements, size_t localNumElements, const Teuchos::RCP< const Teuchos::Comm< int >> &comm)
Create a (potentially) non-uniform, contiguous Map with a user-specified node.
#define XPETRA_FACTORY_END
size_t global_size_t
Global size_t object.
static Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > createUniformContigMapWithNode(UnderlyingLib lib, global_size_t numElements, const Teuchos::RCP< const Teuchos::Comm< int >> &comm)
Create a uniform, contiguous Map with a user-specified node.
static Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > createLocalMapWithNode(UnderlyingLib lib, size_t numElements, const Teuchos::RCP< const Teuchos::Comm< int >> &comm)
Create a locally replicated Map with a specified node.
#define XPETRA_MONITOR(funcName)
static Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > createUniformContigMap(UnderlyingLib lib, global_size_t numElements, const Teuchos::RCP< const Teuchos::Comm< int >> &comm)
Create a uniform, contiguous Map with the default node.