Kokkos Node API and Local Linear Algebra Kernels Version of the Day
KokkosExamples_EmptySparseKernelClass.hpp
00001 /*
00002 //@HEADER
00003 // ************************************************************************
00004 //
00005 //          Kokkos: Node API and Parallel Node Kernels
00006 //              Copyright (2008) Sandia Corporation
00007 //
00008 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
00009 // the U.S. Government retains certain rights in this software.
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 Michael A. Heroux (maherou@sandia.gov)
00039 //
00040 // ************************************************************************
00041 //@HEADER
00042 */
00043 
00044 #ifndef KOKKOS_EMPTY_SPARSE_KERNEL_CLASS_HPP
00045 #define KOKKOS_EMPTY_SPARSE_KERNEL_CLASS_HPP
00046 
00047 #include <Kokkos_CrsMatrixBase.hpp>
00048 #include <Kokkos_CrsGraphBase.hpp>
00049 #include <Kokkos_MultiVector.hpp>
00050 #include <Kokkos_DefaultNode.hpp>
00051 #include <Teuchos_BLAS_types.hpp>
00052 
00056 
00057 namespace KokkosExamples {
00058 
00059   using Teuchos::RCP;
00060   using Teuchos::ArrayRCP;
00061   using Teuchos::arcp;
00062   using Teuchos::ArrayView;
00063   using Teuchos::ParameterList;
00064 
00066 
00068   template <class Node>
00069   class EmptyCrsGraph : public Kokkos::CrsGraphBase<int,Node> {
00070   public:
00071     EmptyCrsGraph(size_t numrows, const RCP<Node> &node, const RCP<ParameterList> &params) : Kokkos::CrsGraphBase<int,Node>(numrows,node,params) {}
00072     ~EmptyCrsGraph() {}
00073     void setStructure(const ArrayRCP<const size_t>&, const ArrayRCP<const int>&) {}
00074   };
00075 
00077 
00079   template <class Scalar, class Node>
00080   class EmptyCrsMatrix : public Kokkos::CrsMatrixBase<Scalar,int,Node> {
00081   public:
00082     EmptyCrsMatrix(const RCP<const EmptyCrsGraph<Node> > &graph, const RCP<ParameterList> &params) : Kokkos::CrsMatrixBase<Scalar,int,Node>(graph,params) {}
00083     ~EmptyCrsMatrix() {}
00084     void setValues(const ArrayRCP<const Scalar> &) {}
00085   };
00086 
00100   template <class Scalar, class Node>
00101   class EmptySparseKernel {
00102   public:
00104 
00105 
00112     typedef Scalar  scalar_type;
00119     typedef void ordinal_type;
00121     typedef Node    node_type;
00123     typedef EmptySparseKernel<Scalar,Node> sparse_ops_type;
00124 
00126     template <class O, class N>
00127     struct graph {
00128       typedef EmptyCrsGraph<N> graph_type;
00129     };
00130 
00132     template <class S, class O, class N>
00133     struct matrix {
00134       typedef EmptyCrsMatrix<S,N> matrix_type;
00135     };
00136 
00151     template <class T>
00152     struct bind_scalar {
00153       typedef EmptySparseKernel<T,Node> other_type;
00154     };
00155 
00157 
00158 
00159 
00161     EmptySparseKernel(const RCP<Node> & node) : node_(node) {}
00162 
00164     ~EmptySparseKernel() {}
00165 
00167 
00168 
00169 
00174     RCP<Node> getNode() const {return node_;}
00175 
00177 
00178 
00179 
00181     static ArrayRCP<size_t> allocRowPtrs(const RCP<Node> &/*node*/, const ArrayView<const size_t> &numEntriesPerRow)
00182     {
00183       ArrayRCP<size_t> ptrs = arcp<size_t>( numEntriesPerRow.size() + 1 );
00184       ptrs[0] = 0;
00185       std::partial_sum( numEntriesPerRow.getRawPtr(), numEntriesPerRow.getRawPtr()+numEntriesPerRow.size(), ptrs.begin()+1 );
00186       return ptrs;
00187     }
00188 
00190     template <class T> 
00191     static ArrayRCP<T> allocStorage(const RCP<Node> &/*node*/, const ArrayView<const size_t> &rowPtrs)
00192     { 
00193       const size_t totalNumEntries = *(rowPtrs.end()-1);
00194       // alloc data
00195       ArrayRCP<T> vals;
00196       if (totalNumEntries > 0) vals = arcp<T>(totalNumEntries);
00197       std::fill( vals.begin(), vals.end(), Teuchos::ScalarTraits<T>::zero() );
00198       return vals;
00199     }
00200 
00202     inline static void finalizeGraph(Teuchos::EUplo uplo, Teuchos::EDiag diag, EmptyCrsGraph<Node> &graph, const RCP<ParameterList> &params) {}
00203 
00205     inline static void finalizeMatrix(const EmptyCrsGraph<Node> &graph, EmptyCrsMatrix<Scalar,Node> &matrix, const RCP<ParameterList> &params) {}
00206     
00208     inline static void finalizeGraphAndMatrix(Teuchos::EUplo uplo, Teuchos::EDiag diag, EmptyCrsGraph<Node> &graph, EmptyCrsMatrix<Scalar,Node> &matrix, const RCP<ParameterList> &params) {}
00209 
00224     void setGraphAndMatrix(const RCP<const EmptyCrsGraph<Node> >         &graph,
00225                            const RCP<const EmptyCrsMatrix<Scalar,Node> > &node) {};
00226 
00228 
00229 
00230 
00255     template <class DomainScalar, class RangeScalar>
00256     void
00257     multiply (Teuchos::ETransp trans,
00258               RangeScalar alpha,
00259               const Kokkos::MultiVector<DomainScalar,Node> &X,
00260               Kokkos::MultiVector<RangeScalar,Node> &Y) const
00261     {}
00262 
00287     template <class DomainScalar, class RangeScalar>
00288     void
00289     multiply (Teuchos::ETransp trans,
00290               RangeScalar alpha,
00291               const Kokkos::MultiVector<DomainScalar,Node> &X,
00292               RangeScalar beta,
00293               Kokkos::MultiVector<RangeScalar,Node> &Y) const
00294     {}
00295 
00322     template <class DomainScalar, class RangeScalar>
00323     void
00324     solve (Teuchos::ETransp trans,
00325            const Kokkos::MultiVector<DomainScalar,Node> &Y,
00326            Kokkos::MultiVector<RangeScalar,Node> &X) const
00327     {}
00328 
00330   protected:
00332     EmptySparseKernel(const EmptySparseKernel& source);
00333 
00335     RCP<Node> node_;
00336   };
00337 
00344 } // end of namespace KokkosExamples
00345 
00346 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends