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>
240 for(
Ordinal i = 0; i < count; ++i, offset += reduct_obj_ext_size_ ) {
242 *op_,num_values_,num_indexes_,num_chars_
243 ,*reduct_objs[i],&charBuffer[offset]
249 template<
class Scalar>
253 return op_->reduct_obj_create();
256 template<
class Scalar>
259 ,
const char charBuffer[]
271 for(
Ordinal i = 0; i < count; ++i, offset += reduct_obj_ext_size_ ) {
273 *op_,num_values_,num_indexes_,num_chars_
274 ,&charBuffer[offset],reduct_objs[i]
285 template<
class Scalar>
293 template<
class Scalar>
300 for(
Ordinal i = 0; i < count; ++i )
301 op_->reduce_reduct_objs( *inBuffer[i], Teuchos::ptr(inoutBuffer[i]) );
308 template<
class Scalar>
320 Workspace<Teuchos::RCP<ReductTarget> >
321 i_i_reduct_objs( wss, num_cols );
322 Workspace<ReductTarget*>
323 _i_i_reduct_objs( wss, num_cols );
324 for(
int kc = 0; kc < num_cols; ++kc ) {
326 _i_i_reduct_objs[kc] = &*i_i_reduct_objs[kc];
329 serializer(Teuchos::rcpFromRef(op));
331 reductOp(Teuchos::rcpFromRef(op));
333 *comm, serializer, reductOp,
334 num_cols, &i_reduct_objs[0], &_i_i_reduct_objs[0]);
335 for(
int kc = 0; kc < num_cols; ++kc ) {
341 template<
class Scalar>
347 const int num_targ_vecs,
354 comm,op,1,num_vecs,sub_vecs,num_targ_vecs,targ_sub_vecs
355 ,reduct_obj ? reduct_objs : NULL
361 template<
class Scalar>
366 const int num_multi_vecs,
368 const int num_targ_multi_vecs,
377 Workspace<ConstSubVectorView<Scalar> > c_sub_vecs(wss,num_multi_vecs*num_cols);
379 for( off = 0, j = 0; j < num_cols; ++j ) {
380 for( k = 0; k < num_multi_vecs; ++k ) {
384 arcp(&mv(0,j), 0, mv.
subDim(),
false), 1);
393 Workspace<SubVectorView<Scalar> > c_targ_sub_vecs(wss,num_targ_multi_vecs*num_cols);
394 if(targ_sub_multi_vecs) {
395 for( off = 0, j = 0; j < num_cols; ++j ) {
396 for( k = 0; k < num_targ_multi_vecs; ++k ) {
399 if (mv.
subDim()) { mv_j = arcp(&mv(0,j), 0, mv.
subDim(),
false); }
406 ,num_multi_vecs, num_multi_vecs && sub_multi_vecs ? &c_sub_vecs[0] : NULL
407 ,num_targ_multi_vecs, num_targ_multi_vecs && targ_sub_multi_vecs ? &c_targ_sub_vecs[0] : NULL
413 template<
class Scalar>
420 const int num_targ_vecs,
425 using Teuchos::arrayView;
429 *out <<
"\nEntering RTOpPack::SPMD_apply_op(...) ...\n";
431 <<
"\ncomm = " << (comm?comm->
description():
"NULL")
433 <<
"\nnum_cols = " << num_cols
434 <<
"\nnum_vecs = " << num_vecs
435 <<
"\nnum_targ_vecs = " << num_targ_vecs
437 if( num_vecs && sub_vecs ) {
438 *out <<
"\nInput vectors:\n";
440 for(
int kc = 0; kc < num_cols; ++kc ) {
441 for(
int k = 0; k < num_vecs; ++k ) {
442 *out <<
"\nvecs["<<kc<<
","<<k<<
"] =\n";
443 print(sub_vecs[kc*num_vecs+k],*out);
447 if( num_targ_vecs && sub_targ_vecs ) {
448 *out <<
"\nInput/output vectors *before* transforamtion:\n";
450 for(
int kc = 0; kc < num_cols; ++kc ) {
451 for(
int k = 0; k < num_targ_vecs; ++k ) {
452 *out <<
"\nvecs["<<kc<<
","<<k<<
"] =\n";
453 print(sub_targ_vecs[kc*num_targ_vecs+k],*out);
458 *out <<
"\nInput/output reduction objects *before* reduction:\n";
460 for(
int kc = 0; kc < num_cols; ++kc ) {
462 <<
"\nreduct_objs["<<kc<<
"] =\n"
469 if( reduct_objs == NULL && sub_vecs == NULL && sub_targ_vecs == NULL ) {
474 const int localSubDim =
476 ? ( sub_vecs ? sub_vecs[0].
subDim() : 0 )
477 : ( sub_targ_vecs ? sub_targ_vecs[0].subDim() : 0 )
480 if( comm==NULL || reduct_objs == NULL ) {
481 if( ( sub_vecs || sub_targ_vecs ) && localSubDim ) {
482 for(
int kc = 0; kc < num_cols; ++kc ) {
484 arrayView(sub_vecs+kc*num_vecs, num_vecs),
485 arrayView(sub_targ_vecs+kc*num_targ_vecs, num_targ_vecs),
486 reduct_objs ? Teuchos::ptr(reduct_objs[kc]) : Teuchos::null
494 ( ( num_vecs && !sub_vecs) || ( num_targ_vecs && !sub_targ_vecs) ) && !( !sub_vecs && !sub_targ_vecs )
496 ,
"SPMD_apply_op(...): Error, invalid arguments num_vecs = " << num_vecs
497 <<
", sub_vecs = " << sub_vecs <<
", num_targ_vecs = " << num_targ_vecs
498 <<
", sub_targ_vecs = " << sub_targ_vecs
507 Workspace<Teuchos::RCP<ReductTarget> >
508 i_reduct_objs( wss, num_cols );
509 for(
int kc = 0; kc < num_cols; ++kc ) {
511 if( ( sub_vecs || sub_targ_vecs ) && localSubDim ) {
513 arrayView(sub_vecs+kc*num_vecs, num_vecs),
514 arrayView(sub_targ_vecs+kc*num_targ_vecs, num_targ_vecs),
515 i_reduct_objs[kc].ptr()
521 *out <<
"\nIntermediate reduction objects in this process before global reduction:\n";
523 for(
int kc = 0; kc < num_cols; ++kc ) {
525 <<
"\ni_reduct_objs["<<kc<<
"] =\n"
533 Workspace<const ReductTarget*>
534 _i_reduct_objs( wss, num_cols );
535 for(
int kc = 0; kc < num_cols; ++kc ) {
536 _i_reduct_objs[kc] = &*i_reduct_objs[kc];
540 *out <<
"\nPerforming global reduction ...\n";
547 if( num_targ_vecs && sub_targ_vecs ) {
548 *out <<
"\nInput/output vectors *after* transforamtion:\n";
550 for(
int kc = 0; kc < num_cols; ++kc ) {
551 for(
int k = 0; k < num_targ_vecs; ++k ) {
552 *out <<
"\nvecs["<<kc<<
","<<k<<
"] =\n";
553 print(sub_targ_vecs[kc*num_targ_vecs+k],*out);
558 *out <<
"\nInput/output reduction objects *after* reduction:\n";
560 for(
int kc = 0; kc < num_cols; ++kc ) {
562 <<
"\nreduct_objs["<<kc<<
"] =\n"
566 *out <<
"\nLeaving RTOpPack::SPMD_apply_op(...) ...\n";
577 #define RTOPPACK_SPMD_APPLY_OP_INSTANT_SCALAR(SCALAR) \
579 template int serializedSize<SCALAR >( \
585 template void serialize<SCALAR >( \
586 const RTOpT<SCALAR > &op, \
587 Ordinal num_values, \
588 Ordinal num_indexes, \
590 const ReductTarget &reduct_obj, \
591 char reduct_obj_ext[] \
594 template void deserialize<SCALAR >( \
595 const RTOpT<SCALAR > &op, \
597 int num_indexes_in, \
599 const char reduct_obj_ext[], \
600 ReductTarget *reduct_obj \
603 template class ReductTargetSerializer<SCALAR >; \
605 template class ReductTargetReductionOp<SCALAR >; \
607 template void SPMD_all_reduce<SCALAR >( \
608 const Teuchos::Comm<index_type> *comm, \
609 const RTOpT<SCALAR > &op, \
610 const int num_cols, \
611 const ReductTarget*const i_reduct_objs[], \
612 ReductTarget*const reduct_objs[] \
615 template void SPMD_apply_op<SCALAR >( \
616 const Teuchos::Comm<index_type> *comm, \
617 const RTOpT<SCALAR > &op, \
618 const int num_vecs, \
619 const RTOpPack::ConstSubVectorView<SCALAR > sub_vecs[], \
620 const int num_targ_vecs, \
621 const RTOpPack::SubVectorView<SCALAR > targ_sub_vecs[], \
622 ReductTarget *reduct_obj \
625 template void SPMD_apply_op<SCALAR >( \
626 const Teuchos::Comm<index_type> *comm, \
627 const RTOpT<SCALAR > &op, \
628 const int num_cols, \
629 const int num_multi_vecs, \
630 const RTOpPack::ConstSubMultiVectorView<SCALAR > sub_multi_vecs[], \
631 const int num_targ_multi_vecs, \
632 const RTOpPack::SubMultiVectorView<SCALAR > targ_sub_multi_vecs[], \
633 RTOpPack::ReductTarget*const reduct_objs[] \
636 template void SPMD_apply_op<SCALAR >( \
637 const Teuchos::Comm<index_type> *comm, \
638 const RTOpT<SCALAR > &op, \
639 const int num_cols, \
640 const int num_vecs, \
641 const ConstSubVectorView<SCALAR > sub_vecs[], \
642 const int num_targ_vecs, \
643 const SubVectorView<SCALAR > sub_targ_vecs[], \
644 ReductTarget*const reduct_objs[] \
648 #endif // RTOPPACK_SPMD_APPLY_OP_DEF_HPP