42 #ifndef TPETRA_MATRIXMATRIX_DECL_HPP
43 #define TPETRA_MATRIXMATRIX_DECL_HPP
46 #include <Teuchos_RCP.hpp>
47 #include <Teuchos_Array.hpp>
48 #include "Tpetra_ConfigDefs.hpp"
49 #include "Tpetra_CrsMatrix.hpp"
50 #include "Tpetra_Vector.hpp"
51 #include "TpetraExt_MMHelpers.hpp"
61 namespace MatrixMatrix {
93 template <
class Scalar,
98 const CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>& A,
100 const CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>& B,
102 CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>& C,
103 bool call_FillComplete_on_result =
true,
104 const std::string& label = std::string(),
105 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
120 template <
class Scalar,
125 const CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>& A,
128 CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>& B,
160 template <
class Scalar,
164 Teuchos::RCP<CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
165 add (
const Scalar& alpha,
166 const bool transposeA,
167 const CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>& A,
169 const bool transposeB,
170 const CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>& B,
171 const Teuchos::RCP<
const Map<LocalOrdinal, GlobalOrdinal, Node> >& domainMap = Teuchos::null,
172 const Teuchos::RCP<
const Map<LocalOrdinal, GlobalOrdinal, Node> >& rangeMap = Teuchos::null,
173 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
211 template <
class Scalar,
216 add (
const Scalar& alpha,
217 const bool transposeA,
218 const CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>& A,
220 const bool transposeB,
221 const CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>& B,
222 CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> & C,
223 const Teuchos::RCP<
const Map<LocalOrdinal, GlobalOrdinal, Node> >& domainMap = Teuchos::null,
224 const Teuchos::RCP<
const Map<LocalOrdinal, GlobalOrdinal, Node> >& rangeMap = Teuchos::null,
225 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
257 template <
class Scalar,
262 const CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>& A,
265 const CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>& B,
268 Teuchos::RCP<CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> > C);
292 template <
class Scalar,
297 const Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node> & Dinv,
298 const CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>& A,
299 const CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>& B,
300 CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>& C,
301 bool call_FillComplete_on_result =
true,
302 const std::string& label = std::string(),
303 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
310 template<
class Scalar,
314 void mult_AT_B_newmatrix(
315 const CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>& A,
316 const CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>& B,
317 CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>& C,
318 const std::string& label = std::string(),
319 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
322 template<
class Scalar,
327 CrsMatrixStruct<Scalar, LocalOrdinal, GlobalOrdinal, Node>& Aview,
328 CrsMatrixStruct<Scalar, LocalOrdinal, GlobalOrdinal, Node>& Bview,
329 CrsWrapper<Scalar, LocalOrdinal, GlobalOrdinal, Node>& C,
330 const std::string& label = std::string(),
331 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
333 template<
class Scalar,
337 void mult_A_B_newmatrix(
338 CrsMatrixStruct<Scalar, LocalOrdinal, GlobalOrdinal, Node>& Aview,
339 CrsMatrixStruct<Scalar, LocalOrdinal, GlobalOrdinal, Node>& Bview,
340 CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>& C,
341 const std::string& label = std::string(),
342 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
347 template<
class Scalar,
352 CrsMatrixStruct<Scalar, LocalOrdinal, GlobalOrdinal, Node>& Aview,
353 CrsMatrixStruct<Scalar, LocalOrdinal, GlobalOrdinal, Node>& Bview,
354 CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>& C,
355 const std::string& label = std::string(),
356 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
362 template<
class Scalar,
366 void jacobi_A_B_newmatrix(
368 const Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node> & Dinv,
369 CrsMatrixStruct<Scalar, LocalOrdinal, GlobalOrdinal, Node>& Aview,
370 CrsMatrixStruct<Scalar, LocalOrdinal, GlobalOrdinal, Node>& Bview,
371 CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>& C,
372 const std::string & label = std::string(),
373 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
376 template<
class Scalar,
380 void jacobi_A_B_reuse(
382 const Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node> & Dinv,
383 CrsMatrixStruct<Scalar, LocalOrdinal, GlobalOrdinal, Node>& Aview,
384 CrsMatrixStruct<Scalar, LocalOrdinal, GlobalOrdinal, Node>& Bview,
385 CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>& C,
386 const std::string & label = std::string(),
387 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
390 template<
class Scalar,
394 void import_and_extract_views(
395 const CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>& M,
396 Teuchos::RCP<
const Map<LocalOrdinal, GlobalOrdinal, Node> > targetMap,
397 CrsMatrixStruct<Scalar, LocalOrdinal, GlobalOrdinal, Node>& Mview,
398 Teuchos::RCP<
const Import<LocalOrdinal,GlobalOrdinal, Node> > prototypeImporter = Teuchos::null,
399 bool userAssertsThereAreNoRemotes =
false,
400 const std::string& label = std::string(),
401 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
403 template<
class Scalar,
407 void setMaxNumEntriesPerRow(
408 CrsMatrixStruct<Scalar, LocalOrdinal, GlobalOrdinal, Node>& Mview);
413 template<
class Scalar,
417 class LocalOrdinalViewType>
418 struct KernelWrappers {
419 static inline void mult_A_B_newmatrix_kernel_wrapper(CrsMatrixStruct<Scalar, LocalOrdinal, GlobalOrdinal, Node>& Aview,
420 CrsMatrixStruct<Scalar, LocalOrdinal, GlobalOrdinal, Node>& Bview,
421 const LocalOrdinalViewType & Acol2Brow,
422 const LocalOrdinalViewType & Acol2Irow,
423 const LocalOrdinalViewType & Bcol2Ccol,
424 const LocalOrdinalViewType & Icol2Ccol,
425 CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>& C,
426 Teuchos::RCP<
const Import<LocalOrdinal,GlobalOrdinal,Node> > Cimport,
427 const std::string& label = std::string(),
428 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
430 static inline void mult_A_B_reuse_kernel_wrapper(CrsMatrixStruct<Scalar, LocalOrdinal, GlobalOrdinal, Node>& Aview,
431 CrsMatrixStruct<Scalar, LocalOrdinal, GlobalOrdinal, Node>& Bview,
432 const LocalOrdinalViewType & Acol2Brow,
433 const LocalOrdinalViewType & Acol2Irow,
434 const LocalOrdinalViewType & Bcol2Ccol,
435 const LocalOrdinalViewType & Icol2Ccol,
436 CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>& C,
437 Teuchos::RCP<
const Import<LocalOrdinal,GlobalOrdinal,Node> > Cimport,
438 const std::string& label = std::string(),
439 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
445 template<
class Scalar,
449 class LocalOrdinalViewType>
450 struct KernelWrappers2 {
451 static inline void jacobi_A_B_newmatrix_kernel_wrapper(Scalar omega,
452 const Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> & Dinv,
453 CrsMatrixStruct<Scalar, LocalOrdinal, GlobalOrdinal, Node>& Aview,
454 CrsMatrixStruct<Scalar, LocalOrdinal, GlobalOrdinal, Node>& Bview,
455 const LocalOrdinalViewType & Acol2Brow,
456 const LocalOrdinalViewType & Acol2Irow,
457 const LocalOrdinalViewType & Bcol2Ccol,
458 const LocalOrdinalViewType & Icol2Ccol,
459 CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>& C,
460 Teuchos::RCP<
const Import<LocalOrdinal,GlobalOrdinal,Node> > Cimport,
461 const std::string& label = std::string(),
462 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
464 static inline void jacobi_A_B_reuse_kernel_wrapper(Scalar omega,
465 const Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> & Dinv,
466 CrsMatrixStruct<Scalar, LocalOrdinal, GlobalOrdinal, Node>& Aview,
467 CrsMatrixStruct<Scalar, LocalOrdinal, GlobalOrdinal, Node>& Bview,
468 const LocalOrdinalViewType & Acol2Brow,
469 const LocalOrdinalViewType & Acol2Irow,
470 const LocalOrdinalViewType & Bcol2Ccol,
471 const LocalOrdinalViewType & Icol2Ccol,
472 CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>& C,
473 Teuchos::RCP<
const Import<LocalOrdinal,GlobalOrdinal,Node> > Cimport,
474 const std::string& label = std::string(),
475 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
481 template<
class Scalar,
485 class LocalOrdinalViewType>
486 struct KernelWrappers3 {
487 static inline void mult_R_A_P_newmatrix_kernel_wrapper(CrsMatrixStruct<Scalar, LocalOrdinal, GlobalOrdinal, Node>& Rview,
488 CrsMatrixStruct<Scalar, LocalOrdinal, GlobalOrdinal, Node>& Aview,
489 CrsMatrixStruct<Scalar, LocalOrdinal, GlobalOrdinal, Node>& Pview,
490 const LocalOrdinalViewType & Acol2Prow,
491 const LocalOrdinalViewType & Acol2PIrow,
492 const LocalOrdinalViewType & Pcol2Ccol,
493 const LocalOrdinalViewType & PIcol2Ccol,
494 CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>& Ac,
495 Teuchos::RCP<
const Import<LocalOrdinal,GlobalOrdinal,Node> > Acimport,
496 const std::string& label = std::string(),
497 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
499 static inline void mult_R_A_P_reuse_kernel_wrapper(CrsMatrixStruct<Scalar, LocalOrdinal, GlobalOrdinal, Node>& Rview,
500 CrsMatrixStruct<Scalar, LocalOrdinal, GlobalOrdinal, Node>& Aview,
501 CrsMatrixStruct<Scalar, LocalOrdinal, GlobalOrdinal, Node>& Pview,
502 const LocalOrdinalViewType & Acol2Prow,
503 const LocalOrdinalViewType & Acol2PIrow,
504 const LocalOrdinalViewType & Pcol2Ccol,
505 const LocalOrdinalViewType & PIcol2Ccol,
506 CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>& Ac,
507 Teuchos::RCP<
const Import<LocalOrdinal,GlobalOrdinal,Node> > Acimport,
508 const std::string& label = std::string(),
509 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
512 static inline void mult_PT_A_P_newmatrix_kernel_wrapper(CrsMatrixStruct<Scalar, LocalOrdinal, GlobalOrdinal, Node>& Aview,
513 CrsMatrixStruct<Scalar, LocalOrdinal, GlobalOrdinal, Node>& Pview,
514 const LocalOrdinalViewType & Acol2Prow,
515 const LocalOrdinalViewType & Acol2PIrow,
516 const LocalOrdinalViewType & Pcol2Ccol,
517 const LocalOrdinalViewType & PIcol2Ccol,
518 CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>& Ac,
519 Teuchos::RCP<
const Import<LocalOrdinal,GlobalOrdinal,Node> > Acimport,
520 const std::string& label = std::string(),
521 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
523 static inline void mult_PT_A_P_reuse_kernel_wrapper(CrsMatrixStruct<Scalar, LocalOrdinal, GlobalOrdinal, Node>& Aview,
524 CrsMatrixStruct<Scalar, LocalOrdinal, GlobalOrdinal, Node>& Pview,
525 const LocalOrdinalViewType & Acol2Prow,
526 const LocalOrdinalViewType & Acol2PIrow,
527 const LocalOrdinalViewType & Pcol2Ccol,
528 const LocalOrdinalViewType & PIcol2Ccol,
529 CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>& Ac,
530 Teuchos::RCP<
const Import<LocalOrdinal,GlobalOrdinal,Node> > Acimport,
531 const std::string& label = std::string(),
532 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
536 template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalOrdinalViewType>
538 merge_matrices(CrsMatrixStruct<Scalar, LocalOrdinal, GlobalOrdinal, Node>& Aview,
539 CrsMatrixStruct<Scalar, LocalOrdinal, GlobalOrdinal, Node>& Bview,
540 const LocalOrdinalViewType & Acol2Brow,
541 const LocalOrdinalViewType & Acol2Irow,
542 const LocalOrdinalViewType & Bcol2Ccol,
543 const LocalOrdinalViewType & Icol2Ccol,
544 const size_t mergedNodeNumCols);
549 template<
class CrsMatrixType>
550 size_t C_estimate_nnz(CrsMatrixType & A, CrsMatrixType &B);
552 template<
typename Scalar,
typename LocalOrdinal,
typename GlobalOrdinal,
typename Node>
557 typedef typename Node::device_type device_type;
558 typedef typename device_type::execution_space execution_space;
559 typedef typename execution_space::memory_space memory_space;
562 typedef typename KCRS::values_type::non_const_type values_array;
563 typedef typename KCRS::row_map_type::non_const_type row_ptrs_array;
564 typedef typename KCRS::row_map_type row_ptrs_array_const;
565 typedef typename KCRS::index_type::non_const_type col_inds_array;
567 typedef typename Kokkos::View<GlobalOrdinal*, device_type> global_col_inds_array;
568 typedef Kokkos::RangePolicy<execution_space> range_type;
583 static void addSorted(
584 const values_array& Avals,
585 const row_ptrs_array_const& Arowptrs,
586 const col_inds_array& Acolinds,
587 const impl_scalar_type scalarA,
588 const values_array& Bvals,
589 const row_ptrs_array_const& Browptrs,
590 const col_inds_array& Bcolinds,
591 const impl_scalar_type scalarB,
593 row_ptrs_array& Crowptrs,
594 col_inds_array& Ccolinds);
607 static void convertToGlobalAndAdd(
609 const impl_scalar_type scalarA,
611 const impl_scalar_type scalarB,
612 const local_map_type& AcolMap,
613 const local_map_type& BcolMap,
615 row_ptrs_array& Crowptrs,
616 global_col_inds_array& Ccolinds);
632 static void addUnsorted(
633 const values_array& Avals,
634 const row_ptrs_array_const& Arowptrs,
635 const col_inds_array& Acolinds,
636 const impl_scalar_type scalarA,
637 const values_array& Bvals,
638 const row_ptrs_array_const& Browptrs,
639 const col_inds_array& Bcolinds,
640 const impl_scalar_type scalarB,
641 GlobalOrdinal numGlobalCols,
643 row_ptrs_array& Crowptrs,
644 col_inds_array& Ccolinds);
651 #endif // TPETRA_MATRIXMATRIX_DECL_HPP
Sparse matrix that presents a row-oriented interface that lets users read or modify entries...
KokkosSparse::CrsMatrix< impl_scalar_type, local_ordinal_type, device_type, void, typename local_graph_type::size_type > local_matrix_type
The specialization of Kokkos::CrsMatrix that represents the part of the sparse matrix on each MPI pro...
void Jacobi(Scalar omega, const Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &Dinv, const CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > &A, const CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > &B, CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > &C, bool call_FillComplete_on_result=true, const std::string &label=std::string(), const Teuchos::RCP< Teuchos::ParameterList > ¶ms=Teuchos::null)
typename Kokkos::ArithTraits< Scalar >::val_type impl_scalar_type
The type used internally in place of Scalar.
void Add(const CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > &A, bool transposeA, Scalar scalarA, CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > &B, Scalar scalarB)
void Multiply(const CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > &A, bool transposeA, const CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > &B, bool transposeB, CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > &C, bool call_FillComplete_on_result=true, const std::string &label=std::string(), const Teuchos::RCP< Teuchos::ParameterList > ¶ms=Teuchos::null)
Sparse matrix-matrix multiply.
A parallel distribution of indices over processes.
Teuchos::RCP< CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > add(const Scalar &alpha, const bool transposeA, const CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > &A, const Scalar &beta, const bool transposeB, const CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > &B, const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &domainMap=Teuchos::null, const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rangeMap=Teuchos::null, const Teuchos::RCP< Teuchos::ParameterList > ¶ms=Teuchos::null)
Compute the sparse matrix sum C = scalarA * Op(A) + scalarB * Op(B), where Op(X) is either X or its t...
::Tpetra::Details::LocalMap< local_ordinal_type, global_ordinal_type, device_type > local_map_type
Type of the "local" Map.