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 // ***********************************************************************
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 #include "Xpetra_MapFactory.hpp"
47 
48 #include "Xpetra_BlockedMap.hpp"
49 #include "Xpetra_EpetraMap.hpp"
50 #ifdef HAVE_XPETRA_TPETRA
51 #include "Xpetra_TpetraMap.hpp"
52 #endif
53 
54 namespace Xpetra {
55 
56 #if defined(HAVE_XPETRA_EPETRA)
57 
58 #if !defined(XPETRA_EPETRA_NO_32BIT_GLOBAL_INDICES)
59 
62 }
63 
64 RCP<Map<int, int, EpetraNode>>
67  global_size_t numGlobalElements,
68  int indexBase,
69  const Teuchos::RCP<const Teuchos::Comm<int>> &comm,
70  LocalGlobal lg) {
71  XPETRA_MONITOR("MapFactory::Build");
72 
73 #ifdef HAVE_XPETRA_TPETRA
74  if (lib == UseTpetra)
75  return rcp(new Xpetra::TpetraMap<LocalOrdinal, GlobalOrdinal, Node>(numGlobalElements, indexBase, comm, lg));
76 #endif
77 
78  if (lib == UseEpetra)
79  return rcp(new EpetraMapT<int, Node>(numGlobalElements, indexBase, comm, lg));
80 
82 }
83 
84 RCP<Map<int, int, EpetraNode>>
87  global_size_t numGlobalElements,
88  size_t numLocalElements,
89  int indexBase,
90  const Teuchos::RCP<const Teuchos::Comm<int>> &comm) {
91  XPETRA_MONITOR("MapFactory::Build");
92 
93 #ifdef HAVE_XPETRA_TPETRA
94  if (lib == UseTpetra)
95  return rcp(new TpetraMap<LocalOrdinal, GlobalOrdinal, Node>(numGlobalElements, numLocalElements, indexBase, comm));
96 #endif
97 
98  if (lib == UseEpetra)
99  return rcp(new EpetraMapT<int, Node>(numGlobalElements, numLocalElements, indexBase, comm));
100 
102 }
103 
104 RCP<Map<int, int, EpetraNode>>
107  global_size_t numGlobalElements,
108  const Teuchos::ArrayView<const int> &elementList,
109  int indexBase,
110  const Teuchos::RCP<const Teuchos::Comm<int>> &comm) {
111  XPETRA_MONITOR("MapFactory::Build");
112 #ifdef HAVE_XPETRA_TPETRA
113  if (lib == UseTpetra)
114  return rcp(new TpetraMap<LocalOrdinal, GlobalOrdinal, Node>(numGlobalElements, elementList, indexBase, comm));
115 #endif // HAVE_XPETRA_TPETRA
116 
117  if (lib == UseEpetra)
118  return rcp(new EpetraMapT<int, Node>(numGlobalElements, elementList, indexBase, comm));
119 
121 }
122 
125 Teuchos::RCP<Map<int, int, EpetraNode>>
127  Build(const Teuchos::RCP<const Map<int, int, EpetraNode>> &map,
128  const int numDofPerNode, const int gidOffset) {
129  XPETRA_MONITOR("MapFactory::Build");
130 
131  RCP<const BlockedMap<LocalOrdinal, GlobalOrdinal, Node>> bmap = Teuchos::rcp_dynamic_cast<const BlockedMap<LocalOrdinal, GlobalOrdinal, Node>>(map);
132  if (!bmap.is_null()) {
133  TEUCHOS_TEST_FOR_EXCEPTION(numDofPerNode != 1, Xpetra::Exceptions::RuntimeError,
134  "Xpetra::MapFactory::Build: When provided a BlockedMap numDofPerNode must set to be one. It is set to " << numDofPerNode << ".");
135  return rcp(new BlockedMap<LocalOrdinal, GlobalOrdinal, Node>(*bmap));
136  }
137 
138  LocalOrdinal N = Teuchos::as<LocalOrdinal>(map->getLocalNumElements());
139  Teuchos::ArrayView<const GlobalOrdinal> oldElements = map->getLocalElementList();
140  Teuchos::Array<GlobalOrdinal> newElements(map->getLocalNumElements() * numDofPerNode);
141  for (LocalOrdinal i = 0; i < N; i++) {
142  for (LocalOrdinal j = 0; j < numDofPerNode; j++) {
143  newElements[i * numDofPerNode + j] = oldElements[i] * numDofPerNode + j + gidOffset;
144  }
145  }
146 
147 #ifdef HAVE_XPETRA_TPETRA
148  if (map->lib() == UseTpetra) {
149  return rcp(new TpetraMap<LocalOrdinal, GlobalOrdinal, Node>(map->getGlobalNumElements() * numDofPerNode, newElements, map->getIndexBase(), map->getComm()));
150  }
151 #endif // HAVE_XPETRA_TPETRA
152 
153  if (map->lib() == UseEpetra) {
154  return rcp(new EpetraMapT<int, Node>(map->getGlobalNumElements() * numDofPerNode, newElements, map->getIndexBase(), map->getComm()));
155  }
156 
158 }
159 
160 Teuchos::RCP<const Map<int, int, EpetraNode>>
163  size_t numElements,
164  const Teuchos::RCP<const Teuchos::Comm<int>> &comm) {
165  XPETRA_MONITOR("MapFactory::Build");
166 
167 #ifdef HAVE_XPETRA_TPETRA
168  if (lib == UseTpetra)
169 #if ((defined(EPETRA_HAVE_OMP) && (defined(HAVE_TPETRA_INST_OPENMP) && defined(HAVE_TPETRA_INST_INT_INT))) || \
170  (!defined(EPETRA_HAVE_OMP) && (defined(HAVE_TPETRA_INST_SERIAL) && defined(HAVE_TPETRA_INST_INT_INT))))
171  return rcp(new TpetraMap<LocalOrdinal, GlobalOrdinal, Node>(Tpetra::createLocalMapWithNode<LocalOrdinal, GlobalOrdinal, Node>(numElements, comm)));
172 #else
173  TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::RuntimeError,
174  "Xpetra::MapFactory::createLocalMap: Cannot create Xpetra::TpetraMap, since Tpetra is not instantiated on EpetraNode (Serial or OpenMP, depending on configuration) and/or GO=int");
175 #endif
176 #endif // HAVE_XPETRA_TPETRA
177 
178  if (lib == UseEpetra) {
179  Teuchos::RCP<EpetraMapT<int, Node>> map;
180  map = Teuchos::rcp(new EpetraMapT<int, Node>((Xpetra::global_size_t)numElements, // num elements, global and local
181  0, // index base is zero
182  comm, LocallyReplicated));
183  return map.getConst();
184  }
185 
187 }
188 
189 // TODO remove this
190 
191 #ifdef HAVE_XPETRA_TPETRA
192 Teuchos::RCP<Map<int, int, EpetraNode>>
195  global_size_t numGlobalElements,
196  const Kokkos::View<const int *, typename Node::device_type> &indexList,
197  int indexBase,
198  const Teuchos::RCP<const Teuchos::Comm<int>> &comm) {
199  XPETRA_MONITOR("MapFactory::Build");
200  if (lib == UseTpetra)
201  return rcp(new TpetraMap<LocalOrdinal, GlobalOrdinal, Node>(numGlobalElements, indexList, indexBase, comm));
202  if (lib == UseEpetra) {
203  Teuchos::ArrayView<const int> v(indexList.data(), indexList.size());
204  return rcp(new EpetraMapT<int, Node>(numGlobalElements, v, indexBase, comm));
205  }
207 }
208 #endif // HAVE_XPETRA_TPETRA
209 
210 Teuchos::RCP<const Map<int, int, EpetraNode>>
213  size_t numElements,
214  const Teuchos::RCP<const Teuchos::Comm<int>> &comm) {
215  XPETRA_MONITOR("MapFactory::Build");
216 
217 #ifdef HAVE_XPETRA_TPETRA
218  if (lib == UseTpetra)
219 #if ((defined(EPETRA_HAVE_OMP) && (defined(HAVE_TPETRA_INST_OPENMP) && defined(HAVE_TPETRA_INST_INT_INT))) || \
220  (!defined(EPETRA_HAVE_OMP) && (defined(HAVE_TPETRA_INST_SERIAL) && defined(HAVE_TPETRA_INST_INT_INT))))
221  return rcp(new TpetraMap<LocalOrdinal, GlobalOrdinal, Node>(Tpetra::createLocalMapWithNode<int, GlobalOrdinal, Node>(numElements, comm)));
222 #else
223  TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::RuntimeError,
224  "Xpetra::MapFactory::createLocalMapWithNode: Cannot create Xpetra::TpetraMap, since Tpetra is not instantiated on EpetraNode (Serial or OpenMP, depending on configuration) and/or GO=int");
225 #endif
226 #endif // HAVE_XPETRA_TPETRA
227 
228  if (lib == UseEpetra) {
229  Teuchos::RCP<EpetraMapT<int, Node>> map;
230  map = Teuchos::rcp(new EpetraMapT<int, Node>((Xpetra::global_size_t)numElements, // num elements, global and local
231  0, // index base is zero
232  comm, LocallyReplicated));
233  return map.getConst();
234  }
235 
237 }
238 
239 // TODO remove this
240 
241 Teuchos::RCP<const Map<int, int, EpetraNode>>
244  global_size_t numElements,
245  const Teuchos::RCP<const Teuchos::Comm<int>> &comm) {
246  XPETRA_MONITOR("MapFactory::Build");
247 
248 #ifdef HAVE_XPETRA_TPETRA
249  if (lib == UseTpetra)
250 #if ((defined(EPETRA_HAVE_OMP) && (defined(HAVE_TPETRA_INST_OPENMP) && defined(HAVE_TPETRA_INST_INT_INT))) || \
251  (!defined(EPETRA_HAVE_OMP) && (defined(HAVE_TPETRA_INST_SERIAL) && defined(HAVE_TPETRA_INST_INT_INT))))
252  return rcp(new TpetraMap<LocalOrdinal, GlobalOrdinal, Node>(Tpetra::createUniformContigMapWithNode<int, GlobalOrdinal, Node>(numElements, comm)));
253 #else
254  TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::RuntimeError,
255  "Xpetra::MapFactory::createUniformContigMapWithNode: Cannot create Xpetra::TpetraMap, since Tpetra is not instantiated on EpetraNode (Serial or OpenMP, depending on configuration) and/or GO=int");
256 #endif
257 #endif // HAVE_XPETRA_TPETRA
258 
259  if (lib == UseEpetra) {
260  Teuchos::RCP<EpetraMapT<int, Node>> map;
261  map = Teuchos::rcp(new EpetraMapT<int, Node>(numElements, // num elements, global and local
262  0, // index base is zero
263  comm, GloballyDistributed));
264  return map.getConst();
265  }
266 
268 }
269 
270 Teuchos::RCP<const Map<int, int, EpetraNode>>
273  global_size_t numElements,
274  const Teuchos::RCP<const Teuchos::Comm<int>> &comm) {
275  XPETRA_MONITOR("MapFactory::Build");
276 
277 #ifdef HAVE_XPETRA_TPETRA
278  if (lib == UseTpetra)
279 #if ((defined(EPETRA_HAVE_OMP) && (defined(HAVE_TPETRA_INST_OPENMP) && defined(HAVE_TPETRA_INST_INT_INT))) || \
280  (!defined(EPETRA_HAVE_OMP) && (defined(HAVE_TPETRA_INST_SERIAL) && defined(HAVE_TPETRA_INST_INT_INT))))
281  return rcp(new TpetraMap<LocalOrdinal, GlobalOrdinal, Node>(Tpetra::createUniformContigMapWithNode<LocalOrdinal, GlobalOrdinal, Node>(numElements, comm)));
282 #else
283  TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::RuntimeError,
284  "Xpetra::MapFactory::createUniformContigMapWithNode: Cannot create Xpetra::TpetraMap, since Tpetra is not instantiated on EpetraNode (Serial or OpenMP, depending on configuration) and/or GO=int");
285 #endif
286 #endif // HAVE_XPETRA_TPETRA
287 
288  if (lib == UseEpetra) {
289  Teuchos::RCP<EpetraMapT<int, Node>> map;
290  map = Teuchos::rcp(new EpetraMapT<int, Node>(numElements, // num elements, global and local
291  0, // index base is zero
292  comm, GloballyDistributed));
293  return map.getConst();
294  }
296 }
297 
298 Teuchos::RCP<const Map<int, int, EpetraNode>>
301  global_size_t numElements,
302  size_t localNumElements,
303  const Teuchos::RCP<const Teuchos::Comm<int>> &comm) {
304  XPETRA_MONITOR("MapFactory::Build");
305 
306 #ifdef HAVE_XPETRA_TPETRA
307  if (lib == UseTpetra)
308 #if ((defined(EPETRA_HAVE_OMP) && (defined(HAVE_TPETRA_INST_OPENMP) && defined(HAVE_TPETRA_INST_INT_INT))) || \
309  (!defined(EPETRA_HAVE_OMP) && (defined(HAVE_TPETRA_INST_SERIAL) && defined(HAVE_TPETRA_INST_INT_INT))))
310  return rcp(new TpetraMap<LocalOrdinal, GlobalOrdinal, Node>(Tpetra::createContigMapWithNode<int, GlobalOrdinal, Node>(numElements, localNumElements, comm)));
311 #else
312  TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::RuntimeError,
313  "Xpetra::MapFactory::createContigMap: Cannot create Xpetra::TpetraMap, since Tpetra is not instantiated on EpetraNode (Serial or OpenMP, depending on configuration) and/or GO=int");
314 #endif
315 #endif
316 
317  if (lib == UseEpetra) {
318  return MapFactory<int, GlobalOrdinal, Node>::createContigMapWithNode(lib, numElements, localNumElements, comm);
319  }
320 
322 }
323 
324 Teuchos::RCP<const Map<int, int, EpetraNode>>
327  global_size_t numElements,
328  size_t localNumElements,
329  const Teuchos::RCP<const Teuchos::Comm<int>> &comm) {
330  XPETRA_MONITOR("MapFactory::Build");
331 
332 #ifdef HAVE_XPETRA_TPETRA
333  if (lib == UseTpetra)
334 #if ((defined(EPETRA_HAVE_OMP) && (defined(HAVE_TPETRA_INST_OPENMP) && defined(HAVE_TPETRA_INST_INT_INT))) || \
335  (!defined(EPETRA_HAVE_OMP) && (defined(HAVE_TPETRA_INST_SERIAL) && defined(HAVE_TPETRA_INST_INT_INT))))
336  return rcp(new TpetraMap<LocalOrdinal, GlobalOrdinal, Node>(Tpetra::createContigMapWithNode<int, GlobalOrdinal, Node>(numElements, localNumElements, comm)));
337 #else
338  TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::RuntimeError,
339  "Xpetra::MapFactory::createContigMapWithNode: Cannot create Xpetra::TpetraMap, since Tpetra is not instantiated on EpetraNode (Serial or OpenMP, depending on configuration) and/or GO=int");
340 #endif
341 #endif
342 
343  if (lib == UseEpetra) {
344  Teuchos::RCP<EpetraMapT<int, Node>> map;
345  map = Teuchos::rcp(new EpetraMapT<int, Node>(numElements, localNumElements,
346  0, // index base is zero
347  comm));
348  return map.getConst();
349  }
351 }
352 
353 Teuchos::RCP<const Map<int, int, EpetraNode>>
355  const Teuchos::RCP<const Teuchos::Comm<int>> &newComm) {
356  XPETRA_MONITOR("MapFactory::Build");
358  global_size_t INVALID = Teuchos::OrdinalTraits<global_size_t>::invalid();
359 
360  size_t Nlocal = oldmap->getLocalNumElements();
361  global_size_t Nglobal = oldmap->getGlobalNumElements();
362 
363  // Sanity check -- if there's no comm, we can't keep elements on the map (vice versa is OK)
364  TEUCHOS_TEST_FOR_EXCEPTION(Nlocal && newComm.is_null(),
365  std::logic_error, "MapFactory::copyMapWithNewComm needs the comm to match the map.");
366 
367  // We'll return null if we don't have a Comm on this rank
368  RCP<const Map<int, int, Node>> newMap;
369  if (!newComm.is_null()) {
370  if (oldmap->isContiguous()) {
371  newMap = XMF::Build(oldmap->lib(), INVALID, Nlocal, oldmap->getIndexBase(), newComm);
372  } else {
373  newMap = XMF::Build(oldmap->lib(), Nglobal, oldmap->getLocalElementList(), oldmap->getIndexBase(), newComm);
374  }
375  }
376 
377  return newMap;
379 }
380 
381 #endif // #if !defined(XPETRA_EPETRA_NO_32BIT_GLOBAL_INDICES)
382 
383 // we need the Epetra specialization only if Epetra is enabled
384 #if !defined(XPETRA_EPETRA_NO_64BIT_GLOBAL_INDICES)
385 
389 }
390 
391 RCP<Map<int, long long, EpetraNode>>
394  global_size_t numGlobalElements,
395  int indexBase,
396  const Teuchos::RCP<const Teuchos::Comm<int>> &comm,
397  LocalGlobal lg) {
398  XPETRA_MONITOR("MapFactory::Build");
399 
400 #ifdef HAVE_XPETRA_TPETRA
401  if (lib == UseTpetra)
402  return rcp(new TpetraMap<LocalOrdinal, GlobalOrdinal, Node>(numGlobalElements, indexBase, comm, lg));
403 #endif
404 
405  if (lib == UseEpetra)
406  return rcp(new EpetraMapT<long long, Node>(numGlobalElements, indexBase, comm, lg));
407 
409 }
410 
411 RCP<Map<int, long long, EpetraNode>>
414  global_size_t numGlobalElements,
415  size_t numLocalElements,
416  int indexBase,
417  const Teuchos::RCP<const Teuchos::Comm<int>> &comm) {
418  XPETRA_MONITOR("MapFactory::Build");
419 
420 #ifdef HAVE_XPETRA_TPETRA
421  if (lib == UseTpetra)
422  return rcp(new TpetraMap<LocalOrdinal, GlobalOrdinal, Node>(numGlobalElements, numLocalElements, indexBase, comm));
423 #endif
424 
425  if (lib == UseEpetra)
426  return rcp(new EpetraMapT<long long, Node>(numGlobalElements, numLocalElements, indexBase, comm));
427 
429 }
430 
431 RCP<Map<int, long long, EpetraNode>>
434  global_size_t numGlobalElements,
435  const Teuchos::ArrayView<const long long> &elementList,
436  int indexBase,
437  const Teuchos::RCP<const Teuchos::Comm<int>> &comm) {
438  XPETRA_MONITOR("MapFactory::Build");
439 
440 #ifdef HAVE_XPETRA_TPETRA
441  if (lib == UseTpetra)
442  return rcp(new TpetraMap<LocalOrdinal, GlobalOrdinal, Node>(numGlobalElements, elementList, indexBase, comm));
443 #endif
444 
445  if (lib == UseEpetra)
446  return rcp(new EpetraMapT<long long, Node>(numGlobalElements, elementList, indexBase, comm));
447 
449 }
450 
453 Teuchos::RCP<Map<int, long long, EpetraNode>>
455  Build(const Teuchos::RCP<const Map<int, long long, EpetraNode>> &map,
456  int numDofPerNode) {
457  XPETRA_MONITOR("MapFactory::Build");
458 
459  RCP<const BlockedMap<LocalOrdinal, GlobalOrdinal, Node>> bmap = Teuchos::rcp_dynamic_cast<const BlockedMap<LocalOrdinal, GlobalOrdinal, Node>>(map);
460  if (!bmap.is_null()) {
461  TEUCHOS_TEST_FOR_EXCEPTION(numDofPerNode != 1, Xpetra::Exceptions::RuntimeError,
462  "Xpetra::MapFactory::Build: When provided a BlockedMap numDofPerNode must set to be one. It is set to " << numDofPerNode << ".");
464  }
465 
466  LocalOrdinal N = map->getLocalNumElements();
467  Teuchos::ArrayView<const GlobalOrdinal> oldElements = map->getLocalElementList();
468  Teuchos::Array<GlobalOrdinal> newElements(map->getLocalNumElements() * numDofPerNode);
469  for (LocalOrdinal i = 0; i < N; i++)
470  for (LocalOrdinal j = 0; j < numDofPerNode; j++)
471  newElements[i * numDofPerNode + j] = oldElements[i] * numDofPerNode + j;
472 
473 #ifdef HAVE_XPETRA_TPETRA
474  if (map->lib() == UseTpetra)
475  return rcp(new TpetraMap<LocalOrdinal, GlobalOrdinal, Node>(map->getGlobalNumElements() * numDofPerNode, newElements, map->getIndexBase(), map->getComm()));
476 #endif
477 
478  if (map->lib() == UseEpetra)
479  return rcp(new EpetraMapT<long long, Node>(map->getGlobalNumElements() * numDofPerNode, newElements, map->getIndexBase(), map->getComm()));
480 
482 }
483 
484 #ifdef HAVE_XPETRA_TPETRA
485 Teuchos::RCP<Map<LocalOrdinal, GlobalOrdinal, Node>>
488  global_size_t numGlobalElements,
489  const Kokkos::View<const long long *, typename Node::device_type> &indexList,
490  long long indexBase,
491  const Teuchos::RCP<const Teuchos::Comm<int>> &comm) {
492  XPETRA_MONITOR("MapFactory::Build");
493  if (lib == UseTpetra)
494  return rcp(new TpetraMap<LocalOrdinal, GlobalOrdinal, Node>(numGlobalElements, indexList, indexBase, comm));
495  if (lib == UseEpetra) {
496  Teuchos::ArrayView<const long long> v(indexList.data(), indexList.size());
497  return rcp(new EpetraMapT<long long, Node>(numGlobalElements, v, indexBase, comm));
498  }
501 }
502 #endif // HAVE_XPETRA_TPETRA
503 
504 Teuchos::RCP<const Map<int, long long, EpetraNode>>
507  size_t numElements,
508  const Teuchos::RCP<const Teuchos::Comm<int>> &comm) {
509  XPETRA_MONITOR("MapFactory::Build");
510 
511 #ifdef HAVE_XPETRA_TPETRA
512  if (lib == UseTpetra)
513 #if ((defined(EPETRA_HAVE_OMP) && (defined(HAVE_TPETRA_INST_OPENMP) && defined(HAVE_TPETRA_INST_INT_LONG_LONG))) || \
514  (!defined(EPETRA_HAVE_OMP) && (defined(HAVE_TPETRA_INST_SERIAL) && defined(HAVE_TPETRA_INST_INT_LONG_LONG))))
515  return rcp(new TpetraMap<LocalOrdinal, GlobalOrdinal, Node>(Tpetra::createLocalMapWithNode<LocalOrdinal, GlobalOrdinal, Node>(numElements, comm)));
516 #else
517  TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::RuntimeError,
518  "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");
519 #endif
520 #endif
521 
522  if (lib == UseEpetra)
524 
526 }
527 
528 Teuchos::RCP<const Map<int, long long, EpetraNode>>
531  size_t numElements,
532  const Teuchos::RCP<const Teuchos::Comm<int>> &comm) {
533  XPETRA_MONITOR("MapFactory::Build");
534 
535 #ifdef HAVE_XPETRA_TPETRA
536  if (lib == UseTpetra)
537 #if ((defined(EPETRA_HAVE_OMP) && (defined(HAVE_TPETRA_INST_OPENMP) && defined(HAVE_TPETRA_INST_INT_LONG_LONG))) || \
538  (!defined(EPETRA_HAVE_OMP) && (defined(HAVE_TPETRA_INST_SERIAL) && defined(HAVE_TPETRA_INST_INT_LONG_LONG))))
539  return rcp(new TpetraMap<LocalOrdinal, GlobalOrdinal, Node>(Tpetra::createLocalMapWithNode<int, GlobalOrdinal, Node>(numElements, comm)));
540 #else
541  TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::RuntimeError,
542  "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");
543 #endif
544 #endif
545 
546  if (lib == UseEpetra) {
547  Teuchos::RCP<EpetraMapT<long long, Node>> map;
548  map = Teuchos::rcp(new EpetraMapT<long long, Node>((Xpetra::global_size_t)numElements, // num elements, global and local
549  0, // index base is zero
550  comm, LocallyReplicated));
551  return map.getConst();
552  }
554 }
555 
556 Teuchos::RCP<const Map<int, long long, EpetraNode>>
559  global_size_t numElements,
560  const Teuchos::RCP<const Teuchos::Comm<int>> &comm) {
561  XPETRA_MONITOR("MapFactory::Build");
562 
563 #ifdef HAVE_XPETRA_TPETRA
564  if (lib == UseTpetra)
565 #if ((defined(EPETRA_HAVE_OMP) && (defined(HAVE_TPETRA_INST_OPENMP) && defined(HAVE_TPETRA_INST_INT_LONG_LONG))) || \
566  (!defined(EPETRA_HAVE_OMP) && (defined(HAVE_TPETRA_INST_SERIAL) && defined(HAVE_TPETRA_INST_INT_LONG_LONG))))
567  return rcp(new TpetraMap<LocalOrdinal, GlobalOrdinal, Node>(Tpetra::createUniformContigMapWithNode<int, GlobalOrdinal, Node>(numElements, comm)));
568 #else
569  TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::RuntimeError,
570  "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");
571 #endif
572 #endif
573 
574  if (lib == UseEpetra) {
575  Teuchos::RCP<EpetraMapT<long long, Node>> map;
576  map = Teuchos::rcp(new EpetraMapT<long long, Node>(numElements, // num elements, global and local
577  0, // index base is zero
578  comm, GloballyDistributed));
579  return map.getConst();
580  }
582 }
583 
584 Teuchos::RCP<const Map<int, long long, EpetraNode>>
587  global_size_t numElements,
588  const Teuchos::RCP<const Teuchos::Comm<int>> &comm) {
589  XPETRA_MONITOR("MapFactory::Build");
590 
591 #ifdef HAVE_XPETRA_TPETRA
592  if (lib == UseTpetra)
593 #if ((defined(EPETRA_HAVE_OMP) && (defined(HAVE_TPETRA_INST_OPENMP) && defined(HAVE_TPETRA_INST_INT_LONG_LONG))) || \
594  (!defined(EPETRA_HAVE_OMP) && (defined(HAVE_TPETRA_INST_SERIAL) && defined(HAVE_TPETRA_INST_INT_LONG_LONG))))
595  return rcp(new TpetraMap<LocalOrdinal, GlobalOrdinal, Node>(Tpetra::createUniformContigMapWithNode<LocalOrdinal, GlobalOrdinal, Node>(numElements, comm)));
596 #else
597  TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::RuntimeError,
598  "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");
599 #endif
600 #endif
601 
602  if (lib == UseEpetra)
604 
606 }
607 
608 Teuchos::RCP<const Map<int, long long, EpetraNode>>
610  global_size_t numElements,
611  size_t localNumElements,
612  const Teuchos::RCP<const Teuchos::Comm<int>> &comm) {
613  XPETRA_MONITOR("MapFactory::Build");
614 
615 #ifdef HAVE_XPETRA_TPETRA
616  if (lib == UseTpetra)
617 #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))))
619  Tpetra::createContigMapWithNode<int, GlobalOrdinal, Node>(numElements, localNumElements, comm)));
620 #else
621  TEUCHOS_TEST_FOR_EXCEPTION(true,
623  "Xpetra::MapFactory::createContigMap: Cannot create Xpetra::TpetraMap, since Tpetra is not instantiated on "
624  "EpetraNode (Serial or OpenMP, depending on configuration) and/or GO=long long");
625 #endif
626 #endif
627 
628  if (lib == UseEpetra)
629  return MapFactory<int, GlobalOrdinal, Node>::createContigMapWithNode(lib, numElements, localNumElements, comm);
630 
632 }
633 
634 Teuchos::RCP<const Map<int, long long, EpetraNode>>
637  global_size_t numElements,
638  size_t localNumElements,
639  const Teuchos::RCP<const Teuchos::Comm<int>> &comm) {
640  XPETRA_MONITOR("MapFactory::Build");
641 
642 #ifdef HAVE_XPETRA_TPETRA
643  if (lib == UseTpetra)
644 #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))))
646  Tpetra::createContigMapWithNode<int, GlobalOrdinal, Node>(numElements, localNumElements, comm)));
647 #else
648  TEUCHOS_TEST_FOR_EXCEPTION(true,
650  "Xpetra::MapFactory::createContigMapWithNode: Cannot create Xpetra::TpetraMap, since Tpetra is not "
651  "instantiated on EpetraNode (Serial or OpenMP, depending on configuration) and/or GO=long long");
652 #endif
653 #endif // HAVE_XPETRA_TPETRA
654 
655  if (lib == UseEpetra) {
656  Teuchos::RCP<EpetraMapT<long long, Node>> map;
657  map = Teuchos::rcp(new EpetraMapT<long long, Node>(numElements,
658  localNumElements,
659  0, // index base is zero
660  comm));
661  return map.getConst();
662  }
663 
665 }
666 
667 Teuchos::RCP<const Map<int, long long, EpetraNode>>
669  const Teuchos::RCP<const Teuchos::Comm<int>> &newComm) {
670  XPETRA_MONITOR("MapFactory::Build");
672  global_size_t INVALID = Teuchos::OrdinalTraits<global_size_t>::invalid();
673 
674  size_t Nlocal = oldmap->getLocalNumElements();
675  global_size_t Nglobal = oldmap->getGlobalNumElements();
676 
677  // Sanity check -- if there's no comm, we can't keep elements on the map (vice versa is OK)
678  TEUCHOS_TEST_FOR_EXCEPTION(Nlocal && newComm.is_null(),
679  std::logic_error, "MapFactory::copyMapWithNewComm needs the comm to match the map.");
680 
681  // We'll return null if we don't have a Comm on this rank
682  RCP<const Map<int, long long, Node>> newMap;
683  if (!newComm.is_null()) {
684  if (oldmap->isContiguous()) {
685  newMap = XMF::Build(oldmap->lib(), INVALID, Nlocal, oldmap->getIndexBase(), newComm);
686  } else {
687  newMap = XMF::Build(oldmap->lib(), Nglobal, oldmap->getLocalElementList(), oldmap->getIndexBase(), newComm);
688  }
689  }
690 
691  return newMap;
693 }
694 
695 #endif // #if !defined(XPETRA_EPETRA_NO_64BIT_GLOBAL_INDICES)
696 
697 #endif // #if defined(HAVE_XPETRA_EPETRA)
698 
699 } // namespace Xpetra
700 
701 // 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.