Amesos2 - Direct Sparse Solver Interfaces  Version of the Day
Amesos2_MultiVecAdapter_decl.hpp
1 // @HEADER
2 //
3 // ***********************************************************************
4 //
5 // Amesos2: Templated Direct Sparse Solver Package
6 // Copyright 2011 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 Michael A. Heroux (maherou@sandia.gov)
39 //
40 // ***********************************************************************
41 //
42 // @HEADER
43 
55 #ifndef AMESOS2_MULTIVEC_ADAPTER_DECL_HPP
56 #define AMESOS2_MULTIVEC_ADAPTER_DECL_HPP
57 
58 #include <Teuchos_RCP.hpp>
59 #include <Teuchos_Ptr.hpp>
60 #include <Teuchos_ArrayView.hpp>
61 #include <Tpetra_Map.hpp>
62 
63 #include "Amesos2_TypeDecl.hpp"
64 
65 namespace Amesos2 {
66 
67 
174  template <class MV>
175  struct MultiVecAdapter {};
176 
184  template <class MV>
185  Teuchos::RCP<MultiVecAdapter<MV> >
186  createMultiVecAdapter(Teuchos::RCP<MV> mv){
187  using Teuchos::rcp;
188 
189  if(mv.is_null()) return Teuchos::null;
190  return( rcp(new MultiVecAdapter<MV>(mv)) );
191  }
192 
193  template <class MV>
194  Teuchos::RCP<const MultiVecAdapter<MV> >
195  createConstMultiVecAdapter(Teuchos::RCP<const MV> mv){
196  using Teuchos::rcp;
197  using Teuchos::rcp_const_cast;
198 
199  if(mv.is_null()) return Teuchos::null;
200  return( rcp(new MultiVecAdapter<MV>(Teuchos::rcp_const_cast<MV,const MV>(mv))).getConst() );
201  }
202 
203 
205  // Utilities for getting and putting data from MultiVecs //
207 
208  namespace Util {
209 
210  /*
211  * If the multivector scalar type and the desired scalar tpye are
212  * the same, then we can do a simple straight copy.
213  */
214  template <typename MV>
215  struct same_type_get_copy {
216  static void apply(const Teuchos::Ptr<const MV>& mv,
217  const Teuchos::ArrayView<typename MV::scalar_t>& v,
218  const size_t ldx,
219  Teuchos::Ptr<const Tpetra::Map<typename MV::local_ordinal_t, typename MV::global_ordinal_t, typename MV::node_t> > distribution_map );
220  };
221 
222  /*
223  * In the case where the scalar type of the multi-vector and the
224  * corresponding S type are different, then we need to first get a
225  * copy of the scalar values, then convert each one into the S
226  * type before inserting into the vals array.
227  */
228  template <typename MV, typename S>
229  struct diff_type_get_copy {
230  static void apply(const Teuchos::Ptr<const MV>& mv,
231  const Teuchos::ArrayView<S>& v,
232  const size_t& ldx,
233  Teuchos::Ptr<const Tpetra::Map<typename MV::local_ordinal_t, typename MV::global_ordinal_t, typename MV::node_t> > distribution_map );
234  };
235 
242  template <class MV, typename S>
244  static void
245  do_get (const Teuchos::Ptr<const MV>& mv,
246  const Teuchos::ArrayView<S>& vals,
247  const size_t ldx,
248  Teuchos::Ptr<const Tpetra::Map<typename MV::local_ordinal_t, typename MV::global_ordinal_t, typename MV::node_t> > distribution_map );
249 
250  static void
251  do_get (const Teuchos::Ptr<const MV>& mv,
252  const Teuchos::ArrayView<S>& vals,
253  const size_t ldx,
254  EDistribution distribution,
255  typename MV::global_ordinal_t indexBase = 0);
256 
257  static void
258  do_get (const Teuchos::Ptr<const MV>& mv,
259  const Teuchos::ArrayView<S>& vals,
260  const size_t ldx);
261  };
262 
263  /*
264  * If the multivector scalar type and the desired scalar tpye are
265  * the same, then we can do a simple straight copy.
266  */
267  template <typename MV>
268  struct same_type_data_put {
269  static void apply(const Teuchos::Ptr<MV>& mv,
270  const Teuchos::ArrayView<typename MV::scalar_t>& data,
271  const size_t ldx,
272  Teuchos::Ptr<const Tpetra::Map<typename MV::local_ordinal_t, typename MV::global_ordinal_t, typename MV::node_t> > distribution_map );
273  };
274 
275  /*
276  * In the case where the scalar type of the multi-vector and the
277  * corresponding S type are different, then we need to first get a
278  * copy of the scalar values, then convert each one into the S
279  * type before inserting into the vals array.
280  */
281  template <typename MV, typename S>
282  struct diff_type_data_put {
283  static void apply(const Teuchos::Ptr<MV>& mv,
284  const Teuchos::ArrayView<S>& data,
285  const size_t& ldx,
286  Teuchos::Ptr<const Tpetra::Map<typename MV::local_ordinal_t, typename MV::global_ordinal_t, typename MV::node_t> > distribution_map );
287  };
288 
295  template <class MV, typename S>
297  static void do_put(const Teuchos::Ptr<MV>& mv,
298  const Teuchos::ArrayView<S>& data,
299  const size_t ldx,
300  Teuchos::Ptr<const Tpetra::Map<typename MV::local_ordinal_t, typename MV::global_ordinal_t, typename MV::node_t> > distribution_map );
301 
302  static void do_put(const Teuchos::Ptr<MV>& mv,
303  const Teuchos::ArrayView<S>& data,
304  const size_t ldx,
305  EDistribution distribution, typename MV::global_ordinal_t indexBase = 0);
306 
307  static void do_put(const Teuchos::Ptr<MV>& mv,
308  const Teuchos::ArrayView<S>& data,
309  const size_t ldx);
310  };
311  }
312 } // end namespace Amesos2
313 
315 #ifdef HAVE_AMESOS2_EPETRA
317 #endif
318 
319 #endif // AMESOS2_MULTIVEC_ADAPTER_DECL_HPP
Teuchos::RCP< MultiVecAdapter< MV > > createMultiVecAdapter(Teuchos::RCP< MV > mv)
Factory creation method for MultiVecAdapters.
Definition: Amesos2_MultiVecAdapter_decl.hpp:186
static void do_get(const Teuchos::Ptr< const MV > &mv, const Teuchos::ArrayView< S > &vals, const size_t ldx, Teuchos::Ptr< const Tpetra::Map< typename MV::local_ordinal_t, typename MV::global_ordinal_t, typename MV::node_t > > distribution_map)
Helper class for getting 1-D copies of multivectors.
Definition: Amesos2_MultiVecAdapter_def.hpp:114
Helper class for getting 1-D copies of multivectors.
Definition: Amesos2_MultiVecAdapter_decl.hpp:243
Definition: Amesos2_AbstractConcreteMatrixAdapter.hpp:48
static void do_put(const Teuchos::Ptr< MV > &mv, const Teuchos::ArrayView< S > &data, const size_t ldx, Teuchos::Ptr< const Tpetra::Map< typename MV::local_ordinal_t, typename MV::global_ordinal_t, typename MV::node_t > > distribution_map)
Helper class for putting 1-D data arrays into multivectors.
Definition: Amesos2_MultiVecAdapter_def.hpp:220
Amesos2::MultiVecAdapter specialization for the Tpetra::MultiVector class.
Amesos2::MultiVecAdapter specialization for the Epetra_MultiVector class.
Enum and other types declarations for Amesos2.
EDistribution
Definition: Amesos2_TypeDecl.hpp:123
Helper class for putting 1-D data arrays into multivectors.
Definition: Amesos2_MultiVecAdapter_decl.hpp:296
A templated MultiVector class adapter for Amesos2.
Definition: Amesos2_MultiVecAdapter_decl.hpp:175