Amesos2 - Direct Sparse Solver Interfaces Version of the Day
Amesos2_MultiVecAdapter_decl.hpp
1// @HEADER
2// *****************************************************************************
3// Amesos2: Templated Direct Sparse Solver Package
4//
5// Copyright 2011 NTESS and the Amesos2 contributors.
6// SPDX-License-Identifier: BSD-3-Clause
7// *****************************************************************************
8// @HEADER
9
21#ifndef AMESOS2_MULTIVEC_ADAPTER_DECL_HPP
22#define AMESOS2_MULTIVEC_ADAPTER_DECL_HPP
23
24#include <Teuchos_RCP.hpp>
25#include <Teuchos_Ptr.hpp>
26#include <Teuchos_ArrayView.hpp>
27#include <Tpetra_Map.hpp>
28
29#include "Amesos2_TypeDecl.hpp"
30#include "Amesos2_VectorTraits.hpp"
31
32namespace Amesos2 {
33
34
141 template <class MV>
143
144
152 template <class MV>
153 Teuchos::RCP<MultiVecAdapter<MV> >
154 createMultiVecAdapter(Teuchos::RCP<MV> mv){
155 using Teuchos::rcp;
156
157 if(mv.is_null()) return Teuchos::null;
158 return( rcp(new MultiVecAdapter<MV>(mv)) );
159 }
160
161 template <class MV>
162 Teuchos::RCP<const MultiVecAdapter<MV> >
163 createConstMultiVecAdapter(Teuchos::RCP<const MV> mv){
164 using Teuchos::rcp;
165 using Teuchos::rcp_const_cast;
166
167 if(mv.is_null()) return Teuchos::null;
168 return( rcp(new MultiVecAdapter<MV>(Teuchos::rcp_const_cast<MV,const MV>(mv))).getConst() );
169 }
170
171
173 // Utilities for getting and putting data from MultiVecs //
175
176 namespace Util {
177
184 template <typename MV, typename V>
186
187 typedef typename VectorTraits<V>::ptr_scalar_type ptr_return_type ;
188
189 static ptr_return_type * get_pointer_to_vector ( const Teuchos::Ptr< MV> &mv ) ;
190
191 static ptr_return_type * get_pointer_to_vector ( Teuchos::Ptr< MV> &mv ) ;
192
193 static ptr_return_type * get_pointer_to_vector ( const Teuchos::Ptr< const MV > &mv ) ;
194
195 static ptr_return_type * get_pointer_to_vector ( Teuchos::Ptr< const MV > &mv ) ;
196 };
197
198 /*
199 * If the multivector scalar type and the desired scalar tpye are
200 * the same, then we can do a simple straight copy.
201 */
202 template <typename MV>
203 struct same_type_get_copy {
204 static void apply(const Teuchos::Ptr<const MV> mv,
205 const Teuchos::ArrayView<typename MV::scalar_t>& v,
206 const size_t ldx,
207 Teuchos::Ptr<const Tpetra::Map<typename MV::local_ordinal_t, typename MV::global_ordinal_t, typename MV::node_t> > distribution_map,
208 EDistribution distribution );
209 };
210
211 template <typename MV, typename KV>
212 struct same_type_get_view {
213 static bool apply (bool bInitialize,
214 const Teuchos::Ptr<const MV>& mv,
215 KV& kokkos_vals,
216 const size_t ldx,
217 Teuchos::Ptr<const Tpetra::Map<typename MV::local_ordinal_t, typename MV::global_ordinal_t, typename MV::node_t> > distribution_map,
218 EDistribution distribution);
219 };
220
221 /*
222 * In the case where the scalar type of the multi-vector and the
223 * corresponding S type are different, then we need to first get a
224 * copy of the scalar values, then convert each one into the S
225 * type before inserting into the vals array.
226 */
227 template <typename MV, typename S>
228 struct diff_type_get_copy {
229 static void apply(const Teuchos::Ptr<const MV> mv,
230 const Teuchos::ArrayView<S>& v,
231 const size_t ldx,
232 Teuchos::Ptr<const Tpetra::Map<typename MV::local_ordinal_t, typename MV::global_ordinal_t, typename MV::node_t> > distribution_map,
233 EDistribution distribution );
234 };
235
236 template <typename MV, typename KV>
237 struct diff_type_get_view {
238 static bool apply (bool bInitialize,
239 const Teuchos::Ptr<const MV>& mv,
240 KV& kokkos_vals,
241 const size_t ldx,
242 Teuchos::Ptr<const Tpetra::Map<typename MV::local_ordinal_t, typename MV::global_ordinal_t, typename MV::node_t> > distribution_map,
243 EDistribution distribution);
244 };
245
252 template <class MV, typename S>
254 static void
255 do_get (const Teuchos::Ptr<const MV>& mv,
256 const Teuchos::ArrayView<S>& vals,
257 const size_t ldx,
258 Teuchos::Ptr<const Tpetra::Map<typename MV::local_ordinal_t, typename MV::global_ordinal_t, typename MV::node_t> > distribution_map,
259 EDistribution distribution = ROOTED);
260
261 static void
262 do_get (const Teuchos::Ptr<const MV>& mv,
263 const Teuchos::ArrayView<S>& vals,
264 const size_t ldx,
265 EDistribution distribution,
266 typename MV::global_ordinal_t indexBase = 0);
267
268 static void
269 do_get (const Teuchos::Ptr<const MV>& mv,
270 const Teuchos::ArrayView<S>& vals,
271 const size_t ldx);
272 };
273
274 /*
275 do_get
276
277 Return type (bool):
278 true: The input kokkos_vals view is now pointing directly to the adapter's data (same memory and type).
279 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.
280 false: The input kokkos_vals view is now resized to match the adapter's size.
281 kokkos_vals will only have the adapter values deep_copied if bInitialize is true (see below).
282 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.
283
284 Inputs
285 bInitialize (bool): tells the adapter whether kokkos_vals needs to have the values of the adapter.
286 true: We require kokkos_vals to have the same size and values of the adapter.
287 For b in Ax=b solves, set bInitialize true because you need the size and values of the adapter.
288 false: We require kokkos_vals to have the same size as the adapter but we don't need the values.
289 For x in Ax=b solves, set bInitialize false because you just need the size, not the values.
290
291 Note: When this method returns true, meaning direct assignment of the view occurred,
292 bInitialize is not used because you already have the values whether you need them or not.
293
294 kokkos_vals (View<scalar_t**>): The view which will contain the x or b data.
295 Do not allocate the size of kokkos_vals, let the do_get method do it for you.
296 This is because kokkos_vals may be set to point directly to the adapter memory
297 and then any pre-allocation of size will have been wasted.
298 */
299 template <class MV, typename KV>
300 struct get_1d_copy_helper_kokkos_view {
301 static bool
302 do_get (bool bInitialize,
303 const Teuchos::Ptr<const MV>& mv,
304 KV& kokkos_vals,
305 const size_t ldx,
306 Teuchos::Ptr<const Tpetra::Map<typename MV::local_ordinal_t, typename MV::global_ordinal_t, typename MV::node_t> > distribution_map,
307 EDistribution distribution = ROOTED);
308
309 static bool
310 do_get (bool bInitialize,
311 const Teuchos::Ptr<const MV>& mv,
312 KV& kokkos_vals,
313 const size_t ldx,
314 EDistribution distribution,
315 typename MV::global_ordinal_t indexBase = 0);
316
317 static bool
318 do_get (bool bInitialize,
319 const Teuchos::Ptr<const MV>& mv,
320 KV& kokkos_vals,
321 const size_t ldx);
322 };
323
324 /*
325 * If the multivector scalar type and the desired scalar tpye are
326 * the same, then we can do a simple straight copy.
327 */
328 template <typename MV>
329 struct same_type_data_put {
330 static void apply(const Teuchos::Ptr<MV>& mv,
331 const Teuchos::ArrayView<typename MV::scalar_t>& data,
332 const size_t ldx,
333 Teuchos::Ptr<const Tpetra::Map<typename MV::local_ordinal_t, typename MV::global_ordinal_t, typename MV::node_t> > distribution_map,
334 EDistribution distribution );
335 };
336
337 template <typename MV, typename KV>
338 struct same_type_put_view {
339 static void apply(const Teuchos::Ptr<MV>& mv,
340 KV& data,
341 const size_t ldx,
342 Teuchos::Ptr<const Tpetra::Map<typename MV::local_ordinal_t, typename MV::global_ordinal_t, typename MV::node_t> > distribution_map,
343 EDistribution distribution );
344 };
345
346 /*
347 * In the case where the scalar type of the multi-vector and the
348 * corresponding S type are different, then we need to first get a
349 * copy of the scalar values, then convert each one into the S
350 * type before inserting into the vals array.
351 */
352 template <typename MV, typename S>
353 struct diff_type_data_put {
354 static void apply(const Teuchos::Ptr<MV>& mv,
355 const Teuchos::ArrayView<S>& data,
356 const size_t ldx,
357 Teuchos::Ptr<const Tpetra::Map<typename MV::local_ordinal_t, typename MV::global_ordinal_t, typename MV::node_t> > distribution_map,
358 EDistribution distribution );
359 };
360
361 template <typename MV, typename KV>
362 struct diff_type_put_view {
363 static void apply(const Teuchos::Ptr<MV>& mv,
364 KV& kokkos_data,
365 const size_t ldx,
366 Teuchos::Ptr<const Tpetra::Map<typename MV::local_ordinal_t, typename MV::global_ordinal_t, typename MV::node_t> > distribution_map,
367 EDistribution distribution );
368 };
369
376 template <class MV, typename S>
378 static void do_put(const Teuchos::Ptr<MV>& mv,
379 const Teuchos::ArrayView<S>& data,
380 const size_t ldx,
381 Teuchos::Ptr<const Tpetra::Map<typename MV::local_ordinal_t, typename MV::global_ordinal_t, typename MV::node_t> > distribution_map,
382 EDistribution distribution = ROOTED);
383
384 static void do_put(const Teuchos::Ptr<MV>& mv,
385 const Teuchos::ArrayView<S>& data,
386 const size_t ldx,
387 EDistribution distribution, typename MV::global_ordinal_t indexBase = 0);
388
389 static void do_put(const Teuchos::Ptr<MV>& mv,
390 const Teuchos::ArrayView<S>& data,
391 const size_t ldx);
392 };
393
394 template <class MV, typename KV>
395 struct put_1d_data_helper_kokkos_view {
396 static void do_put(const Teuchos::Ptr<MV>& mv,
397 KV& kokkos_data,
398 const size_t ldx,
399 Teuchos::Ptr<const Tpetra::Map<typename MV::local_ordinal_t, typename MV::global_ordinal_t, typename MV::node_t> > distribution_map,
400 EDistribution distribution = ROOTED);
401
402 static void do_put(const Teuchos::Ptr<MV>& mv,
403 KV& kokkos_data,
404 const size_t ldx,
405 EDistribution distribution, typename MV::global_ordinal_t indexBase = 0);
406
407 static void do_put(const Teuchos::Ptr<MV>& mv,
408 KV& kokkos_data,
409 const size_t ldx);
410 };
411 }
412} // end namespace Amesos2
413
416
417#endif // AMESOS2_MULTIVEC_ADAPTER_DECL_HPP
Amesos2::MultiVecAdapter specialization for the Kokkos::View class.
Amesos2::MultiVecAdapter specialization for the Tpetra::MultiVector class.
Enum and other types declarations for Amesos2.
EDistribution
Definition Amesos2_TypeDecl.hpp:89
@ ROOTED
Definition Amesos2_TypeDecl.hpp:93
A templated MultiVector class adapter for Amesos2.
Definition Amesos2_MultiVecAdapter_decl.hpp:142
Teuchos::RCP< MultiVecAdapter< MV > > createMultiVecAdapter(Teuchos::RCP< MV > mv)
Factory creation method for MultiVecAdapters.
Definition Amesos2_MultiVecAdapter_decl.hpp:154
Helper class for getting 1-D copies of multivectors.
Definition Amesos2_MultiVecAdapter_decl.hpp:253
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:111
Helper class for putting 1-D data arrays into multivectors.
Definition Amesos2_MultiVecAdapter_decl.hpp:377
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:350
Helper struct for getting pointers to the MV data - only used when number of vectors = 1 and single M...
Definition Amesos2_MultiVecAdapter_decl.hpp:185