45 const typename std::remove_pointer<typename MultiVectorArray::value_type>::type &X,
47 typename std::remove_pointer<typename MatrixArray::value_type>::type::scalar_type alpha = Teuchos::ScalarTraits<
typename std::remove_pointer<typename MatrixArray::value_type>::type::scalar_type>::one(),
48 typename std::remove_pointer<typename MatrixArray::value_type>::type::scalar_type beta = Teuchos::ScalarTraits<
typename std::remove_pointer<typename MatrixArray::value_type>::type::scalar_type>::zero(),
49 Teuchos::RCP<Teuchos::ParameterList> params = Teuchos::null) {
52 using size_type =
typename MatrixArray::size_type;
53 using matrix_type =
typename std::remove_pointer<typename MatrixArray::value_type>::type;
54 using map_type =
typename matrix_type::map_type;
55 using import_type =
typename matrix_type::import_type;
56 using export_type =
typename matrix_type::export_type;
57 using MV =
typename matrix_type::MV;
58 using scalar_type =
typename matrix_type::scalar_type;
61 using Teuchos::rcp_const_cast;
63 const scalar_type ONE = Teuchos::ScalarTraits<scalar_type>::one();
66 size_type N = Matrices.size();
68 int numRanks = X.getMap()->getComm()->getSize();
71 for(size_type i=0; i<N-1; i++) {
72 TEUCHOS_TEST_FOR_EXCEPTION( &X == Y[i], std::runtime_error,
"Tpetra::batchedApply(): X cannot be aliased to any Y except the final one.");
76 RCP<const map_type> compare_colMap = Matrices[0]->getColMap();
77 RCP<const import_type> importer = Matrices[0]->getGraph()->getImporter();
80 bool can_batch, check_maps;
81 if(params.is_null() || !params->isParameter(
"can batch")) {
82 can_batch = (importer.is_null() || N==1) ? false :
true;
86 can_batch = (!params->get<
bool>(
"can batch") || importer.is_null() || N==1) ? false :
true;
91 for(size_type i=0; i<N && can_batch; i++) {
98 for(size_type i=1; i<N && check_maps && can_batch; i++) {
99 if(!Matrices[i]->
getColMap()->isSameAs(*compare_colMap)) {
110 for(size_type i=0; i<N; i++) Y[i]->putScalar(
ZERO);
111 }
else if (beta != ONE) {
112 for(size_type i=0; i<N; i++) Y[i]->
scale(beta);
114 if(!params.is_null()) params->set(
"can batch",
true);
118 const bool Y_is_overwritten = (beta ==
ZERO);
121 RCP<const MV> X_colMap;
124 RCP<MV> X_colMapNonConst = Matrices[0]->getColumnMapMultiVector(X);
127 X_colMapNonConst->doImport(X, *importer,
INSERT);
128 X_colMap = rcp_const_cast<const MV>(X_colMapNonConst);
131 for(size_type i=0; i<N; i++) {
132 RCP<const export_type> exporter = Matrices[i]->getGraph()->getExporter();
135 RCP<MV> Y_rowMap = Matrices[i]->getRowMapMultiVector(*Y[i]);
136 if (!exporter.is_null()) {
137 Matrices[i]->localApply(*X_colMap, *Y_rowMap, Teuchos::NO_TRANS, alpha,
ZERO);
140 if (Y_is_overwritten) {
141 Y[i]->putScalar(
ZERO);
146 Y[i]->doExport(*Y_rowMap, *exporter,
ADD_ASSIGN);
151 if (! Y[i]->isConstantStride() || X_colMap.getRawPtr() == Y[i]) {
152 Y_rowMap = Matrices[i]->getRowMapMultiVector(*Y[i],
true);
157 Matrices[i]->localApply(*X_colMap, *Y_rowMap, Teuchos::NO_TRANS, alpha, beta);
161 Matrices[i]->localApply(*X_colMap, *Y[i], Teuchos::NO_TRANS, alpha, beta);
165 if(!params.is_null()) params->set(
"can batch",
true);
169 for(size_type i=0; i<N; i++) {
170 Matrices[i]->apply(X,*Y[i],Teuchos::NO_TRANS, alpha, beta);
172 if(!params.is_null()) params->set(
"can batch",
false);
void batchedApply(const MatrixArray &Matrices, const typename std::remove_pointer< typename MultiVectorArray::value_type >::type &X, MultiVectorArray &Y, typename std::remove_pointer< typename MatrixArray::value_type >::type::scalar_type alpha=Teuchos::ScalarTraits< typename std::remove_pointer< typename MatrixArray::value_type >::type::scalar_type >::one(), typename std::remove_pointer< typename MatrixArray::value_type >::type::scalar_type beta=Teuchos::ScalarTraits< typename std::remove_pointer< typename MatrixArray::value_type >::type::scalar_type >::zero(), Teuchos::RCP< Teuchos::ParameterList > params=Teuchos::null)
Does multiply matrix apply() calls with a single X vector.