46 #ifndef BELOS_XPETRA_ADAPTER_MULTIVECTOR_MP_VECTOR_HPP
47 #define BELOS_XPETRA_ADAPTER_MULTIVECTOR_MP_VECTOR_HPP
49 #include "BelosXpetraAdapterMultiVector.hpp"
53 #ifdef HAVE_XPETRA_TPETRA
70 template<
class Storage,
class LO,
class GO,
class Node>
72 Xpetra::MultiVector<Sacado::MP::Vector<Storage>,
78 typedef typename Tpetra::MultiVector<Scalar,LO,GO,Node>::dot_type dot_type;
79 typedef typename Tpetra::MultiVector<Scalar,LO,GO,Node>::mag_type mag_type;
83 typedef Xpetra::TpetraMultiVector<Scalar,LO,GO,Node> TpetraMultiVector;
84 typedef MultiVecTraits<dot_type,Tpetra::MultiVector<Scalar,LO,GO,Node> > MultiVecTraitsTpetra;
88 #ifdef HAVE_BELOS_XPETRA_TIMERS
89 static RCP<Teuchos::Time> mvTimesMatAddMvTimer_, mvTransMvTimer_;
92 static RCP<Xpetra::MultiVector<Scalar,LO,GO,Node> > Clone(
const Xpetra::MultiVector<Scalar,LO,GO,Node>& mv,
const int numvecs )
94 if (mv.getMap()->lib() == Xpetra::UseTpetra)
95 return rcp(
new TpetraMultiVector(MultiVecTraitsTpetra::Clone(toTpetra(mv), numvecs)));
98 static RCP<Xpetra::MultiVector<Scalar,LO,GO,Node> > CloneCopy(
const Xpetra::MultiVector<Scalar,LO,GO,Node>& mv )
100 if (mv.getMap()->lib() == Xpetra::UseTpetra)
101 return rcp(
new TpetraMultiVector(MultiVecTraitsTpetra::CloneCopy(toTpetra(mv))));
104 static RCP<Xpetra::MultiVector<Scalar,LO,GO,Node> > CloneCopy(
const Xpetra::MultiVector<Scalar,LO,GO,Node>& mv,
const std::vector<int>& index )
106 if (mv.getMap()->lib() == Xpetra::UseTpetra)
107 return rcp(
new TpetraMultiVector(MultiVecTraitsTpetra::CloneCopy(toTpetra(mv), index)));
110 static RCP<Xpetra::MultiVector<Scalar,LO,GO,Node> >
111 CloneCopy (
const Xpetra::MultiVector<Scalar,LO,GO,Node>& mv,
114 if (mv.getMap()->lib() == Xpetra::UseTpetra)
115 return rcp(
new TpetraMultiVector(MultiVecTraitsTpetra::CloneCopy(toTpetra(mv), index)));
118 static RCP<Xpetra::MultiVector<Scalar,LO,GO,Node> > CloneViewNonConst( Xpetra::MultiVector<Scalar,LO,GO,Node>& mv,
const std::vector<int>& index )
120 if (mv.getMap()->lib() == Xpetra::UseTpetra)
121 return rcp(
new TpetraMultiVector(MultiVecTraitsTpetra::CloneViewNonConst(toTpetra(mv), index)));
124 static RCP<Xpetra::MultiVector<Scalar,LO,GO,Node> >
125 CloneViewNonConst(Xpetra::MultiVector<Scalar,LO,GO,Node>& mv,
128 if (mv.getMap()->lib() == Xpetra::UseTpetra)
129 return rcp(
new TpetraMultiVector(MultiVecTraitsTpetra::CloneViewNonConst(toTpetra(mv), index)));
132 static RCP<const Xpetra::MultiVector<Scalar,LO,GO,Node> > CloneView(
const Xpetra::MultiVector<Scalar,LO,GO,Node>& mv,
const std::vector<int>& index )
134 if (mv.getMap()->lib() == Xpetra::UseTpetra) {
136 RCP<const Tpetra::MultiVector<Scalar,LO,GO,Node> > r = MultiVecTraitsTpetra::CloneView(toTpetra(mv), index);
137 return rcp(
new TpetraMultiVector(Teuchos::rcp_const_cast<Tpetra::MultiVector<Scalar,LO,GO,Node> >(r)));
141 static RCP<const Xpetra::MultiVector<Scalar,LO,GO,Node> >
142 CloneView (
const Xpetra::MultiVector<Scalar,LO,GO,Node>& mv,
145 if (mv.getMap()->lib() == Xpetra::UseTpetra) {
147 RCP<const Tpetra::MultiVector<Scalar,LO,GO,Node> > r = MultiVecTraitsTpetra::CloneView(toTpetra(mv), index);
148 return rcp(
new TpetraMultiVector(Teuchos::rcp_const_cast<Tpetra::MultiVector<Scalar,LO,GO,Node> >(r)));
152 static ptrdiff_t GetGlobalLength(
const Xpetra::MultiVector<Scalar,LO,GO,Node>& mv )
154 if (mv.getMap()->lib() == Xpetra::UseTpetra)
155 return MultiVecTraitsTpetra::GetGlobalLength(toTpetra(mv));
158 static int GetNumberVecs(
const Xpetra::MultiVector<Scalar,LO,GO,Node>& mv )
160 if (mv.getMap()->lib() == Xpetra::UseTpetra)
161 return MultiVecTraitsTpetra::GetNumberVecs(toTpetra(mv));
164 static bool HasConstantStride(
const Xpetra::MultiVector<Scalar,LO,GO,Node>& mv )
166 if (mv.getMap()->lib() == Xpetra::UseTpetra)
167 return MultiVecTraitsTpetra::HasConstantStride(toTpetra(mv));
170 static void MvTimesMatAddMv( dot_type alpha,
const Xpetra::MultiVector<Scalar,LO,GO,Node>&
A,
172 dot_type beta, Xpetra::MultiVector<Scalar,LO,GO,Node>& mv )
174 #ifdef HAVE_BELOS_XPETRA_TIMERS
177 if (mv.getMap()->lib() == Xpetra::UseTpetra) {
178 MultiVecTraitsTpetra::MvTimesMatAddMv(alpha, toTpetra(A), B, beta, toTpetra(mv));
183 static void MvAddMv(
Scalar alpha,
const Xpetra::MultiVector<Scalar,LO,GO,Node>& A,
Scalar beta,
const Xpetra::MultiVector<Scalar,LO,GO,Node>& B, Xpetra::MultiVector<Scalar,LO,GO,Node>& mv )
185 if (mv.getMap()->lib() == Xpetra::UseTpetra) {
186 MultiVecTraitsTpetra::MvAddMv(alpha, toTpetra(A), beta, toTpetra(B), toTpetra(mv));
191 static void MvScale ( Xpetra::MultiVector<Scalar,LO,GO,Node>& mv,
Scalar alpha )
193 if (mv.getMap()->lib() == Xpetra::UseTpetra) {
194 MultiVecTraitsTpetra::MvScale(toTpetra(mv), alpha);
199 static void MvScale ( Xpetra::MultiVector<Scalar,LO,GO,Node>& mv,
const std::vector<BaseScalar>& alphas )
201 std::vector<Scalar> alphas_mp(alphas.size());
202 const size_t sz = alphas.size();
203 for (
size_t i=0; i<sz; ++i)
204 alphas_mp[i] = alphas[i];
205 MvScale (mv, alphas_mp);
208 static void MvScale ( Xpetra::MultiVector<Scalar,LO,GO,Node>& mv,
const std::vector<Scalar>& alphas )
210 if (mv.getMap()->lib() == Xpetra::UseTpetra) {
211 MultiVecTraitsTpetra::MvScale(toTpetra(mv), alphas);
216 static void MvTransMv( dot_type alpha,
const Xpetra::MultiVector<Scalar,LO,GO,Node>& A,
const Xpetra::MultiVector<Scalar,LO,GO,Node>& B,
Teuchos::SerialDenseMatrix<int,dot_type>&
C)
218 #ifdef HAVE_BELOS_XPETRA_TIMERS
222 if (A.getMap()->lib() == Xpetra::UseTpetra) {
223 MultiVecTraitsTpetra::MvTransMv(alpha, toTpetra(A), toTpetra(B), C);
228 static void MvDot(
const Xpetra::MultiVector<Scalar,LO,GO,Node>& A,
const Xpetra::MultiVector<Scalar,LO,GO,Node>& B, std::vector<dot_type> &dots)
230 if (A.getMap()->lib() == Xpetra::UseTpetra) {
231 MultiVecTraitsTpetra::MvDot(toTpetra(A), toTpetra(B), dots);
236 static void MvNorm(
const Xpetra::MultiVector<Scalar,LO,GO,Node>& mv, std::vector<mag_type> &normvec, NormType type=TwoNorm)
238 if (mv.getMap()->lib() == Xpetra::UseTpetra) {
239 MultiVecTraitsTpetra::MvNorm(toTpetra(mv), normvec, type);
244 static void SetBlock(
const Xpetra::MultiVector<Scalar,LO,GO,Node>& A,
const std::vector<int>& index, Xpetra::MultiVector<Scalar,LO,GO,Node>& mv )
246 if (mv.getMap()->lib() == Xpetra::UseTpetra) {
247 MultiVecTraitsTpetra::SetBlock(toTpetra(A), index, toTpetra(mv));
253 SetBlock (
const Xpetra::MultiVector<Scalar,LO,GO,Node>& A,
255 Xpetra::MultiVector<Scalar,LO,GO,Node>& mv)
257 if (mv.getMap()->lib() == Xpetra::UseTpetra) {
258 MultiVecTraitsTpetra::SetBlock(toTpetra(A), index, toTpetra(mv));
264 Assign (
const Xpetra::MultiVector<Scalar,LO,GO,Node>& A,
265 Xpetra::MultiVector<Scalar,LO,GO,Node>& mv)
267 if (mv.getMap()->lib() == Xpetra::UseTpetra) {
268 MultiVecTraitsTpetra::Assign(toTpetra(A), toTpetra(mv));
273 static void MvRandom( Xpetra::MultiVector<Scalar,LO,GO,Node>& mv )
275 if (mv.getMap()->lib() == Xpetra::UseTpetra) {
276 MultiVecTraitsTpetra::MvRandom(toTpetra(mv));
283 if (mv.getMap()->lib() == Xpetra::UseTpetra) {
284 MultiVecTraitsTpetra::MvInit(toTpetra(mv), alpha);
289 static void MvPrint(
const Xpetra::MultiVector<Scalar,LO,GO,Node>& mv, std::ostream& os )
291 if (mv.getMap()->lib() == Xpetra::UseTpetra) {
292 MultiVecTraitsTpetra::MvPrint(toTpetra(mv), os);
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)