10 #ifndef TPETRA_MATRIXMATRIX_DECL_HPP
11 #define TPETRA_MATRIXMATRIX_DECL_HPP
14 #include <Teuchos_RCP.hpp>
15 #include <Teuchos_Array.hpp>
16 #include "Tpetra_ConfigDefs.hpp"
17 #include "Tpetra_CrsMatrix.hpp"
18 #include "Tpetra_BlockCrsMatrix.hpp"
19 #include "Tpetra_Vector.hpp"
20 #include "TpetraExt_MMHelpers.hpp"
21 #include "KokkosKernels_Handle.hpp"
31 namespace MatrixMatrix {
63 template <
class Scalar,
68 const CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>& A,
70 const CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>& B,
72 CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>& C,
73 bool call_FillComplete_on_result =
true,
74 const std::string& label = std::string(),
75 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
92 template <
class Scalar,
97 const Teuchos::RCP<
const BlockCrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> >& A,
99 const Teuchos::RCP<
const BlockCrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> >& B,
101 Teuchos::RCP<BlockCrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> >& C,
102 const std::string& label = std::string());
115 template <
class Scalar,
120 const CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>& A,
123 CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>& B,
155 template <
class Scalar,
159 Teuchos::RCP<CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
160 add (
const Scalar& alpha,
161 const bool transposeA,
162 const CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>& A,
164 const bool transposeB,
165 const CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>& B,
166 const Teuchos::RCP<
const Map<LocalOrdinal, GlobalOrdinal, Node> >& domainMap = Teuchos::null,
167 const Teuchos::RCP<
const Map<LocalOrdinal, GlobalOrdinal, Node> >& rangeMap = Teuchos::null,
168 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
206 template <
class Scalar,
211 add (
const Scalar& alpha,
212 const bool transposeA,
213 const CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>& A,
215 const bool transposeB,
216 const CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>& B,
217 CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> & C,
218 const Teuchos::RCP<
const Map<LocalOrdinal, GlobalOrdinal, Node> >& domainMap = Teuchos::null,
219 const Teuchos::RCP<
const Map<LocalOrdinal, GlobalOrdinal, Node> >& rangeMap = Teuchos::null,
220 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);
299 template <
class Scalar,
304 const CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>& A,
307 const CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>& B,
310 const Teuchos::RCP<CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> >& C);
333 template <
class Scalar,
338 const Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node> & Dinv,
339 const CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>& A,
340 const CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>& B,
341 CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>& C,
342 bool call_FillComplete_on_result =
true,
343 const std::string& label = std::string(),
344 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
351 template<
class Scalar,
355 void mult_AT_B_newmatrix(
356 const CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>& A,
357 const CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>& B,
358 CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>& C,
359 const std::string& label = std::string(),
360 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
363 template<
class Scalar,
368 CrsMatrixStruct<Scalar, LocalOrdinal, GlobalOrdinal, Node>& Aview,
369 CrsMatrixStruct<Scalar, LocalOrdinal, GlobalOrdinal, Node>& Bview,
370 CrsWrapper<Scalar, LocalOrdinal, GlobalOrdinal, Node>& C,
371 const std::string& label = std::string(),
372 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
374 template<
class Scalar,
378 void mult_A_B_newmatrix(
379 CrsMatrixStruct<Scalar, LocalOrdinal, GlobalOrdinal, Node>& Aview,
380 CrsMatrixStruct<Scalar, LocalOrdinal, GlobalOrdinal, Node>& Bview,
381 CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>& C,
382 const std::string& label = std::string(),
383 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
385 template<
class Scalar,
389 void mult_A_B_newmatrix(
390 BlockCrsMatrixStruct<Scalar, LocalOrdinal, GlobalOrdinal, Node>& Aview,
391 BlockCrsMatrixStruct<Scalar, LocalOrdinal, GlobalOrdinal, Node>& Bview,
392 Teuchos::RCP<BlockCrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> >& C);
394 template<
class Scalar,
399 CrsMatrixStruct<Scalar, LocalOrdinal, GlobalOrdinal, Node>& Aview,
400 CrsMatrixStruct<Scalar, LocalOrdinal, GlobalOrdinal, Node>& Bview,
401 CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>& C,
402 const std::string& label = std::string(),
403 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
409 template<
class Scalar,
413 void jacobi_A_B_newmatrix(
415 const Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node> & Dinv,
416 CrsMatrixStruct<Scalar, LocalOrdinal, GlobalOrdinal, Node>& Aview,
417 CrsMatrixStruct<Scalar, LocalOrdinal, GlobalOrdinal, Node>& Bview,
418 CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>& C,
419 const std::string & label = std::string(),
420 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
423 template<
class Scalar,
427 void jacobi_A_B_reuse(
429 const Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node> & Dinv,
430 CrsMatrixStruct<Scalar, LocalOrdinal, GlobalOrdinal, Node>& Aview,
431 CrsMatrixStruct<Scalar, LocalOrdinal, GlobalOrdinal, Node>& Bview,
432 CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>& C,
433 const std::string & label = std::string(),
434 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
437 template<
class Scalar,
441 void import_and_extract_views(
442 const CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>& M,
443 Teuchos::RCP<
const Map<LocalOrdinal, GlobalOrdinal, Node> > targetMap,
444 CrsMatrixStruct<Scalar, LocalOrdinal, GlobalOrdinal, Node>& Mview,
445 Teuchos::RCP<
const Import<LocalOrdinal,GlobalOrdinal, Node> > prototypeImporter,
446 bool userAssertsThereAreNoRemotes,
447 const std::string& label,
448 const Teuchos::RCP<Teuchos::ParameterList>& params);
450 template<
class Scalar,
454 void import_and_extract_views(
455 const BlockCrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>& M,
456 Teuchos::RCP<
const Map<LocalOrdinal, GlobalOrdinal, Node> > targetMap,
457 BlockCrsMatrixStruct<Scalar, LocalOrdinal, GlobalOrdinal, Node>& Mview,
458 Teuchos::RCP<
const Import<LocalOrdinal,GlobalOrdinal, Node> > prototypeImporter,
459 bool userAssertsThereAreNoRemotes);
461 template<
class Scalar,
465 void setMaxNumEntriesPerRow(
466 CrsMatrixStruct<Scalar, LocalOrdinal, GlobalOrdinal, Node>& Mview);
471 template<
class Scalar,
475 class LocalOrdinalViewType>
476 struct KernelWrappers {
477 static inline void mult_A_B_newmatrix_kernel_wrapper(CrsMatrixStruct<Scalar, LocalOrdinal, GlobalOrdinal, Node>& Aview,
478 CrsMatrixStruct<Scalar, LocalOrdinal, GlobalOrdinal, Node>& Bview,
479 const LocalOrdinalViewType & Acol2Brow,
480 const LocalOrdinalViewType & Acol2Irow,
481 const LocalOrdinalViewType & Bcol2Ccol,
482 const LocalOrdinalViewType & Icol2Ccol,
483 CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>& C,
484 Teuchos::RCP<
const Import<LocalOrdinal,GlobalOrdinal,Node> > Cimport,
485 const std::string& label = std::string(),
486 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
488 static inline void mult_A_B_reuse_kernel_wrapper(CrsMatrixStruct<Scalar, LocalOrdinal, GlobalOrdinal, Node>& Aview,
489 CrsMatrixStruct<Scalar, LocalOrdinal, GlobalOrdinal, Node>& Bview,
490 const LocalOrdinalViewType & Acol2Brow,
491 const LocalOrdinalViewType & Acol2Irow,
492 const LocalOrdinalViewType & Bcol2Ccol,
493 const LocalOrdinalViewType & Icol2Ccol,
494 CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>& C,
495 Teuchos::RCP<
const Import<LocalOrdinal,GlobalOrdinal,Node> > Cimport,
496 const std::string& label = std::string(),
497 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
503 template<
class Scalar,
507 class LocalOrdinalViewType>
508 struct KernelWrappers2 {
509 static inline void jacobi_A_B_newmatrix_kernel_wrapper(Scalar omega,
510 const Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> & Dinv,
511 CrsMatrixStruct<Scalar, LocalOrdinal, GlobalOrdinal, Node>& Aview,
512 CrsMatrixStruct<Scalar, LocalOrdinal, GlobalOrdinal, Node>& Bview,
513 const LocalOrdinalViewType & Acol2Brow,
514 const LocalOrdinalViewType & Acol2Irow,
515 const LocalOrdinalViewType & Bcol2Ccol,
516 const LocalOrdinalViewType & Icol2Ccol,
517 CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>& C,
518 Teuchos::RCP<
const Import<LocalOrdinal,GlobalOrdinal,Node> > Cimport,
519 const std::string& label = std::string(),
520 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
522 static inline void jacobi_A_B_reuse_kernel_wrapper(Scalar omega,
523 const Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> & Dinv,
524 CrsMatrixStruct<Scalar, LocalOrdinal, GlobalOrdinal, Node>& Aview,
525 CrsMatrixStruct<Scalar, LocalOrdinal, GlobalOrdinal, Node>& Bview,
526 const LocalOrdinalViewType & Acol2Brow,
527 const LocalOrdinalViewType & Acol2Irow,
528 const LocalOrdinalViewType & Bcol2Ccol,
529 const LocalOrdinalViewType & Icol2Ccol,
530 CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>& C,
531 Teuchos::RCP<
const Import<LocalOrdinal,GlobalOrdinal,Node> > Cimport,
532 const std::string& label = std::string(),
533 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
539 template<
class Scalar,
543 class LocalOrdinalViewType>
544 struct KernelWrappers3 {
545 static inline void mult_R_A_P_newmatrix_kernel_wrapper(CrsMatrixStruct<Scalar, LocalOrdinal, GlobalOrdinal, Node>& Rview,
546 CrsMatrixStruct<Scalar, LocalOrdinal, GlobalOrdinal, Node>& Aview,
547 CrsMatrixStruct<Scalar, LocalOrdinal, GlobalOrdinal, Node>& Pview,
548 const LocalOrdinalViewType & Acol2Prow,
549 const LocalOrdinalViewType & Acol2PIrow,
550 const LocalOrdinalViewType & Pcol2Ccol,
551 const LocalOrdinalViewType & PIcol2Ccol,
552 CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>& Ac,
553 Teuchos::RCP<
const Import<LocalOrdinal,GlobalOrdinal,Node> > Acimport,
554 const std::string& label = std::string(),
555 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
557 static inline void mult_R_A_P_reuse_kernel_wrapper(CrsMatrixStruct<Scalar, LocalOrdinal, GlobalOrdinal, Node>& Rview,
558 CrsMatrixStruct<Scalar, LocalOrdinal, GlobalOrdinal, Node>& Aview,
559 CrsMatrixStruct<Scalar, LocalOrdinal, GlobalOrdinal, Node>& Pview,
560 const LocalOrdinalViewType & Acol2Prow,
561 const LocalOrdinalViewType & Acol2PIrow,
562 const LocalOrdinalViewType & Pcol2Ccol,
563 const LocalOrdinalViewType & PIcol2Ccol,
564 CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>& Ac,
565 Teuchos::RCP<
const Import<LocalOrdinal,GlobalOrdinal,Node> > Acimport,
566 const std::string& label = std::string(),
567 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
570 static inline void mult_PT_A_P_newmatrix_kernel_wrapper(CrsMatrixStruct<Scalar, LocalOrdinal, GlobalOrdinal, Node>& Aview,
571 CrsMatrixStruct<Scalar, LocalOrdinal, GlobalOrdinal, Node>& Pview,
572 const LocalOrdinalViewType & Acol2Prow,
573 const LocalOrdinalViewType & Acol2PIrow,
574 const LocalOrdinalViewType & Pcol2Ccol,
575 const LocalOrdinalViewType & PIcol2Ccol,
576 CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>& Ac,
577 Teuchos::RCP<
const Import<LocalOrdinal,GlobalOrdinal,Node> > Acimport,
578 const std::string& label = std::string(),
579 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
581 static inline void mult_PT_A_P_reuse_kernel_wrapper(CrsMatrixStruct<Scalar, LocalOrdinal, GlobalOrdinal, Node>& Aview,
582 CrsMatrixStruct<Scalar, LocalOrdinal, GlobalOrdinal, Node>& Pview,
583 const LocalOrdinalViewType & Acol2Prow,
584 const LocalOrdinalViewType & Acol2PIrow,
585 const LocalOrdinalViewType & Pcol2Ccol,
586 const LocalOrdinalViewType & PIcol2Ccol,
587 CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>& Ac,
588 Teuchos::RCP<
const Import<LocalOrdinal,GlobalOrdinal,Node> > Acimport,
589 const std::string& label = std::string(),
590 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
594 template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalOrdinalViewType>
596 merge_matrices(CrsMatrixStruct<Scalar, LocalOrdinal, GlobalOrdinal, Node>& Aview,
597 CrsMatrixStruct<Scalar, LocalOrdinal, GlobalOrdinal, Node>& Bview,
598 const LocalOrdinalViewType & Acol2Brow,
599 const LocalOrdinalViewType & Acol2Irow,
600 const LocalOrdinalViewType & Bcol2Ccol,
601 const LocalOrdinalViewType & Icol2Ccol,
602 const size_t mergedNodeNumCols);
605 template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalOrdinalViewType>
606 inline const typename Tpetra::BlockCrsMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node>::local_matrix_device_type
607 merge_matrices(BlockCrsMatrixStruct<Scalar, LocalOrdinal, GlobalOrdinal, Node>& Aview,
608 BlockCrsMatrixStruct<Scalar, LocalOrdinal, GlobalOrdinal, Node>& Bview,
609 const LocalOrdinalViewType & Acol2Brow,
610 const LocalOrdinalViewType & Acol2Irow,
611 const LocalOrdinalViewType & Bcol2Ccol,
612 const LocalOrdinalViewType & Icol2Ccol,
613 const size_t mergedNodeNumCols);
618 template<
class CrsMatrixType>
619 size_t C_estimate_nnz(CrsMatrixType & A, CrsMatrixType &B);
621 template<
typename Scalar,
typename LocalOrdinal,
typename GlobalOrdinal,
typename Node>
626 typedef typename Node::device_type device_type;
627 typedef typename device_type::execution_space execution_space;
628 typedef typename device_type::memory_space memory_space;
631 typedef typename KCRS::values_type::non_const_type values_array;
632 typedef typename KCRS::row_map_type::non_const_type row_ptrs_array;
633 typedef typename KCRS::row_map_type row_ptrs_array_const;
634 typedef typename KCRS::index_type::non_const_type col_inds_array;
636 typedef typename Kokkos::View<GlobalOrdinal*, device_type> global_col_inds_array;
637 typedef Kokkos::RangePolicy<execution_space> range_type;
638 typedef KokkosKernels::Experimental::KokkosKernelsHandle<size_t, LocalOrdinal, impl_scalar_type,
639 execution_space, memory_space, memory_space> KKH;
655 static void addSorted(
656 const values_array& Avals,
657 const row_ptrs_array_const& Arowptrs,
658 const col_inds_array& Acolinds,
659 const impl_scalar_type scalarA,
660 const values_array& Bvals,
661 const row_ptrs_array_const& Browptrs,
662 const col_inds_array& Bcolinds,
663 const impl_scalar_type scalarB,
664 #
if KOKKOSKERNELS_VERSION >= 40299
665 GlobalOrdinal numGlobalCols,
668 row_ptrs_array& Crowptrs,
669 col_inds_array& Ccolinds);
682 static void convertToGlobalAndAdd(
684 const impl_scalar_type scalarA,
686 const impl_scalar_type scalarB,
687 const local_map_type& AcolMap,
688 const local_map_type& BcolMap,
690 row_ptrs_array& Crowptrs,
691 global_col_inds_array& Ccolinds);
707 static void addUnsorted(
708 const values_array& Avals,
709 const row_ptrs_array_const& Arowptrs,
710 const col_inds_array& Acolinds,
711 const impl_scalar_type scalarA,
712 const values_array& Bvals,
713 const row_ptrs_array_const& Browptrs,
714 const col_inds_array& Bcolinds,
715 const impl_scalar_type scalarB,
716 GlobalOrdinal numGlobalCols,
718 row_ptrs_array& Crowptrs,
719 col_inds_array& Ccolinds);
726 #endif // TPETRA_MATRIXMATRIX_DECL_HPP
Sparse matrix that presents a row-oriented interface that lets users read or modify entries...
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)
KokkosSparse::CrsMatrix< impl_scalar_type, local_ordinal_type, device_type, void, typename local_graph_device_type::size_type > local_matrix_device_type
The specialization of Kokkos::CrsMatrix that represents the part of the sparse matrix on each MPI pro...
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.
typename row_matrix_type::impl_scalar_type impl_scalar_type
The type used internally in place of Scalar.
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.