Xpetra  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Xpetra_EpetraMapFactory.cpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // Xpetra: A linear algebra interface package
4 //
5 // Copyright 2012 NTESS and the Xpetra contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
10 #include "Xpetra_MapFactory.hpp"
11 
12 #include "Xpetra_BlockedMap.hpp"
13 #include "Xpetra_EpetraMap.hpp"
14 #ifdef HAVE_XPETRA_TPETRA
15 #include "Xpetra_TpetraMap.hpp"
16 #endif
17 
18 namespace Xpetra {
19 
20 #if defined(HAVE_XPETRA_EPETRA)
21 
22 #if !defined(XPETRA_EPETRA_NO_32BIT_GLOBAL_INDICES)
23 
26 }
27 
28 RCP<Map<int, int, EpetraNode>>
31  global_size_t numGlobalElements,
32  int indexBase,
33  const Teuchos::RCP<const Teuchos::Comm<int>> &comm,
34  LocalGlobal lg) {
35  XPETRA_MONITOR("MapFactory::Build");
36 
37 #ifdef HAVE_XPETRA_TPETRA
38  if (lib == UseTpetra)
39  return rcp(new Xpetra::TpetraMap<LocalOrdinal, GlobalOrdinal, Node>(numGlobalElements, indexBase, comm, lg));
40 #endif
41 
42  if (lib == UseEpetra)
43  return rcp(new EpetraMapT<int, Node>(numGlobalElements, indexBase, comm, lg));
44 
46 }
47 
48 RCP<Map<int, int, EpetraNode>>
51  global_size_t numGlobalElements,
52  size_t numLocalElements,
53  int indexBase,
54  const Teuchos::RCP<const Teuchos::Comm<int>> &comm) {
55  XPETRA_MONITOR("MapFactory::Build");
56 
57 #ifdef HAVE_XPETRA_TPETRA
58  if (lib == UseTpetra)
59  return rcp(new TpetraMap<LocalOrdinal, GlobalOrdinal, Node>(numGlobalElements, numLocalElements, indexBase, comm));
60 #endif
61 
62  if (lib == UseEpetra)
63  return rcp(new EpetraMapT<int, Node>(numGlobalElements, numLocalElements, indexBase, comm));
64 
66 }
67 
68 RCP<Map<int, int, EpetraNode>>
71  global_size_t numGlobalElements,
72  const Teuchos::ArrayView<const int> &elementList,
73  int indexBase,
74  const Teuchos::RCP<const Teuchos::Comm<int>> &comm) {
75  XPETRA_MONITOR("MapFactory::Build");
76 #ifdef HAVE_XPETRA_TPETRA
77  if (lib == UseTpetra)
78  return rcp(new TpetraMap<LocalOrdinal, GlobalOrdinal, Node>(numGlobalElements, elementList, indexBase, comm));
79 #endif // HAVE_XPETRA_TPETRA
80 
81  if (lib == UseEpetra)
82  return rcp(new EpetraMapT<int, Node>(numGlobalElements, elementList, indexBase, comm));
83 
85 }
86 
89 Teuchos::RCP<Map<int, int, EpetraNode>>
91  Build(const Teuchos::RCP<const Map<int, int, EpetraNode>> &map,
92  const int numDofPerNode, const int gidOffset) {
93  XPETRA_MONITOR("MapFactory::Build");
94 
95  RCP<const BlockedMap<LocalOrdinal, GlobalOrdinal, Node>> bmap = Teuchos::rcp_dynamic_cast<const BlockedMap<LocalOrdinal, GlobalOrdinal, Node>>(map);
96  if (!bmap.is_null()) {
97  TEUCHOS_TEST_FOR_EXCEPTION(numDofPerNode != 1, Xpetra::Exceptions::RuntimeError,
98  "Xpetra::MapFactory::Build: When provided a BlockedMap numDofPerNode must set to be one. It is set to " << numDofPerNode << ".");
99  return rcp(new BlockedMap<LocalOrdinal, GlobalOrdinal, Node>(*bmap));
100  }
101 
102  LocalOrdinal N = Teuchos::as<LocalOrdinal>(map->getLocalNumElements());
103  Teuchos::ArrayView<const GlobalOrdinal> oldElements = map->getLocalElementList();
104  Teuchos::Array<GlobalOrdinal> newElements(map->getLocalNumElements() * numDofPerNode);
105  for (LocalOrdinal i = 0; i < N; i++) {
106  for (LocalOrdinal j = 0; j < numDofPerNode; j++) {
107  newElements[i * numDofPerNode + j] = oldElements[i] * numDofPerNode + j + gidOffset;
108  }
109  }
110 
111 #ifdef HAVE_XPETRA_TPETRA
112  if (map->lib() == UseTpetra) {
113  return rcp(new TpetraMap<LocalOrdinal, GlobalOrdinal, Node>(map->getGlobalNumElements() * numDofPerNode, newElements, map->getIndexBase(), map->getComm()));
114  }
115 #endif // HAVE_XPETRA_TPETRA
116 
117  if (map->lib() == UseEpetra) {
118  return rcp(new EpetraMapT<int, Node>(map->getGlobalNumElements() * numDofPerNode, newElements, map->getIndexBase(), map->getComm()));
119  }
120 
122 }
123 
124 Teuchos::RCP<const Map<int, int, EpetraNode>>
127  size_t numElements,
128  const Teuchos::RCP<const Teuchos::Comm<int>> &comm) {
129  XPETRA_MONITOR("MapFactory::Build");
130 
131 #ifdef HAVE_XPETRA_TPETRA
132  if (lib == UseTpetra)
133 #if ((defined(EPETRA_HAVE_OMP) && (defined(HAVE_TPETRA_INST_OPENMP) && defined(HAVE_TPETRA_INST_INT_INT))) || \
134  (!defined(EPETRA_HAVE_OMP) && (defined(HAVE_TPETRA_INST_SERIAL) && defined(HAVE_TPETRA_INST_INT_INT))))
135  return rcp(new TpetraMap<LocalOrdinal, GlobalOrdinal, Node>(Tpetra::createLocalMapWithNode<LocalOrdinal, GlobalOrdinal, Node>(numElements, comm)));
136 #else
137  TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::RuntimeError,
138  "Xpetra::MapFactory::createLocalMap: Cannot create Xpetra::TpetraMap, since Tpetra is not instantiated on EpetraNode (Serial or OpenMP, depending on configuration) and/or GO=int");
139 #endif
140 #endif // HAVE_XPETRA_TPETRA
141 
142  if (lib == UseEpetra) {
143  Teuchos::RCP<EpetraMapT<int, Node>> map;
144  map = Teuchos::rcp(new EpetraMapT<int, Node>((Xpetra::global_size_t)numElements, // num elements, global and local
145  0, // index base is zero
146  comm, LocallyReplicated));
147  return map.getConst();
148  }
149 
151 }
152 
153 // TODO remove this
154 
155 #ifdef HAVE_XPETRA_TPETRA
156 Teuchos::RCP<Map<int, int, EpetraNode>>
159  global_size_t numGlobalElements,
160  const Kokkos::View<const int *, typename Node::device_type> &indexList,
161  int indexBase,
162  const Teuchos::RCP<const Teuchos::Comm<int>> &comm) {
163  XPETRA_MONITOR("MapFactory::Build");
164  if (lib == UseTpetra)
165  return rcp(new TpetraMap<LocalOrdinal, GlobalOrdinal, Node>(numGlobalElements, indexList, indexBase, comm));
166  if (lib == UseEpetra) {
167  Teuchos::ArrayView<const int> v(indexList.data(), indexList.size());
168  return rcp(new EpetraMapT<int, Node>(numGlobalElements, v, indexBase, comm));
169  }
171 }
172 #endif // HAVE_XPETRA_TPETRA
173 
174 Teuchos::RCP<const Map<int, int, EpetraNode>>
177  size_t numElements,
178  const Teuchos::RCP<const Teuchos::Comm<int>> &comm) {
179  XPETRA_MONITOR("MapFactory::Build");
180 
181 #ifdef HAVE_XPETRA_TPETRA
182  if (lib == UseTpetra)
183 #if ((defined(EPETRA_HAVE_OMP) && (defined(HAVE_TPETRA_INST_OPENMP) && defined(HAVE_TPETRA_INST_INT_INT))) || \
184  (!defined(EPETRA_HAVE_OMP) && (defined(HAVE_TPETRA_INST_SERIAL) && defined(HAVE_TPETRA_INST_INT_INT))))
185  return rcp(new TpetraMap<LocalOrdinal, GlobalOrdinal, Node>(Tpetra::createLocalMapWithNode<int, GlobalOrdinal, Node>(numElements, comm)));
186 #else
187  TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::RuntimeError,
188  "Xpetra::MapFactory::createLocalMapWithNode: Cannot create Xpetra::TpetraMap, since Tpetra is not instantiated on EpetraNode (Serial or OpenMP, depending on configuration) and/or GO=int");
189 #endif
190 #endif // HAVE_XPETRA_TPETRA
191 
192  if (lib == UseEpetra) {
193  Teuchos::RCP<EpetraMapT<int, Node>> map;
194  map = Teuchos::rcp(new EpetraMapT<int, Node>((Xpetra::global_size_t)numElements, // num elements, global and local
195  0, // index base is zero
196  comm, LocallyReplicated));
197  return map.getConst();
198  }
199 
201 }
202 
203 // TODO remove this
204 
205 Teuchos::RCP<const Map<int, int, EpetraNode>>
208  global_size_t numElements,
209  const Teuchos::RCP<const Teuchos::Comm<int>> &comm) {
210  XPETRA_MONITOR("MapFactory::Build");
211 
212 #ifdef HAVE_XPETRA_TPETRA
213  if (lib == UseTpetra)
214 #if ((defined(EPETRA_HAVE_OMP) && (defined(HAVE_TPETRA_INST_OPENMP) && defined(HAVE_TPETRA_INST_INT_INT))) || \
215  (!defined(EPETRA_HAVE_OMP) && (defined(HAVE_TPETRA_INST_SERIAL) && defined(HAVE_TPETRA_INST_INT_INT))))
216  return rcp(new TpetraMap<LocalOrdinal, GlobalOrdinal, Node>(Tpetra::createUniformContigMapWithNode<int, GlobalOrdinal, Node>(numElements, comm)));
217 #else
218  TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::RuntimeError,
219  "Xpetra::MapFactory::createUniformContigMapWithNode: Cannot create Xpetra::TpetraMap, since Tpetra is not instantiated on EpetraNode (Serial or OpenMP, depending on configuration) and/or GO=int");
220 #endif
221 #endif // HAVE_XPETRA_TPETRA
222 
223  if (lib == UseEpetra) {
224  Teuchos::RCP<EpetraMapT<int, Node>> map;
225  map = Teuchos::rcp(new EpetraMapT<int, Node>(numElements, // num elements, global and local
226  0, // index base is zero
227  comm, GloballyDistributed));
228  return map.getConst();
229  }
230 
232 }
233 
234 Teuchos::RCP<const Map<int, int, EpetraNode>>
237  global_size_t numElements,
238  const Teuchos::RCP<const Teuchos::Comm<int>> &comm) {
239  XPETRA_MONITOR("MapFactory::Build");
240 
241 #ifdef HAVE_XPETRA_TPETRA
242  if (lib == UseTpetra)
243 #if ((defined(EPETRA_HAVE_OMP) && (defined(HAVE_TPETRA_INST_OPENMP) && defined(HAVE_TPETRA_INST_INT_INT))) || \
244  (!defined(EPETRA_HAVE_OMP) && (defined(HAVE_TPETRA_INST_SERIAL) && defined(HAVE_TPETRA_INST_INT_INT))))
245  return rcp(new TpetraMap<LocalOrdinal, GlobalOrdinal, Node>(Tpetra::createUniformContigMapWithNode<LocalOrdinal, GlobalOrdinal, Node>(numElements, comm)));
246 #else
247  TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::RuntimeError,
248  "Xpetra::MapFactory::createUniformContigMapWithNode: Cannot create Xpetra::TpetraMap, since Tpetra is not instantiated on EpetraNode (Serial or OpenMP, depending on configuration) and/or GO=int");
249 #endif
250 #endif // HAVE_XPETRA_TPETRA
251 
252  if (lib == UseEpetra) {
253  Teuchos::RCP<EpetraMapT<int, Node>> map;
254  map = Teuchos::rcp(new EpetraMapT<int, Node>(numElements, // num elements, global and local
255  0, // index base is zero
256  comm, GloballyDistributed));
257  return map.getConst();
258  }
260 }
261 
262 Teuchos::RCP<const Map<int, int, EpetraNode>>
265  global_size_t numElements,
266  size_t localNumElements,
267  const Teuchos::RCP<const Teuchos::Comm<int>> &comm) {
268  XPETRA_MONITOR("MapFactory::Build");
269 
270 #ifdef HAVE_XPETRA_TPETRA
271  if (lib == UseTpetra)
272 #if ((defined(EPETRA_HAVE_OMP) && (defined(HAVE_TPETRA_INST_OPENMP) && defined(HAVE_TPETRA_INST_INT_INT))) || \
273  (!defined(EPETRA_HAVE_OMP) && (defined(HAVE_TPETRA_INST_SERIAL) && defined(HAVE_TPETRA_INST_INT_INT))))
274  return rcp(new TpetraMap<LocalOrdinal, GlobalOrdinal, Node>(Tpetra::createContigMapWithNode<int, GlobalOrdinal, Node>(numElements, localNumElements, comm)));
275 #else
276  TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::RuntimeError,
277  "Xpetra::MapFactory::createContigMap: Cannot create Xpetra::TpetraMap, since Tpetra is not instantiated on EpetraNode (Serial or OpenMP, depending on configuration) and/or GO=int");
278 #endif
279 #endif
280 
281  if (lib == UseEpetra) {
282  return MapFactory<int, GlobalOrdinal, Node>::createContigMapWithNode(lib, numElements, localNumElements, comm);
283  }
284 
286 }
287 
288 Teuchos::RCP<const Map<int, int, EpetraNode>>
291  global_size_t numElements,
292  size_t localNumElements,
293  const Teuchos::RCP<const Teuchos::Comm<int>> &comm) {
294  XPETRA_MONITOR("MapFactory::Build");
295 
296 #ifdef HAVE_XPETRA_TPETRA
297  if (lib == UseTpetra)
298 #if ((defined(EPETRA_HAVE_OMP) && (defined(HAVE_TPETRA_INST_OPENMP) && defined(HAVE_TPETRA_INST_INT_INT))) || \
299  (!defined(EPETRA_HAVE_OMP) && (defined(HAVE_TPETRA_INST_SERIAL) && defined(HAVE_TPETRA_INST_INT_INT))))
300  return rcp(new TpetraMap<LocalOrdinal, GlobalOrdinal, Node>(Tpetra::createContigMapWithNode<int, GlobalOrdinal, Node>(numElements, localNumElements, comm)));
301 #else
302  TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::RuntimeError,
303  "Xpetra::MapFactory::createContigMapWithNode: Cannot create Xpetra::TpetraMap, since Tpetra is not instantiated on EpetraNode (Serial or OpenMP, depending on configuration) and/or GO=int");
304 #endif
305 #endif
306 
307  if (lib == UseEpetra) {
308  Teuchos::RCP<EpetraMapT<int, Node>> map;
309  map = Teuchos::rcp(new EpetraMapT<int, Node>(numElements, localNumElements,
310  0, // index base is zero
311  comm));
312  return map.getConst();
313  }
315 }
316 
317 Teuchos::RCP<const Map<int, int, EpetraNode>>
319  const Teuchos::RCP<const Teuchos::Comm<int>> &newComm) {
320  XPETRA_MONITOR("MapFactory::Build");
322  global_size_t INVALID = Teuchos::OrdinalTraits<global_size_t>::invalid();
323 
324  size_t Nlocal = oldmap->getLocalNumElements();
325  global_size_t Nglobal = oldmap->getGlobalNumElements();
326 
327  // Sanity check -- if there's no comm, we can't keep elements on the map (vice versa is OK)
328  TEUCHOS_TEST_FOR_EXCEPTION(Nlocal && newComm.is_null(),
329  std::logic_error, "MapFactory::copyMapWithNewComm needs the comm to match the map.");
330 
331  // We'll return null if we don't have a Comm on this rank
332  RCP<const Map<int, int, Node>> newMap;
333  if (!newComm.is_null()) {
334  if (oldmap->isContiguous()) {
335  newMap = XMF::Build(oldmap->lib(), INVALID, Nlocal, oldmap->getIndexBase(), newComm);
336  } else {
337  newMap = XMF::Build(oldmap->lib(), Nglobal, oldmap->getLocalElementList(), oldmap->getIndexBase(), newComm);
338  }
339  }
340 
341  return newMap;
343 }
344 
345 #endif // #if !defined(XPETRA_EPETRA_NO_32BIT_GLOBAL_INDICES)
346 
347 // we need the Epetra specialization only if Epetra is enabled
348 #if !defined(XPETRA_EPETRA_NO_64BIT_GLOBAL_INDICES)
349 
353 }
354 
355 RCP<Map<int, long long, EpetraNode>>
358  global_size_t numGlobalElements,
359  int indexBase,
360  const Teuchos::RCP<const Teuchos::Comm<int>> &comm,
361  LocalGlobal lg) {
362  XPETRA_MONITOR("MapFactory::Build");
363 
364 #ifdef HAVE_XPETRA_TPETRA
365  if (lib == UseTpetra)
366  return rcp(new TpetraMap<LocalOrdinal, GlobalOrdinal, Node>(numGlobalElements, indexBase, comm, lg));
367 #endif
368 
369  if (lib == UseEpetra)
370  return rcp(new EpetraMapT<long long, Node>(numGlobalElements, indexBase, comm, lg));
371 
373 }
374 
375 RCP<Map<int, long long, EpetraNode>>
378  global_size_t numGlobalElements,
379  size_t numLocalElements,
380  int indexBase,
381  const Teuchos::RCP<const Teuchos::Comm<int>> &comm) {
382  XPETRA_MONITOR("MapFactory::Build");
383 
384 #ifdef HAVE_XPETRA_TPETRA
385  if (lib == UseTpetra)
386  return rcp(new TpetraMap<LocalOrdinal, GlobalOrdinal, Node>(numGlobalElements, numLocalElements, indexBase, comm));
387 #endif
388 
389  if (lib == UseEpetra)
390  return rcp(new EpetraMapT<long long, Node>(numGlobalElements, numLocalElements, indexBase, comm));
391 
393 }
394 
395 RCP<Map<int, long long, EpetraNode>>
398  global_size_t numGlobalElements,
399  const Teuchos::ArrayView<const long long> &elementList,
400  int indexBase,
401  const Teuchos::RCP<const Teuchos::Comm<int>> &comm) {
402  XPETRA_MONITOR("MapFactory::Build");
403 
404 #ifdef HAVE_XPETRA_TPETRA
405  if (lib == UseTpetra)
406  return rcp(new TpetraMap<LocalOrdinal, GlobalOrdinal, Node>(numGlobalElements, elementList, indexBase, comm));
407 #endif
408 
409  if (lib == UseEpetra)
410  return rcp(new EpetraMapT<long long, Node>(numGlobalElements, elementList, indexBase, comm));
411 
413 }
414 
417 Teuchos::RCP<Map<int, long long, EpetraNode>>
419  Build(const Teuchos::RCP<const Map<int, long long, EpetraNode>> &map,
420  int numDofPerNode) {
421  XPETRA_MONITOR("MapFactory::Build");
422 
423  RCP<const BlockedMap<LocalOrdinal, GlobalOrdinal, Node>> bmap = Teuchos::rcp_dynamic_cast<const BlockedMap<LocalOrdinal, GlobalOrdinal, Node>>(map);
424  if (!bmap.is_null()) {
425  TEUCHOS_TEST_FOR_EXCEPTION(numDofPerNode != 1, Xpetra::Exceptions::RuntimeError,
426  "Xpetra::MapFactory::Build: When provided a BlockedMap numDofPerNode must set to be one. It is set to " << numDofPerNode << ".");
428  }
429 
430  LocalOrdinal N = map->getLocalNumElements();
431  Teuchos::ArrayView<const GlobalOrdinal> oldElements = map->getLocalElementList();
432  Teuchos::Array<GlobalOrdinal> newElements(map->getLocalNumElements() * numDofPerNode);
433  for (LocalOrdinal i = 0; i < N; i++)
434  for (LocalOrdinal j = 0; j < numDofPerNode; j++)
435  newElements[i * numDofPerNode + j] = oldElements[i] * numDofPerNode + j;
436 
437 #ifdef HAVE_XPETRA_TPETRA
438  if (map->lib() == UseTpetra)
439  return rcp(new TpetraMap<LocalOrdinal, GlobalOrdinal, Node>(map->getGlobalNumElements() * numDofPerNode, newElements, map->getIndexBase(), map->getComm()));
440 #endif
441 
442  if (map->lib() == UseEpetra)
443  return rcp(new EpetraMapT<long long, Node>(map->getGlobalNumElements() * numDofPerNode, newElements, map->getIndexBase(), map->getComm()));
444 
446 }
447 
448 #ifdef HAVE_XPETRA_TPETRA
449 Teuchos::RCP<Map<LocalOrdinal, GlobalOrdinal, Node>>
452  global_size_t numGlobalElements,
453  const Kokkos::View<const long long *, typename Node::device_type> &indexList,
454  long long indexBase,
455  const Teuchos::RCP<const Teuchos::Comm<int>> &comm) {
456  XPETRA_MONITOR("MapFactory::Build");
457  if (lib == UseTpetra)
458  return rcp(new TpetraMap<LocalOrdinal, GlobalOrdinal, Node>(numGlobalElements, indexList, indexBase, comm));
459  if (lib == UseEpetra) {
460  Teuchos::ArrayView<const long long> v(indexList.data(), indexList.size());
461  return rcp(new EpetraMapT<long long, Node>(numGlobalElements, v, indexBase, comm));
462  }
465 }
466 #endif // HAVE_XPETRA_TPETRA
467 
468 Teuchos::RCP<const Map<int, long long, EpetraNode>>
471  size_t numElements,
472  const Teuchos::RCP<const Teuchos::Comm<int>> &comm) {
473  XPETRA_MONITOR("MapFactory::Build");
474 
475 #ifdef HAVE_XPETRA_TPETRA
476  if (lib == UseTpetra)
477 #if ((defined(EPETRA_HAVE_OMP) && (defined(HAVE_TPETRA_INST_OPENMP) && defined(HAVE_TPETRA_INST_INT_LONG_LONG))) || \
478  (!defined(EPETRA_HAVE_OMP) && (defined(HAVE_TPETRA_INST_SERIAL) && defined(HAVE_TPETRA_INST_INT_LONG_LONG))))
479  return rcp(new TpetraMap<LocalOrdinal, GlobalOrdinal, Node>(Tpetra::createLocalMapWithNode<LocalOrdinal, GlobalOrdinal, Node>(numElements, comm)));
480 #else
481  TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::RuntimeError,
482  "Xpetra::MapFactory::createLocalMap: Cannot create Xpetra::TpetraMap, since Tpetra is not instantiated on EpetraNode (Serial or OpenMP, depending on configuration) and/or GO=long long");
483 #endif
484 #endif
485 
486  if (lib == UseEpetra)
488 
490 }
491 
492 Teuchos::RCP<const Map<int, long long, EpetraNode>>
495  size_t numElements,
496  const Teuchos::RCP<const Teuchos::Comm<int>> &comm) {
497  XPETRA_MONITOR("MapFactory::Build");
498 
499 #ifdef HAVE_XPETRA_TPETRA
500  if (lib == UseTpetra)
501 #if ((defined(EPETRA_HAVE_OMP) && (defined(HAVE_TPETRA_INST_OPENMP) && defined(HAVE_TPETRA_INST_INT_LONG_LONG))) || \
502  (!defined(EPETRA_HAVE_OMP) && (defined(HAVE_TPETRA_INST_SERIAL) && defined(HAVE_TPETRA_INST_INT_LONG_LONG))))
503  return rcp(new TpetraMap<LocalOrdinal, GlobalOrdinal, Node>(Tpetra::createLocalMapWithNode<int, GlobalOrdinal, Node>(numElements, comm)));
504 #else
505  TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::RuntimeError,
506  "Xpetra::MapFactory::createLocalMapWithNode: Cannot create Xpetra::TpetraMap, since Tpetra is not instantiated on EpetraNode (Serial or OpenMP, depending on configuration) and/or GO=long long");
507 #endif
508 #endif
509 
510  if (lib == UseEpetra) {
511  Teuchos::RCP<EpetraMapT<long long, Node>> map;
512  map = Teuchos::rcp(new EpetraMapT<long long, Node>((Xpetra::global_size_t)numElements, // num elements, global and local
513  0, // index base is zero
514  comm, LocallyReplicated));
515  return map.getConst();
516  }
518 }
519 
520 Teuchos::RCP<const Map<int, long long, EpetraNode>>
523  global_size_t numElements,
524  const Teuchos::RCP<const Teuchos::Comm<int>> &comm) {
525  XPETRA_MONITOR("MapFactory::Build");
526 
527 #ifdef HAVE_XPETRA_TPETRA
528  if (lib == UseTpetra)
529 #if ((defined(EPETRA_HAVE_OMP) && (defined(HAVE_TPETRA_INST_OPENMP) && defined(HAVE_TPETRA_INST_INT_LONG_LONG))) || \
530  (!defined(EPETRA_HAVE_OMP) && (defined(HAVE_TPETRA_INST_SERIAL) && defined(HAVE_TPETRA_INST_INT_LONG_LONG))))
531  return rcp(new TpetraMap<LocalOrdinal, GlobalOrdinal, Node>(Tpetra::createUniformContigMapWithNode<int, GlobalOrdinal, Node>(numElements, comm)));
532 #else
533  TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::RuntimeError,
534  "Xpetra::MapFactory::createUniformContigMapWithNode: Cannot create Xpetra::TpetraMap, since Tpetra is not instantiated on EpetraNode (Serial or OpenMP, depending on configuration) and/or GO=long long");
535 #endif
536 #endif
537 
538  if (lib == UseEpetra) {
539  Teuchos::RCP<EpetraMapT<long long, Node>> map;
540  map = Teuchos::rcp(new EpetraMapT<long long, Node>(numElements, // num elements, global and local
541  0, // index base is zero
542  comm, GloballyDistributed));
543  return map.getConst();
544  }
546 }
547 
548 Teuchos::RCP<const Map<int, long long, EpetraNode>>
551  global_size_t numElements,
552  const Teuchos::RCP<const Teuchos::Comm<int>> &comm) {
553  XPETRA_MONITOR("MapFactory::Build");
554 
555 #ifdef HAVE_XPETRA_TPETRA
556  if (lib == UseTpetra)
557 #if ((defined(EPETRA_HAVE_OMP) && (defined(HAVE_TPETRA_INST_OPENMP) && defined(HAVE_TPETRA_INST_INT_LONG_LONG))) || \
558  (!defined(EPETRA_HAVE_OMP) && (defined(HAVE_TPETRA_INST_SERIAL) && defined(HAVE_TPETRA_INST_INT_LONG_LONG))))
559  return rcp(new TpetraMap<LocalOrdinal, GlobalOrdinal, Node>(Tpetra::createUniformContigMapWithNode<LocalOrdinal, GlobalOrdinal, Node>(numElements, comm)));
560 #else
561  TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::RuntimeError,
562  "Xpetra::MapFactory::createUniformContigMap: Cannot create Xpetra::TpetraMap, since Tpetra is not instantiated on EpetraNode (Serial or OpenMP, depending on configuration) and/or GO=long long");
563 #endif
564 #endif
565 
566  if (lib == UseEpetra)
568 
570 }
571 
572 Teuchos::RCP<const Map<int, long long, EpetraNode>>
574  global_size_t numElements,
575  size_t localNumElements,
576  const Teuchos::RCP<const Teuchos::Comm<int>> &comm) {
577  XPETRA_MONITOR("MapFactory::Build");
578 
579 #ifdef HAVE_XPETRA_TPETRA
580  if (lib == UseTpetra)
581 #if ((defined(EPETRA_HAVE_OMP) && (defined(HAVE_TPETRA_INST_OPENMP) && defined(HAVE_TPETRA_INST_INT_LONG_LONG))) || (!defined(EPETRA_HAVE_OMP) && (defined(HAVE_TPETRA_INST_SERIAL) && defined(HAVE_TPETRA_INST_INT_LONG_LONG))))
583  Tpetra::createContigMapWithNode<int, GlobalOrdinal, Node>(numElements, localNumElements, comm)));
584 #else
585  TEUCHOS_TEST_FOR_EXCEPTION(true,
587  "Xpetra::MapFactory::createContigMap: Cannot create Xpetra::TpetraMap, since Tpetra is not instantiated on "
588  "EpetraNode (Serial or OpenMP, depending on configuration) and/or GO=long long");
589 #endif
590 #endif
591 
592  if (lib == UseEpetra)
593  return MapFactory<int, GlobalOrdinal, Node>::createContigMapWithNode(lib, numElements, localNumElements, comm);
594 
596 }
597 
598 Teuchos::RCP<const Map<int, long long, EpetraNode>>
601  global_size_t numElements,
602  size_t localNumElements,
603  const Teuchos::RCP<const Teuchos::Comm<int>> &comm) {
604  XPETRA_MONITOR("MapFactory::Build");
605 
606 #ifdef HAVE_XPETRA_TPETRA
607  if (lib == UseTpetra)
608 #if ((defined(EPETRA_HAVE_OMP) && (defined(HAVE_TPETRA_INST_OPENMP) && defined(HAVE_TPETRA_INST_INT_LONG_LONG))) || (!defined(EPETRA_HAVE_OMP) && (defined(HAVE_TPETRA_INST_SERIAL) && defined(HAVE_TPETRA_INST_INT_LONG_LONG))))
610  Tpetra::createContigMapWithNode<int, GlobalOrdinal, Node>(numElements, localNumElements, comm)));
611 #else
612  TEUCHOS_TEST_FOR_EXCEPTION(true,
614  "Xpetra::MapFactory::createContigMapWithNode: Cannot create Xpetra::TpetraMap, since Tpetra is not "
615  "instantiated on EpetraNode (Serial or OpenMP, depending on configuration) and/or GO=long long");
616 #endif
617 #endif // HAVE_XPETRA_TPETRA
618 
619  if (lib == UseEpetra) {
620  Teuchos::RCP<EpetraMapT<long long, Node>> map;
621  map = Teuchos::rcp(new EpetraMapT<long long, Node>(numElements,
622  localNumElements,
623  0, // index base is zero
624  comm));
625  return map.getConst();
626  }
627 
629 }
630 
631 Teuchos::RCP<const Map<int, long long, EpetraNode>>
633  const Teuchos::RCP<const Teuchos::Comm<int>> &newComm) {
634  XPETRA_MONITOR("MapFactory::Build");
636  global_size_t INVALID = Teuchos::OrdinalTraits<global_size_t>::invalid();
637 
638  size_t Nlocal = oldmap->getLocalNumElements();
639  global_size_t Nglobal = oldmap->getGlobalNumElements();
640 
641  // Sanity check -- if there's no comm, we can't keep elements on the map (vice versa is OK)
642  TEUCHOS_TEST_FOR_EXCEPTION(Nlocal && newComm.is_null(),
643  std::logic_error, "MapFactory::copyMapWithNewComm needs the comm to match the map.");
644 
645  // We'll return null if we don't have a Comm on this rank
646  RCP<const Map<int, long long, Node>> newMap;
647  if (!newComm.is_null()) {
648  if (oldmap->isContiguous()) {
649  newMap = XMF::Build(oldmap->lib(), INVALID, Nlocal, oldmap->getIndexBase(), newComm);
650  } else {
651  newMap = XMF::Build(oldmap->lib(), Nglobal, oldmap->getLocalElementList(), oldmap->getIndexBase(), newComm);
652  }
653  }
654 
655  return newMap;
657 }
658 
659 #endif // #if !defined(XPETRA_EPETRA_NO_64BIT_GLOBAL_INDICES)
660 
661 #endif // #if defined(HAVE_XPETRA_EPETRA)
662 
663 } // namespace Xpetra
664 
665 // EOF
static Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > copyMapWithNewComm(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node >> &oldmap, const Teuchos::RCP< const Teuchos::Comm< int >> &newComm)
Create a copy of the map, only using the new Comm object if the Comm would be valid.
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.
Create an Xpetra::Map instance.
#define XPETRA_MONITOR(funcName)
X P E T R A E P E T R A S P E C I A L I Z A T I O N.
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.