Xpetra_MapFactory.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_HPP
47 #define XPETRA_MAPFACTORY_HPP
48 
49 #include "Xpetra_ConfigDefs.hpp"
50 #include "Xpetra_Map.hpp"
51 
52 #ifdef HAVE_XPETRA_TPETRA
53 # include "Xpetra_TpetraMap.hpp"
54 #endif
55 #ifdef HAVE_XPETRA_EPETRA
56 # include "Xpetra_EpetraMap.hpp"
57 #endif
58 #include "Xpetra_BlockedMap.hpp"
59 
60 #include "Xpetra_Exceptions.hpp"
61 
62 namespace Xpetra {
63 
69  template <class LocalOrdinal = Map<>::local_ordinal_type,
70  class GlobalOrdinal = typename Map<LocalOrdinal>::global_ordinal_type,
71  class Node = typename Map<LocalOrdinal, GlobalOrdinal>::node_type>
72  class MapFactory {
73 
74  private:
77 
78  public:
80  // Workaround function for a deferred visual studio bug
81  //
82  // http://connect.microsoft.com/VisualStudio/feedback/details/719847/erroneous-error-c2783-could-not-deduce-template-argument
83  //
84  // Use this function for default arguments rather than calling
85  // what is the return value below. Also helps in reducing
86  // duplication in various constructors.
87  return KokkosClassic::Details::getNode<Node>();
88  }
89 
93  global_size_t numGlobalElements,
94  GlobalOrdinal indexBase,
95  const Teuchos::RCP<const Teuchos::Comm<int> > &comm,
97  const Teuchos::RCP<Node> &node = defaultArgNode ())
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, node) );
104 #endif
105 
108  }
109 
113  global_size_t numGlobalElements,
114  size_t numLocalElements,
115  GlobalOrdinal indexBase,
116  const Teuchos::RCP<const Teuchos::Comm<int> > &comm,
117  const Teuchos::RCP<Node> &node = defaultArgNode ())
118  {
119  XPETRA_MONITOR("MapFactory::Build");
120 
121 #ifdef HAVE_XPETRA_TPETRA
122  if (lib == UseTpetra)
123  return rcp( new TpetraMap<LocalOrdinal,GlobalOrdinal, Node> (numGlobalElements, numLocalElements, indexBase, comm, node) );
124 #endif
125 
128  }
129 
133  global_size_t numGlobalElements,
134  const Teuchos::ArrayView<const GlobalOrdinal> &elementList,
135  GlobalOrdinal indexBase,
136  const Teuchos::RCP<const Teuchos::Comm<int> > &comm,
137  const Teuchos::RCP<Node> &node = defaultArgNode ())
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, elementList, indexBase, comm, node) );
144 #endif
145 
148  }
149 
154  LocalOrdinal numDofPerNode)
155  {
156  XPETRA_MONITOR("MapFactory::Build");
157 
159  if(!bmap.is_null()) {
161  "Xpetra::MapFactory::Build: When provided a BlockedMap numDofPerNode must set to be one. It is set to " << numDofPerNode << ".");
163  }
164 
165 #ifdef HAVE_XPETRA_TPETRA
166  LocalOrdinal N = map->getNodeNumElements();
167  Teuchos::ArrayView<const GlobalOrdinal> oldElements = map->getNodeElementList();
168  Teuchos::Array<GlobalOrdinal> newElements(map->getNodeNumElements()*numDofPerNode);
169  for (LocalOrdinal i = 0; i < N; i++)
170  for (LocalOrdinal j = 0; j < numDofPerNode; j++)
171  newElements[i*numDofPerNode + j] = oldElements[i]*numDofPerNode + j;
172  if (map->lib() == UseTpetra)
173  return rcp( new TpetraMap<LocalOrdinal,GlobalOrdinal, Node> (map->getGlobalNumElements()*numDofPerNode, newElements, map->getIndexBase(), map->getComm(), map->getNode()) );
174 #endif
175 
176  XPETRA_FACTORY_ERROR_IF_EPETRA(map->lib());
178  }
179 
183  size_t numElements,
184  const Teuchos::RCP< const Teuchos::Comm< int > > &comm)
185  {
186  XPETRA_MONITOR("MapFactory::Build");
187 
188 #ifdef HAVE_XPETRA_TPETRA
189  if (lib == UseTpetra)
190  return rcp(new Xpetra::TpetraMap<LocalOrdinal,GlobalOrdinal,Node>(Tpetra::createLocalMap<LocalOrdinal,GlobalOrdinal>(numElements, comm)));
191 #endif
192 
195  }
196 
200  size_t numElements,
201  const Teuchos::RCP< const Teuchos::Comm< int > > &comm,
202  const Teuchos::RCP< Node > &node)
203  {
204  XPETRA_MONITOR("MapFactory::Build");
205 
206 #ifdef HAVE_XPETRA_TPETRA
207  if (lib == UseTpetra)
208  return rcp(new TpetraMap<LocalOrdinal,GlobalOrdinal, Node> (Tpetra::createLocalMapWithNode<LocalOrdinal,GlobalOrdinal,Node>(numElements, comm, node)));
209 #endif
210 
213  }
214 
218  global_size_t numElements,
219  const Teuchos::RCP< const Teuchos::Comm< int > > &comm,
220  const Teuchos::RCP< Node > &node)
221  {
222  XPETRA_MONITOR("MapFactory::Build");
223 
224 #ifdef HAVE_XPETRA_TPETRA
225  if (lib == UseTpetra)
226  return rcp(new TpetraMap<LocalOrdinal,GlobalOrdinal, Node> (Tpetra::createUniformContigMapWithNode<LocalOrdinal,GlobalOrdinal,Node>(numElements, comm, node)));
227 #endif
228 
231  }
232 
236  global_size_t numElements,
237  const Teuchos::RCP< const Teuchos::Comm< int > > &comm)
238  {
239  XPETRA_MONITOR("MapFactory::Build");
240 
241 #ifdef HAVE_XPETRA_TPETRA
242  if (lib == UseTpetra)
243  return rcp(new Xpetra::TpetraMap<LocalOrdinal,GlobalOrdinal,Node>(Tpetra::createUniformContigMapWithNode<LocalOrdinal,GlobalOrdinal,Node>(numElements, comm)));
244 #endif
245 
248  }
249 
253  global_size_t numElements,
254  size_t localNumElements,
255  const Teuchos::RCP< const Teuchos::Comm< int > > &comm)
256  {
257  XPETRA_MONITOR("MapFactory::Build");
258 
259 #ifdef HAVE_XPETRA_TPETRA
260  if (lib == UseTpetra)
261  return rcp(new Xpetra::TpetraMap<LocalOrdinal,GlobalOrdinal,Node>(Tpetra::createContigMapWithNode<LocalOrdinal,GlobalOrdinal,Node>(numElements, localNumElements, comm)));
262 #endif
263 
266  }
267 
271  global_size_t numElements,
272  size_t localNumElements,
273  const Teuchos::RCP< const Teuchos::Comm< int > > &comm,
274  const Teuchos::RCP< Node > &node)
275  {
276  XPETRA_MONITOR("MapFactory::Build");
277 
278 #ifdef HAVE_XPETRA_TPETRA
279  if (lib == UseTpetra)
280  return rcp(new TpetraMap<LocalOrdinal,GlobalOrdinal, Node> (Tpetra::createContigMapWithNode<LocalOrdinal,GlobalOrdinal,Node>(numElements, localNumElements, comm, node)));
281 #endif
282 
285  }
286  };
287 
288 // we need the Epetra specialization only if Epetra is enabled
289 #if (defined(HAVE_XPETRA_EPETRA) && !defined(XPETRA_EPETRA_NO_32BIT_GLOBAL_INDICES))
290  template <>
291  class MapFactory<int, int, EpetraNode> {
292 
293  typedef int LocalOrdinal;
294  typedef int GlobalOrdinal;
295  typedef EpetraNode Node;
296 
297  private:
300 
301  public:
302 
304  // Workaround function for a deferred visual studio bug
305  //
306  // http://connect.microsoft.com/VisualStudio/feedback/details/719847/erroneous-error-c2783-could-not-deduce-template-argument
307  //
308  // Use this function for default arguments rather than calling
309  // what is the return value below. Also helps in reducing
310  // duplication in various constructors.
311  return KokkosClassic::Details::getNode<Node>();
312  }
313 
316  global_size_t numGlobalElements,
317  int indexBase,
318  const Teuchos::RCP<const Teuchos::Comm<int> > &comm,
320  const Teuchos::RCP<Node>& node = defaultArgNode ()) {
321  XPETRA_MONITOR("MapFactory::Build");
322 
323 #ifdef HAVE_XPETRA_TPETRA
324  if (lib == UseTpetra)
325  return rcp( new TpetraMap<LocalOrdinal,GlobalOrdinal, Node> (numGlobalElements, indexBase, comm, lg, node) );
326 #endif
327 
328  if (lib == UseEpetra)
329  return rcp( new EpetraMapT<int, Node>(numGlobalElements, indexBase, comm, lg, node) );
330 
332  }
333 
336  global_size_t numGlobalElements,
337  size_t numLocalElements,
338  int indexBase,
339  const Teuchos::RCP<const Teuchos::Comm<int> > &comm,
340  const Teuchos::RCP<Node>& node = defaultArgNode())
341  {
342  XPETRA_MONITOR("MapFactory::Build");
343 #ifdef HAVE_XPETRA_TPETRA
344  if (lib == UseTpetra)
345  return rcp( new TpetraMap<LocalOrdinal,GlobalOrdinal, Node> (numGlobalElements, numLocalElements, indexBase, comm, node) );
346 #endif
347 
348  if (lib == UseEpetra)
349  return rcp( new EpetraMapT<int, Node>(numGlobalElements, numLocalElements, indexBase, comm, node) );
350 
352  }
353 
354  static RCP<Map<LocalOrdinal,GlobalOrdinal, Node> > Build(UnderlyingLib lib, global_size_t numGlobalElements, const Teuchos::ArrayView<const GlobalOrdinal> &elementList, int indexBase, const Teuchos::RCP<const Teuchos::Comm<int> > &comm, const Teuchos::RCP<Node>& node = defaultArgNode ()) {
355  XPETRA_MONITOR("MapFactory::Build");
356 #ifdef HAVE_XPETRA_TPETRA
357  if (lib == UseTpetra)
358  return rcp( new TpetraMap<LocalOrdinal,GlobalOrdinal, Node> (numGlobalElements, elementList, indexBase, comm, node) );
359 #endif
360 
361  if (lib == UseEpetra)
362  return rcp( new EpetraMapT<int, Node>(numGlobalElements, elementList, indexBase, comm, node) );
363 
365  }
366 
370  XPETRA_MONITOR("MapFactory::Build");
371 
373  if(!bmap.is_null()) {
375  "Xpetra::MapFactory::Build: When provided a BlockedMap numDofPerNode must set to be one. It is set to " << numDofPerNode << ".");
377  }
378 
379  LocalOrdinal N = map->getNodeNumElements();
380  Teuchos::ArrayView<const GlobalOrdinal> oldElements = map->getNodeElementList();
381  Teuchos::Array<GlobalOrdinal> newElements(map->getNodeNumElements()*numDofPerNode);
382  for (LocalOrdinal i = 0; i < N; i++)
383  for (LocalOrdinal j = 0; j < numDofPerNode; j++)
384  newElements[i*numDofPerNode + j] = oldElements[i]*numDofPerNode + j;
385 
386 #ifdef HAVE_XPETRA_TPETRA
387  if (map->lib() == UseTpetra)
388  return rcp( new TpetraMap<LocalOrdinal,GlobalOrdinal, Node> (map->getGlobalNumElements()*numDofPerNode, newElements, map->getIndexBase(), map->getComm(), map->getNode()) );
389 #endif
390 
391  if (map->lib() == UseEpetra)
392  return rcp( new EpetraMapT<int, Node>(map->getGlobalNumElements()*numDofPerNode, newElements, map->getIndexBase(), map->getComm(), map->getNode()) );
393 
395  }
396 
398  createLocalMap(UnderlyingLib lib, size_t numElements, const Teuchos::RCP< const Teuchos::Comm< int > > &comm) {
399  XPETRA_MONITOR("MapFactory::Build");
400 
401 #ifdef HAVE_XPETRA_TPETRA
402  if (lib == UseTpetra)
403 #if ((defined(EPETRA_HAVE_OMP) && (defined(HAVE_TPETRA_INST_OPENMP) && defined(HAVE_TPETRA_INST_INT_INT))) || \
404  (!defined(EPETRA_HAVE_OMP) && (defined(HAVE_TPETRA_INST_SERIAL) && defined(HAVE_TPETRA_INST_INT_INT))))
405  return rcp( new TpetraMap<LocalOrdinal,GlobalOrdinal, Node> (Tpetra::createLocalMapWithNode<LocalOrdinal,GlobalOrdinal, Node>(numElements, comm)));
406 #else
408  "Xpetra::MapFactory::createLocalMap: Cannot create Xpetra::TpetraMap, since Tpetra is not instantiated on EpetraNode (Serial or OpenMP, depending on configuration) and/or GO=int");
409 #endif
410 #endif
411 
412  if (lib == UseEpetra) {
414  map = Teuchos::rcp( new EpetraMapT<int, Node>((Xpetra::global_size_t)numElements, // num elements, global and local
415  0, // index base is zero
416  comm, LocallyReplicated));
417  return map.getConst();
418  }
419 
421  }
422 
423  // TODO remove this
425  createLocalMapWithNode(UnderlyingLib lib, size_t numElements, const Teuchos::RCP< const Teuchos::Comm< int > > &comm, const Teuchos::RCP<Node> &node) {
426  XPETRA_MONITOR("MapFactory::Build");
427 
428 #ifdef HAVE_XPETRA_TPETRA
429  if (lib == UseTpetra)
430 #if ((defined(EPETRA_HAVE_OMP) && (defined(HAVE_TPETRA_INST_OPENMP) && defined(HAVE_TPETRA_INST_INT_INT))) || \
431  (!defined(EPETRA_HAVE_OMP) && (defined(HAVE_TPETRA_INST_SERIAL) && defined(HAVE_TPETRA_INST_INT_INT))))
432  return rcp (new TpetraMap<LocalOrdinal,GlobalOrdinal, Node> (Tpetra::createLocalMapWithNode<int, GlobalOrdinal, Node> (numElements, comm, node)));
433 #else
435  "Xpetra::MapFactory::createLocalMapWithNode: Cannot create Xpetra::TpetraMap, since Tpetra is not instantiated on EpetraNode (Serial or OpenMP, depending on configuration) and/or GO=int");
436 #endif
437 #endif
438 
439  if (lib == UseEpetra) {
441  map = Teuchos::rcp( new EpetraMapT<int, Node>((Xpetra::global_size_t)numElements, // num elements, global and local
442  0, // index base is zero
443  comm, LocallyReplicated, node));
444  return map.getConst();
445  }
446 
448  }
449 
450  // TODO remove this
453  const Teuchos::RCP< const Teuchos::Comm< int > > &comm,
454  const Teuchos::RCP<Node>& node)
455  {
456  XPETRA_MONITOR("MapFactory::Build");
457 
458 #ifdef HAVE_XPETRA_TPETRA
459  if (lib == UseTpetra)
460 #if ((defined(EPETRA_HAVE_OMP) && (defined(HAVE_TPETRA_INST_OPENMP) && defined(HAVE_TPETRA_INST_INT_INT))) || \
461  (!defined(EPETRA_HAVE_OMP) && (defined(HAVE_TPETRA_INST_SERIAL) && defined(HAVE_TPETRA_INST_INT_INT))))
462  return rcp (new TpetraMap<LocalOrdinal,GlobalOrdinal, Node> (Tpetra::createUniformContigMapWithNode<int,GlobalOrdinal,Node> (numElements, comm, node)));
463 #else
465  "Xpetra::MapFactory::createUniformContigMapWithNode: Cannot create Xpetra::TpetraMap, since Tpetra is not instantiated on EpetraNode (Serial or OpenMP, depending on configuration) and/or GO=int");
466 #endif
467 #endif
468 
469  if (lib == UseEpetra) {
471  map = Teuchos::rcp( new EpetraMapT<int,Node>(numElements, // num elements, global and local
472  0, //index base is zero
473  comm, GloballyDistributed, node));
474  return map.getConst();
475  }
476 
478  }
479 
482  XPETRA_MONITOR("MapFactory::Build");
483 
484 #ifdef HAVE_XPETRA_TPETRA
485  if (lib == UseTpetra)
486 #if ((defined(EPETRA_HAVE_OMP) && (defined(HAVE_TPETRA_INST_OPENMP) && defined(HAVE_TPETRA_INST_INT_INT))) || \
487  (!defined(EPETRA_HAVE_OMP) && (defined(HAVE_TPETRA_INST_SERIAL) && defined(HAVE_TPETRA_INST_INT_INT))))
488  return rcp( new TpetraMap<LocalOrdinal,GlobalOrdinal, Node> (Tpetra::createUniformContigMapWithNode<LocalOrdinal,GlobalOrdinal, Node>(numElements, comm)));
489 #else
491  "Xpetra::MapFactory::createUniformContigMapWithNode: Cannot create Xpetra::TpetraMap, since Tpetra is not instantiated on EpetraNode (Serial or OpenMP, depending on configuration) and/or GO=int");
492 #endif
493 #endif
494 
495  if (lib == UseEpetra) {
496 
498  map = Teuchos::rcp( new EpetraMapT<int,Node>(numElements, // num elements, global and local
499  0, //index base is zero
500  comm, GloballyDistributed));
501  return map.getConst();
502  }
503 
505  }
506 
508  createContigMap(UnderlyingLib lib, global_size_t numElements, size_t localNumElements, 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_INT))) || \
514  (!defined(EPETRA_HAVE_OMP) && (defined(HAVE_TPETRA_INST_SERIAL) && defined(HAVE_TPETRA_INST_INT_INT))))
515  return rcp( new TpetraMap<LocalOrdinal,GlobalOrdinal, Node> (Tpetra::createContigMapWithNode<int,GlobalOrdinal,Node>(numElements, localNumElements, comm)));
516 #else
518  "Xpetra::MapFactory::createContigMap: Cannot create Xpetra::TpetraMap, since Tpetra is not instantiated on EpetraNode (Serial or OpenMP, depending on configuration) and/or GO=int");
519 #endif
520 #endif
521 
522  if (lib == UseEpetra)
523  return MapFactory<int, GlobalOrdinal, Node>::createContigMapWithNode(lib, numElements, localNumElements, comm, defaultArgNode() );
524 
526  }
527 
529  createContigMapWithNode(UnderlyingLib lib, global_size_t numElements, size_t localNumElements,
530  const Teuchos::RCP< const Teuchos::Comm< int > > &comm, const Teuchos::RCP<Node> &node) {
531  XPETRA_MONITOR("MapFactory::Build");
532 
533 #ifdef HAVE_XPETRA_TPETRA
534  if (lib == UseTpetra)
535 #if ((defined(EPETRA_HAVE_OMP) && (defined(HAVE_TPETRA_INST_OPENMP) && defined(HAVE_TPETRA_INST_INT_INT))) || \
536  (!defined(EPETRA_HAVE_OMP) && (defined(HAVE_TPETRA_INST_SERIAL) && defined(HAVE_TPETRA_INST_INT_INT))))
537  return rcp( new TpetraMap<LocalOrdinal,GlobalOrdinal, Node> (Tpetra::createContigMapWithNode<int,GlobalOrdinal,Node>(numElements, localNumElements, comm, node)));
538 #else
540  "Xpetra::MapFactory::createContigMapWithNode: Cannot create Xpetra::TpetraMap, since Tpetra is not instantiated on EpetraNode (Serial or OpenMP, depending on configuration) and/or GO=int");
541 #endif
542 #endif
543 
544  if (lib == UseEpetra) {
545 
547  map = Teuchos::rcp( new EpetraMapT<int, Node>(numElements,localNumElements,
548  0, // index base is zero
549  comm, node) );
550  return map.getConst();
551  }
552 
554  }
555 
556  };
557 #endif
558 
559  // we need the Epetra specialization only if Epetra is enabled
560 #if (defined(HAVE_XPETRA_EPETRA) && !defined(XPETRA_EPETRA_NO_64BIT_GLOBAL_INDICES))
561  template <>
562  class MapFactory<int, long long, EpetraNode> {
563 
564  typedef int LocalOrdinal;
565  typedef long long GlobalOrdinal;
566  typedef EpetraNode Node;
567 
568  private:
571 
572  public:
573 
575  // Workaround function for a deferred visual studio bug
576  //
577  // http://connect.microsoft.com/VisualStudio/feedback/details/719847/erroneous-error-c2783-could-not-deduce-template-argument
578  //
579  // Use this function for default arguments rather than calling
580  // what is the return value below. Also helps in reducing
581  // duplication in various constructors.
582  return KokkosClassic::Details::getNode<Node>();
583  }
584 
587  global_size_t numGlobalElements,
588  int indexBase,
589  const Teuchos::RCP<const Teuchos::Comm<int> > &comm,
591  const Teuchos::RCP<Node>& node = defaultArgNode ()) {
592  XPETRA_MONITOR("MapFactory::Build");
593 
594 #ifdef HAVE_XPETRA_TPETRA
595  if (lib == UseTpetra)
596  return rcp( new TpetraMap<LocalOrdinal,GlobalOrdinal, Node> (numGlobalElements, indexBase, comm, lg, node) );
597 #endif
598 
599  if (lib == UseEpetra)
600  return rcp( new EpetraMapT<long long, Node>(numGlobalElements, indexBase, comm, lg, node) );
601 
603  }
604 
607  global_size_t numGlobalElements,
608  size_t numLocalElements,
609  int indexBase,
610  const Teuchos::RCP<const Teuchos::Comm<int> > &comm,
611  const Teuchos::RCP<Node>& node = defaultArgNode())
612  {
613  XPETRA_MONITOR("MapFactory::Build");
614 
615 #ifdef HAVE_XPETRA_TPETRA
616  if (lib == UseTpetra)
617  return rcp( new TpetraMap<LocalOrdinal,GlobalOrdinal, Node> (numGlobalElements, numLocalElements, indexBase, comm, node) );
618 #endif
619 
620  if (lib == UseEpetra)
621  return rcp( new EpetraMapT<long long, Node>(numGlobalElements, numLocalElements, indexBase, comm, node) );
622 
624  }
625 
626  static RCP<Map<LocalOrdinal,GlobalOrdinal, Node> > Build(UnderlyingLib lib, global_size_t numGlobalElements, const Teuchos::ArrayView<const GlobalOrdinal> &elementList, int indexBase, const Teuchos::RCP<const Teuchos::Comm<int> > &comm, const Teuchos::RCP<Node>& node = defaultArgNode ()) {
627  XPETRA_MONITOR("MapFactory::Build");
628 
629 #ifdef HAVE_XPETRA_TPETRA
630  if (lib == UseTpetra)
631  return rcp( new TpetraMap<LocalOrdinal,GlobalOrdinal, Node> (numGlobalElements, elementList, indexBase, comm, node) );
632 #endif
633 
634  if (lib == UseEpetra)
635  return rcp( new EpetraMapT<long long, Node>(numGlobalElements, elementList, indexBase, comm, node) );
636 
638  }
639 
643  XPETRA_MONITOR("MapFactory::Build");
644 
646  if(!bmap.is_null()) {
648  "Xpetra::MapFactory::Build: When provided a BlockedMap numDofPerNode must set to be one. It is set to " << numDofPerNode << ".");
650  }
651 
652  LocalOrdinal N = map->getNodeNumElements();
653  Teuchos::ArrayView<const GlobalOrdinal> oldElements = map->getNodeElementList();
654  Teuchos::Array<GlobalOrdinal> newElements(map->getNodeNumElements()*numDofPerNode);
655  for (LocalOrdinal i = 0; i < N; i++)
656  for (LocalOrdinal j = 0; j < numDofPerNode; j++)
657  newElements[i*numDofPerNode + j] = oldElements[i]*numDofPerNode + j;
658 
659 #ifdef HAVE_XPETRA_TPETRA
660  if (map->lib() == UseTpetra)
661  return rcp( new TpetraMap<LocalOrdinal,GlobalOrdinal, Node> (map->getGlobalNumElements()*numDofPerNode, newElements, map->getIndexBase(), map->getComm(), map->getNode()) );
662 #endif
663 
664  if (map->lib() == UseEpetra)
665  return rcp( new EpetraMapT<long long, Node>(map->getGlobalNumElements()*numDofPerNode, newElements, map->getIndexBase(), map->getComm(), map->getNode()) );
666 
668  }
669 
671  createLocalMap(UnderlyingLib lib, size_t numElements, const Teuchos::RCP< const Teuchos::Comm< int > > &comm) {
672  XPETRA_MONITOR("MapFactory::Build");
673 
674 #ifdef HAVE_XPETRA_TPETRA
675  if (lib == UseTpetra)
676 #if ((defined(EPETRA_HAVE_OMP) && (defined(HAVE_TPETRA_INST_OPENMP) && defined(HAVE_TPETRA_INST_INT_LONG_LONG))) || \
677  (!defined(EPETRA_HAVE_OMP) && (defined(HAVE_TPETRA_INST_SERIAL) && defined(HAVE_TPETRA_INST_INT_LONG_LONG))))
678  return rcp( new TpetraMap<LocalOrdinal,GlobalOrdinal, Node> (Tpetra::createLocalMapWithNode<LocalOrdinal,GlobalOrdinal, Node>(numElements, comm)));
679 #else
681  "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");
682 #endif
683 #endif
684 
685  if (lib == UseEpetra)
687  defaultArgNode());
688 
690  }
691 
693  createLocalMapWithNode(UnderlyingLib lib, size_t numElements, const Teuchos::RCP< const Teuchos::Comm< int > > &comm, const Teuchos::RCP<Node> &node) {
694  XPETRA_MONITOR("MapFactory::Build");
695 
696 #ifdef HAVE_XPETRA_TPETRA
697  if (lib == UseTpetra)
698 #if ((defined(EPETRA_HAVE_OMP) && (defined(HAVE_TPETRA_INST_OPENMP) && defined(HAVE_TPETRA_INST_INT_LONG_LONG))) || \
699  (!defined(EPETRA_HAVE_OMP) && (defined(HAVE_TPETRA_INST_SERIAL) && defined(HAVE_TPETRA_INST_INT_LONG_LONG))))
700  return rcp (new TpetraMap<LocalOrdinal,GlobalOrdinal, Node> (Tpetra::createLocalMapWithNode<int, GlobalOrdinal, Node> (numElements, comm, node)));
701 #else
703  "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");
704 #endif
705 #endif
706 
707  if (lib == UseEpetra) {
709  map = Teuchos::rcp( new EpetraMapT<long long, Node>((Xpetra::global_size_t)numElements, // num elements, global and local
710  0, // index base is zero
711  comm, LocallyReplicated, node));
712  return map.getConst();
713  }
714 
716  }
717 
720  const Teuchos::RCP< const Teuchos::Comm< int > > &comm,
721  const Teuchos::RCP<Node>& node)
722  {
723  XPETRA_MONITOR("MapFactory::Build");
724 
725 #ifdef HAVE_XPETRA_TPETRA
726  if (lib == UseTpetra)
727 #if ((defined(EPETRA_HAVE_OMP) && (defined(HAVE_TPETRA_INST_OPENMP) && defined(HAVE_TPETRA_INST_INT_LONG_LONG))) || \
728  (!defined(EPETRA_HAVE_OMP) && (defined(HAVE_TPETRA_INST_SERIAL) && defined(HAVE_TPETRA_INST_INT_LONG_LONG))))
729  return rcp (new TpetraMap<LocalOrdinal,GlobalOrdinal, Node> (Tpetra::createUniformContigMapWithNode<int,GlobalOrdinal,Node> (numElements, comm, node)));
730 #else
732  "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");
733 #endif
734 #endif
735 
736  if (lib == UseEpetra) {
738  map = Teuchos::rcp( new EpetraMapT<long long, Node>(numElements, // num elements, global and local
739  0, //index base is zero
740  comm, GloballyDistributed, node));
741  return map.getConst();
742  }
743 
745  }
746 
749  XPETRA_MONITOR("MapFactory::Build");
750 
751 #ifdef HAVE_XPETRA_TPETRA
752  if (lib == UseTpetra)
753 #if ((defined(EPETRA_HAVE_OMP) && (defined(HAVE_TPETRA_INST_OPENMP) && defined(HAVE_TPETRA_INST_INT_LONG_LONG))) || \
754  (!defined(EPETRA_HAVE_OMP) && (defined(HAVE_TPETRA_INST_SERIAL) && defined(HAVE_TPETRA_INST_INT_LONG_LONG))))
755  return rcp( new TpetraMap<LocalOrdinal,GlobalOrdinal, Node> (Tpetra::createUniformContigMapWithNode<LocalOrdinal,GlobalOrdinal, Node>(numElements, comm)));
756 #else
758  "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");
759 #endif
760 #endif
761 
762  if (lib == UseEpetra)
764  defaultArgNode());
765 
767  }
768 
770  createContigMap(UnderlyingLib lib, global_size_t numElements, size_t localNumElements, const Teuchos::RCP< const Teuchos::Comm< int > > &comm) {
771  XPETRA_MONITOR("MapFactory::Build");
772 
773 #ifdef HAVE_XPETRA_TPETRA
774  if (lib == UseTpetra)
775 #if ((defined(EPETRA_HAVE_OMP) && (defined(HAVE_TPETRA_INST_OPENMP) && defined(HAVE_TPETRA_INST_INT_LONG_LONG))) || \
776  (!defined(EPETRA_HAVE_OMP) && (defined(HAVE_TPETRA_INST_SERIAL) && defined(HAVE_TPETRA_INST_INT_LONG_LONG))))
777  return rcp( new TpetraMap<LocalOrdinal,GlobalOrdinal, Node> (Tpetra::createContigMapWithNode<int,GlobalOrdinal,Node>(numElements, localNumElements, comm)));
778 #else
780  "Xpetra::MapFactory::createContigMap: Cannot create Xpetra::TpetraMap, since Tpetra is not instantiated on EpetraNode (Serial or OpenMP, depending on configuration) and/or GO=long long");
781 #endif
782 #endif
783 
784  if (lib == UseEpetra)
785  return MapFactory<int, GlobalOrdinal, Node>::createContigMapWithNode(lib, numElements, localNumElements, comm, defaultArgNode() );
786 
788  }
789 
791  createContigMapWithNode(UnderlyingLib lib, global_size_t numElements, size_t localNumElements,
792  const Teuchos::RCP< const Teuchos::Comm< int > > &comm, const Teuchos::RCP<Node> &node) {
793  XPETRA_MONITOR("MapFactory::Build");
794 
795 #ifdef HAVE_XPETRA_TPETRA
796  if (lib == UseTpetra)
797 #if ((defined(EPETRA_HAVE_OMP) && (defined(HAVE_TPETRA_INST_OPENMP) && defined(HAVE_TPETRA_INST_INT_LONG_LONG))) || \
798  (!defined(EPETRA_HAVE_OMP) && (defined(HAVE_TPETRA_INST_SERIAL) && defined(HAVE_TPETRA_INST_INT_LONG_LONG))))
799  return rcp( new TpetraMap<LocalOrdinal,GlobalOrdinal, Node> (Tpetra::createContigMapWithNode<int,GlobalOrdinal,Node>(numElements, localNumElements, comm, node)));
800 #else
802  "Xpetra::MapFactory::createContigMapWithNode: Cannot create Xpetra::TpetraMap, since Tpetra is not instantiated on EpetraNode (Serial or OpenMP, depending on configuration) and/or GO=long long");
803 #endif
804 #endif
805 
806  if (lib == UseEpetra) {
808  map = Teuchos::rcp( new EpetraMapT<long long, Node>(numElements,localNumElements,
809  0, // index base is zero
810  comm, node) );
811  return map.getConst();
812  }
813 
815  }
816 
817  };
818 #endif
819 
820 }
821 
822 #define XPETRA_MAPFACTORY_SHORT
823 #endif
824 //TODO: removed unused methods
static RCP< Map< LocalOrdinal, GlobalOrdinal, Node > > Build(UnderlyingLib lib, global_size_t numGlobalElements, size_t numLocalElements, int indexBase, const Teuchos::RCP< const Teuchos::Comm< int > > &comm, const Teuchos::RCP< Node > &node=defaultArgNode())
static Teuchos::RCP< Map< LocalOrdinal, GlobalOrdinal, Node > > Build(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &map, LocalOrdinal numDofPerNode)
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, const Teuchos::RCP< Node > &node)
Create a (potentially) non-uniform, contiguous Map with a user-specified 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, const Teuchos::RCP< Node > &node=defaultArgNode())
Map constructor with Xpetra-defined contiguous uniform distribution.
static RCP< Map< LocalOrdinal, GlobalOrdinal, Node > > Build(UnderlyingLib lib, global_size_t numGlobalElements, int indexBase, const Teuchos::RCP< const Teuchos::Comm< int > > &comm, LocalGlobal lg=GloballyDistributed, const Teuchos::RCP< Node > &node=defaultArgNode())
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.
GlobalOrdinal global_ordinal_type
Definition: Xpetra_Map.hpp:86
static Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > createUniformContigMapWithNode(UnderlyingLib lib, global_size_t numElements, const Teuchos::RCP< const Teuchos::Comm< int > > &comm, const Teuchos::RCP< Node > &node)
Create a uniform, contiguous Map with a user-specified 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)
static Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > createUniformContigMapWithNode(UnderlyingLib lib, global_size_t numElements, const Teuchos::RCP< const Teuchos::Comm< int > > &comm, const Teuchos::RCP< Node > &node)
static Teuchos::RCP< Map< LocalOrdinal, GlobalOrdinal, Node > > Build(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &map, LocalOrdinal numDofPerNode)
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, const Teuchos::RCP< Node > &node)
static Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > createLocalMap(UnderlyingLib lib, size_t numElements, const Teuchos::RCP< const Teuchos::Comm< int > > &comm)
Node node_type
Definition: Xpetra_Map.hpp:87
static Teuchos::RCP< Map< LocalOrdinal, GlobalOrdinal, Node > > Build(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &map, LocalOrdinal numDofPerNode)
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Xpetra namespace
MapFactory()
Private constructor. This is a static class.
Exception throws to report errors in the internal logical of the program.
#define XPETRA_FACTORY_ERROR_IF_EPETRA(lib)
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< Node > defaultArgNode()
bool is_null() const
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.
static Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > createLocalMapWithNode(UnderlyingLib lib, size_t numElements, const Teuchos::RCP< const Teuchos::Comm< int > > &comm, const Teuchos::RCP< Node > &node)
MapFactory()
Private constructor. This is a static class.
static Teuchos::RCP< Map< LocalOrdinal, GlobalOrdinal, Node > > Build(UnderlyingLib lib, global_size_t numGlobalElements, size_t numLocalElements, GlobalOrdinal indexBase, const Teuchos::RCP< const Teuchos::Comm< int > > &comm, const Teuchos::RCP< Node > &node=defaultArgNode())
Map constructor with a user-defined contiguous distribution.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
static Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > createLocalMap(UnderlyingLib lib, size_t numElements, const Teuchos::RCP< const Teuchos::Comm< int > > &comm)
static RCP< Map< LocalOrdinal, GlobalOrdinal, Node > > Build(UnderlyingLib lib, global_size_t numGlobalElements, const Teuchos::ArrayView< const GlobalOrdinal > &elementList, int indexBase, const Teuchos::RCP< const Teuchos::Comm< int > > &comm, const Teuchos::RCP< Node > &node=defaultArgNode())
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, const Teuchos::RCP< Node > &node)
static Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > createUniformContigMap(UnderlyingLib lib, global_size_t numElements, const Teuchos::RCP< const Teuchos::Comm< int > > &comm)
#define XPETRA_FACTORY_END
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)
static Teuchos::RCP< Node > defaultArgNode()
size_t global_size_t
Global size_t object.
static Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > createLocalMapWithNode(UnderlyingLib lib, size_t numElements, const Teuchos::RCP< const Teuchos::Comm< int > > &comm, const Teuchos::RCP< Node > &node)
Create a locally replicated Map with a specified node.
static Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > createLocalMapWithNode(UnderlyingLib lib, size_t numElements, const Teuchos::RCP< const Teuchos::Comm< int > > &comm, const Teuchos::RCP< Node > &node)
static RCP< Map< LocalOrdinal, GlobalOrdinal, Node > > Build(UnderlyingLib lib, global_size_t numGlobalElements, size_t numLocalElements, int indexBase, const Teuchos::RCP< const Teuchos::Comm< int > > &comm, const Teuchos::RCP< Node > &node=defaultArgNode())
Create an Xpetra::Map instance.
static Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > createUniformContigMap(UnderlyingLib lib, global_size_t numElements, const Teuchos::RCP< const Teuchos::Comm< int > > &comm)
#define XPETRA_MONITOR(funcName)
static Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > createUniformContigMapWithNode(UnderlyingLib lib, global_size_t numElements, const Teuchos::RCP< const Teuchos::Comm< int > > &comm, const Teuchos::RCP< Node > &node)
RCP< const T > getConst() const
static RCP< Map< LocalOrdinal, GlobalOrdinal, Node > > Build(UnderlyingLib lib, global_size_t numGlobalElements, const Teuchos::ArrayView< const GlobalOrdinal > &elementList, int indexBase, const Teuchos::RCP< const Teuchos::Comm< int > > &comm, const Teuchos::RCP< Node > &node=defaultArgNode())
static Teuchos::RCP< Map< LocalOrdinal, GlobalOrdinal, Node > > Build(UnderlyingLib lib, global_size_t numGlobalElements, const Teuchos::ArrayView< const GlobalOrdinal > &elementList, GlobalOrdinal indexBase, const Teuchos::RCP< const Teuchos::Comm< int > > &comm, const Teuchos::RCP< Node > &node=defaultArgNode())
Map constructor with user-defined non-contiguous (arbitrary) distribution.
static RCP< Map< LocalOrdinal, GlobalOrdinal, Node > > Build(UnderlyingLib lib, global_size_t numGlobalElements, int indexBase, const Teuchos::RCP< const Teuchos::Comm< int > > &comm, LocalGlobal lg=GloballyDistributed, const Teuchos::RCP< Node > &node=defaultArgNode())
MapFactory()
Private constructor. This is a static class.