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 
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 
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  template <>
112  class MultiVectorFactory<double, int, int> {
113 
114  typedef double Scalar;
115  typedef int LocalOrdinal;
116  typedef int GlobalOrdinal;
118 
119  private:
122 
123  public:
124 
126  XPETRA_MONITOR("MultiVectorFactory::Build");
127 
128 #ifdef HAVE_XPETRA_TPETRA
129  if (map->lib() == UseTpetra)
130  return rcp( new TpetraMultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> (map, NumVectors, zeroOut) );
131 #endif
132 
133 #ifdef HAVE_XPETRA_EPETRA
134 #ifndef XPETRA_EPETRA_NO_32BIT_GLOBAL_INDICES
135  if (map->lib() == UseEpetra)
136  return rcp( new EpetraMultiVectorT<int>(map, NumVectors, zeroOut) );
137 #endif
138 #endif
139 
141  }
142 
145  XPETRA_MONITOR("MultiVectorFactory::Build");
146 
147 #ifdef HAVE_XPETRA_TPETRA
148  if (map->lib() == UseTpetra)
149  return rcp( new TpetraMultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> (map, ArrayOfPtrs, NumVectors) );
150 #endif
151 
152 #ifdef HAVE_XPETRA_EPETRA
153 #ifndef XPETRA_EPETRA_NO_32BIT_GLOBAL_INDICES
154  if (map->lib() == UseEpetra)
155  return rcp( new EpetraMultiVectorT<int>(map, ArrayOfPtrs, NumVectors) );
156 #endif
157 #endif
158 
160  }
161 
162  };
163 
164 #ifdef HAVE_XPETRA_INT_LONG_LONG
165  template <>
166  class MultiVectorFactory<double, int, long long> {
167 
168  typedef double Scalar;
169  typedef int LocalOrdinal;
170  typedef long long GlobalOrdinal;
172 
173  private:
175  MultiVectorFactory() {}
176 
177  public:
178 
179  static RCP<MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> > Build(const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &map, size_t NumVectors, bool zeroOut=true) {
180  XPETRA_MONITOR("MultiVectorFactory::Build");
181 
182 #ifdef HAVE_XPETRA_TPETRA
183  if (map->lib() == UseTpetra)
184  return rcp( new TpetraMultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> (map, NumVectors, zeroOut) );
185 #endif
186 
187 #ifdef HAVE_XPETRA_EPETRA
188 #ifndef XPETRA_EPETRA_NO_64BIT_GLOBAL_INDICES
189  if (map->lib() == UseEpetra)
190  return rcp( new EpetraMultiVectorT<long long>(map, NumVectors, zeroOut) );
191 #endif
192 #endif
193 
195  }
196 
199  XPETRA_MONITOR("MultiVectorFactory::Build");
200 
201 #ifdef HAVE_XPETRA_TPETRA
202  if (map->lib() == UseTpetra)
203  return rcp( new TpetraMultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> (map, ArrayOfPtrs, NumVectors) );
204 #endif
205 
206 #ifdef HAVE_XPETRA_EPETRA
207 #ifndef XPETRA_EPETRA_NO_64BIT_GLOBAL_INDICES
208  if (map->lib() == UseEpetra)
209  return rcp( new EpetraMultiVectorT<long long>(map, ArrayOfPtrs, NumVectors) );
210 #endif
211 #endif
212 
214  }
215 
216  };
217 #endif // HAVE_XPETRA_INT_LONG_LONG
218 
219 }
220 
221 #define XPETRA_MULTIVECTORFACTORY_SHORT
222 #endif
static RCP< MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > Build(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &map, size_t NumVectors, bool zeroOut=true)
Xpetra namespace
#define XPETRA_FACTORY_ERROR_IF_EPETRA(lib)
MultiVector< double, int, GlobalOrdinal >::node_type Node
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
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).
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).
#define XPETRA_FACTORY_END
LocalOrdinal local_ordinal_type
GlobalOrdinal global_ordinal_type
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)