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#include "Amesos2_VectorTraits.hpp"
65
66namespace Amesos2 {
67
68
175 template <class MV>
177
185 template <class MV>
186 Teuchos::RCP<MultiVecAdapter<MV> >
187 createMultiVecAdapter(Teuchos::RCP<MV> mv){
188 using Teuchos::rcp;
189
190 if(mv.is_null()) return Teuchos::null;
191 return( rcp(new MultiVecAdapter<MV>(mv)) );
192 }
193
194 template <class MV>
195 Teuchos::RCP<const MultiVecAdapter<MV> >
196 createConstMultiVecAdapter(Teuchos::RCP<const MV> mv){
197 using Teuchos::rcp;
198 using Teuchos::rcp_const_cast;
199
200 if(mv.is_null()) return Teuchos::null;
201 return( rcp(new MultiVecAdapter<MV>(Teuchos::rcp_const_cast<MV,const MV>(mv))).getConst() );
202 }
203
204
206 // Utilities for getting and putting data from MultiVecs //
208
209 namespace Util {
210
217 template <typename MV, typename V>
219
220 typedef typename VectorTraits<V>::ptr_scalar_type ptr_return_type ;
221
222 static ptr_return_type * get_pointer_to_vector ( const Teuchos::Ptr< MV> &mv ) ;
223
224 static ptr_return_type * get_pointer_to_vector ( Teuchos::Ptr< MV> &mv ) ;
225
226 static ptr_return_type * get_pointer_to_vector ( const Teuchos::Ptr< const MV > &mv ) ;
227
228 static ptr_return_type * get_pointer_to_vector ( Teuchos::Ptr< const MV > &mv ) ;
229 };
230
231 /*
232 * If the multivector scalar type and the desired scalar tpye are
233 * the same, then we can do a simple straight copy.
234 */
235 template <typename MV>
236 struct same_type_get_copy {
237 static void apply(const Teuchos::Ptr<const MV> mv,
238 const Teuchos::ArrayView<typename MV::scalar_t>& v,
239 const size_t ldx,
240 Teuchos::Ptr<const Tpetra::Map<typename MV::local_ordinal_t, typename MV::global_ordinal_t, typename MV::node_t> > distribution_map,
241 EDistribution distribution );
242 };
243
244 /*
245 * In the case where the scalar type of the multi-vector and the
246 * corresponding S type are different, then we need to first get a
247 * copy of the scalar values, then convert each one into the S
248 * type before inserting into the vals array.
249 */
250 template <typename MV, typename S>
251 struct diff_type_get_copy {
252 static void apply(const Teuchos::Ptr<const MV> mv,
253 const Teuchos::ArrayView<S>& v,
254 const size_t ldx,
255 Teuchos::Ptr<const Tpetra::Map<typename MV::local_ordinal_t, typename MV::global_ordinal_t, typename MV::node_t> > distribution_map,
256 EDistribution distribution );
257 };
258
265 template <class MV, typename S>
267 static void
268 do_get (const Teuchos::Ptr<const MV>& mv,
269 const Teuchos::ArrayView<S>& vals,
270 const size_t ldx,
271 Teuchos::Ptr<const Tpetra::Map<typename MV::local_ordinal_t, typename MV::global_ordinal_t, typename MV::node_t> > distribution_map,
272 EDistribution distribution = ROOTED);
273
274 static void
275 do_get (const Teuchos::Ptr<const MV>& mv,
276 const Teuchos::ArrayView<S>& vals,
277 const size_t ldx,
278 EDistribution distribution,
279 typename MV::global_ordinal_t indexBase = 0);
280
281 static void
282 do_get (const Teuchos::Ptr<const MV>& mv,
283 const Teuchos::ArrayView<S>& vals,
284 const size_t ldx);
285 };
286
287 /*
288 do_get
289
290 Return type (bool):
291 true: The input kokkos_vals view is now pointing directly to the adapter's data (same memory and type).
292 If this is x for an Ax=b solve, you don't need 'do_put x' after the solve since you modified the adapter directly.
293 false: The input kokkos_vals view is now resized to match the adapter's size.
294 kokkos_vals will only have the adapter values deep_copied if bInitialize is true (see below).
295 If this is x for an Ax=b solve, you must call 'do_put x' after the solve to deep copy back to the adapter.
296
297 Inputs
298 bInitialize (bool): tells the adapter whether kokkos_vals needs to have the values of the adapter.
299 true: We require kokkos_vals to have the same size and values of the adapter.
300 For b in Ax=b solves, set bInitialize true because you need the size and values of the adapter.
301 false: We require kokkos_vals to have the same size as the adapter but we don't need the values.
302 For x in Ax=b solves, set bInitialize false because you just need the size, not the values.
303
304 Note: When this method returns true, meaning direct assignment of the view occurred,
305 bInitialize is not used because you already have the values whether you need them or not.
306
307 kokkos_vals (View<scalar_t**>): The view which will contain the x or b data.
308 Do not allocate the size of kokkos_vals, let the do_get method do it for you.
309 This is because kokkos_vals may be set to point directly to the adapter memory
310 and then any pre-allocation of size will have been wasted.
311 */
312 template <class MV, typename KV>
313 struct get_1d_copy_helper_kokkos_view {
314 static bool
315 do_get (bool bInitialize,
316 const Teuchos::Ptr<const MV>& mv,
317 KV& kokkos_vals,
318 const size_t ldx,
319 Teuchos::Ptr<const Tpetra::Map<typename MV::local_ordinal_t, typename MV::global_ordinal_t, typename MV::node_t> > distribution_map,
320 EDistribution distribution = ROOTED);
321
322 static bool
323 do_get (bool bInitialize,
324 const Teuchos::Ptr<const MV>& mv,
325 KV& kokkos_vals,
326 const size_t ldx,
327 EDistribution distribution,
328 typename MV::global_ordinal_t indexBase = 0);
329
330 static bool
331 do_get (bool bInitialize,
332 const Teuchos::Ptr<const MV>& mv,
333 KV& kokkos_vals,
334 const size_t ldx);
335 };
336
337 /*
338 * If the multivector scalar type and the desired scalar tpye are
339 * the same, then we can do a simple straight copy.
340 */
341 template <typename MV>
342 struct same_type_data_put {
343 static void apply(const Teuchos::Ptr<MV>& mv,
344 const Teuchos::ArrayView<typename MV::scalar_t>& data,
345 const size_t ldx,
346 Teuchos::Ptr<const Tpetra::Map<typename MV::local_ordinal_t, typename MV::global_ordinal_t, typename MV::node_t> > distribution_map,
347 EDistribution distribution );
348 };
349
350 /*
351 * In the case where the scalar type of the multi-vector and the
352 * corresponding S type are different, then we need to first get a
353 * copy of the scalar values, then convert each one into the S
354 * type before inserting into the vals array.
355 */
356 template <typename MV, typename S>
357 struct diff_type_data_put {
358 static void apply(const Teuchos::Ptr<MV>& mv,
359 const Teuchos::ArrayView<S>& data,
360 const size_t ldx,
361 Teuchos::Ptr<const Tpetra::Map<typename MV::local_ordinal_t, typename MV::global_ordinal_t, typename MV::node_t> > distribution_map,
362 EDistribution distribution );
363 };
364
371 template <class MV, typename S>
373 static void do_put(const Teuchos::Ptr<MV>& mv,
374 const Teuchos::ArrayView<S>& data,
375 const size_t ldx,
376 Teuchos::Ptr<const Tpetra::Map<typename MV::local_ordinal_t, typename MV::global_ordinal_t, typename MV::node_t> > distribution_map,
377 EDistribution distribution = ROOTED);
378
379 static void do_put(const Teuchos::Ptr<MV>& mv,
380 const Teuchos::ArrayView<S>& data,
381 const size_t ldx,
382 EDistribution distribution, typename MV::global_ordinal_t indexBase = 0);
383
384 static void do_put(const Teuchos::Ptr<MV>& mv,
385 const Teuchos::ArrayView<S>& data,
386 const size_t ldx);
387 };
388
389 template <class MV, typename KV>
390 struct put_1d_data_helper_kokkos_view {
391 static void do_put(const Teuchos::Ptr<MV>& mv,
392 KV& kokkos_data,
393 const size_t ldx,
394 Teuchos::Ptr<const Tpetra::Map<typename MV::local_ordinal_t, typename MV::global_ordinal_t, typename MV::node_t> > distribution_map,
395 EDistribution distribution = ROOTED);
396
397 static void do_put(const Teuchos::Ptr<MV>& mv,
398 KV& kokkos_data,
399 const size_t ldx,
400 EDistribution distribution, typename MV::global_ordinal_t indexBase = 0);
401
402 static void do_put(const Teuchos::Ptr<MV>& mv,
403 KV& kokkos_data,
404 const size_t ldx);
405 };
406 }
407} // end namespace Amesos2
408
411#ifdef HAVE_AMESOS2_EPETRA
413#endif
414
415#endif // AMESOS2_MULTIVEC_ADAPTER_DECL_HPP
Amesos2::MultiVecAdapter specialization for the Epetra_MultiVector class.
Amesos2::MultiVecAdapter specialization for the Kokkos::View class.
Amesos2::MultiVecAdapter specialization for the Tpetra::MultiVector class.
Enum and other types declarations for Amesos2.
@ ROOTED
Definition: Amesos2_TypeDecl.hpp:127
EDistribution
Definition: Amesos2_TypeDecl.hpp:123
A templated MultiVector class adapter for Amesos2.
Definition: Amesos2_MultiVecAdapter_decl.hpp:176
Teuchos::RCP< MultiVecAdapter< MV > > createMultiVecAdapter(Teuchos::RCP< MV > mv)
Factory creation method for MultiVecAdapters.
Definition: Amesos2_MultiVecAdapter_decl.hpp:187
Helper class for getting 1-D copies of multivectors.
Definition: Amesos2_MultiVecAdapter_decl.hpp:266
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, EDistribution distribution=ROOTED)
Helper class for getting 1-D copies of multivectors.
Definition: Amesos2_MultiVecAdapter_def.hpp:146
Helper class for putting 1-D data arrays into multivectors.
Definition: Amesos2_MultiVecAdapter_decl.hpp:372
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, EDistribution distribution=ROOTED)
Helper class for putting 1-D data arrays into multivectors.
Definition: Amesos2_MultiVecAdapter_def.hpp:321
Helper struct for getting pointers to the MV data - only used when number of vectors = 1 and single M...
Definition: Amesos2_MultiVecAdapter_decl.hpp:218