10 #ifndef THYRA_EXAMPLE_TRIDIAG_SPMD_LINEAR_OP_HPP
11 #define THYRA_EXAMPLE_TRIDIAG_SPMD_LINEAR_OP_HPP
13 #include "Thyra_LinearOpDefaultBase.hpp"
14 #include "Thyra_DefaultSpmdVectorSpace.hpp"
15 #include "Thyra_DetachedSpmdVectorView.hpp"
16 #include "Teuchos_DefaultComm.hpp"
17 #include "Teuchos_CommHelpers.hpp"
110 template<
class Scalar>
125 { this->
initialize(comm, localDim, lower, diag, upper); }
191 void communicate(
const bool first,
const bool last,
199 template<
class Scalar>
210 space_ = Thyra::defaultSpmdVectorSpace<Scalar>(comm, localDim, -1);
217 template<
class Scalar>
229 using Teuchos::outArg;
234 const Scalar
zero = ST::zero();
235 const Ordinal localDim = space_->localSubDim();
236 const Ordinal procRank = comm_->getRank();
237 const Ordinal numProcs = comm_->getSize();
238 const Ordinal m = X_in.
domain()->dim();
242 for (Ordinal col_j = 0; col_j < m; ++col_j) {
251 const bool first = (procRank == 0), last = ( procRank == numProcs-1 );
255 communicate( first, last, x(), outArg(x_km1), outArg(x_kp1) );
262 y[k] = alpha * ( (first?zero:lower_[lk]*x_km1) + diag_[k]*x[k]
263 + upper_[k]*x[k+1] );
266 for( k = 1; k < localDim - 1; ++lk, ++k )
267 y[k] = alpha * ( lower_[lk]*x[k-1] + diag_[k]*x[k] + upper_[k]*x[k+1] );
269 y[k] = alpha * ( lower_[lk]*x[k-1] + diag_[k]*x[k]
270 + (last?zero:upper_[k]*x_kp1) );
274 y[k] = alpha * ( (first?zero:lower_[lk]*x_km1) + diag_[k]*x[k]
275 + upper_[k]*x[k+1] ) + beta*y[k];
278 for( k = 1; k < localDim - 1; ++lk, ++k )
279 y[k] = alpha * ( lower_[lk]*x[k-1] + diag_[k]*x[k] + upper_[k]*x[k+1] )
282 y[k] = alpha * ( lower_[lk]*x[k-1] + diag_[k]*x[k]
283 + (last?zero:upper_[k]*x_kp1) ) + beta*y[k];
291 template<
class Scalar>
293 const bool first,
const bool last,
300 const Ordinal localDim = space_->localSubDim();
301 const Ordinal procRank = comm_->getRank();
302 const Ordinal numProcs = comm_->getSize();
303 const bool isEven = (procRank % 2 == 0);
304 const bool isOdd = !isEven;
307 if(isEven && procRank+1 < numProcs) send(*comm_, x[localDim-1], procRank+1);
308 if(isOdd && procRank-1 >= 0) receive(*comm_, procRank-1, &*x_km1);
311 if( isOdd && procRank-1 >= 0 ) send(*comm_, x[0], procRank-1);
312 if( isEven && procRank+1 < numProcs ) receive(*comm_, procRank+1, &*x_kp1);
315 if (isOdd && procRank+1 < numProcs) send(*comm_, x[localDim-1], procRank+1);
316 if (isEven && procRank-1 >= 0) receive(*comm_, procRank-1, &*x_km1);
319 if (isEven && procRank-1 >= 0) send(*comm_, x[0], procRank-1);
320 if (isOdd && procRank+1 < numProcs) receive(*comm_, procRank+1, &*x_kp1);
324 #endif // THYRA_EXAMPLE_TRIDIAG_SPMD_LINEAR_OP_HPP
Create an explicit detached mutable (non-const) view of all of the local elements on this process of ...
EOpTransp
Enumeration for determining how a linear operator is applied. `*.
bool opSupportedImpl(Thyra::EOpTransp M_trans) const
ExampleTridiagSpmdLinearOp(const Teuchos::RCP< const Teuchos::Comm< Thyra::Ordinal > > &comm, const Thyra::Ordinal localDim, const Teuchos::ArrayView< const Scalar > &lower, const Teuchos::ArrayView< const Scalar > &diag, const Teuchos::ArrayView< const Scalar > &upper)
Use the non-transposed operator.
Teuchos::RCP< const Thyra::VectorSpaceBase< Scalar > > range() const
Node subclass that provides a good default implementation for the describe() function.
RCP< const LinearOpBase< Scalar > > zero(const RCP< const VectorSpaceBase< Scalar > > &range, const RCP< const VectorSpaceBase< Scalar > > &domain)
Create a zero linear operator with given range and domain spaces.
Teuchos::RCP< const Thyra::VectorSpaceBase< Scalar > > domain() const
Simple example subclass for Spmd tridiagonal matrices.
Teuchos::Ordinal Ordinal
Type for the dimension of a vector space. `*.
Interface for a collection of column vectors called a multi-vector.
bool opSupported(const LinearOpBase< Scalar > &M, EOpTransp M_trans)
Determines if an operation is supported for a single scalar type.
RCP< const VectorBase< Scalar > > col(Ordinal j) const
Calls colImpl().
virtual RCP< const VectorSpaceBase< Scalar > > domain() const =0
Return a smart pointer for the domain space for this operator.
void initialize(const Teuchos::RCP< const Teuchos::Comm< Thyra::Ordinal > > &comm, const Thyra::Ordinal localDim, const Teuchos::ArrayView< const Scalar > &lower, const Teuchos::ArrayView< const Scalar > &diag, const Teuchos::ArrayView< const Scalar > &upper)
ExampleTridiagSpmdLinearOp()
Create an explicit detached non-mutable (const) view of all of the local elements on this process of ...
#define TEUCHOS_ASSERT(assertion_test)
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)
void applyImpl(const Thyra::EOpTransp M_trans, const Thyra::MultiVectorBase< Scalar > &X_in, const Teuchos::Ptr< Thyra::MultiVectorBase< Scalar > > &Y_inout, const Scalar alpha, const Scalar beta) const