All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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
54 #include "Xpetra_TpetraMultiVector.hpp"
55 #endif
56 
57 #ifdef HAVE_XPETRA_EPETRA
60 #endif
61 
62 #include "Xpetra_BlockedMap.hpp"
64 
65 #include "Xpetra_Exceptions.hpp"
66 
67 namespace Xpetra {
68 
69 #ifndef DOXYGEN_SHOULD_SKIP_THIS
70  // forward declaration of BlockedMultiVector, needed to prevent circular inclusions
71  //template<class SC, class LO, class GO, class N> class BlockedMultiVector;
72 #endif
73 
74  template <class Scalar = MultiVector<>::scalar_type,
75  class LocalOrdinal =
76  typename MultiVector<Scalar>::local_ordinal_type,
77  class GlobalOrdinal =
78  typename MultiVector<Scalar, LocalOrdinal>::global_ordinal_type,
79  class Node =
80  typename MultiVector<Scalar, LocalOrdinal, GlobalOrdinal>::node_type>
82  private:
85 
86  public:
87 
91  size_t NumVectors,
92  bool zeroOut=true)
93  {
94  XPETRA_MONITOR("MultiVectorFactory::Build");
95 
97  if(!bmap.is_null()) {
99  }
100 
101 #ifdef HAVE_XPETRA_TPETRA
102  if (map->lib() == UseTpetra)
103  return rcp( new TpetraMultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> (map, NumVectors, zeroOut) );
104 #endif
105 
106  XPETRA_FACTORY_ERROR_IF_EPETRA(map->lib());
108  }
109 
113  const Teuchos::ArrayView< const Teuchos::ArrayView< const Scalar > > &ArrayOfPtrs,
114  size_t NumVectors) {
115  XPETRA_MONITOR("MultiVectorFactory::Build");
116 
117 #ifdef HAVE_XPETRA_TPETRA
118  if (map->lib() == UseTpetra)
119  return rcp( new TpetraMultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> (map, ArrayOfPtrs, NumVectors) );
120 #endif
121 
122  XPETRA_FACTORY_ERROR_IF_EPETRA(map->lib());
124  }
125 
126  };
127 
128 
129 // we need the Epetra specialization only if Epetra is enabled
130 #if (defined(HAVE_XPETRA_EPETRA) && !defined(XPETRA_EPETRA_NO_32BIT_GLOBAL_INDICES))
131 
132 
133  // Specialization for Scalar=double, LO=GO=int and Serial node
134  // Used both for Epetra and Tpetra
135  // For any other node definition the general default implementation is used which allows Tpetra only
136  template <>
137  class MultiVectorFactory<double, int, int, EpetraNode> {
138 
139  typedef double Scalar;
140  typedef int LocalOrdinal;
141  typedef int GlobalOrdinal;
142  typedef EpetraNode Node;
143 
144  private:
147 
148  public:
149 
152  size_t NumVectors,
153  bool zeroOut=true) {
154  XPETRA_MONITOR("MultiVectorFactory::Build");
155 
157  if(!bmap.is_null()) {
158  return rcp(new BlockedMultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>(bmap, NumVectors, zeroOut));
159  }
160 
161 #ifdef HAVE_XPETRA_TPETRA
162  if (map->lib() == UseTpetra)
163  return rcp( new TpetraMultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> (map, NumVectors, zeroOut) );
164 #endif
165 
166  if (map->lib() == UseEpetra)
167  return rcp( new EpetraMultiVectorT<int,Node>(map, NumVectors, zeroOut) );
168 
170  }
171 
175  const Teuchos::ArrayView< const Teuchos::ArrayView< const Scalar > > &ArrayOfPtrs,
176  size_t NumVectors) {
177  XPETRA_MONITOR("MultiVectorFactory::Build");
178 
179 #ifdef HAVE_XPETRA_TPETRA
180  if (map->lib() == UseTpetra)
181  return rcp( new TpetraMultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> (map, ArrayOfPtrs, NumVectors) );
182 #endif
183 
184  if (map->lib() == UseEpetra)
185  return rcp( new EpetraMultiVectorT<int,Node>(map, ArrayOfPtrs, NumVectors) );
186 
188  }
189 
190  };
191 
192  template <>
193  class MultiVectorFactory<int, int, int, EpetraNode> {
194 
195  typedef int Scalar;
196  typedef int LocalOrdinal;
197  typedef int GlobalOrdinal;
198  typedef EpetraNode Node;
199 
200  private:
203 
204  public:
205 
208  size_t NumVectors,
209  bool zeroOut=true) {
210  XPETRA_MONITOR("MultiVectorFactory::Build");
211 
213  if(!bmap.is_null()) {
214  return rcp(new BlockedMultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>(bmap, NumVectors, zeroOut));
215  }
216 
217 #ifdef HAVE_XPETRA_TPETRA
218  if (map->lib() == UseTpetra)
219  return rcp( new TpetraMultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> (map, NumVectors, zeroOut) );
220 #endif
221 
222  if (map->lib() == UseEpetra)
223  return rcp( new EpetraIntMultiVectorT<int,Node>(map, NumVectors, zeroOut) );
224 
226  }
227 
231  const Teuchos::ArrayView< const Teuchos::ArrayView< const Scalar > > &ArrayOfPtrs,
232  size_t NumVectors) {
233  XPETRA_MONITOR("MultiVectorFactory::Build");
234 
235 #ifdef HAVE_XPETRA_TPETRA
236  if (map->lib() == UseTpetra)
237  return rcp( new TpetraMultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> (map, ArrayOfPtrs, NumVectors) );
238 #endif
239 
240  if (map->lib() == UseEpetra)
241  return rcp( new EpetraIntMultiVectorT<int,Node>(map, ArrayOfPtrs, NumVectors) );
242 
244  }
245 
246  };
247 
248 // we need the Epetra specialization only if Epetra is enabled
249 #if (defined(HAVE_XPETRA_EPETRA) && !defined(XPETRA_EPETRA_NO_64BIT_GLOBAL_INDICES))
250 
251  template <>
252  class MultiVectorFactory<double, int, long long, EpetraNode> {
253 
254  typedef double Scalar;
255  typedef int LocalOrdinal;
256  typedef long long GlobalOrdinal;
257  typedef EpetraNode Node;
258 
259  private:
262 
263  public:
264 
267  size_t NumVectors,
268  bool zeroOut = true) {
269  XPETRA_MONITOR("MultiVectorFactory::Build");
270 
272  if(!bmap.is_null()) {
273  return rcp(new BlockedMultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>(bmap, NumVectors, zeroOut));
274  }
275 
276 #ifdef HAVE_XPETRA_TPETRA
277  if (map->lib() == UseTpetra)
278  return rcp( new TpetraMultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> (map, NumVectors, zeroOut) );
279 #endif
280 
281  if (map->lib() == UseEpetra)
282  return rcp( new EpetraMultiVectorT<long long,Node>(map, NumVectors, zeroOut) );
283 
285  }
286 
290  const Teuchos::ArrayView< const Teuchos::ArrayView< const Scalar > > &ArrayOfPtrs,
291  size_t NumVectors) {
292  XPETRA_MONITOR("MultiVectorFactory::Build");
293 
294 #ifdef HAVE_XPETRA_TPETRA
295  if (map->lib() == UseTpetra)
296  return rcp( new TpetraMultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> (map, ArrayOfPtrs, NumVectors) );
297 #endif
298 
299  if (map->lib() == UseEpetra)
300  return rcp( new EpetraMultiVectorT<long long,Node>(map, ArrayOfPtrs, NumVectors) );
301 
303  }
304 
305  };
306 
307  template <>
308  class MultiVectorFactory<int, int, long long, EpetraNode> {
309 
310  typedef int Scalar;
311  typedef int LocalOrdinal;
312  typedef long long GlobalOrdinal;
313  typedef EpetraNode Node;
314 
315  private:
318 
319  public:
320 
323  size_t NumVectors,
324  bool zeroOut = true) {
325  XPETRA_MONITOR("MultiVectorFactory::Build");
326 
328  if(!bmap.is_null()) {
329  return rcp(new BlockedMultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>(bmap, NumVectors, zeroOut));
330  }
331 
332 #ifdef HAVE_XPETRA_TPETRA
333  if (map->lib() == UseTpetra)
334  return rcp( new TpetraMultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> (map, NumVectors, zeroOut) );
335 #endif
336 
337  if (map->lib() == UseEpetra)
338  return rcp( new EpetraIntMultiVectorT<long long,Node>(map, NumVectors, zeroOut) );
339 
341  }
342 
346  const Teuchos::ArrayView< const Teuchos::ArrayView< const Scalar > > &ArrayOfPtrs,
347  size_t NumVectors) {
348  XPETRA_MONITOR("MultiVectorFactory::Build");
349 
350 #ifdef HAVE_XPETRA_TPETRA
351  if (map->lib() == UseTpetra)
352  return rcp( new TpetraMultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> (map, ArrayOfPtrs, NumVectors) );
353 #endif
354 
355  if (map->lib() == UseEpetra)
356  return rcp( new EpetraIntMultiVectorT<long long,Node>(map, ArrayOfPtrs, NumVectors) );
357 
359  }
360 
361  };
362 #endif // Epetra64
363 #endif // HAVE_XPETRA_EPETRA
364 
365 }
366 
367 #define XPETRA_MULTIVECTORFACTORY_SHORT
368 #endif
MultiVectorFactory()
Private constructor. This is a static class.
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, 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_ERROR_IF_EPETRA(lib)
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
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
MultiVectorFactory()
Private constructor. This is a static class.
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.
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_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)
static RCP< MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > Build(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &map, size_t NumVectors, bool zeroOut=true)
bool is_null() const