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 do_get(const Teuchos::Ptr<const MV>& mv,
245  const Teuchos::ArrayView<S>& vals,
246  const size_t ldx,
247  Teuchos::Ptr<const Tpetra::Map<typename MV::local_ordinal_t, typename MV::global_ordinal_t, typename MV::node_t> > distribution_map );
248 
249  static void do_get(const Teuchos::Ptr<const MV>& mv,
250  const Teuchos::ArrayView<S>& vals,
251  const size_t ldx,
252  EDistribution distribution, typename MV::global_ordinal_t indexBase = 0);
253 
254  static void do_get(const Teuchos::Ptr<const MV>& mv,
255  const Teuchos::ArrayView<S>& vals,
256  const size_t ldx);
257  };
258 
259  /*
260  * If the multivector scalar type and the desired scalar tpye are
261  * the same, then we can do a simple straight copy.
262  */
263  template <typename MV>
264  struct same_type_data_put {
265  static void apply(const Teuchos::Ptr<MV>& mv,
266  const Teuchos::ArrayView<typename MV::scalar_t>& data,
267  const size_t ldx,
268  Teuchos::Ptr<const Tpetra::Map<typename MV::local_ordinal_t, typename MV::global_ordinal_t, typename MV::node_t> > distribution_map );
269  };
270 
271  /*
272  * In the case where the scalar type of the multi-vector and the
273  * corresponding S type are different, then we need to first get a
274  * copy of the scalar values, then convert each one into the S
275  * type before inserting into the vals array.
276  */
277  template <typename MV, typename S>
278  struct diff_type_data_put {
279  static void apply(const Teuchos::Ptr<MV>& mv,
280  const Teuchos::ArrayView<S>& data,
281  const size_t& ldx,
282  Teuchos::Ptr<const Tpetra::Map<typename MV::local_ordinal_t, typename MV::global_ordinal_t, typename MV::node_t> > distribution_map );
283  };
284 
291  template <class MV, typename S>
293  static void do_put(const Teuchos::Ptr<MV>& mv,
294  const Teuchos::ArrayView<S>& data,
295  const size_t ldx,
296  Teuchos::Ptr<const Tpetra::Map<typename MV::local_ordinal_t, typename MV::global_ordinal_t, typename MV::node_t> > distribution_map );
297 
298  static void do_put(const Teuchos::Ptr<MV>& mv,
299  const Teuchos::ArrayView<S>& data,
300  const size_t ldx,
301  EDistribution distribution, typename MV::global_ordinal_t indexBase = 0);
302 
303  static void do_put(const Teuchos::Ptr<MV>& mv,
304  const Teuchos::ArrayView<S>& data,
305  const size_t ldx);
306  };
307  }
308 } // end namespace Amesos2
309 
311 #ifdef HAVE_AMESOS2_EPETRA
313 #endif
314 
315 #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
Helper class for getting 1-D copies of multivectors.
Definition: Amesos2_MultiVecAdapter_decl.hpp:243
Definition: Amesos2_AbstractConcreteMatrixAdapter.hpp:48
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:115
Helper class for putting 1-D data arrays into multivectors.
Definition: Amesos2_MultiVecAdapter_decl.hpp:292
A templated MultiVector class adapter for Amesos2.
Definition: Amesos2_MultiVecAdapter_decl.hpp:175