|
Support Software for Vector Reduction/Transformation Operators
Version of the Day
|
00001 // @HEADER 00002 // *********************************************************************** 00003 // 00004 // RTOp: Interfaces and Support Software for Vector Reduction Transformation 00005 // Operations 00006 // Copyright (2006) Sandia Corporation 00007 // 00008 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive 00009 // license for use of this work by or on behalf of the U.S. Government. 00010 // 00011 // Redistribution and use in source and binary forms, with or without 00012 // modification, are permitted provided that the following conditions are 00013 // met: 00014 // 00015 // 1. Redistributions of source code must retain the above copyright 00016 // notice, this list of conditions and the following disclaimer. 00017 // 00018 // 2. Redistributions in binary form must reproduce the above copyright 00019 // notice, this list of conditions and the following disclaimer in the 00020 // documentation and/or other materials provided with the distribution. 00021 // 00022 // 3. Neither the name of the Corporation nor the names of the 00023 // contributors may be used to endorse or promote products derived from 00024 // this software without specific prior written permission. 00025 // 00026 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY 00027 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00028 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 00029 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE 00030 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00031 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00032 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00033 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00034 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00035 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00036 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00037 // 00038 // Questions? Contact Roscoe A. Bartlett (rabartl@sandia.gov) 00039 // 00040 // *********************************************************************** 00041 // @HEADER 00042 00043 #ifndef RTOPPACK_SPMD_APPLY_OP_DECL_HPP 00044 #define RTOPPACK_SPMD_APPLY_OP_DECL_HPP 00045 00046 #include "RTOpPack_RTOpT.hpp" 00047 #include "Teuchos_Serializer.hpp" 00048 #include "Teuchos_ReductionOp.hpp" 00049 00050 00051 namespace Teuchos { template<typename Ordinal> class Comm; } 00052 00053 00054 // Enable this by hand to enable showing the dump of the RTOp 00055 #define RTOPPACK_ENABLE_SHOW_DUMP 00056 00057 00058 #ifdef RTOP_DEBUG 00059 # define RTOPPACK_ENABLE_SHOW_DUMP 00060 #endif 00061 00062 00063 namespace RTOpPack { 00064 00065 00073 void set_SPMD_apply_op_dump_out(const RCP<FancyOStream> &dumpOut); 00074 00075 #ifdef RTOPPACK_ENABLE_SHOW_DUMP 00076 RTOP_DEPRECATED extern bool show_spmd_apply_op_dump; 00077 #endif // RTOPPACK_ENABLE_SHOW_DUMP 00078 00079 00085 template<class PrimitiveScalar> 00086 int serializedSize( 00087 int num_values 00088 ,int num_indexes 00089 ,int num_chars 00090 ); 00091 00092 00097 template<class Scalar> 00098 void serialize( 00099 const RTOpT<Scalar> &op, 00100 Ordinal num_values, 00101 Ordinal num_indexes, 00102 Ordinal num_chars, 00103 const ReductTarget &reduct_obj, 00104 char reduct_obj_ext[] 00105 ); 00106 00107 00112 template<class Scalar> 00113 void deserialize( 00114 const RTOpT<Scalar> &op, 00115 int num_values, 00116 int num_indexes, 00117 int num_chars, 00118 const char reduct_obj_ext[], 00119 ReductTarget *reduct_obj 00120 ); 00121 00122 00127 template<class Scalar> 00128 class ReductTargetSerializer : public Teuchos::Serializer<index_type,ReductTarget> { 00129 public: 00131 ReductTargetSerializer( 00132 const Teuchos::RCP<const RTOpT<Scalar> > &op 00133 ); 00137 index_type getBufferSize(const index_type count) const; 00139 void serialize( 00140 const index_type count 00141 ,const ReductTarget* const reduct_objs[] 00142 ,const index_type bytes 00143 ,char charBuffer[] 00144 ) const; 00146 Teuchos::RCP<ReductTarget> createObj() const; 00148 void deserialize( 00149 const index_type bytes 00150 ,const char charBuffer[] 00151 ,const index_type count 00152 ,ReductTarget* const reduct_objs[] 00153 ) const; 00155 private: 00156 Teuchos::RCP<const RTOpT<Scalar> > op_; 00157 int num_values_; 00158 int num_indexes_; 00159 int num_chars_; 00160 int reduct_obj_ext_size_; 00161 // Not defined and not to be called! 00162 ReductTargetSerializer(); 00163 ReductTargetSerializer& operator=(const ReductTargetSerializer&); 00164 }; 00165 00166 00171 template<class Scalar> 00172 class ReductTargetReductionOp 00173 : public Teuchos::ReferenceTypeReductionOp<Teuchos_Ordinal,ReductTarget> 00174 { 00175 public: 00177 typedef Teuchos_Ordinal Ordinal; 00179 ReductTargetReductionOp( 00180 const Teuchos::RCP<const RTOpT<Scalar> > &op 00181 ); 00185 void reduce( 00186 const Ordinal count 00187 ,const ReductTarget*const inBuffer[] 00188 ,ReductTarget*const inoutBuffer[] 00189 ) const; 00191 private: 00192 Teuchos::RCP<const RTOpT<Scalar> > op_; 00193 // Not defined and not to be called! 00194 ReductTargetReductionOp(); 00195 ReductTargetReductionOp<Scalar>(const ReductTargetReductionOp<Scalar>&); 00196 ReductTargetReductionOp<Scalar>& operator=(const ReductTargetReductionOp<Scalar>&); 00197 }; 00198 00199 00206 template<class Scalar> 00207 void SPMD_all_reduce( 00208 const Teuchos::Comm<index_type> *comm 00209 ,const RTOpT<Scalar> &op 00210 ,const int num_cols 00211 ,const ReductTarget*const i_reduct_objs[] 00212 ,ReductTarget*const reduct_objs[] 00213 ); 00214 00215 00223 template<class Scalar> 00224 void SPMD_apply_op( 00225 const Teuchos::Comm<index_type> *comm 00226 ,const RTOpT<Scalar> &op 00227 ,const int num_vecs 00228 ,const ConstSubVectorView<Scalar> sub_vecs[] 00229 ,const int num_targ_vecs 00230 ,const SubVectorView<Scalar> targ_sub_vecs[] 00231 ,ReductTarget *reduct_obj 00232 ); 00233 00234 00242 template<class Scalar> 00243 void SPMD_apply_op( 00244 const Teuchos::Comm<index_type> *comm 00245 ,const RTOpT<Scalar> &op 00246 ,const int num_cols 00247 ,const int num_multi_vecs 00248 ,const ConstSubMultiVectorView<Scalar> sub_multi_vecs[] 00249 ,const int num_targ_multi_vecs 00250 ,const SubMultiVectorView<Scalar> targ_sub_multi_vecs[] 00251 ,ReductTarget*const reduct_objs[] 00252 ); 00253 00254 00262 template<class Scalar> 00263 void SPMD_apply_op( 00264 const Teuchos::Comm<index_type> *comm 00265 ,const RTOpT<Scalar> &op 00266 ,const int num_cols 00267 ,const int num_vecs 00268 ,const ConstSubVectorView<Scalar> sub_vecs[] 00269 ,const int num_targ_vecs 00270 ,const SubVectorView<Scalar> sub_targ_vecs[] 00271 ,ReductTarget*const reduct_objs[] 00272 ); 00273 00274 00275 } // end namespace RTOpPack 00276 00277 00278 #endif // RTOPPACK_SPMD_APPLY_OP_DECL_HPP
1.7.6.1