All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Xpetra_VectorFactory.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_VECTORFACTORY_HPP
47 #define XPETRA_VECTORFACTORY_HPP
48 
49 #include "Xpetra_ConfigDefs.hpp"
50 #include "Xpetra_Vector.hpp"
51 
52 #ifdef HAVE_XPETRA_TPETRA
53 # include "Xpetra_TpetraVector.hpp"
54 #endif
55 #ifdef HAVE_XPETRA_EPETRA
56 # include "Xpetra_EpetraVector.hpp"
58 #endif
59 
60 #include "Xpetra_BlockedMap.hpp"
61 #include <Xpetra_BlockedVector.hpp>
62 
63 #include "Xpetra_Exceptions.hpp"
64 
65 namespace Xpetra {
66 
67  template <class Scalar/* = Vector<>::scalar_type*/,
68  class LocalOrdinal/* = typename Vector<Scalar>::local_ordinal_type*/,
69  class GlobalOrdinal/* = typename Vector<Scalar, LocalOrdinal>::local_ordinal_type*/,
70  class Node/* = typename Vector<Scalar, LocalOrdinal, GlobalOrdinal>::node_type*/>
71  class VectorFactory
72  {
73 #undef XPETRA_VECTORFACTORY_SHORT
74 #include "Xpetra_UseShortNames.hpp"
75 
76  private:
79 
80  public:
81 
83  static RCP<Vector> Build(const Teuchos::RCP<const Map> &map, bool zeroOut=true) {
84  XPETRA_MONITOR("VectorFactory::Build");
85 
87  if(!bmap.is_null())
88  {
90  }
91 
92 #ifdef HAVE_XPETRA_TPETRA
93  if (map->lib() == UseTpetra)
94  return rcp( new TpetraVector(map, zeroOut) );
95 #endif
96 
99  }
100 
101  };
102 #define XPETRA_VECTORFACTORY_SHORT
103 
104 // we need the Epetra specialization only if Epetra is enabled
105 #if (defined(HAVE_XPETRA_EPETRA) && !defined(XPETRA_EPETRA_NO_32BIT_GLOBAL_INDICES))
106 
107  // Specialization for Scalar=double, LO=GO=int and EpetraNode node
108  // Used both for Epetra and Tpetra
109  // For any other node definition the general default implementation is used which allows Tpetra only
110  template <>
111  class VectorFactory<double, int, int, EpetraNode> {
112  typedef double Scalar;
113  typedef int LocalOrdinal;
114  typedef int GlobalOrdinal;
115  typedef EpetraNode Node;
116 
117 #undef XPETRA_VECTORFACTORY_SHORT
118 #include "Xpetra_UseShortNames.hpp"
119 
120  private:
123 
124  public:
125 
126  static RCP<Vector> Build(const Teuchos::RCP<const Map>& map, bool zeroOut=true) {
127  XPETRA_MONITOR("VectorFactory::Build");
128 
130  if(!bmap.is_null()) {
132  }
133 
134 
135 #ifdef HAVE_XPETRA_TPETRA
136  if (map->lib() == UseTpetra)
137  return rcp( new TpetraVector(map, zeroOut) );
138 #endif
139 
140  if (map->lib() == UseEpetra)
141  return rcp( new EpetraVectorT<int,Node>(map, zeroOut) );
142 
144  }
145 
146  };
147 #endif
148 
149  // Specialization for Scalar=double, LO=int, GO=long long and EpetraNode
150  // Used both for Epetra and Tpetra
151  // For any other node definition the general default implementation is used which allows Tpetra only
152 #if (defined(HAVE_XPETRA_EPETRA) && !defined(XPETRA_EPETRA_NO_64BIT_GLOBAL_INDICES))
153 
154  template <>
155  class VectorFactory<double, int, long long, EpetraNode> {
156 
157  typedef double Scalar;
158  typedef int LocalOrdinal;
159  typedef long long GlobalOrdinal;
160  typedef EpetraNode Node;
161 
162 #undef XPETRA_VECTORFACTORY_SHORT
163 #include "Xpetra_UseShortNames.hpp"
164 
165  private:
168 
169  public:
170 
171  static RCP<Vector> Build(const Teuchos::RCP<const Map>& map, bool zeroOut=true) {
172  XPETRA_MONITOR("VectorFactory::Build");
173 
175  if(!bmap.is_null()) {
177  }
178 
179 #ifdef HAVE_XPETRA_TPETRA
180  if (map->lib() == UseTpetra)
181  return rcp( new TpetraVector(map, zeroOut) );
182 #endif
183 
184  if (map->lib() == UseEpetra)
185  return rcp( new EpetraVectorT<long long,Node>(map, zeroOut) );
186 
188  }
189 
190  };
191 #endif
192 
193 #define XPETRA_VECTORFACTORY_SHORT
194 
195 // we need the Epetra specialization only if Epetra is enabled
196 #if (defined(HAVE_XPETRA_EPETRA) && !defined(XPETRA_EPETRA_NO_32BIT_GLOBAL_INDICES))
197 
198 
199  // Specialization for Scalar=int, LO=GO=int and EpetraNode
200  // Used both for Epetra and Tpetra
201  // For any other node definition the general default implementation is used which allows Tpetra only
202  template <>
203  class VectorFactory<int, int, int, EpetraNode> {
204 
205  typedef int Scalar;
206  typedef int LocalOrdinal;
207  typedef int GlobalOrdinal;
208  typedef EpetraNode Node;
209 
210 #undef XPETRA_VECTORFACTORY_SHORT
211 #include "Xpetra_UseShortNames.hpp"
212 
213  private:
216 
217  public:
218 
219  static RCP<Vector> Build(const Teuchos::RCP<const Map>& map, bool zeroOut=true) {
220  XPETRA_MONITOR("VectorFactory::Build");
221 
223  if(!bmap.is_null()) {
225  }
226 
227 #ifdef HAVE_XPETRA_TPETRA
228  if (map->lib() == UseTpetra)
229  return rcp( new TpetraVector(map, zeroOut) );
230 #endif
231 
232  if (map->lib() == UseEpetra)
233  return rcp( new EpetraIntVectorT<int,Node>(map, zeroOut) );
234 
236  }
237 
238  };
239 #endif
240 
241 // we need the Epetra specialization only if Epetra is enabled
242 #if (defined(HAVE_XPETRA_EPETRA) && !defined(XPETRA_EPETRA_NO_64BIT_GLOBAL_INDICES))
243 
244  // Specialization for Scalar=int, LO=int, GO=long long and Serial node
245  // Used both for Epetra and Tpetra
246  // For any other node definition the general default implementation is used which allows Tpetra only
247 
248  template <>
249  class VectorFactory<int, int, long long, EpetraNode> {
250 
251  typedef int Scalar;
252  typedef int LocalOrdinal;
253  typedef long long GlobalOrdinal;
254  typedef EpetraNode Node;
255 
256 #undef XPETRA_VECTORFACTORY_SHORT
257 #include "Xpetra_UseShortNames.hpp"
258 
259  private:
262 
263  public:
264 
265  static RCP<Vector> Build(const Teuchos::RCP<const Map>& map, bool zeroOut=true) {
266  XPETRA_MONITOR("VectorFactory::Build");
267 
269  if(!bmap.is_null()) {
271  }
272 
273 #ifdef HAVE_XPETRA_TPETRA
274  if (map->lib() == UseTpetra)
275  return rcp( new TpetraVector(map, zeroOut) );
276 #endif
277 
278  if (map->lib() == UseEpetra)
279  return rcp( new EpetraIntVectorT<long long,Node>(map, zeroOut) );
280 
282  }
283 
284  };
285 #endif
286 }
287 
288 #define XPETRA_VECTORFACTORY_SHORT
289 #endif
static RCP< Vector > Build(const Teuchos::RCP< const Map > &map, bool zeroOut=true)
VectorFactory()
Private constructor. This is a static class.
VectorFactory()
Private constructor. This is a static class.
VectorFactory()
Private constructor. This is a static class.
#define XPETRA_FACTORY_ERROR_IF_EPETRA(lib)
static RCP< Vector > Build(const Teuchos::RCP< const Map > &map, bool zeroOut=true)
static RCP< Vector > Build(const Teuchos::RCP< const Map > &map, bool zeroOut=true)
VectorFactory()
Private constructor. This is a static class.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
static RCP< Vector > Build(const Teuchos::RCP< const Map > &map, bool zeroOut=true)
#define XPETRA_FACTORY_END
static RCP< Vector > Build(const Teuchos::RCP< const Map > &map, bool zeroOut=true)
Constructor specifying the number of non-zeros for all rows.
VectorFactory()
Private constructor. This is a static class.
#define XPETRA_MONITOR(funcName)
bool is_null() const