Xpetra_MultiVectorFactory.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_MULTIVECTORFACTORY_HPP
47 #define XPETRA_MULTIVECTORFACTORY_HPP
48 
49 #include "Xpetra_ConfigDefs.hpp"
50 
51 #include "Xpetra_MultiVector.hpp"
52 
53 #ifdef HAVE_XPETRA_TPETRA
55 #endif
56 
57 #ifdef HAVE_XPETRA_EPETRA
59 #endif
60 
61 #include "Xpetra_Exceptions.hpp"
62 
63 namespace Xpetra {
64 
65  template <class Scalar = MultiVector<>::scalar_type,
66  class LocalOrdinal =
68  class GlobalOrdinal =
70  class Node =
73  private:
76 
77  public:
78 
80  static Teuchos::RCP<MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
81  Build (const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &map,
82  size_t NumVectors,
83  bool zeroOut=true)
84  {
85  XPETRA_MONITOR("MultiVectorFactory::Build");
86 
87 #ifdef HAVE_XPETRA_TPETRA
88  if (map->lib() == UseTpetra)
89  return rcp( new TpetraMultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> (map, NumVectors, zeroOut) );
90 #endif
91 
94  }
95 
97  static Teuchos::RCP<MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> > Build(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &map, const Teuchos::ArrayView< const Teuchos::ArrayView< const Scalar > > &ArrayOfPtrs, size_t NumVectors) {
98  XPETRA_MONITOR("MultiVectorFactory::Build");
99 
100 #ifdef HAVE_XPETRA_TPETRA
101  if (map->lib() == UseTpetra)
102  return rcp( new TpetraMultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> (map, ArrayOfPtrs, NumVectors) );
103 #endif
104 
105  XPETRA_FACTORY_ERROR_IF_EPETRA(map->lib());
107  }
108 
109  };
110 
111 
112 // we need the Epetra specialization only if Epetra is enabled
113 #if (defined(HAVE_XPETRA_EPETRA) && !defined(XPETRA_EPETRA_NO_32BIT_GLOBAL_INDICES))
114 
115 
116  // Specialization for Scalar=double, LO=GO=int and Serial node
117  // Used both for Epetra and Tpetra
118  // For any other node definition the general default implementation is used which allows Tpetra only
119  template <>
120  class MultiVectorFactory<double, int, int, EpetraNode> {
121 
122  typedef double Scalar;
123  typedef int LocalOrdinal;
124  typedef int GlobalOrdinal;
125  typedef EpetraNode Node;
126 
127  private:
130 
131  public:
132 
133  static RCP<MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> > Build(const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &map, size_t NumVectors, bool zeroOut=true) {
134  XPETRA_MONITOR("MultiVectorFactory::Build");
135 
136 #ifdef HAVE_XPETRA_TPETRA
137  if (map->lib() == UseTpetra)
138  return rcp( new TpetraMultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> (map, NumVectors, zeroOut) );
139 #endif
140 
141  if (map->lib() == UseEpetra)
142  return rcp( new EpetraMultiVectorT<int,Node>(map, NumVectors, zeroOut) );
143 
145  }
146 
148  static Teuchos::RCP<MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> > Build(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &map, const Teuchos::ArrayView< const Teuchos::ArrayView< const Scalar > > &ArrayOfPtrs, size_t NumVectors) {
149  XPETRA_MONITOR("MultiVectorFactory::Build");
150 
151 #ifdef HAVE_XPETRA_TPETRA
152  if (map->lib() == UseTpetra)
153  return rcp( new TpetraMultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> (map, ArrayOfPtrs, NumVectors) );
154 #endif
155 
156  if (map->lib() == UseEpetra)
157  return rcp( new EpetraMultiVectorT<int,Node>(map, ArrayOfPtrs, NumVectors) );
158 
160  }
161 
162  };
163 
164 // we need the Epetra specialization only if Epetra is enabled
165 #if (defined(HAVE_XPETRA_EPETRA) && !defined(XPETRA_EPETRA_NO_64BIT_GLOBAL_INDICES))
166 
167  template <>
168  class MultiVectorFactory<double, int, long long, EpetraNode> {
169 
170  typedef double Scalar;
171  typedef int LocalOrdinal;
172  typedef long long GlobalOrdinal;
173  typedef EpetraNode Node;
174 
175  private:
178 
179  public:
180 
181  static RCP<MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> > Build(const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &map, size_t NumVectors, bool zeroOut=true) {
182  XPETRA_MONITOR("MultiVectorFactory::Build");
183 
184 #ifdef HAVE_XPETRA_TPETRA
185  if (map->lib() == UseTpetra)
186  return rcp( new TpetraMultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> (map, NumVectors, zeroOut) );
187 #endif
188 
189  if (map->lib() == UseEpetra)
190  return rcp( new EpetraMultiVectorT<long long,Node>(map, NumVectors, zeroOut) );
191 
193  }
194 
196  static Teuchos::RCP<MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> > Build(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &map, const Teuchos::ArrayView< const Teuchos::ArrayView< const Scalar > > &ArrayOfPtrs, size_t NumVectors) {
197  XPETRA_MONITOR("MultiVectorFactory::Build");
198 
199 #ifdef HAVE_XPETRA_TPETRA
200  if (map->lib() == UseTpetra)
201  return rcp( new TpetraMultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> (map, ArrayOfPtrs, NumVectors) );
202 #endif
203 
204  if (map->lib() == UseEpetra)
205  return rcp( new EpetraMultiVectorT<long long,Node>(map, ArrayOfPtrs, NumVectors) );
206 
208  }
209 
210  };
211 #endif // Epetra64
212 #endif // HAVE_XPETRA_EPETRA
213 
214 }
215 
216 #define XPETRA_MULTIVECTORFACTORY_SHORT
217 #endif
static Teuchos::RCP< MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > Build(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &map, const Teuchos::ArrayView< const Teuchos::ArrayView< const Scalar > > &ArrayOfPtrs, size_t NumVectors)
Set multi-vector values from array of pointers using Teuchos memory management classes. (copy).
Xpetra namespace
#define XPETRA_FACTORY_ERROR_IF_EPETRA(lib)
MultiVectorFactory()
Private constructor. This is a static class.
MultiVectorFactory()
Private constructor. This is a static class.
static Teuchos::RCP< MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > Build(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &map, const Teuchos::ArrayView< const Teuchos::ArrayView< const Scalar > > &ArrayOfPtrs, size_t NumVectors)
Set multi-vector values from array of pointers using Teuchos memory management classes. (copy).
static Teuchos::RCP< MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > Build(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &map, const Teuchos::ArrayView< const Teuchos::ArrayView< const Scalar > > &ArrayOfPtrs, size_t NumVectors)
Set multi-vector values from array of pointers using Teuchos memory management classes. (copy).
#define XPETRA_FACTORY_END
LocalOrdinal local_ordinal_type
GlobalOrdinal global_ordinal_type
static RCP< MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > Build(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &map, size_t NumVectors, bool zeroOut=true)
static Teuchos::RCP< MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > Build(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &map, size_t NumVectors, bool zeroOut=true)
Constructor specifying the number of non-zeros for all rows.
#define XPETRA_MONITOR(funcName)
static RCP< MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > Build(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &map, size_t NumVectors, bool zeroOut=true)