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 #include "Xpetra_BlockedMap.hpp"
60 #include "Xpetra_BlockedVector.hpp"
61 
62 #include "Xpetra_Exceptions.hpp"
63 
64 namespace Xpetra {
65 
66  template <class Scalar/* = Vector<>::scalar_type*/,
67  class LocalOrdinal/* = typename Vector<Scalar>::local_ordinal_type*/,
68  class GlobalOrdinal/* = typename Vector<Scalar, LocalOrdinal>::local_ordinal_type*/,
69  class Node/* = typename Vector<Scalar, LocalOrdinal, GlobalOrdinal>::node_type*/>
70  class VectorFactory {
71 #undef XPETRA_VECTORFACTORY_SHORT
72 #include "Xpetra_UseShortNames.hpp"
73 
74  private:
77 
78  public:
79 
81  static RCP<Vector> Build(const Teuchos::RCP<const Map> &map, bool zeroOut=true) {
82  XPETRA_MONITOR("VectorFactory::Build");
83 
85  if(!bmap.is_null()) {
87  }
88 
89 #ifdef HAVE_XPETRA_TPETRA
90  if (map->lib() == UseTpetra)
91  return rcp( new TpetraVector(map, zeroOut) );
92 #endif
93 
96  }
97 
98  };
99 #define XPETRA_VECTORFACTORY_SHORT
100 
101 // we need the Epetra specialization only if Epetra is enabled
102 #if (defined(HAVE_XPETRA_EPETRA) && !defined(XPETRA_EPETRA_NO_32BIT_GLOBAL_INDICES))
103 
104  // Specialization for Scalar=double, LO=GO=int and EpetraNode node
105  // Used both for Epetra and Tpetra
106  // For any other node definition the general default implementation is used which allows Tpetra only
107  template <>
108  class VectorFactory<double, int, int, EpetraNode> {
109  typedef double Scalar;
110  typedef int LocalOrdinal;
111  typedef int GlobalOrdinal;
112  typedef EpetraNode Node;
113 
114 #undef XPETRA_VECTORFACTORY_SHORT
115 #include "Xpetra_UseShortNames.hpp"
116 
117  private:
120 
121  public:
122 
123  static RCP<Vector> Build(const Teuchos::RCP<const Map>& map, bool zeroOut=true) {
124  XPETRA_MONITOR("VectorFactory::Build");
125 
127  if(!bmap.is_null()) {
129  }
130 
131 
132 #ifdef HAVE_XPETRA_TPETRA
133  if (map->lib() == UseTpetra)
134  return rcp( new TpetraVector(map, zeroOut) );
135 #endif
136 
137  if (map->lib() == UseEpetra)
138  return rcp( new EpetraVectorT<int,Node>(map, zeroOut) );
139 
141  }
142 
143  };
144 #endif
145 
146  // Specialization for Scalar=double, LO=int, GO=long long and EpetraNode
147  // Used both for Epetra and Tpetra
148  // For any other node definition the general default implementation is used which allows Tpetra only
149 #if (defined(HAVE_XPETRA_EPETRA) && !defined(XPETRA_EPETRA_NO_64BIT_GLOBAL_INDICES))
150 
151  template <>
152  class VectorFactory<double, int, long long, EpetraNode> {
153 
154  typedef double Scalar;
155  typedef int LocalOrdinal;
156  typedef long long GlobalOrdinal;
157  typedef EpetraNode Node;
158 
159 #undef XPETRA_VECTORFACTORY_SHORT
160 #include "Xpetra_UseShortNames.hpp"
161 
162  private:
165 
166  public:
167 
168  static RCP<Vector> Build(const Teuchos::RCP<const Map>& map, bool zeroOut=true) {
169  XPETRA_MONITOR("VectorFactory::Build");
170 
172  if(!bmap.is_null()) {
174  }
175 
176 #ifdef HAVE_XPETRA_TPETRA
177  if (map->lib() == UseTpetra)
178  return rcp( new TpetraVector(map, zeroOut) );
179 #endif
180 
181  if (map->lib() == UseEpetra)
182  return rcp( new EpetraVectorT<long long,Node>(map, zeroOut) );
183 
185  }
186 
187  };
188 #endif
189 
190 #define XPETRA_VECTORFACTORY_SHORT
191 
192 // we need the Epetra specialization only if Epetra is enabled
193 #if (defined(HAVE_XPETRA_EPETRA) && !defined(XPETRA_EPETRA_NO_32BIT_GLOBAL_INDICES))
194 
195 
196  // Specialization for Scalar=int, LO=GO=int and EpetraNode
197  // Used both for Epetra and Tpetra
198  // For any other node definition the general default implementation is used which allows Tpetra only
199  template <>
200  class VectorFactory<int, int, int, EpetraNode> {
201 
202  typedef int Scalar;
203  typedef int LocalOrdinal;
204  typedef int GlobalOrdinal;
205  typedef EpetraNode Node;
206 
207 #undef XPETRA_VECTORFACTORY_SHORT
208 #include "Xpetra_UseShortNames.hpp"
209 
210  private:
213 
214  public:
215 
216  static RCP<Vector> Build(const Teuchos::RCP<const Map>& map, bool zeroOut=true) {
217  XPETRA_MONITOR("VectorFactory::Build");
218 
220  if(!bmap.is_null()) {
222  }
223 
224 #ifdef HAVE_XPETRA_TPETRA
225  if (map->lib() == UseTpetra)
226  return rcp( new TpetraVector(map, zeroOut) );
227 #endif
228 
229  if (map->lib() == UseEpetra)
230  return rcp( new EpetraIntVectorT<int,Node>(map, zeroOut) );
231 
233  }
234 
235  };
236 #endif
237 
238 // we need the Epetra specialization only if Epetra is enabled
239 #if (defined(HAVE_XPETRA_EPETRA) && !defined(XPETRA_EPETRA_NO_64BIT_GLOBAL_INDICES))
240 
241  // Specialization for Scalar=int, LO=int, GO=long long and Serial node
242  // Used both for Epetra and Tpetra
243  // For any other node definition the general default implementation is used which allows Tpetra only
244 
245  template <>
246  class VectorFactory<int, int, long long, EpetraNode> {
247 
248  typedef int Scalar;
249  typedef int LocalOrdinal;
250  typedef long long GlobalOrdinal;
251  typedef EpetraNode Node;
252 
253 #undef XPETRA_VECTORFACTORY_SHORT
254 #include "Xpetra_UseShortNames.hpp"
255 
256  private:
259 
260  public:
261 
262  static RCP<Vector> Build(const Teuchos::RCP<const Map>& map, bool zeroOut=true) {
263  XPETRA_MONITOR("VectorFactory::Build");
264 
266  if(!bmap.is_null()) {
268  }
269 
270 #ifdef HAVE_XPETRA_TPETRA
271  if (map->lib() == UseTpetra)
272  return rcp( new TpetraVector(map, zeroOut) );
273 #endif
274 
275  if (map->lib() == UseEpetra)
276  return rcp( new EpetraIntVectorT<long long,Node>(map, zeroOut) );
277 
279  }
280 
281  };
282 #endif
283 }
284 
285 #define XPETRA_VECTORFACTORY_SHORT
286 #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