43 #ifndef RTOPPACK_SPMD_APPLY_OP_DEF_HPP
44 #define RTOPPACK_SPMD_APPLY_OP_DEF_HPP
62 template<
class Scalar>
68 *out <<
"subDim="<<v.
subDim()<<
"\n";
71 for(
int i = 0; i < v.
subDim(); ++i )
89 template<
class PrimitiveScalar>
97 + num_values *
sizeof(PrimitiveScalar)
103 template<
class Scalar>
110 char reduct_obj_ext[]
113 using Teuchos::arrayView;
119 prim_value_type_size = PVTST::fromCountToDirectBytes(1),
120 index_type_size = ITST::fromCountToDirectBytes(1);
124 num_indexes_off = num_values_off + index_type_size,
125 num_chars_off = num_indexes_off + index_type_size,
126 values_off = num_chars_off + index_type_size,
127 indexes_off = values_off + num_values * prim_value_type_size,
128 chars_off = indexes_off + num_indexes * index_type_size;
129 ITST::serialize(1, &num_values, index_type_size, &reduct_obj_ext[num_values_off]);
130 ITST::serialize(1, &num_indexes, index_type_size, &reduct_obj_ext[num_indexes_off]);
131 ITST::serialize(1, &num_chars, index_type_size, &reduct_obj_ext[num_chars_off]);
134 arrayView(PVTST::convertFromCharPtr(&reduct_obj_ext[values_off]), num_values),
135 arrayView(ITST::convertFromCharPtr(&reduct_obj_ext[indexes_off]), num_indexes),
136 arrayView(CTST::convertFromCharPtr(&reduct_obj_ext[chars_off]), num_chars)
142 template<
class Scalar>
148 const char reduct_obj_ext[],
152 using Teuchos::arrayView;
158 prim_value_type_size = PVTST::fromCountToDirectBytes(1),
159 index_type_size = ITST::fromCountToDirectBytes(1);
163 num_indexes_off = num_values_off + index_type_size,
164 num_chars_off = num_indexes_off + index_type_size,
165 values_off = num_chars_off + index_type_size,
166 indexes_off = values_off + num_values_in * prim_value_type_size,
167 chars_off = indexes_off + num_indexes_in * index_type_size;
169 Ordinal num_values = -1, num_indexes = -1, num_chars = -1;
170 ITST::deserialize(index_type_size, &reduct_obj_ext[num_values_off], 1, &num_values);
171 ITST::deserialize(index_type_size, &reduct_obj_ext[num_indexes_off], 1, &num_indexes);
172 ITST::deserialize(index_type_size, &reduct_obj_ext[num_chars_off], 1, &num_chars);
175 num_values==num_values_in && num_indexes==num_indexes_in
176 && num_chars==num_chars_in ),
179 <<
", num_values="<<num_values<<
", num_values_in="<<num_values_in
180 <<
", num_indexes="<<num_indexes<<
", num_indexes_in="<<num_indexes_in
181 <<
", num_chars="<<num_chars<<
", num_chars_in="<<num_chars_in
185 arrayView(PVTST::convertFromCharPtr(&reduct_obj_ext[values_off]), num_values_in),
186 arrayView(ITST::convertFromCharPtr(&reduct_obj_ext[indexes_off]), num_indexes_in),
187 arrayView(CTST::convertFromCharPtr(&reduct_obj_ext[chars_off]), num_chars_in),
188 Teuchos::ptr(reduct_obj)
202 template<
class Scalar>
206 :op_(op.assert_not_null())
208 using Teuchos::outArg;
210 op_->get_reduct_type_num_entries(
217 template<
class Scalar>
221 return reduct_obj_ext_size_ * count;
225 template<
class Scalar>
242 for(
Ordinal i = 0; i < count; ++i, offset += reduct_obj_ext_size_ ) {
244 *op_,num_values_,num_indexes_,num_chars_
245 ,*reduct_objs[i],&charBuffer[offset]
251 template<
class Scalar>
255 return op_->reduct_obj_create();
258 template<
class Scalar>
261 ,
const char charBuffer[]
275 for(
Ordinal i = 0; i < count; ++i, offset += reduct_obj_ext_size_ ) {
277 *op_,num_values_,num_indexes_,num_chars_
278 ,&charBuffer[offset],reduct_objs[i]
289 template<
class Scalar>
297 template<
class Scalar>
304 for(
Ordinal i = 0; i < count; ++i )
305 op_->reduce_reduct_objs( *inBuffer[i], Teuchos::ptr(inoutBuffer[i]) );
312 template<
class Scalar>
324 Workspace<Teuchos::RCP<ReductTarget> >
325 i_i_reduct_objs( wss, num_cols );
326 Workspace<ReductTarget*>
327 _i_i_reduct_objs( wss, num_cols );
328 for(
int kc = 0; kc < num_cols; ++kc ) {
330 _i_i_reduct_objs[kc] = &*i_i_reduct_objs[kc];
333 serializer(Teuchos::rcpFromRef(op));
335 reductOp(Teuchos::rcpFromRef(op));
337 *comm, serializer, reductOp,
338 num_cols, &i_reduct_objs[0], &_i_i_reduct_objs[0]);
339 for(
int kc = 0; kc < num_cols; ++kc ) {
345 template<
class Scalar>
351 const int num_targ_vecs,
358 comm,op,1,num_vecs,sub_vecs,num_targ_vecs,targ_sub_vecs
359 ,reduct_obj ? reduct_objs : NULL
365 template<
class Scalar>
370 const int num_multi_vecs,
372 const int num_targ_multi_vecs,
381 Workspace<ConstSubVectorView<Scalar> > c_sub_vecs(wss,num_multi_vecs*num_cols);
383 for( off = 0, j = 0; j < num_cols; ++j ) {
384 for( k = 0; k < num_multi_vecs; ++k ) {
388 arcp(&mv(0,j), 0, mv.
subDim(),
false), 1);
397 Workspace<SubVectorView<Scalar> > c_targ_sub_vecs(wss,num_targ_multi_vecs*num_cols);
398 if(targ_sub_multi_vecs) {
399 for( off = 0, j = 0; j < num_cols; ++j ) {
400 for( k = 0; k < num_targ_multi_vecs; ++k ) {
403 if (mv.
subDim()) { mv_j = arcp(&mv(0,j), 0, mv.
subDim(),
false); }
410 ,num_multi_vecs, num_multi_vecs && sub_multi_vecs ? &c_sub_vecs[0] : NULL
411 ,num_targ_multi_vecs, num_targ_multi_vecs && targ_sub_multi_vecs ? &c_targ_sub_vecs[0] : NULL
417 template<
class Scalar>
424 const int num_targ_vecs,
429 using Teuchos::arrayView;
433 *out <<
"\nEntering RTOpPack::SPMD_apply_op(...) ...\n";
435 <<
"\ncomm = " << (comm?comm->
description():
"NULL")
437 <<
"\nnum_cols = " << num_cols
438 <<
"\nnum_vecs = " << num_vecs
439 <<
"\nnum_targ_vecs = " << num_targ_vecs
441 if( num_vecs && sub_vecs ) {
442 *out <<
"\nInput vectors:\n";
444 for(
int kc = 0; kc < num_cols; ++kc ) {
445 for(
int k = 0; k < num_vecs; ++k ) {
446 *out <<
"\nvecs["<<kc<<
","<<k<<
"] =\n";
447 print(sub_vecs[kc*num_vecs+k],*out);
451 if( num_targ_vecs && sub_targ_vecs ) {
452 *out <<
"\nInput/output vectors *before* transforamtion:\n";
454 for(
int kc = 0; kc < num_cols; ++kc ) {
455 for(
int k = 0; k < num_targ_vecs; ++k ) {
456 *out <<
"\nvecs["<<kc<<
","<<k<<
"] =\n";
457 print(sub_targ_vecs[kc*num_targ_vecs+k],*out);
462 *out <<
"\nInput/output reduction objects *before* reduction:\n";
464 for(
int kc = 0; kc < num_cols; ++kc ) {
466 <<
"\nreduct_objs["<<kc<<
"] =\n"
473 if( reduct_objs == NULL && sub_vecs == NULL && sub_targ_vecs == NULL ) {
478 const int localSubDim =
480 ? ( sub_vecs ? sub_vecs[0].
subDim() : 0 )
481 : ( sub_targ_vecs ? sub_targ_vecs[0].subDim() : 0 )
484 if( comm==NULL || reduct_objs == NULL ) {
485 if( ( sub_vecs || sub_targ_vecs ) && localSubDim ) {
486 for(
int kc = 0; kc < num_cols; ++kc ) {
488 arrayView(sub_vecs+kc*num_vecs, num_vecs),
489 arrayView(sub_targ_vecs+kc*num_targ_vecs, num_targ_vecs),
498 ( ( num_vecs && !sub_vecs) || ( num_targ_vecs && !sub_targ_vecs) ) && !( !sub_vecs && !sub_targ_vecs )
500 ,
"SPMD_apply_op(...): Error, invalid arguments num_vecs = " << num_vecs
501 <<
", sub_vecs = " << sub_vecs <<
", num_targ_vecs = " << num_targ_vecs
502 <<
", sub_targ_vecs = " << sub_targ_vecs
511 Workspace<Teuchos::RCP<ReductTarget> >
512 i_reduct_objs( wss, num_cols );
513 for(
int kc = 0; kc < num_cols; ++kc ) {
515 if( ( sub_vecs || sub_targ_vecs ) && localSubDim ) {
517 arrayView(sub_vecs+kc*num_vecs, num_vecs),
518 arrayView(sub_targ_vecs+kc*num_targ_vecs, num_targ_vecs),
519 i_reduct_objs[kc].ptr()
525 *out <<
"\nIntermediate reduction objects in this process before global reduction:\n";
527 for(
int kc = 0; kc < num_cols; ++kc ) {
529 <<
"\ni_reduct_objs["<<kc<<
"] =\n"
537 Workspace<const ReductTarget*>
538 _i_reduct_objs( wss, num_cols );
539 for(
int kc = 0; kc < num_cols; ++kc ) {
540 _i_reduct_objs[kc] = &*i_reduct_objs[kc];
544 *out <<
"\nPerforming global reduction ...\n";
551 if( num_targ_vecs && sub_targ_vecs ) {
552 *out <<
"\nInput/output vectors *after* transforamtion:\n";
554 for(
int kc = 0; kc < num_cols; ++kc ) {
555 for(
int k = 0; k < num_targ_vecs; ++k ) {
556 *out <<
"\nvecs["<<kc<<
","<<k<<
"] =\n";
557 print(sub_targ_vecs[kc*num_targ_vecs+k],*out);
562 *out <<
"\nInput/output reduction objects *after* reduction:\n";
564 for(
int kc = 0; kc < num_cols; ++kc ) {
566 <<
"\nreduct_objs["<<kc<<
"] =\n"
570 *out <<
"\nLeaving RTOpPack::SPMD_apply_op(...) ...\n";
581 #define RTOPPACK_SPMD_APPLY_OP_INSTANT_SCALAR(SCALAR) \
583 template int serializedSize<SCALAR >( \
589 template void serialize<SCALAR >( \
590 const RTOpT<SCALAR > &op, \
591 Ordinal num_values, \
592 Ordinal num_indexes, \
594 const ReductTarget &reduct_obj, \
595 char reduct_obj_ext[] \
598 template void deserialize<SCALAR >( \
599 const RTOpT<SCALAR > &op, \
601 int num_indexes_in, \
603 const char reduct_obj_ext[], \
604 ReductTarget *reduct_obj \
607 template class ReductTargetSerializer<SCALAR >; \
609 template class ReductTargetReductionOp<SCALAR >; \
611 template void SPMD_all_reduce<SCALAR >( \
612 const Teuchos::Comm<index_type> *comm, \
613 const RTOpT<SCALAR > &op, \
614 const int num_cols, \
615 const ReductTarget*const i_reduct_objs[], \
616 ReductTarget*const reduct_objs[] \
619 template void SPMD_apply_op<SCALAR >( \
620 const Teuchos::Comm<index_type> *comm, \
621 const RTOpT<SCALAR > &op, \
622 const int num_vecs, \
623 const RTOpPack::ConstSubVectorView<SCALAR > sub_vecs[], \
624 const int num_targ_vecs, \
625 const RTOpPack::SubVectorView<SCALAR > targ_sub_vecs[], \
626 ReductTarget *reduct_obj \
629 template void SPMD_apply_op<SCALAR >( \
630 const Teuchos::Comm<index_type> *comm, \
631 const RTOpT<SCALAR > &op, \
632 const int num_cols, \
633 const int num_multi_vecs, \
634 const RTOpPack::ConstSubMultiVectorView<SCALAR > sub_multi_vecs[], \
635 const int num_targ_multi_vecs, \
636 const RTOpPack::SubMultiVectorView<SCALAR > targ_sub_multi_vecs[], \
637 RTOpPack::ReductTarget*const reduct_objs[] \
640 template void SPMD_apply_op<SCALAR >( \
641 const Teuchos::Comm<index_type> *comm, \
642 const RTOpT<SCALAR > &op, \
643 const int num_cols, \
644 const int num_vecs, \
645 const ConstSubVectorView<SCALAR > sub_vecs[], \
646 const int num_targ_vecs, \
647 const SubVectorView<SCALAR > sub_targ_vecs[], \
648 ReductTarget*const reduct_objs[] \
652 #endif // RTOPPACK_SPMD_APPLY_OP_DEF_HPP
std::string op_name() const
Return the name (as a null-terminated C-style string) of the operator.
int serializedSize(int num_values, int num_indexes, int num_chars)
Return the size in bytes of an external representation of a ReductTarget object.
void SPMD_all_reduce(const Teuchos::Comm< index_type > *comm, const RTOpT< Scalar > &op, const int num_cols, const ReductTarget *const i_reduct_objs[], ReductTarget *const reduct_objs[])
Reduce a set of reduction objects.
Teuchos::RCP< ReductTarget > createObj() const
Class for a changeable sub-vector.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
void serialize(const index_type count, const ReductTarget *const reduct_objs[], const index_type bytes, char charBuffer[]) const
basic_OSTab< CharT, Traits > & incrTab(const int tabs=1)
Teuchos_Ordinal index_type
ReductionOp subclass for ReductTarget objects.
void serialize(const RTOpT< Scalar > &op, Ordinal num_values, Ordinal num_indexes, Ordinal num_chars, const ReductTarget &reduct_obj, char reduct_obj_ext[])
Serialize a ReductTarget object.
Class for a non-changeable sub-vector.
void deserialize(const RTOpT< Scalar > &op, int num_values, int num_indexes, int num_chars, const char reduct_obj_ext[], ReductTarget *reduct_obj)
Deserialize a ReductTarget object.
Serializer subclass for ReductTarget objects.
Ordinal globalOffset() const
Templated interface to vector reduction/transformation operators {abstract}.
index_type getBufferSize(const index_type count) const
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Class for a changeable sub-vector.
void extract_reduct_obj_state(const ReductTarget &reduct_obj, const ArrayView< primitive_value_type > &value_data, const ArrayView< index_type > &index_data, const ArrayView< char_type > &char_data) const
Extract the state of an already created reduction object.
void deserialize(const index_type bytes, const char charBuffer[], const index_type count, ReductTarget *const reduct_objs[]) const
void load_reduct_obj_state(const ArrayView< const primitive_value_type > &value_data, const ArrayView< const index_type > &index_data, const ArrayView< const char_type > &char_data, const Ptr< ReductTarget > &reduct_obj) const
Load the state of an already created reduction object given arrays of primitive objects.
virtual std::string description() const
PrimitiveTypeTraits< Scalar, Scalar >::primitiveType primitive_value_type
TEUCHOS_DEPRECATED void reduceAll(const Comm< Ordinal > &comm, const EReductionType reductType, const Packet &send, Packet *globalReduct)
Abstract base class for all reduction objects.
void print(const ConstSubVectorView< Scalar > &v, Teuchos::FancyOStream &out_arg)
Ordinal globalOffset() const
void reduce_reduct_objs(const ReductTarget &in_reduct_obj, const Ptr< ReductTarget > &inout_reduct_obj) const
Reduce intermediate reduction target objects.
Teuchos::RCP< ReductTarget > reduct_obj_create() const
Creates a new reduction target object initialized and ready to be used in a reduction.
bool nonnull(const boost::shared_ptr< T > &p)
Class for a non-changeable sub-multi-vector (submatrix).
void initialize(Ordinal globalOffset_in, Ordinal subDim_in, Ordinal colOffset_in, Ordinal numSubCols_in, const ArrayRCP< const Scalar > &values_in, Ordinal leadingDim_in)
Teuchos::RCP< const RTOpT< Scalar > > op_
ReductTargetReductionOp()
void apply_op(const ArrayView< const ConstSubVectorView< Scalar > > &sub_vecs, const ArrayView< const SubVectorView< Scalar > > &targ_sub_vecs, const Ptr< ReductTarget > &reduct_obj) const
Apply the reduction/transformation operator to a set of sub-vectors.
void SPMD_apply_op(const Teuchos::Comm< index_type > *comm, const RTOpT< Scalar > &op, const int num_vecs, const ConstSubVectorView< Scalar > sub_vecs[], const int num_targ_vecs, const SubVectorView< Scalar > targ_sub_vecs[], ReductTarget *reduct_obj)
Apply an RTOp in SMPD mode to a set of vectors with contiguous storage per process.
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)
TEUCHOSCORE_LIB_DLL_EXPORT Teuchos::RCP< WorkspaceStore > get_default_workspace_store()
void reduce(const Ordinal count, const ReductTarget *const inBuffer[], ReductTarget *const inoutBuffer[]) const
RCP< FancyOStream > & spmdApplyOpDumpOut()