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,
134 template<
typename Scalar,
typename LocalOrdinal,
typename GlobalOrdinal,
typename Node>
139 typedef typename Node::device_type device_type;
140 typedef typename device_type::execution_space execution_space;
141 typedef typename execution_space::memory_space memory_space;
144 typedef typename KCRS::values_type::non_const_type values_array;
145 typedef typename KCRS::row_map_type::non_const_type row_ptrs_array;
146 typedef typename KCRS::row_map_type row_ptrs_array_const;
147 typedef typename KCRS::index_type::non_const_type col_inds_array;
148 typedef typename Kokkos::View<const GlobalOrdinal*, device_type> local_map_type;
149 typedef typename Kokkos::View<GlobalOrdinal*, device_type> global_col_inds_array;
150 typedef Kokkos::RangePolicy<execution_space, size_t> range_type;
165 static void addSorted(
166 const values_array& Avals,
167 const row_ptrs_array_const& Arowptrs,
168 const col_inds_array& Acolinds,
169 const impl_scalar_type scalarA,
170 const values_array& Bvals,
171 const row_ptrs_array_const& Browptrs,
172 const col_inds_array& Bcolinds,
173 const impl_scalar_type scalarB,
175 row_ptrs_array& Crowptrs,
176 col_inds_array& Ccolinds);
189 static void convertToGlobalAndAdd(
191 const impl_scalar_type scalarA,
193 const impl_scalar_type scalarB,
194 const local_map_type& AcolMap,
195 const local_map_type& BcolMap,
196 GlobalOrdinal minGlobalCol,
197 GlobalOrdinal globalNumCols,
199 row_ptrs_array& Crowptrs,
200 global_col_inds_array& Ccolinds);
216 static void addUnsorted(
217 const values_array& Avals,
218 const row_ptrs_array_const& Arowptrs,
219 const col_inds_array& Acolinds,
220 const impl_scalar_type scalarA,
221 const values_array& Bvals,
222 const row_ptrs_array_const& Browptrs,
223 const col_inds_array& Bcolinds,
224 const impl_scalar_type scalarB,
225 GlobalOrdinal numGlobalCols,
227 row_ptrs_array& Crowptrs,
228 col_inds_array& Ccolinds);
230 static Teuchos::RCP<map_type> makeColMapAndConvertGids(GlobalOrdinal ncols,
const global_col_inds_array& gids, col_inds_array& lids,
const Teuchos::RCP<
const Teuchos::Comm<int>>& comm);
263 template <
class Scalar,
267 Teuchos::RCP<CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
268 add (
const Scalar& alpha,
269 const bool transposeA,
270 const CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>& A,
272 const bool transposeB,
273 const CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>& B,
274 const Teuchos::RCP<
const Map<LocalOrdinal, GlobalOrdinal, Node> >& domainMap = Teuchos::null,
275 const Teuchos::RCP<
const Map<LocalOrdinal, GlobalOrdinal, Node> >& rangeMap = Teuchos::null,
276 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
310 template <
class Scalar,
315 add (
const Scalar& alpha,
316 const bool transposeA,
317 const CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>& A,
319 const bool transposeB,
320 const CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>& B,
321 CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> & C,
322 const Teuchos::RCP<
const Map<LocalOrdinal, GlobalOrdinal, Node> >& domainMap = Teuchos::null,
323 const Teuchos::RCP<
const Map<LocalOrdinal, GlobalOrdinal, Node> >& rangeMap = Teuchos::null,
324 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
356 template <
class Scalar,
361 const CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>& A,
364 const CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>& B,
367 Teuchos::RCP<CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> > C);
391 template <
class Scalar,
396 const Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node> & Dinv,
397 const CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>& A,
398 const CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>& B,
399 CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>& C,
400 bool call_FillComplete_on_result =
true,
401 const std::string& label = std::string(),
402 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
409 template<
class Scalar,
413 void mult_AT_B_newmatrix(
414 const CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>& A,
415 const CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>& B,
416 CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>& C,
417 const std::string& label = std::string(),
418 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
421 template<
class Scalar,
426 CrsMatrixStruct<Scalar, LocalOrdinal, GlobalOrdinal, Node>& Aview,
427 CrsMatrixStruct<Scalar, LocalOrdinal, GlobalOrdinal, Node>& Bview,
428 CrsWrapper<Scalar, LocalOrdinal, GlobalOrdinal, Node>& C,
429 const std::string& label = std::string(),
430 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
432 template<
class Scalar,
436 void mult_A_B_newmatrix(
437 CrsMatrixStruct<Scalar, LocalOrdinal, GlobalOrdinal, Node>& Aview,
438 CrsMatrixStruct<Scalar, LocalOrdinal, GlobalOrdinal, Node>& Bview,
439 CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>& C,
440 const std::string& label = std::string(),
441 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
446 template<
class Scalar,
451 CrsMatrixStruct<Scalar, LocalOrdinal, GlobalOrdinal, Node>& Aview,
452 CrsMatrixStruct<Scalar, LocalOrdinal, GlobalOrdinal, Node>& Bview,
453 CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>& C,
454 const std::string& label = std::string(),
455 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
461 template<
class Scalar,
465 void jacobi_A_B_newmatrix(
467 const Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node> & Dinv,
468 CrsMatrixStruct<Scalar, LocalOrdinal, GlobalOrdinal, Node>& Aview,
469 CrsMatrixStruct<Scalar, LocalOrdinal, GlobalOrdinal, Node>& Bview,
470 CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>& C,
471 const std::string & label = std::string(),
472 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
475 template<
class Scalar,
479 void jacobi_A_B_reuse(
481 const Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node> & Dinv,
482 CrsMatrixStruct<Scalar, LocalOrdinal, GlobalOrdinal, Node>& Aview,
483 CrsMatrixStruct<Scalar, LocalOrdinal, GlobalOrdinal, Node>& Bview,
484 CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>& C,
485 const std::string & label = std::string(),
486 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
489 template<
class Scalar,
493 void import_and_extract_views(
494 const CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>& M,
495 Teuchos::RCP<
const Map<LocalOrdinal, GlobalOrdinal, Node> > targetMap,
496 CrsMatrixStruct<Scalar, LocalOrdinal, GlobalOrdinal, Node>& Mview,
497 Teuchos::RCP<
const Import<LocalOrdinal,GlobalOrdinal, Node> > prototypeImporter = Teuchos::null,
498 bool userAssertsThereAreNoRemotes =
false,
499 const std::string& label = std::string(),
500 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
502 template<
class Scalar,
506 void setMaxNumEntriesPerRow(
507 CrsMatrixStruct<Scalar, LocalOrdinal, GlobalOrdinal, Node>& Mview);
512 template<
class Scalar,
516 class LocalOrdinalViewType>
517 struct KernelWrappers {
518 static inline void mult_A_B_newmatrix_kernel_wrapper(CrsMatrixStruct<Scalar, LocalOrdinal, GlobalOrdinal, Node>& Aview,
519 CrsMatrixStruct<Scalar, LocalOrdinal, GlobalOrdinal, Node>& Bview,
520 const LocalOrdinalViewType & Acol2Brow,
521 const LocalOrdinalViewType & Acol2Irow,
522 const LocalOrdinalViewType & Bcol2Ccol,
523 const LocalOrdinalViewType & Icol2Ccol,
524 CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>& C,
525 Teuchos::RCP<
const Import<LocalOrdinal,GlobalOrdinal,Node> > Cimport,
526 const std::string& label = std::string(),
527 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
529 static inline void mult_A_B_reuse_kernel_wrapper(CrsMatrixStruct<Scalar, LocalOrdinal, GlobalOrdinal, Node>& Aview,
530 CrsMatrixStruct<Scalar, LocalOrdinal, GlobalOrdinal, Node>& Bview,
531 const LocalOrdinalViewType & Acol2Brow,
532 const LocalOrdinalViewType & Acol2Irow,
533 const LocalOrdinalViewType & Bcol2Ccol,
534 const LocalOrdinalViewType & Icol2Ccol,
535 CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>& C,
536 Teuchos::RCP<
const Import<LocalOrdinal,GlobalOrdinal,Node> > Cimport,
537 const std::string& label = std::string(),
538 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
544 template<
class Scalar,
548 class LocalOrdinalViewType>
549 struct KernelWrappers2 {
550 static inline void jacobi_A_B_newmatrix_kernel_wrapper(Scalar omega,
551 const Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> & Dinv,
552 CrsMatrixStruct<Scalar, LocalOrdinal, GlobalOrdinal, Node>& Aview,
553 CrsMatrixStruct<Scalar, LocalOrdinal, GlobalOrdinal, Node>& Bview,
554 const LocalOrdinalViewType & Acol2Brow,
555 const LocalOrdinalViewType & Acol2Irow,
556 const LocalOrdinalViewType & Bcol2Ccol,
557 const LocalOrdinalViewType & Icol2Ccol,
558 CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>& C,
559 Teuchos::RCP<
const Import<LocalOrdinal,GlobalOrdinal,Node> > Cimport,
560 const std::string& label = std::string(),
561 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
563 static inline void jacobi_A_B_reuse_kernel_wrapper(Scalar omega,
564 const Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> & Dinv,
565 CrsMatrixStruct<Scalar, LocalOrdinal, GlobalOrdinal, Node>& Aview,
566 CrsMatrixStruct<Scalar, LocalOrdinal, GlobalOrdinal, Node>& Bview,
567 const LocalOrdinalViewType & Acol2Brow,
568 const LocalOrdinalViewType & Acol2Irow,
569 const LocalOrdinalViewType & Bcol2Ccol,
570 const LocalOrdinalViewType & Icol2Ccol,
571 CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>& C,
572 Teuchos::RCP<
const Import<LocalOrdinal,GlobalOrdinal,Node> > Cimport,
573 const std::string& label = std::string(),
574 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
580 template<
class Scalar,
584 class LocalOrdinalViewType>
585 struct KernelWrappers3 {
586 static inline void mult_R_A_P_newmatrix_kernel_wrapper(CrsMatrixStruct<Scalar, LocalOrdinal, GlobalOrdinal, Node>& Rview,
587 CrsMatrixStruct<Scalar, LocalOrdinal, GlobalOrdinal, Node>& Aview,
588 CrsMatrixStruct<Scalar, LocalOrdinal, GlobalOrdinal, Node>& Pview,
589 const LocalOrdinalViewType & Acol2Prow,
590 const LocalOrdinalViewType & Acol2PIrow,
591 const LocalOrdinalViewType & Pcol2Ccol,
592 const LocalOrdinalViewType & PIcol2Ccol,
593 CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>& Ac,
594 Teuchos::RCP<
const Import<LocalOrdinal,GlobalOrdinal,Node> > Acimport,
595 const std::string& label = std::string(),
596 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
598 static inline void mult_R_A_P_reuse_kernel_wrapper(CrsMatrixStruct<Scalar, LocalOrdinal, GlobalOrdinal, Node>& Rview,
599 CrsMatrixStruct<Scalar, LocalOrdinal, GlobalOrdinal, Node>& Aview,
600 CrsMatrixStruct<Scalar, LocalOrdinal, GlobalOrdinal, Node>& Pview,
601 const LocalOrdinalViewType & Acol2Prow,
602 const LocalOrdinalViewType & Acol2PIrow,
603 const LocalOrdinalViewType & Pcol2Ccol,
604 const LocalOrdinalViewType & PIcol2Ccol,
605 CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>& Ac,
606 Teuchos::RCP<
const Import<LocalOrdinal,GlobalOrdinal,Node> > Acimport,
607 const std::string& label = std::string(),
608 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
611 static inline void mult_PT_A_P_newmatrix_kernel_wrapper(CrsMatrixStruct<Scalar, LocalOrdinal, GlobalOrdinal, Node>& Aview,
612 CrsMatrixStruct<Scalar, LocalOrdinal, GlobalOrdinal, Node>& Pview,
613 const LocalOrdinalViewType & Acol2Prow,
614 const LocalOrdinalViewType & Acol2PIrow,
615 const LocalOrdinalViewType & Pcol2Ccol,
616 const LocalOrdinalViewType & PIcol2Ccol,
617 CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>& Ac,
618 Teuchos::RCP<
const Import<LocalOrdinal,GlobalOrdinal,Node> > Acimport,
619 const std::string& label = std::string(),
620 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
622 static inline void mult_PT_A_P_reuse_kernel_wrapper(CrsMatrixStruct<Scalar, LocalOrdinal, GlobalOrdinal, Node>& Aview,
623 CrsMatrixStruct<Scalar, LocalOrdinal, GlobalOrdinal, Node>& Pview,
624 const LocalOrdinalViewType & Acol2Prow,
625 const LocalOrdinalViewType & Acol2PIrow,
626 const LocalOrdinalViewType & Pcol2Ccol,
627 const LocalOrdinalViewType & PIcol2Ccol,
628 CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>& Ac,
629 Teuchos::RCP<
const Import<LocalOrdinal,GlobalOrdinal,Node> > Acimport,
630 const std::string& label = std::string(),
631 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
635 template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalOrdinalViewType>
637 merge_matrices(CrsMatrixStruct<Scalar, LocalOrdinal, GlobalOrdinal, Node>& Aview,
638 CrsMatrixStruct<Scalar, LocalOrdinal, GlobalOrdinal, Node>& Bview,
639 const LocalOrdinalViewType & Acol2Brow,
640 const LocalOrdinalViewType & Acol2Irow,
641 const LocalOrdinalViewType & Bcol2Ccol,
642 const LocalOrdinalViewType & Icol2Ccol,
643 const size_t mergedNodeNumCols);
648 template<
class CrsMatrixType>
649 size_t C_estimate_nnz(CrsMatrixType & A, CrsMatrixType &B);
655 #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)
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.
KokkosSparse::CrsMatrix< impl_scalar_type, local_ordinal_type, execution_space, 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...
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...