RTOpPack_ROpMinIndexGreaterThanBound.hpp

Go to the documentation of this file.
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 // This library is free software; you can redistribute it and/or modify
00012 // it under the terms of the GNU Lesser General Public License as
00013 // published by the Free Software Foundation; either version 2.1 of the
00014 // License, or (at your option) any later version.
00015 //  
00016 // This library is distributed in the hope that it will be useful, but
00017 // WITHOUT ANY WARRANTY; without even the implied warranty of
00018 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00019 // Lesser General Public License for more details.
00020 //  
00021 // You should have received a copy of the GNU Lesser General Public
00022 // License along with this library; if not, write to the Free Software
00023 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00024 // USA
00025 // Questions? Contact Roscoe A. Bartlett (rabartl@sandia.gov) 
00026 // 
00027 // ***********************************************************************
00028 // @HEADER
00029 
00030 #ifndef RTOPPACK_ROP_MIN_INDEX_GREATER_THAN_BOUND_HPP
00031 #define RTOPPACK_ROP_MIN_INDEX_GREATER_THAN_BOUND_HPP
00032 
00033 #include "RTOpPack_RTOpTHelpers.hpp"
00034 #include "Teuchos_StandardMemberCompositionMacros.hpp"
00035 
00036 namespace RTOpPack {
00037 
00051 template<class Scalar>
00052 class ROpMinIndexGreaterThanBound : public ROpScalarIndexReductionBase<Scalar> {
00053 public:
00055   STANDARD_MEMBER_COMPOSITION_MEMBERS( Scalar, bound )
00057   ROpMinIndexGreaterThanBound( const Scalar &bound = Teuchos::ScalarTraits<Scalar>::zero() )
00058     :RTOpT<Scalar>("ROpMinIndexGreaterThanBound")
00059     ,ROpScalarIndexReductionBase<Scalar>(+Teuchos::ScalarTraits<Scalar>::rmax(),-1)
00060     ,bound_(bound)
00061     {}
00063   ScalarIndex<Scalar> operator()(const ReductTarget& reduct_obj ) const { return this->getRawVal(reduct_obj); }
00066 
00067   bool coord_invariant() const { return false; }
00069   void reduce_reduct_objs(
00070     const ReductTarget& in_reduct_obj, ReductTarget* inout_reduct_obj
00071     ) const
00072     {
00073       const ScalarIndex<Scalar> in    = this->getRawVal(in_reduct_obj);
00074       const ScalarIndex<Scalar> inout = this->getRawVal(*inout_reduct_obj);
00075       if( in.scalar < inout.scalar || (in.scalar == inout.scalar && in.index < inout.index) )
00076         this->setRawVal(in,inout_reduct_obj);
00077     }
00079   void apply_op(
00080     const int   num_vecs,       const ConstSubVectorView<Scalar>         sub_vecs[]
00081     ,const int  num_targ_vecs,  const SubVectorView<Scalar>  targ_sub_vecs[]
00082     ,ReductTarget *reduct_obj
00083     ) const
00084     {
00085       RTOP_APPLY_OP_1_0(num_vecs,sub_vecs,num_targ_vecs,targ_sub_vecs);
00086       ScalarIndex<Scalar> minEle = this->getRawVal(*reduct_obj);
00087       if( v0_s == 1 ) {
00088         for( Teuchos_Index i = 0; i < subDim; ++i ) {
00089           const Scalar &v0_i = *v0_val++;
00090           if( v0_i > bound() && (v0_i < minEle.scalar || ( v0_i == minEle.scalar && globalOffset + i < minEle.index ) ) )
00091             minEle = ScalarIndex<Scalar>(v0_i,globalOffset+i);
00092         }
00093       }
00094       else {
00095         for( Teuchos_Index i = 0; i < subDim; ++i, v0_val += v0_s ) {
00096           const Scalar &v0_i = *v0_val;
00097           if( v0_i > bound() && (v0_i < minEle.scalar || ( v0_i == minEle.scalar && globalOffset + i < minEle.index ) ) )
00098             minEle = ScalarIndex<Scalar>(v0_i,globalOffset+i);
00099         }
00100       }
00101       this->setRawVal(minEle,reduct_obj);
00102     }
00104 }; // class ROpMinIndexGreaterThanBound
00105 
00106 } // namespace RTOpPack
00107 
00108 #endif // RTOPPACK_ROP_MIN_INDEX_GREATER_THAN_BOUND_HPP

Generated on Thu Sep 18 12:30:42 2008 for RTOp Package Browser (Single Doxygen Collection) by doxygen 1.3.9.1