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_Exceptions.hpp"
61 
62 namespace Xpetra {
63 
64  template <class Scalar/* = Vector<>::scalar_type*/,
65  class LocalOrdinal/* = typename Vector<Scalar>::local_ordinal_type*/,
66  class GlobalOrdinal/* = typename Vector<Scalar, LocalOrdinal>::local_ordinal_type*/,
67  class Node/* = typename Vector<Scalar, LocalOrdinal, GlobalOrdinal>::node_type*/>
68  class VectorFactory {
69 #undef XPETRA_VECTORFACTORY_SHORT
70 #include "Xpetra_UseShortNames.hpp"
71 
72  private:
75 
76  public:
77 
79  static RCP<Vector> Build(const Teuchos::RCP<const Map> &map, bool zeroOut=true) {
80  XPETRA_MONITOR("VectorFactory::Build");
81 
82 #ifdef HAVE_XPETRA_TPETRA
83  if (map->lib() == UseTpetra)
84  return rcp( new TpetraVector(map, zeroOut) );
85 #endif
86 
89  }
90 
91  };
92 #define XPETRA_VECTORFACTORY_SHORT
93 
94 // we need the Epetra specialization only if Epetra is enabled
95 #if (defined(HAVE_XPETRA_EPETRA) && !defined(XPETRA_EPETRA_NO_32BIT_GLOBAL_INDICES))
96 
97  // Specialization for Scalar=double, LO=GO=int and EpetraNode node
98  // Used both for Epetra and Tpetra
99  // For any other node definition the general default implementation is used which allows Tpetra only
100  template <>
101  class VectorFactory<double, int, int, EpetraNode> {
102  typedef double Scalar;
103  typedef int LocalOrdinal;
104  typedef int GlobalOrdinal;
105  typedef EpetraNode Node;
106 
107 #undef XPETRA_VECTORFACTORY_SHORT
108 #include "Xpetra_UseShortNames.hpp"
109 
110  private:
113 
114  public:
115 
116  static RCP<Vector> Build(const Teuchos::RCP<const Map>& map, bool zeroOut=true) {
117  XPETRA_MONITOR("VectorFactory::Build");
118 
119 #ifdef HAVE_XPETRA_TPETRA
120  if (map->lib() == UseTpetra)
121  return rcp( new TpetraVector(map, zeroOut) );
122 #endif
123 
124  if (map->lib() == UseEpetra)
125  return rcp( new EpetraVectorT<int,Node>(map, zeroOut) );
126 
128  }
129 
130  };
131 #endif
132 
133  // Specialization for Scalar=double, LO=int, GO=long long and EpetraNode
134  // Used both for Epetra and Tpetra
135  // For any other node definition the general default implementation is used which allows Tpetra only
136 #if (defined(HAVE_XPETRA_EPETRA) && !defined(XPETRA_EPETRA_NO_64BIT_GLOBAL_INDICES))
137 
138  template <>
139  class VectorFactory<double, int, long long, EpetraNode> {
140 
141  typedef double Scalar;
142  typedef int LocalOrdinal;
143  typedef long long GlobalOrdinal;
144  typedef EpetraNode Node;
145 
146 #undef XPETRA_VECTORFACTORY_SHORT
147 #include "Xpetra_UseShortNames.hpp"
148 
149  private:
152 
153  public:
154 
155  static RCP<Vector> Build(const Teuchos::RCP<const Map>& map, bool zeroOut=true) {
156  XPETRA_MONITOR("VectorFactory::Build");
157 
158 #ifdef HAVE_XPETRA_TPETRA
159  if (map->lib() == UseTpetra)
160  return rcp( new TpetraVector(map, zeroOut) );
161 #endif
162 
163  if (map->lib() == UseEpetra)
164  return rcp( new EpetraVectorT<long long,Node>(map, zeroOut) );
165 
167  }
168 
169  };
170 #endif
171 
172 #define XPETRA_VECTORFACTORY_SHORT
173 
174 // we need the Epetra specialization only if Epetra is enabled
175 #if (defined(HAVE_XPETRA_EPETRA) && !defined(XPETRA_EPETRA_NO_32BIT_GLOBAL_INDICES))
176 
177 
178  // Specialization for Scalar=int, LO=GO=int and EpetraNode
179  // Used both for Epetra and Tpetra
180  // For any other node definition the general default implementation is used which allows Tpetra only
181  template <>
182  class VectorFactory<int, int, int, EpetraNode> {
183 
184  typedef int Scalar;
185  typedef int LocalOrdinal;
186  typedef int GlobalOrdinal;
187  typedef EpetraNode Node;
188 
189 #undef XPETRA_VECTORFACTORY_SHORT
190 #include "Xpetra_UseShortNames.hpp"
191 
192  private:
195 
196  public:
197 
198  static RCP<Vector> Build(const Teuchos::RCP<const Map>& map, bool zeroOut=true) {
199  XPETRA_MONITOR("VectorFactory::Build");
200 
201 #ifdef HAVE_XPETRA_TPETRA
202  if (map->lib() == UseTpetra)
203  return rcp( new TpetraVector(map, zeroOut) );
204 #endif
205 
206  if (map->lib() == UseEpetra)
207  return rcp( new EpetraIntVectorT<int,Node>(map, zeroOut) );
208 
210  }
211 
212  };
213 #endif
214 
215 // we need the Epetra specialization only if Epetra is enabled
216 #if (defined(HAVE_XPETRA_EPETRA) && !defined(XPETRA_EPETRA_NO_64BIT_GLOBAL_INDICES))
217 
218  // Specialization for Scalar=int, LO=int, GO=long long and Serial node
219  // Used both for Epetra and Tpetra
220  // For any other node definition the general default implementation is used which allows Tpetra only
221 
222  template <>
223  class VectorFactory<int, int, long long, EpetraNode> {
224 
225  typedef int Scalar;
226  typedef int LocalOrdinal;
227  typedef long long GlobalOrdinal;
228  typedef EpetraNode Node;
229 
230 #undef XPETRA_VECTORFACTORY_SHORT
231 #include "Xpetra_UseShortNames.hpp"
232 
233  private:
236 
237  public:
238 
239  static RCP<Vector> Build(const Teuchos::RCP<const Map>& map, bool zeroOut=true) {
240  XPETRA_MONITOR("VectorFactory::Build");
241 
242 #ifdef HAVE_XPETRA_TPETRA
243  if (map->lib() == UseTpetra)
244  return rcp( new TpetraVector(map, zeroOut) );
245 #endif
246 
247  if (map->lib() == UseEpetra)
248  return rcp( new EpetraIntVectorT<long long,Node>(map, zeroOut) );
249 
251  }
252 
253  };
254 #endif
255 }
256 
257 #define XPETRA_VECTORFACTORY_SHORT
258 #endif
static RCP< Vector > Build(const Teuchos::RCP< const Map > &map, bool zeroOut=true)
VectorFactory()
Private constructor. This is a static class.
Xpetra namespace
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.
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)