42 #ifndef THYRA_DEFAULT_CLUSTERED_SPMD_PRODUCT_VECTOR_HPP
43 #define THYRA_DEFAULT_CLUSTERED_SPMD_PRODUCT_VECTOR_HPP
45 #include "Thyra_DefaultClusteredSpmdProductVector_decl.hpp"
46 #include "Thyra_DefaultClusteredSpmdProductVectorSpace.hpp"
47 #include "Thyra_SpmdVectorBase.hpp"
48 #include "RTOp_parallel_helpers.h"
49 #include "RTOpPack_SPMD_apply_op.hpp"
50 #include "Teuchos_Workspace.hpp"
51 #include "Teuchos_dyn_cast.hpp"
52 #include "Teuchos_implicit_cast.hpp"
61 template <
class Scalar>
68 template <
class Scalar>
74 initialize(productSpace_in,vecs);
78 template <
class Scalar>
85 productSpace_ = productSpace_in;
86 const int numBlocks = productSpace_->numBlocks();
87 vecs_.resize(numBlocks);
89 std::copy( vecs, vecs + numBlocks, &vecs_[0] );
92 for(
int k = 0; k < numBlocks; ++k )
93 vecs_[k] = createMember(productSpace_->getBlock(k));
98 template <
class Scalar>
104 const int numBlocks = vecs_.size();
105 if(productSpace_in) *productSpace_in = productSpace_;
106 if(vecs) std::copy( &vecs_[0], &vecs_[0]+numBlocks, vecs );
107 productSpace_ = Teuchos::null;
115 template <
class Scalar>
125 template <
class Scalar>
138 template <
class Scalar>
142 return productSpace_;
146 template <
class Scalar>
155 template <
class Scalar>
159 return getNonconstVectorBlock(k);
163 template <
class Scalar>
167 return getVectorBlock(k);
174 template <
class Scalar>
178 return productSpace_;
185 template <
class Scalar>
195 const Ordinal first_ele_offset_in = 0;
199 using Teuchos::ptr_dynamic_cast;
200 using Teuchos::tuple;
202 const int num_vecs = vecs.size();
203 const int num_targ_vecs = targ_vecs.size();
208 global_offset_in < 0, std::invalid_argument,
209 "DefaultClusteredSpmdProductVector::applyOp(...): Error, "
210 "global_offset_in = " << global_offset_in <<
" is not acceptable" );
212 for (
int k = 0; k < num_vecs; ++k) {
213 test_failed = !this->space()->isCompatible(*vecs[k]->space());
216 "DefaultClusteredSpmdProductVector::applyOp(...): Error vecs["<<k<<
"]->space() "
217 <<
"of type \'"<<
typeName(*vecs[k]->space())<<
"\' is not compatible with this "
218 <<
"\'VectorSpaceBlocked\' vector space!"
221 for (
int k = 0; k < num_targ_vecs; ++k) {
222 test_failed = !this->space()->isCompatible(*targ_vecs[k]->space());
225 ,
"DefaultClusteredSpmdProductVector::applyOp(...): Error targ_vecs["<<k<<
"]->space() "
226 <<
"of type \'"<<
typeName(*vecs[k]->space())<<
"\' is not compatible with this "
227 <<
"\'VectorSpaceBlocked\' vector space!"
237 for (
int k = 0; k < num_vecs; ++k ) {
244 for (
int k = 0; k < num_targ_vecs; ++k ) {
256 intraClusterComm = productSpace_->intraClusterComm(),
257 interClusterComm = productSpace_->interClusterComm();
259 clusterSubDim = productSpace_->clusterSubDim(),
260 clusterOffset = productSpace_->clusterOffset(),
261 globalDim = productSpace_->dim();
262 Ordinal overlap_first_cluster_ele_off = 0;
263 Ordinal overlap_cluster_sub_dim = 0;
264 Ordinal overlap_global_off = 0;
266 RTOp_parallel_calc_overlap(
267 globalDim,clusterSubDim,clusterOffset,first_ele_offset_in,sub_dim_in
269 ,&overlap_first_cluster_ele_off,&overlap_cluster_sub_dim,&overlap_global_off
282 const int numBlocks = vecs_.size();
283 if (overlap_first_cluster_ele_off >=0) {
291 Ordinal overall_global_offset = overlap_global_off;
292 for(
int j = 0; j < numBlocks; ++j ) {
296 &v_space = *v.
space();
298 for(
int k = 0; k < num_vecs ; ++k )
299 v_vecs[k] = cl_vecs[k]->vecs_[j].ptr();
300 for(
int k = 0; k < num_targ_vecs ; ++k )
301 v_targ_vecs[k] = cl_targ_vecs[k]->vecs_[j].ptr();
303 numBlocks > 1, std::logic_error
304 ,
"Error, Have not implemented general support for numBlocks > 1!"
306 Ordinal v_global_offset = overall_global_offset;
308 Thyra::applyOp<Scalar>(
309 op, v_vecs(), v_targ_vecs(), i_reduct_obj.
ptr(),
312 overall_global_offset += v_space.
dim();
328 if (interClusterComm.get()) {
329 RTOpPack::SPMD_all_reduce(
333 tuple<const RTOpPack::ReductTarget*>(&*i_reduct_obj).getRawPtr(),
334 tuple<RTOpPack::ReductTarget*>(&*icl_reduct_obj).getRawPtr()
342 RTOpPack::SPMD_all_reduce(
346 tuple<const RTOpPack::ReductTarget*>(&*icl_reduct_obj).getRawPtr(),
347 tuple<RTOpPack::ReductTarget*>(&*reduct_obj).getRawPtr()
360 #endif // THYRA_DEFAULT_CLUSTERED_SPMD_PRODUCT_VECTOR_HPP
virtual RCP< const VectorSpaceBase< Scalar > > space() const =0
Return a smart pointer to the vector space that this vector belongs to.
void uninitialize(Teuchos::RCP< const DefaultClusteredSpmdProductVectorSpace< Scalar > > *productSpace=NULL, Teuchos::RCP< VectorBase< Scalar > > vecs[]=NULL)
Uninitialize.
Teuchos::RCP< const ProductVectorSpaceBase< Scalar > > productSpace() const
bool is_null(const boost::shared_ptr< T > &p)
Thrown if vector spaces are incompatible.
void applyOpImpl(const RTOpPack::RTOpT< Scalar > &op, const ArrayView< const Ptr< const VectorBase< Scalar > > > &vecs, const ArrayView< const Ptr< VectorBase< Scalar > > > &targ_vecs, const Ptr< RTOpPack::ReductTarget > &reduct_obj, const Ordinal global_offset) const
Teuchos::RCP< const VectorBase< Scalar > > getVectorBlock(const int k) const
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
bool blockIsConst(const int k) const
Abstract interface for objects that represent a space for vectors.
Teuchos::RCP< const MultiVectorBase< Scalar > > getMultiVectorBlock(const int k) const
Teuchos::Ordinal Ordinal
Type for the dimension of a vector space. `*.
void initialize(const Teuchos::RCP< const DefaultClusteredSpmdProductVectorSpace< Scalar > > &productSpace, const Teuchos::RCP< VectorBase< Scalar > > vecs[])
Initialize.
Teuchos::RCP< MultiVectorBase< Scalar > > getNonconstMultiVectorBlock(const int k)
Concrete implementation of a clustered Spmd-based product vector.
TypeTo implicit_cast(const TypeFrom &t)
Abstract interface for finite-dimensional dense vectors.
Teuchos::RCP< const VectorSpaceBase< Scalar > > space() const
Teuchos::RCP< ReductTarget > reduct_obj_create() const
Teuchos::RCP< VectorBase< Scalar > > getNonconstVectorBlock(const int k)
virtual Ordinal dim() const =0
Return the dimension of the vector space.
DefaultClusteredSpmdProductVector()
Constructs to uninitialized (see postconditions for uninitialize()).
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)
std::string typeName(const T &t)