All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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 #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  const Teuchos::RCP<const Teuchos::Comm<int>>& comm,
81  LocalGlobal lg,
82  const Teuchos::RCP<Node>& /* node */)
83 {
84  return Build(lib, numGlobalElements, indexBase, comm, lg);
85 }
86 #endif // TPETRA_ENABLE_DEPRECATED_CODE
87 
88 
89 
90 template<class LocalOrdinal, class GlobalOrdinal, class Node>
94  global_size_t numGlobalElements,
95  GlobalOrdinal indexBase,
96  const Teuchos::RCP<const Teuchos::Comm<int>>& comm,
97  LocalGlobal lg)
98 {
99  XPETRA_MONITOR("MapFactory::Build");
100 
101 #ifdef HAVE_XPETRA_TPETRA
102  if(lib == UseTpetra)
103  return Teuchos::rcp(new TpetraMap<LocalOrdinal, GlobalOrdinal, Node>(numGlobalElements, indexBase, comm, lg));
104 #endif
105 
108 }
109 
110 
111 
112 #ifdef TPETRA_ENABLE_DEPRECATED_CODE
113 template<class LocalOrdinal, class GlobalOrdinal, class Node>
114 TPETRA_DEPRECATED
117 Build(UnderlyingLib lib,
118  global_size_t numGlobalElements,
119  size_t numLocalElements,
120  GlobalOrdinal indexBase,
121  const Teuchos::RCP<const Teuchos::Comm<int>>& comm,
122  const Teuchos::RCP<Node>& /* node */)
123 {
124  return Build(lib, numGlobalElements, numLocalElements, indexBase, comm);
125 }
126 #endif // TPETRA_ENABLE_DEPRECATED_CODE
127 
128 
129 
130 template<class LocalOrdinal, class GlobalOrdinal, class Node>
134  global_size_t numGlobalElements,
135  size_t numLocalElements,
136  GlobalOrdinal indexBase,
137  const Teuchos::RCP<const Teuchos::Comm<int>>& comm)
138 {
139  XPETRA_MONITOR("MapFactory::Build");
140 
141 #ifdef HAVE_XPETRA_TPETRA
142  if(lib == UseTpetra)
143  return rcp(new TpetraMap<LocalOrdinal, GlobalOrdinal, Node>(numGlobalElements, numLocalElements, indexBase, comm));
144 #endif
145 
148 }
149 
150 
151 
152 #ifdef TPETRA_ENABLE_DEPRECATED_CODE
153 template<class LocalOrdinal, class GlobalOrdinal, class Node>
154 TPETRA_DEPRECATED
157 Build(UnderlyingLib lib,
158  global_size_t numGlobalElements,
159  const Teuchos::ArrayView<const GlobalOrdinal>& elementList,
160  GlobalOrdinal indexBase,
161  const Teuchos::RCP<const Teuchos::Comm<int>>& comm,
162  const Teuchos::RCP<Node>& /* node */)
163 {
164  return Build(lib, numGlobalElements, elementList, indexBase, comm);
165 }
166 #endif // TPETRA_ENABLE_DEPRECATED_CODE
167 
168 
169 
170 template<class LocalOrdinal, class GlobalOrdinal, class Node>
174  global_size_t numGlobalElements,
175  const Teuchos::ArrayView<const GlobalOrdinal>& elementList,
176  GlobalOrdinal indexBase,
177  const Teuchos::RCP<const Teuchos::Comm<int>>& comm)
178 {
179  XPETRA_MONITOR("MapFactory::Build");
180 
181 #ifdef HAVE_XPETRA_TPETRA
182  if(lib == UseTpetra)
183  return rcp(new TpetraMap<LocalOrdinal, GlobalOrdinal, Node>(numGlobalElements, elementList, indexBase, comm));
184 #endif
185 
188 }
189 
190 
191 
192 template<class LocalOrdinal, class GlobalOrdinal, class Node>
196  LocalOrdinal numDofPerNode)
197 {
198  XPETRA_MONITOR("MapFactory::Build");
199 
201  Teuchos::rcp_dynamic_cast<const BlockedMap<LocalOrdinal, GlobalOrdinal, Node>>(map);
202  if(!bmap.is_null())
203  {
204  TEUCHOS_TEST_FOR_EXCEPTION(numDofPerNode != 1,
206  "Xpetra::MapFactory::Build: When provided a BlockedMap numDofPerNode must set to be one. It is set to "
207  << numDofPerNode << ".");
209  }
210 
211 #ifdef HAVE_XPETRA_TPETRA
212  LocalOrdinal N = map->getNodeNumElements();
213  Teuchos::ArrayView<const GlobalOrdinal> oldElements = map->getNodeElementList();
214  Teuchos::Array<GlobalOrdinal> newElements(map->getNodeNumElements() * numDofPerNode);
215  for(LocalOrdinal i = 0; i < N; i++)
216  {
217  for(LocalOrdinal j = 0; j < numDofPerNode; j++)
218  {
219  newElements[ i * numDofPerNode + j ] = oldElements[ i ] * numDofPerNode + j;
220  }
221  }
222  if(map->lib() == UseTpetra)
223  {
225  (map->getGlobalNumElements() * numDofPerNode, newElements, map->getIndexBase(), map->getComm())
226  );
227  }
228 #endif
229 
230  XPETRA_FACTORY_ERROR_IF_EPETRA(map->lib());
232 }
233 
234 
235 
236 #ifdef HAVE_XPETRA_KOKKOS_REFACTOR
237 #ifdef HAVE_XPETRA_TPETRA
238 template<class LocalOrdinal, class GlobalOrdinal, class Node>
241 Build(UnderlyingLib lib,
242  global_size_t numGlobalElements,
243  const Kokkos::View<const GlobalOrdinal*, typename Node::device_type>& indexList,
244  GlobalOrdinal indexBase,
245  const Teuchos::RCP<const Teuchos::Comm<int>>& comm)
246 {
247  XPETRA_MONITOR("MapFactory::Build");
248  if(lib == UseTpetra)
249  return rcp(new TpetraMap<LocalOrdinal, GlobalOrdinal, Node>(numGlobalElements, indexList, indexBase, comm));
252 }
253 #endif // HAVE_XPETRA_TPETRA
254 #endif // HAVE_XPETRA_KOKKOS_REFACTOR
255 
256 
257 
258 template<class LocalOrdinal, class GlobalOrdinal, class Node>
262  size_t numElements,
263  const Teuchos::RCP<const Teuchos::Comm<int>>& comm)
264 {
265  XPETRA_MONITOR("MapFactory::Build");
266 
267 #ifdef HAVE_XPETRA_TPETRA
268  if(lib == UseTpetra)
269  {
270  // Pre-ETI code called Tpetra::createLocalMap() but this can result in compile erros
271  // when Trilinos is built with multiple node-types, specifically the GCC 4.8.4 PR
272  // build generates an error because it would try to match Tpetra::Map objects where
273  // Node is Serial in one and OpenMP in the other. See Issue #5672 / PR #5723 for more
274  // information.
275  //return rcp(new Xpetra::TpetraMap<LocalOrdinal,GlobalOrdinal,Node>(Tpetra::createLocalMapWithNode<LocalOrdinal,GlobalOrdinal,Node>(numElements, comm))); // (old version)
276  return rcp(new TpetraMap<LocalOrdinal,GlobalOrdinal,Node>(Tpetra::createLocalMapWithNode<LocalOrdinal,GlobalOrdinal,Node>(numElements, comm)));
277  }
278 #endif // HAVE_XPETRA_TPETRA
279 
282 }
283 
284 
285 
286 #ifdef TPETRA_ENABLE_DEPRECATED_CODE
287 template<class LocalOrdinal, class GlobalOrdinal, class Node>
288 TPETRA_DEPRECATED
292  size_t numElements,
293  const Teuchos::RCP<const Teuchos::Comm<int>>& comm,
294  const Teuchos::RCP<Node>& /* node */)
295 {
296  return createLocalMapWithNode(lib, numElements, comm);
297 }
298 #endif // TPETRA_ENABLE_DEPRECATED_CODE
299 
300 
301 template<class LocalOrdinal, class GlobalOrdinal, class Node>
305  size_t numElements,
306  const Teuchos::RCP<const Teuchos::Comm<int>>& comm)
307 {
308  XPETRA_MONITOR("MapFactory::Build");
309 
310 #ifdef HAVE_XPETRA_TPETRA
311  if(lib == UseTpetra)
312  {
313  return rcp(new TpetraMap<LocalOrdinal,GlobalOrdinal,Node>(Tpetra::createLocalMapWithNode<LocalOrdinal,GlobalOrdinal,Node>(numElements, comm)));
314  }
315 #endif // HAVE_XPETRA_TPETRA
316 
319 }
320 
321 
322 
323 #ifdef TPETRA_ENABLE_DEPRECATED_CODE
324 template<class LocalOrdinal, class GlobalOrdinal, class Node>
325 TPETRA_DEPRECATED
329  global_size_t numElements,
330  const Teuchos::RCP<const Teuchos::Comm<int>>& comm,
331  const Teuchos::RCP<Node>& /* node */)
332 {
333  return createUniformContigMapWithNode(lib, numElements, comm);
334 }
335 #endif // TPETRA_ENABLE_DEPRECATED_CODE
336 
337 
338 
339 template<class LocalOrdinal, class GlobalOrdinal, class Node>
343  global_size_t numElements,
344  const Teuchos::RCP<const Teuchos::Comm<int>>& comm)
345 {
346  XPETRA_MONITOR("MapFactory::Build");
347 
348 #ifdef HAVE_XPETRA_TPETRA
349  if(lib == UseTpetra)
351  Tpetra::createUniformContigMapWithNode<LocalOrdinal, GlobalOrdinal, Node>(numElements, comm)));
352 #endif // HAVE_XPETRA_TPETRA
353 
356 }
357 
358 
359 
360 template<class LocalOrdinal, class GlobalOrdinal, class Node>
364  global_size_t numElements,
365  const Teuchos::RCP<const Teuchos::Comm<int>>& comm)
366 {
367  XPETRA_MONITOR("MapFactory::Build");
368 
369 #ifdef HAVE_XPETRA_TPETRA
370  if(lib == UseTpetra)
372  Tpetra::createUniformContigMapWithNode<LocalOrdinal, GlobalOrdinal, Node>(numElements, comm)));
373 #endif // HAVE_XPETRA_TPETRA
374 
377 }
378 
379 
380 template<class LocalOrdinal, class GlobalOrdinal, class Node>
384  global_size_t numElements,
385  size_t localNumElements,
386  const Teuchos::RCP<const Teuchos::Comm<int>>& comm)
387 {
388  XPETRA_MONITOR("MapFactory::Build");
389 
390 #ifdef HAVE_XPETRA_TPETRA
391  if(lib == UseTpetra)
393  Tpetra::createContigMapWithNode<LocalOrdinal, GlobalOrdinal, Node>(numElements, localNumElements, comm)));
394 #endif // HAVE_XPETRA_TPETRA
395 
398 }
399 
400 
401 
402 #ifdef TPETRA_ENABLE_DEPRECATED_CODE
403 template<class LocalOrdinal, class GlobalOrdinal, class Node>
404 TPETRA_DEPRECATED
408  global_size_t numElements,
409  size_t localNumElements,
410  const Teuchos::RCP<const Teuchos::Comm<int>>& comm,
411  const Teuchos::RCP<Node>& /* node */)
412 {
413  return createContigMapWithNode(lib, numElements, localNumElements, comm);
414 }
415 #endif // TPETRA_ENABLE_DEPRECATED_CODE
416 
417 
418 
419 template<class LocalOrdinal, class GlobalOrdinal, class Node>
423  global_size_t numElements,
424  size_t localNumElements,
425  const Teuchos::RCP<const Teuchos::Comm<int>>& comm)
426 {
427  XPETRA_MONITOR("MapFactory::Build");
428 
429 #ifdef HAVE_XPETRA_TPETRA
430  if(lib == UseTpetra)
431  {
433  Tpetra::createContigMapWithNode<LocalOrdinal, GlobalOrdinal, Node>(numElements, localNumElements, comm)));
434  }
435 #endif // HAVE_XPETRA_TPETRA
436 
439 }
440 
441 
442 } // namespace Xpetra
443 
444 
445 #endif // XPETRA_MAPFACTORY_DEF_HPP
446 
447 
448 //TODO: remove unused methods
449 
450 
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.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
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.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
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.
Teuchos::RCP< const TpetraMap< LocalOrdinal, GlobalOrdinal, Node > > createLocalMapWithNode(size_t numElements, const Teuchos::RCP< const Teuchos::Comm< int > > &comm)
Non-member function to create a locally replicated Map with a 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.
#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)
Teuchos::RCP< const TpetraMap< LocalOrdinal, GlobalOrdinal, Node > > createContigMapWithNode(global_size_t numElements, size_t localNumElements, const Teuchos::RCP< const Teuchos::Comm< int > > &comm)
Non-member function to 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.
bool is_null() const