Xpetra  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Xpetra_VectorFactory_decl.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_DECL_HPP
47 #define XPETRA_VECTORFACTORY_DECL_HPP
48 
49 #include "Xpetra_ConfigDefs.hpp"
50 #include "Xpetra_Vector.hpp"
51 
52 #ifdef HAVE_XPETRA_TPETRA
54 #endif
55 #ifdef HAVE_XPETRA_EPETRA
56 #include "Xpetra_EpetraVector.hpp"
58 #endif
59 
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:
76  VectorFactory() = default;
77 
78  public:
80  static Teuchos::RCP<Xpetra::Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node>>
81  Build(const Teuchos::RCP<const Xpetra::Map<LocalOrdinal, GlobalOrdinal, Node>>& map, bool zeroOut = true) {
82  XPETRA_MONITOR("VectorFactory::Build");
83 
84  RCP<const Xpetra::BlockedMap<LocalOrdinal, GlobalOrdinal, Node>>
85  bmap = Teuchos::rcp_dynamic_cast<const Xpetra::BlockedMap<LocalOrdinal, GlobalOrdinal, Node>>(map);
86 
87  if (!bmap.is_null()) {
89  }
90 
91 #ifdef HAVE_XPETRA_TPETRA
92  if (map->lib() == UseTpetra) {
93  return rcp(new TpetraVector(map, zeroOut));
94  }
95 #endif
96 
99  }
100 
101 }; // class VectorFactory
102 
103 #define XPETRA_VECTORFACTORY_SHORT
104 
105 #if defined(HAVE_XPETRA_EPETRA)
106 
107 // we need the Epetra specialization only if Epetra is enabled
108 #if !defined(XPETRA_EPETRA_NO_32BIT_GLOBAL_INDICES)
109 
110 // Specialization for Scalar=double, LO=GO=int and EpetraNode node
111 // Used both for Epetra and Tpetra
112 // For any other node definition the general default implementation is used which allows Tpetra only
113 template <>
114 class VectorFactory<double, int, int, EpetraNode> {
115  typedef double Scalar;
116  typedef int LocalOrdinal;
117  typedef int GlobalOrdinal;
118  typedef EpetraNode Node;
119 
120 #undef XPETRA_VECTORFACTORY_SHORT
121 #include "Xpetra_UseShortNames.hpp"
122 
123  private:
125  VectorFactory() = default;
126 
127  public:
128  static RCP<Xpetra::Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node>>
129  Build(const Teuchos::RCP<const Xpetra::Map<LocalOrdinal, GlobalOrdinal, Node>>& map,
130  bool zeroOut = true);
131 };
132 #endif // #if !defined(XPETRA_EPETRA_NO_32BIT_GLOBAL_INDICES)
133 
134 // Specialization for Scalar=double, LO=int, GO=long long and EpetraNode
135 // Used both for Epetra and Tpetra
136 // For any other node definition the general default implementation is used which allows Tpetra only
137 #if !defined(XPETRA_EPETRA_NO_64BIT_GLOBAL_INDICES)
138 
139 template <>
140 class VectorFactory<double, int, long long, EpetraNode> {
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:
151  VectorFactory() = default;
152 
153  public:
154  static RCP<Xpetra::Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node>>
155  Build(const Teuchos::RCP<const Xpetra::Map<LocalOrdinal, GlobalOrdinal, Node>>& map,
156  bool zeroOut = true);
157 };
158 #endif // #if !defined(XPETRA_EPETRA_NO_64BIT_GLOBAL_INDICES)
159 #define XPETRA_VECTORFACTORY_SHORT
160 
161 // we need the Epetra specialization only if Epetra is enabled
162 #if !defined(XPETRA_EPETRA_NO_32BIT_GLOBAL_INDICES)
163 
164 // Specialization for Scalar=int, LO=GO=int and EpetraNode
165 // Used both for Epetra and Tpetra
166 // For any other node definition the general default implementation is used which allows Tpetra only
167 template <>
168 class VectorFactory<int, int, int, EpetraNode> {
169  typedef int Scalar;
170  typedef int LocalOrdinal;
171  typedef int GlobalOrdinal;
172  typedef EpetraNode Node;
173 
174 #undef XPETRA_VECTORFACTORY_SHORT
175 #include "Xpetra_UseShortNames.hpp"
176 
177  private:
179  VectorFactory() = default;
180 
181  public:
182  static RCP<Xpetra::Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node>>
183  Build(const Teuchos::RCP<const Xpetra::Map<LocalOrdinal, GlobalOrdinal, Node>>& map,
184  bool zeroOut = true);
185 };
186 #endif // #if !defined(XPETRA_EPETRA_NO_32BIT_GLOBAL_INDICES)
187 
188 // we need the Epetra specialization only if Epetra is enabled
189 #if !defined(XPETRA_EPETRA_NO_64BIT_GLOBAL_INDICES)
190 
191 // Specialization for Scalar=int, LO=int, GO=long long and Serial node
192 // Used both for Epetra and Tpetra
193 // For any other node definition the general default implementation is used which allows Tpetra only
194 
195 template <>
196 class VectorFactory<int, int, long long, EpetraNode> {
197  typedef int Scalar;
198  typedef int LocalOrdinal;
199  typedef long long GlobalOrdinal;
200  typedef EpetraNode Node;
201 
202 #undef XPETRA_VECTORFACTORY_SHORT
203 #include "Xpetra_UseShortNames.hpp"
204 
205  private:
207  VectorFactory() = default;
208 
209  public:
210  static RCP<Xpetra::Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node>>
211  Build(const Teuchos::RCP<const Xpetra::Map<LocalOrdinal, GlobalOrdinal, Node>>& map,
212  bool zeroOut = true);
213 };
214 #endif // !defined(XPETRA_EPETRA_NO_64BIT_GLOBAL_INDICES)
215 
216 #endif // #if defined(HAVE_XPETRA_EPETRA)
217 
218 } // namespace Xpetra
219 
220 #define XPETRA_VECTORFACTORY_SHORT
221 #endif // XPETRA_VECTORFACTORY_DECL_HPP
VectorFactory()=default
Private constructor. This is a static class.
static Teuchos::RCP< Xpetra::Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > Build(const Teuchos::RCP< const Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node >> &map, bool zeroOut=true)
Constructor specifying the number of non-zeros for all rows.
#define XPETRA_FACTORY_ERROR_IF_EPETRA(lib)
#define XPETRA_FACTORY_END
Tpetra::KokkosCompat::KokkosSerialWrapperNode EpetraNode
#define XPETRA_MONITOR(funcName)