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_BlockedMap.hpp"
63 
64 #include "Xpetra_Exceptions.hpp"
65 
66 namespace Xpetra {
67 
68 #ifndef DOXYGEN_SHOULD_SKIP_THIS
69  // forward declaration of BlockedMultiVector, needed to prevent circular inclusions
70  //template<class SC, class LO, class GO, class N> class BlockedMultiVector;
71 #endif
72 
73  template <class Scalar = MultiVector<>::scalar_type,
74  class LocalOrdinal =
76  class GlobalOrdinal =
78  class Node =
81  private:
84 
85  public:
86 
90  size_t NumVectors,
91  bool zeroOut=true)
92  {
93  XPETRA_MONITOR("MultiVectorFactory::Build");
94 
96  if(!bmap.is_null()) {
98  }
99 
100 #ifdef HAVE_XPETRA_TPETRA
101  if (map->lib() == UseTpetra)
102  return rcp( new TpetraMultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> (map, NumVectors, zeroOut) );
103 #endif
104 
105  XPETRA_FACTORY_ERROR_IF_EPETRA(map->lib());
107  }
108 
111  XPETRA_MONITOR("MultiVectorFactory::Build");
112 
113 #ifdef HAVE_XPETRA_TPETRA
114  if (map->lib() == UseTpetra)
115  return rcp( new TpetraMultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> (map, ArrayOfPtrs, NumVectors) );
116 #endif
117 
118  XPETRA_FACTORY_ERROR_IF_EPETRA(map->lib());
120  }
121 
122  };
123 
124 
125 // we need the Epetra specialization only if Epetra is enabled
126 #if (defined(HAVE_XPETRA_EPETRA) && !defined(XPETRA_EPETRA_NO_32BIT_GLOBAL_INDICES))
127 
128 
129  // Specialization for Scalar=double, LO=GO=int and Serial node
130  // Used both for Epetra and Tpetra
131  // For any other node definition the general default implementation is used which allows Tpetra only
132  template <>
133  class MultiVectorFactory<double, int, int, EpetraNode> {
134 
135  typedef double Scalar;
136  typedef int LocalOrdinal;
137  typedef int GlobalOrdinal;
138  typedef EpetraNode Node;
139 
140  private:
143 
144  public:
145 
147  XPETRA_MONITOR("MultiVectorFactory::Build");
148 
150  if(!bmap.is_null()) {
151  return rcp(new BlockedMultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>(bmap, NumVectors, zeroOut));
152  }
153 
154 #ifdef HAVE_XPETRA_TPETRA
155  if (map->lib() == UseTpetra)
156  return rcp( new TpetraMultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> (map, NumVectors, zeroOut) );
157 #endif
158 
159  if (map->lib() == UseEpetra)
160  return rcp( new EpetraMultiVectorT<int,Node>(map, NumVectors, zeroOut) );
161 
163  }
164 
167  XPETRA_MONITOR("MultiVectorFactory::Build");
168 
169 #ifdef HAVE_XPETRA_TPETRA
170  if (map->lib() == UseTpetra)
171  return rcp( new TpetraMultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> (map, ArrayOfPtrs, NumVectors) );
172 #endif
173 
174  if (map->lib() == UseEpetra)
175  return rcp( new EpetraMultiVectorT<int,Node>(map, ArrayOfPtrs, NumVectors) );
176 
178  }
179 
180  };
181 
182 // we need the Epetra specialization only if Epetra is enabled
183 #if (defined(HAVE_XPETRA_EPETRA) && !defined(XPETRA_EPETRA_NO_64BIT_GLOBAL_INDICES))
184 
185  template <>
186  class MultiVectorFactory<double, int, long long, EpetraNode> {
187 
188  typedef double Scalar;
189  typedef int LocalOrdinal;
190  typedef long long GlobalOrdinal;
191  typedef EpetraNode Node;
192 
193  private:
196 
197  public:
198 
200  XPETRA_MONITOR("MultiVectorFactory::Build");
201 
203  if(!bmap.is_null()) {
204  return rcp(new BlockedMultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>(bmap, NumVectors, zeroOut));
205  }
206 
207 #ifdef HAVE_XPETRA_TPETRA
208  if (map->lib() == UseTpetra)
209  return rcp( new TpetraMultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> (map, NumVectors, zeroOut) );
210 #endif
211 
212  if (map->lib() == UseEpetra)
213  return rcp( new EpetraMultiVectorT<long long,Node>(map, NumVectors, zeroOut) );
214 
216  }
217 
220  XPETRA_MONITOR("MultiVectorFactory::Build");
221 
222 #ifdef HAVE_XPETRA_TPETRA
223  if (map->lib() == UseTpetra)
224  return rcp( new TpetraMultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> (map, ArrayOfPtrs, NumVectors) );
225 #endif
226 
227  if (map->lib() == UseEpetra)
228  return rcp( new EpetraMultiVectorT<long long,Node>(map, ArrayOfPtrs, NumVectors) );
229 
231  }
232 
233  };
234 #endif // Epetra64
235 #endif // HAVE_XPETRA_EPETRA
236 
237 }
238 
239 #define XPETRA_MULTIVECTORFACTORY_SHORT
240 #endif
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).
Xpetra namespace
#define XPETRA_FACTORY_ERROR_IF_EPETRA(lib)
bool is_null() const
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
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).
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 RCP< MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > Build(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &map, size_t NumVectors, bool zeroOut=true)
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)
static RCP< MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > Build(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &map, size_t NumVectors, bool zeroOut=true)