|
Teuchos - Trilinos Tools Package Version of the Day
|
00001 // @HEADER 00002 // *********************************************************************** 00003 // 00004 // Teuchos: Common Tools Package 00005 // Copyright (2004) Sandia Corporation 00006 // 00007 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive 00008 // license for use of this work by or on behalf of the U.S. Government. 00009 // 00010 // This library is free software; you can redistribute it and/or modify 00011 // it under the terms of the GNU Lesser General Public License as 00012 // published by the Free Software Foundation; either version 2.1 of the 00013 // License, or (at your option) any later version. 00014 // 00015 // This library is distributed in the hope that it will be useful, but 00016 // WITHOUT ANY WARRANTY; without even the implied warranty of 00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00018 // Lesser General Public License for more details. 00019 // 00020 // You should have received a copy of the GNU Lesser General Public 00021 // License along with this library; if not, write to the Free Software 00022 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 00023 // USA 00024 // Questions? Contact Michael A. Heroux (maherou@sandia.gov) 00025 // 00026 // *********************************************************************** 00027 // @HEADER 00028 00029 #ifndef TEUCHOS_MPI_REDUCTION_OP_SETTER_HPP 00030 #define TEUCHOS_MPI_REDUCTION_OP_SETTER_HPP 00031 00032 #include "Teuchos_RCP.hpp" 00033 #include "Teuchos_ReductionOp.hpp" 00034 #include "mpi.h" 00035 00036 namespace Teuchos { 00037 00046 class TEUCHOS_LIB_DLL_EXPORT MpiReductionOpBase : virtual public Describable { 00047 public: 00049 virtual void reduce( 00050 void *invec 00051 ,void *inoutvec 00052 ,int *len 00053 ,MPI_Datatype *datatype 00054 ) const = 0; 00055 }; 00056 00060 template<typename Ordinal> 00061 class MpiReductionOp : public MpiReductionOpBase { 00062 public: 00064 MpiReductionOp( const RCP<const ValueTypeReductionOp<Ordinal,char> > &reductOp ); 00066 void reduce( 00067 void *invec 00068 ,void *inoutvec 00069 ,int *len 00070 ,MPI_Datatype *datatype 00071 ) const; 00072 private: 00073 RCP<const ValueTypeReductionOp<Ordinal,char> > reductOp_; 00074 // Not defined and not to be called 00075 MpiReductionOp(); 00076 MpiReductionOp(const MpiReductionOp&); 00077 MpiReductionOp& operator=(const MpiReductionOp&); 00078 }; 00079 00083 template<typename Ordinal> 00084 RCP<const MpiReductionOp<Ordinal> > 00085 mpiReductionOp( const RCP<const ValueTypeReductionOp<Ordinal,char> > &reductOp ); 00086 00109 class TEUCHOS_LIB_DLL_EXPORT MpiReductionOpSetter { 00110 public: 00111 00124 MpiReductionOpSetter( const Teuchos::RCP<const MpiReductionOpBase>& reduct_op ); 00125 00127 ~MpiReductionOpSetter(); 00128 00136 MPI_Op mpi_op() const; 00137 00138 private: 00139 // Not defined and not to be called! 00140 MpiReductionOpSetter(); 00141 MpiReductionOpSetter(const MpiReductionOpSetter&); 00142 MpiReductionOpSetter& operator=(const MpiReductionOpSetter&); 00143 }; 00144 00145 // /////////////////////////////////////// 00146 // Template implemenations 00147 00148 template<typename Ordinal> 00149 MpiReductionOp<Ordinal>::MpiReductionOp( 00150 const RCP<const ValueTypeReductionOp<Ordinal,char> > &reductOp 00151 ) 00152 :reductOp_(reductOp) 00153 {} 00154 00155 template<typename Ordinal> 00156 void MpiReductionOp<Ordinal>::reduce( 00157 void *invec 00158 ,void *inoutvec 00159 ,int *len 00160 ,MPI_Datatype *datatype 00161 ) const 00162 { 00163 (void)datatype; 00164 #ifdef TEUCHOS_DEBUG 00165 TEST_FOR_EXCEPT(!invec); 00166 TEST_FOR_EXCEPT(!inoutvec); 00167 TEST_FOR_EXCEPT(!len); 00168 TEST_FOR_EXCEPT(!(*len>0)); 00169 TEST_FOR_EXCEPT(!datatype); 00170 //TEST_FOR_EXCEPT(!(*datatype==MPI_CHAR)); 00171 // We also allow datatypes that are blocks of chars! 00172 #endif 00173 reductOp_->reduce( 00174 *len,reinterpret_cast<char*>(invec),reinterpret_cast<char*>(inoutvec) 00175 ); 00176 } 00177 00178 template<typename Ordinal> 00179 RCP<const MpiReductionOp<Ordinal> > 00180 mpiReductionOp( const RCP<const ValueTypeReductionOp<Ordinal,char> > &reductOp ) 00181 { 00182 return rcp(new MpiReductionOp<Ordinal>(reductOp)); 00183 } 00184 00185 } // namespace Teuchos 00186 00187 #endif // TEUCHOS_MPI_REDUCTION_OP_SETTER_HPP
1.7.4