10 #ifndef BELOS_XPETRA_ADAPTER_MULTIVECTOR_MP_VECTOR_HPP
11 #define BELOS_XPETRA_ADAPTER_MULTIVECTOR_MP_VECTOR_HPP
13 #include "BelosXpetraAdapterMultiVector.hpp"
17 #ifdef HAVE_XPETRA_TPETRA
34 template<
class Storage,
class LO,
class GO,
class Node>
36 Xpetra::MultiVector<Sacado::MP::Vector<Storage>,
42 typedef typename Tpetra::MultiVector<Scalar,LO,GO,Node>::dot_type dot_type;
43 typedef typename Tpetra::MultiVector<Scalar,LO,GO,Node>::mag_type mag_type;
47 typedef Xpetra::TpetraMultiVector<Scalar,LO,GO,Node> TpetraMultiVector;
48 typedef MultiVecTraits<dot_type,Tpetra::MultiVector<Scalar,LO,GO,Node> > MultiVecTraitsTpetra;
52 #ifdef HAVE_BELOS_XPETRA_TIMERS
53 static RCP<Teuchos::Time> mvTimesMatAddMvTimer_, mvTransMvTimer_;
56 static RCP<Xpetra::MultiVector<Scalar,LO,GO,Node> > Clone(
const Xpetra::MultiVector<Scalar,LO,GO,Node>& mv,
const int numvecs )
58 if (mv.getMap()->lib() == Xpetra::UseTpetra)
59 return rcp(
new TpetraMultiVector(MultiVecTraitsTpetra::Clone(toTpetra(mv), numvecs)));
62 static RCP<Xpetra::MultiVector<Scalar,LO,GO,Node> > CloneCopy(
const Xpetra::MultiVector<Scalar,LO,GO,Node>& mv )
64 if (mv.getMap()->lib() == Xpetra::UseTpetra)
65 return rcp(
new TpetraMultiVector(MultiVecTraitsTpetra::CloneCopy(toTpetra(mv))));
68 static RCP<Xpetra::MultiVector<Scalar,LO,GO,Node> > CloneCopy(
const Xpetra::MultiVector<Scalar,LO,GO,Node>& mv,
const std::vector<int>& index )
70 if (mv.getMap()->lib() == Xpetra::UseTpetra)
71 return rcp(
new TpetraMultiVector(MultiVecTraitsTpetra::CloneCopy(toTpetra(mv), index)));
74 static RCP<Xpetra::MultiVector<Scalar,LO,GO,Node> >
75 CloneCopy (
const Xpetra::MultiVector<Scalar,LO,GO,Node>& mv,
78 if (mv.getMap()->lib() == Xpetra::UseTpetra)
79 return rcp(
new TpetraMultiVector(MultiVecTraitsTpetra::CloneCopy(toTpetra(mv), index)));
82 static RCP<Xpetra::MultiVector<Scalar,LO,GO,Node> > CloneViewNonConst( Xpetra::MultiVector<Scalar,LO,GO,Node>& mv,
const std::vector<int>& index )
84 if (mv.getMap()->lib() == Xpetra::UseTpetra)
85 return rcp(
new TpetraMultiVector(MultiVecTraitsTpetra::CloneViewNonConst(toTpetra(mv), index)));
88 static RCP<Xpetra::MultiVector<Scalar,LO,GO,Node> >
89 CloneViewNonConst(Xpetra::MultiVector<Scalar,LO,GO,Node>& mv,
92 if (mv.getMap()->lib() == Xpetra::UseTpetra)
93 return rcp(
new TpetraMultiVector(MultiVecTraitsTpetra::CloneViewNonConst(toTpetra(mv), index)));
96 static RCP<const Xpetra::MultiVector<Scalar,LO,GO,Node> > CloneView(
const Xpetra::MultiVector<Scalar,LO,GO,Node>& mv,
const std::vector<int>& index )
98 if (mv.getMap()->lib() == Xpetra::UseTpetra) {
100 RCP<const Tpetra::MultiVector<Scalar,LO,GO,Node> > r = MultiVecTraitsTpetra::CloneView(toTpetra(mv), index);
101 return rcp(
new TpetraMultiVector(Teuchos::rcp_const_cast<Tpetra::MultiVector<Scalar,LO,GO,Node> >(r)));
105 static RCP<const Xpetra::MultiVector<Scalar,LO,GO,Node> >
106 CloneView (
const Xpetra::MultiVector<Scalar,LO,GO,Node>& mv,
109 if (mv.getMap()->lib() == Xpetra::UseTpetra) {
111 RCP<const Tpetra::MultiVector<Scalar,LO,GO,Node> > r = MultiVecTraitsTpetra::CloneView(toTpetra(mv), index);
112 return rcp(
new TpetraMultiVector(Teuchos::rcp_const_cast<Tpetra::MultiVector<Scalar,LO,GO,Node> >(r)));
116 static ptrdiff_t GetGlobalLength(
const Xpetra::MultiVector<Scalar,LO,GO,Node>& mv )
118 if (mv.getMap()->lib() == Xpetra::UseTpetra)
119 return MultiVecTraitsTpetra::GetGlobalLength(toTpetra(mv));
122 static int GetNumberVecs(
const Xpetra::MultiVector<Scalar,LO,GO,Node>& mv )
124 if (mv.getMap()->lib() == Xpetra::UseTpetra)
125 return MultiVecTraitsTpetra::GetNumberVecs(toTpetra(mv));
128 static bool HasConstantStride(
const Xpetra::MultiVector<Scalar,LO,GO,Node>& mv )
130 if (mv.getMap()->lib() == Xpetra::UseTpetra)
131 return MultiVecTraitsTpetra::HasConstantStride(toTpetra(mv));
134 static void MvTimesMatAddMv( dot_type alpha,
const Xpetra::MultiVector<Scalar,LO,GO,Node>&
A,
136 dot_type beta, Xpetra::MultiVector<Scalar,LO,GO,Node>& mv )
138 #ifdef HAVE_BELOS_XPETRA_TIMERS
141 if (mv.getMap()->lib() == Xpetra::UseTpetra) {
142 MultiVecTraitsTpetra::MvTimesMatAddMv(alpha, toTpetra(A), B, beta, toTpetra(mv));
147 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 )
149 if (mv.getMap()->lib() == Xpetra::UseTpetra) {
150 MultiVecTraitsTpetra::MvAddMv(alpha, toTpetra(A), beta, toTpetra(B), toTpetra(mv));
155 static void MvScale ( Xpetra::MultiVector<Scalar,LO,GO,Node>& mv,
Scalar alpha )
157 if (mv.getMap()->lib() == Xpetra::UseTpetra) {
158 MultiVecTraitsTpetra::MvScale(toTpetra(mv), alpha);
163 static void MvScale ( Xpetra::MultiVector<Scalar,LO,GO,Node>& mv,
const std::vector<BaseScalar>& alphas )
165 std::vector<Scalar> alphas_mp(alphas.size());
166 const size_t sz = alphas.size();
167 for (
size_t i=0; i<sz; ++i)
168 alphas_mp[i] = alphas[i];
169 MvScale (mv, alphas_mp);
172 static void MvScale ( Xpetra::MultiVector<Scalar,LO,GO,Node>& mv,
const std::vector<Scalar>& alphas )
174 if (mv.getMap()->lib() == Xpetra::UseTpetra) {
175 MultiVecTraitsTpetra::MvScale(toTpetra(mv), alphas);
180 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)
182 #ifdef HAVE_BELOS_XPETRA_TIMERS
186 if (A.getMap()->lib() == Xpetra::UseTpetra) {
187 MultiVecTraitsTpetra::MvTransMv(alpha, toTpetra(A), toTpetra(B), C);
192 static void MvDot(
const Xpetra::MultiVector<Scalar,LO,GO,Node>& A,
const Xpetra::MultiVector<Scalar,LO,GO,Node>& B, std::vector<dot_type> &dots)
194 if (A.getMap()->lib() == Xpetra::UseTpetra) {
195 MultiVecTraitsTpetra::MvDot(toTpetra(A), toTpetra(B), dots);
200 static void MvNorm(
const Xpetra::MultiVector<Scalar,LO,GO,Node>& mv, std::vector<mag_type> &normvec, NormType type=TwoNorm)
202 if (mv.getMap()->lib() == Xpetra::UseTpetra) {
203 MultiVecTraitsTpetra::MvNorm(toTpetra(mv), normvec, type);
208 static void SetBlock(
const Xpetra::MultiVector<Scalar,LO,GO,Node>& A,
const std::vector<int>& index, Xpetra::MultiVector<Scalar,LO,GO,Node>& mv )
210 if (mv.getMap()->lib() == Xpetra::UseTpetra) {
211 MultiVecTraitsTpetra::SetBlock(toTpetra(A), index, toTpetra(mv));
217 SetBlock (
const Xpetra::MultiVector<Scalar,LO,GO,Node>& A,
219 Xpetra::MultiVector<Scalar,LO,GO,Node>& mv)
221 if (mv.getMap()->lib() == Xpetra::UseTpetra) {
222 MultiVecTraitsTpetra::SetBlock(toTpetra(A), index, toTpetra(mv));
228 Assign (
const Xpetra::MultiVector<Scalar,LO,GO,Node>& A,
229 Xpetra::MultiVector<Scalar,LO,GO,Node>& mv)
231 if (mv.getMap()->lib() == Xpetra::UseTpetra) {
232 MultiVecTraitsTpetra::Assign(toTpetra(A), toTpetra(mv));
237 static void MvRandom( Xpetra::MultiVector<Scalar,LO,GO,Node>& mv )
239 if (mv.getMap()->lib() == Xpetra::UseTpetra) {
240 MultiVecTraitsTpetra::MvRandom(toTpetra(mv));
247 if (mv.getMap()->lib() == Xpetra::UseTpetra) {
248 MultiVecTraitsTpetra::MvInit(toTpetra(mv), alpha);
253 static void MvPrint(
const Xpetra::MultiVector<Scalar,LO,GO,Node>& mv, std::ostream& os )
255 if (mv.getMap()->lib() == Xpetra::UseTpetra) {
256 MultiVecTraitsTpetra::MvPrint(toTpetra(mv), os);
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)