Xpetra  Version of the Day
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>
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>
103 Build(UnderlyingLib lib,
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>
128 Build(UnderlyingLib lib,
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>
151  const LocalOrdinal numDofPerNode, const GlobalOrdinal gidOffset)
152 {
153  XPETRA_MONITOR("MapFactory::Build");
154 
156  Teuchos::rcp_dynamic_cast<const BlockedMap<LocalOrdinal,GlobalOrdinal,Node>>(nodeMap);
157 
158  if(!bmap.is_null())
159  {
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 numLocalElements = nodeMap->getNodeNumElements();
168  Teuchos::ArrayView<const GlobalOrdinal> oldElements = nodeMap->getNodeElementList();
169  Teuchos::Array<GlobalOrdinal> newElements(nodeMap->getNodeNumElements() * numDofPerNode);
170  for (LocalOrdinal i = 0; i < numLocalElements; i++)
171  {
172  for (LocalOrdinal j = 0; j < numDofPerNode; j++)
173  {
174  newElements[i * numDofPerNode + j] = oldElements[i] * numDofPerNode + j + gidOffset;
175  }
176  }
177  if (nodeMap->lib() == UseTpetra)
178  {
180  (nodeMap->getGlobalNumElements() * numDofPerNode, newElements, nodeMap->getIndexBase(), nodeMap->getComm()));
181  }
182 #endif
183 
184  XPETRA_FACTORY_ERROR_IF_EPETRA(nodeMap->lib());
186 }
187 
188 
189 
190 #ifdef HAVE_XPETRA_KOKKOS_REFACTOR
191 #ifdef HAVE_XPETRA_TPETRA
192 template<class LocalOrdinal, class GlobalOrdinal, class Node>
195 Build(UnderlyingLib lib,
196  global_size_t numGlobalElements,
197  const Kokkos::View<const GlobalOrdinal*, typename Node::device_type>& indexList,
198  GlobalOrdinal indexBase,
199  const Teuchos::RCP<const Teuchos::Comm<int>>& comm)
200 {
201  XPETRA_MONITOR("MapFactory::Build");
202  if(lib == UseTpetra)
203  return rcp(new TpetraMap<LocalOrdinal, GlobalOrdinal, Node>(numGlobalElements, indexList, indexBase, comm));
206 }
207 #endif // HAVE_XPETRA_TPETRA
208 #endif // HAVE_XPETRA_KOKKOS_REFACTOR
209 
210 
211 
212 template<class LocalOrdinal, class GlobalOrdinal, class Node>
216  size_t numElements,
217  const Teuchos::RCP<const Teuchos::Comm<int>>& comm)
218 {
219  XPETRA_MONITOR("MapFactory::Build");
220 
221 #ifdef HAVE_XPETRA_TPETRA
222  if(lib == UseTpetra)
223  {
224  // Pre-ETI code called Tpetra::createLocalMap() but this can result in compile erros
225  // when Trilinos is built with multiple node-types, specifically the GCC 4.8.4 PR
226  // build generates an error because it would try to match Tpetra::Map objects where
227  // Node is Serial in one and OpenMP in the other. See Issue #5672 / PR #5723 for more
228  // information.
229  //return rcp(new Xpetra::TpetraMap<LocalOrdinal,GlobalOrdinal,Node>(Tpetra::createLocalMapWithNode<LocalOrdinal,GlobalOrdinal,Node>(numElements, comm))); // (old version)
230  return rcp(new TpetraMap<LocalOrdinal,GlobalOrdinal,Node>(Tpetra::createLocalMapWithNode<LocalOrdinal,GlobalOrdinal,Node>(numElements, comm)));
231  }
232 #endif // HAVE_XPETRA_TPETRA
233 
236 }
237 
238 
239 
240 
241 
242 template<class LocalOrdinal, class GlobalOrdinal, class Node>
246  size_t numElements,
247  const Teuchos::RCP<const Teuchos::Comm<int>>& comm)
248 {
249  XPETRA_MONITOR("MapFactory::Build");
250 
251 #ifdef HAVE_XPETRA_TPETRA
252  if(lib == UseTpetra)
253  {
254  return rcp(new TpetraMap<LocalOrdinal,GlobalOrdinal,Node>(Tpetra::createLocalMapWithNode<LocalOrdinal,GlobalOrdinal,Node>(numElements, comm)));
255  }
256 #endif // HAVE_XPETRA_TPETRA
257 
260 }
261 
262 
263 
264 
265 
266 
267 template<class LocalOrdinal, class GlobalOrdinal, class Node>
271  global_size_t numElements,
272  const Teuchos::RCP<const Teuchos::Comm<int>>& comm)
273 {
274  XPETRA_MONITOR("MapFactory::Build");
275 
276 #ifdef HAVE_XPETRA_TPETRA
277  if(lib == UseTpetra)
279  Tpetra::createUniformContigMapWithNode<LocalOrdinal, GlobalOrdinal, Node>(numElements, comm)));
280 #endif // HAVE_XPETRA_TPETRA
281 
284 }
285 
286 
287 
288 template<class LocalOrdinal, class GlobalOrdinal, class Node>
292  global_size_t numElements,
293  const Teuchos::RCP<const Teuchos::Comm<int>>& comm)
294 {
295  XPETRA_MONITOR("MapFactory::Build");
296 
297 #ifdef HAVE_XPETRA_TPETRA
298  if(lib == UseTpetra)
300  Tpetra::createUniformContigMapWithNode<LocalOrdinal, GlobalOrdinal, Node>(numElements, comm)));
301 #endif // HAVE_XPETRA_TPETRA
302 
305 }
306 
307 
308 template<class LocalOrdinal, class GlobalOrdinal, class Node>
312  global_size_t numElements,
313  size_t localNumElements,
314  const Teuchos::RCP<const Teuchos::Comm<int>>& comm)
315 {
316  XPETRA_MONITOR("MapFactory::Build");
317 
318 #ifdef HAVE_XPETRA_TPETRA
319  if(lib == UseTpetra)
321  Tpetra::createContigMapWithNode<LocalOrdinal, GlobalOrdinal, Node>(numElements, localNumElements, comm)));
322 #endif // HAVE_XPETRA_TPETRA
323 
326 }
327 
328 
329 
330 
331 
332 
333 template<class LocalOrdinal, class GlobalOrdinal, class Node>
337  global_size_t numElements,
338  size_t localNumElements,
339  const Teuchos::RCP<const Teuchos::Comm<int>>& comm)
340 {
341  XPETRA_MONITOR("MapFactory::Build");
342 
343 #ifdef HAVE_XPETRA_TPETRA
344  if(lib == UseTpetra)
345  {
347  Tpetra::createContigMapWithNode<LocalOrdinal, GlobalOrdinal, Node>(numElements, localNumElements, comm)));
348  }
349 #endif // HAVE_XPETRA_TPETRA
350 
353 }
354 
355 
356 } // namespace Xpetra
357 
358 
359 #endif // XPETRA_MAPFACTORY_DEF_HPP
360 
361 
362 //TODO: remove unused methods
363 
364 
#define XPETRA_MONITOR(funcName)
#define XPETRA_FACTORY_ERROR_IF_EPETRA(lib)
#define XPETRA_FACTORY_END
bool is_null() const
Exception throws to report errors in the internal logical of the program.
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 > > 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.
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.
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 > > createLocalMapWithNode(UnderlyingLib lib, size_t numElements, const Teuchos::RCP< const Teuchos::Comm< int >> &comm)
Create a locally replicated Map with a specified node.
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.
MapFactory()
Private constructor. This is a static class.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Xpetra namespace
size_t global_size_t
Global size_t object.