10 #include "Xpetra_MapFactory.hpp"
12 #include "Xpetra_BlockedMap.hpp"
14 #ifdef HAVE_XPETRA_TPETRA
15 #include "Xpetra_TpetraMap.hpp"
20 #if defined(HAVE_XPETRA_EPETRA)
22 #if !defined(XPETRA_EPETRA_NO_32BIT_GLOBAL_INDICES)
28 RCP<Map<int, int, EpetraNode>>
33 const Teuchos::RCP<
const Teuchos::Comm<int>> &comm,
37 #ifdef HAVE_XPETRA_TPETRA
48 RCP<Map<int, int, EpetraNode>>
52 size_t numLocalElements,
54 const Teuchos::RCP<
const Teuchos::Comm<int>> &comm) {
57 #ifdef HAVE_XPETRA_TPETRA
68 RCP<Map<int, int, EpetraNode>>
72 const Teuchos::ArrayView<const int> &elementList,
74 const Teuchos::RCP<
const Teuchos::Comm<int>> &comm) {
76 #ifdef HAVE_XPETRA_TPETRA
79 #endif // HAVE_XPETRA_TPETRA
89 Teuchos::RCP<Map<int, int, EpetraNode>>
92 const int numDofPerNode,
const int gidOffset) {
96 if (!bmap.is_null()) {
98 "Xpetra::MapFactory::Build: When provided a BlockedMap numDofPerNode must set to be one. It is set to " << numDofPerNode <<
".");
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;
111 #ifdef HAVE_XPETRA_TPETRA
113 return rcp(
new TpetraMap<LocalOrdinal, GlobalOrdinal, Node>(map->getGlobalNumElements() * numDofPerNode, newElements, map->getIndexBase(), map->getComm()));
115 #endif // HAVE_XPETRA_TPETRA
118 return rcp(
new EpetraMapT<int, Node>(map->getGlobalNumElements() * numDofPerNode, newElements, map->getIndexBase(), map->getComm()));
124 Teuchos::RCP<const Map<int, int, EpetraNode>>
128 const Teuchos::RCP<
const Teuchos::Comm<int>> &comm) {
131 #ifdef HAVE_XPETRA_TPETRA
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))))
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");
140 #endif // HAVE_XPETRA_TPETRA
143 Teuchos::RCP<EpetraMapT<int, Node>> map;
147 return map.getConst();
155 #ifdef HAVE_XPETRA_TPETRA
156 Teuchos::RCP<Map<int, int, EpetraNode>>
160 const Kokkos::View<const int *, typename Node::device_type> &indexList,
162 const Teuchos::RCP<
const Teuchos::Comm<int>> &comm) {
167 Teuchos::ArrayView<const int> v(indexList.data(), indexList.size());
172 #endif // HAVE_XPETRA_TPETRA
174 Teuchos::RCP<const Map<int, int, EpetraNode>>
178 const Teuchos::RCP<
const Teuchos::Comm<int>> &comm) {
181 #ifdef HAVE_XPETRA_TPETRA
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))))
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");
190 #endif // HAVE_XPETRA_TPETRA
193 Teuchos::RCP<EpetraMapT<int, Node>> map;
197 return map.getConst();
205 Teuchos::RCP<const Map<int, int, EpetraNode>>
209 const Teuchos::RCP<
const Teuchos::Comm<int>> &comm) {
212 #ifdef HAVE_XPETRA_TPETRA
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))))
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");
221 #endif // HAVE_XPETRA_TPETRA
224 Teuchos::RCP<EpetraMapT<int, Node>> map;
228 return map.getConst();
234 Teuchos::RCP<const Map<int, int, EpetraNode>>
238 const Teuchos::RCP<
const Teuchos::Comm<int>> &comm) {
241 #ifdef HAVE_XPETRA_TPETRA
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))))
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");
250 #endif // HAVE_XPETRA_TPETRA
253 Teuchos::RCP<EpetraMapT<int, Node>> map;
257 return map.getConst();
262 Teuchos::RCP<const Map<int, int, EpetraNode>>
266 size_t localNumElements,
267 const Teuchos::RCP<
const Teuchos::Comm<int>> &comm) {
270 #ifdef HAVE_XPETRA_TPETRA
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))))
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");
288 Teuchos::RCP<const Map<int, int, EpetraNode>>
292 size_t localNumElements,
293 const Teuchos::RCP<
const Teuchos::Comm<int>> &comm) {
296 #ifdef HAVE_XPETRA_TPETRA
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))))
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");
308 Teuchos::RCP<EpetraMapT<int, Node>> map;
312 return map.getConst();
317 Teuchos::RCP<const Map<int, int, EpetraNode>>
319 const Teuchos::RCP<
const Teuchos::Comm<int>> &newComm) {
322 global_size_t INVALID = Teuchos::OrdinalTraits<global_size_t>::invalid();
324 size_t Nlocal = oldmap->getLocalNumElements();
328 TEUCHOS_TEST_FOR_EXCEPTION(Nlocal && newComm.is_null(),
329 std::logic_error,
"MapFactory::copyMapWithNewComm needs the comm to match the map.");
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);
337 newMap = XMF::Build(oldmap->lib(), Nglobal, oldmap->getLocalElementList(), oldmap->getIndexBase(), newComm);
345 #endif // #if !defined(XPETRA_EPETRA_NO_32BIT_GLOBAL_INDICES)
348 #if !defined(XPETRA_EPETRA_NO_64BIT_GLOBAL_INDICES)
355 RCP<Map<int, long long, EpetraNode>>
360 const Teuchos::RCP<
const Teuchos::Comm<int>> &comm,
364 #ifdef HAVE_XPETRA_TPETRA
375 RCP<Map<int, long long, EpetraNode>>
379 size_t numLocalElements,
381 const Teuchos::RCP<
const Teuchos::Comm<int>> &comm) {
384 #ifdef HAVE_XPETRA_TPETRA
395 RCP<Map<int, long long, EpetraNode>>
399 const Teuchos::ArrayView<const long long> &elementList,
401 const Teuchos::RCP<
const Teuchos::Comm<int>> &comm) {
404 #ifdef HAVE_XPETRA_TPETRA
417 Teuchos::RCP<Map<int, long long, EpetraNode>>
424 if (!bmap.is_null()) {
426 "Xpetra::MapFactory::Build: When provided a BlockedMap numDofPerNode must set to be one. It is set to " << numDofPerNode <<
".");
431 Teuchos::ArrayView<const GlobalOrdinal> oldElements = map->getLocalElementList();
432 Teuchos::Array<GlobalOrdinal> newElements(map->getLocalNumElements() * numDofPerNode);
435 newElements[i * numDofPerNode + j] = oldElements[i] * numDofPerNode + j;
437 #ifdef HAVE_XPETRA_TPETRA
443 return rcp(
new EpetraMapT<long long, Node>(map->getGlobalNumElements() * numDofPerNode, newElements, map->getIndexBase(), map->getComm()));
448 #ifdef HAVE_XPETRA_TPETRA
449 Teuchos::RCP<Map<LocalOrdinal, GlobalOrdinal, Node>>
453 const Kokkos::View<const long long *, typename Node::device_type> &indexList,
455 const Teuchos::RCP<
const Teuchos::Comm<int>> &comm) {
460 Teuchos::ArrayView<const long long> v(indexList.data(), indexList.size());
466 #endif // HAVE_XPETRA_TPETRA
468 Teuchos::RCP<const Map<int, long long, EpetraNode>>
472 const Teuchos::RCP<
const Teuchos::Comm<int>> &comm) {
475 #ifdef HAVE_XPETRA_TPETRA
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))))
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");
492 Teuchos::RCP<const Map<int, long long, EpetraNode>>
496 const Teuchos::RCP<
const Teuchos::Comm<int>> &comm) {
499 #ifdef HAVE_XPETRA_TPETRA
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))))
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");
511 Teuchos::RCP<EpetraMapT<long long, Node>> map;
515 return map.getConst();
520 Teuchos::RCP<const Map<int, long long, EpetraNode>>
524 const Teuchos::RCP<
const Teuchos::Comm<int>> &comm) {
527 #ifdef HAVE_XPETRA_TPETRA
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))))
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");
539 Teuchos::RCP<EpetraMapT<long long, Node>> map;
543 return map.getConst();
548 Teuchos::RCP<const Map<int, long long, EpetraNode>>
552 const Teuchos::RCP<
const Teuchos::Comm<int>> &comm) {
555 #ifdef HAVE_XPETRA_TPETRA
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))))
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");
572 Teuchos::RCP<const Map<int, long long, EpetraNode>>
575 size_t localNumElements,
576 const Teuchos::RCP<
const Teuchos::Comm<int>> &comm) {
579 #ifdef HAVE_XPETRA_TPETRA
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)));
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");
598 Teuchos::RCP<const Map<int, long long, EpetraNode>>
602 size_t localNumElements,
603 const Teuchos::RCP<
const Teuchos::Comm<int>> &comm) {
606 #ifdef HAVE_XPETRA_TPETRA
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)));
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");
617 #endif // HAVE_XPETRA_TPETRA
620 Teuchos::RCP<EpetraMapT<long long, Node>> map;
625 return map.getConst();
631 Teuchos::RCP<const Map<int, long long, EpetraNode>>
633 const Teuchos::RCP<
const Teuchos::Comm<int>> &newComm) {
636 global_size_t INVALID = Teuchos::OrdinalTraits<global_size_t>::invalid();
638 size_t Nlocal = oldmap->getLocalNumElements();
642 TEUCHOS_TEST_FOR_EXCEPTION(Nlocal && newComm.is_null(),
643 std::logic_error,
"MapFactory::copyMapWithNewComm needs the comm to match the map.");
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);
651 newMap = XMF::Build(oldmap->lib(), Nglobal, oldmap->getLocalElementList(), oldmap->getIndexBase(), newComm);
659 #endif // #if !defined(XPETRA_EPETRA_NO_64BIT_GLOBAL_INDICES)
661 #endif // #if defined(HAVE_XPETRA_EPETRA)
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.