10 #ifndef THYRA_DEFAULT_CLUSTERED_SPMD_PRODUCT_VECTOR_HPP
11 #define THYRA_DEFAULT_CLUSTERED_SPMD_PRODUCT_VECTOR_HPP
13 #include "Thyra_DefaultClusteredSpmdProductVector_decl.hpp"
14 #include "Thyra_DefaultClusteredSpmdProductVectorSpace.hpp"
15 #include "Thyra_SpmdVectorBase.hpp"
16 #include "RTOp_parallel_helpers.h"
17 #include "RTOpPack_SPMD_apply_op.hpp"
18 #include "Teuchos_Workspace.hpp"
19 #include "Teuchos_dyn_cast.hpp"
20 #include "Teuchos_implicit_cast.hpp"
29 template <
class Scalar>
36 template <
class Scalar>
46 template <
class Scalar>
53 productSpace_ = productSpace_in;
54 const int numBlocks = productSpace_->numBlocks();
55 vecs_.resize(numBlocks);
57 std::copy( vecs, vecs + numBlocks, &vecs_[0] );
60 for(
int k = 0; k < numBlocks; ++k )
61 vecs_[k] = createMember(productSpace_->getBlock(k));
66 template <
class Scalar>
72 const int numBlocks = vecs_.size();
73 if(productSpace_in) *productSpace_in = productSpace_;
74 if(vecs) std::copy( &vecs_[0], &vecs_[0]+numBlocks, vecs );
75 productSpace_ = Teuchos::null;
83 template <
class Scalar>
93 template <
class Scalar>
106 template <
class Scalar>
110 return productSpace_;
114 template <
class Scalar>
123 template <
class Scalar>
127 return getNonconstVectorBlock(k);
131 template <
class Scalar>
135 return getVectorBlock(k);
142 template <
class Scalar>
146 return productSpace_;
153 template <
class Scalar>
163 const Ordinal first_ele_offset_in = 0;
167 using Teuchos::ptr_dynamic_cast;
168 using Teuchos::tuple;
170 const int num_vecs = vecs.size();
171 const int num_targ_vecs = targ_vecs.size();
176 global_offset_in < 0, std::invalid_argument,
177 "DefaultClusteredSpmdProductVector::applyOp(...): Error, "
178 "global_offset_in = " << global_offset_in <<
" is not acceptable" );
180 for (
int k = 0; k < num_vecs; ++k) {
181 test_failed = !this->space()->isCompatible(*vecs[k]->space());
184 "DefaultClusteredSpmdProductVector::applyOp(...): Error vecs["<<k<<
"]->space() "
185 <<
"of type \'"<<
typeName(*vecs[k]->space())<<
"\' is not compatible with this "
186 <<
"\'VectorSpaceBlocked\' vector space!"
189 for (
int k = 0; k < num_targ_vecs; ++k) {
190 test_failed = !this->space()->isCompatible(*targ_vecs[k]->space());
193 ,
"DefaultClusteredSpmdProductVector::applyOp(...): Error targ_vecs["<<k<<
"]->space() "
194 <<
"of type \'"<<
typeName(*vecs[k]->space())<<
"\' is not compatible with this "
195 <<
"\'VectorSpaceBlocked\' vector space!"
205 for (
int k = 0; k < num_vecs; ++k ) {
212 for (
int k = 0; k < num_targ_vecs; ++k ) {
224 intraClusterComm = productSpace_->intraClusterComm(),
225 interClusterComm = productSpace_->interClusterComm();
227 clusterSubDim = productSpace_->clusterSubDim(),
228 clusterOffset = productSpace_->clusterOffset(),
229 globalDim = productSpace_->dim();
230 Ordinal overlap_first_cluster_ele_off = 0;
231 Ordinal overlap_cluster_sub_dim = 0;
232 Ordinal overlap_global_off = 0;
234 RTOp_parallel_calc_overlap(
235 globalDim,clusterSubDim,clusterOffset,first_ele_offset_in,sub_dim_in
237 ,&overlap_first_cluster_ele_off,&overlap_cluster_sub_dim,&overlap_global_off
250 const int numBlocks = vecs_.size();
251 if (overlap_first_cluster_ele_off >=0) {
259 Ordinal overall_global_offset = overlap_global_off;
260 for(
int j = 0; j < numBlocks; ++j ) {
264 &v_space = *v.
space();
266 for(
int k = 0; k < num_vecs ; ++k )
267 v_vecs[k] = cl_vecs[k]->vecs_[j].ptr();
268 for(
int k = 0; k < num_targ_vecs ; ++k )
269 v_targ_vecs[k] = cl_targ_vecs[k]->vecs_[j].ptr();
271 numBlocks > 1, std::logic_error
272 ,
"Error, Have not implemented general support for numBlocks > 1!"
274 Ordinal v_global_offset = overall_global_offset;
276 Thyra::applyOp<Scalar>(
277 op, v_vecs(), v_targ_vecs(), i_reduct_obj.
ptr(),
280 overall_global_offset += v_space.
dim();
296 if (interClusterComm.get()) {
297 RTOpPack::SPMD_all_reduce(
301 tuple<const RTOpPack::ReductTarget*>(&*i_reduct_obj).getRawPtr(),
302 tuple<RTOpPack::ReductTarget*>(&*icl_reduct_obj).getRawPtr()
310 RTOpPack::SPMD_all_reduce(
314 tuple<const RTOpPack::ReductTarget*>(&*icl_reduct_obj).getRawPtr(),
315 tuple<RTOpPack::ReductTarget*>(&*reduct_obj).getRawPtr()
328 #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 initialize(int *argc, char ***argv)
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)