// @HEADER // ***************************************************************************** // RTOp: Interfaces and Support Software for Vector Reduction Transformation // Operations // // Copyright 2006 NTESS and the RTOp contributors. // SPDX-License-Identifier: BSD-3-Clause // ***************************************************************************** // @HEADER #ifndef RTOPPACK_SPMD_APPLY_OP_DEF_HPP #define RTOPPACK_SPMD_APPLY_OP_DEF_HPP #include "RTOpPack_SPMD_apply_op_decl.hpp" #include "Teuchos_Workspace.hpp" #include "Teuchos_CommHelpers.hpp" // // Implementation-only utlities! // namespace RTOpPack { RCP& spmdApplyOpDumpOut(); template void print( const ConstSubVectorView &v, Teuchos::FancyOStream &out_arg ) { Teuchos::RCP out = Teuchos::rcp(&out_arg,false); Teuchos::OSTab tab(out); *out << "globalOffset="< int RTOpPack::serializedSize( int num_values, int num_indexes, int num_chars ) { return 3 * sizeof(index_type) + num_values * sizeof(PrimitiveScalar) + num_indexes * sizeof(index_type) + num_chars * sizeof(char_type); } template void RTOpPack::serialize( const RTOpT &op, Ordinal num_values, Ordinal num_indexes, Ordinal num_chars, const ReductTarget &reduct_obj, char reduct_obj_ext[] ) { using Teuchos::arrayView; typedef typename RTOpT::primitive_value_type primitive_value_type; typedef Teuchos::SerializationTraits PVTST; typedef Teuchos::SerializationTraits ITST; typedef Teuchos::SerializationTraits CTST; const Ordinal prim_value_type_size = PVTST::fromCountToDirectBytes(1), index_type_size = ITST::fromCountToDirectBytes(1); //char_type_size = CTST::fromCountToDirectBytes(1); const Ordinal num_values_off = 0, num_indexes_off = num_values_off + index_type_size, num_chars_off = num_indexes_off + index_type_size, values_off = num_chars_off + index_type_size, indexes_off = values_off + num_values * prim_value_type_size, chars_off = indexes_off + num_indexes * index_type_size; ITST::serialize(1, &num_values, index_type_size, &reduct_obj_ext[num_values_off]); ITST::serialize(1, &num_indexes, index_type_size, &reduct_obj_ext[num_indexes_off]); ITST::serialize(1, &num_chars, index_type_size, &reduct_obj_ext[num_chars_off]); op.extract_reduct_obj_state( reduct_obj, arrayView(PVTST::convertFromCharPtr(&reduct_obj_ext[values_off]), num_values), arrayView(ITST::convertFromCharPtr(&reduct_obj_ext[indexes_off]), num_indexes), arrayView(CTST::convertFromCharPtr(&reduct_obj_ext[chars_off]), num_chars) ); // ToDo: Change above implementation to only require indirect serialization! } template void RTOpPack::deserialize( const RTOpT &op, int num_values_in, int num_indexes_in, int num_chars_in, const char reduct_obj_ext[], ReductTarget *reduct_obj ) { using Teuchos::arrayView; typedef typename RTOpT::primitive_value_type primitive_value_type; typedef Teuchos::SerializationTraits PVTST; typedef Teuchos::SerializationTraits ITST; typedef Teuchos::SerializationTraits CTST; const Ordinal prim_value_type_size = PVTST::fromCountToDirectBytes(1), index_type_size = ITST::fromCountToDirectBytes(1); //char_type_size = CTST::fromCountToDirectBytes(1); const Ordinal num_values_off = 0, num_indexes_off = num_values_off + index_type_size, num_chars_off = num_indexes_off + index_type_size, values_off = num_chars_off + index_type_size, indexes_off = values_off + num_values_in * prim_value_type_size, chars_off = indexes_off + num_indexes_in * index_type_size; #ifdef RTOP_DEBUG Ordinal num_values = -1, num_indexes = -1, num_chars = -1; ITST::deserialize(index_type_size, &reduct_obj_ext[num_values_off], 1, &num_values); ITST::deserialize(index_type_size, &reduct_obj_ext[num_indexes_off], 1, &num_indexes); ITST::deserialize(index_type_size, &reduct_obj_ext[num_chars_off], 1, &num_chars); TEUCHOS_TEST_FOR_EXCEPTION( !( num_values==num_values_in && num_indexes==num_indexes_in && num_chars==num_chars_in ), std::logic_error, "Error: RTOp="< _i_reduct_objs( wss, num_cols ); for( int kc = 0; kc < num_cols; ++kc ) { _i_reduct_objs[kc] = &*i_reduct_objs[kc]; } if(nonnull(out)) { if(reduct_objs) { *out << "\nPerforming global reduction ...\n"; } } SPMD_all_reduce(comm,op,num_cols,&_i_reduct_objs[0],reduct_objs); } } if(nonnull(out)) { if( num_targ_vecs && sub_targ_vecs ) { *out << "\nInput/output vectors *after* transforamtion:\n"; Teuchos::OSTab tab2(out); for( int kc = 0; kc < num_cols; ++kc ) { for( int k = 0; k < num_targ_vecs; ++k ) { *out << "\nvecs["<( \ int num_values, \ int num_indexes, \ int num_chars \ ); \ \ template void serialize( \ const RTOpT &op, \ Ordinal num_values, \ Ordinal num_indexes, \ Ordinal num_chars, \ const ReductTarget &reduct_obj, \ char reduct_obj_ext[] \ ); \ \ template void deserialize( \ const RTOpT &op, \ int num_values_in, \ int num_indexes_in, \ int num_chars_in, \ const char reduct_obj_ext[], \ ReductTarget *reduct_obj \ ); \ \ template class ReductTargetSerializer; \ \ template class ReductTargetReductionOp; \ \ template void SPMD_all_reduce( \ const Teuchos::Comm *comm, \ const RTOpT &op, \ const int num_cols, \ const ReductTarget*const i_reduct_objs[], \ ReductTarget*const reduct_objs[] \ ); \ \ template void SPMD_apply_op( \ const Teuchos::Comm *comm, \ const RTOpT &op, \ const int num_vecs, \ const RTOpPack::ConstSubVectorView sub_vecs[], \ const int num_targ_vecs, \ const RTOpPack::SubVectorView targ_sub_vecs[], \ ReductTarget *reduct_obj \ ); \ \ template void SPMD_apply_op( \ const Teuchos::Comm *comm, \ const RTOpT &op, \ const int num_cols, \ const int num_multi_vecs, \ const RTOpPack::ConstSubMultiVectorView sub_multi_vecs[], \ const int num_targ_multi_vecs, \ const RTOpPack::SubMultiVectorView targ_sub_multi_vecs[], \ RTOpPack::ReductTarget*const reduct_objs[] \ ); \ \ template void SPMD_apply_op( \ const Teuchos::Comm *comm, \ const RTOpT &op, \ const int num_cols, \ const int num_vecs, \ const ConstSubVectorView sub_vecs[], \ const int num_targ_vecs, \ const SubVectorView sub_targ_vecs[], \ ReductTarget*const reduct_objs[] \ ); #endif // RTOPPACK_SPMD_APPLY_OP_DEF_HPP