Amesos2 - Direct Sparse Solver Interfaces Version of the Day
Amesos2_MatrixAdapter_decl.hpp
00001 // @HEADER
00002 //
00003 // ***********************************************************************
00004 //
00005 //           Amesos2: Templated Direct Sparse Solver Package 
00006 //                  Copyright 2011 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 //
00042 // @HEADER
00043 
00044 
00045 #ifndef AMESOS2_MATRIXADAPTER_DECL_HPP
00046 #define AMESOS2_MATRIXADAPTER_DECL_HPP
00047 
00048 #include "Amesos2_config.h"
00049 
00050 #include <Teuchos_Comm.hpp>
00051 #include <Teuchos_ArrayView.hpp>
00052 #include <Teuchos_VerbosityLevel.hpp>
00053 #include <Teuchos_FancyOStream.hpp>
00054 
00055 #include <Tpetra_ConfigDefs.hpp>  // for global_size_t
00056 
00057 // #include "Amesos2_ConcreteMatrixAdapter_decl.hpp"
00058 #include "Amesos2_Util.hpp"
00059 #include "Amesos2_MatrixTraits.hpp"
00060 
00061 namespace Amesos2 {
00062 
00063   template <class M> class ConcreteMatrixAdapter;
00064   
00075   template < class Matrix >
00076   class MatrixAdapter {
00077 
00078   public:
00079 
00080     typedef typename MatrixTraits<Matrix>::scalar_t                 scalar_t;
00081     typedef typename MatrixTraits<Matrix>::local_ordinal_t   local_ordinal_t;
00082     typedef typename MatrixTraits<Matrix>::global_ordinal_t global_ordinal_t;
00083     typedef typename MatrixTraits<Matrix>::node_t                     node_t;
00084     typedef Tpetra::global_size_t                              global_size_t;
00085 
00086     typedef Matrix                                                  matrix_t;
00087     typedef MatrixAdapter<Matrix>                                       type;
00088     typedef ConcreteMatrixAdapter<Matrix>                          adapter_t;
00089 
00090     // template<typename S, typename GO, typename GS, typename Op>
00091     // friend class Util::get_cxs_helper<MatrixAdapter<Matrix>,S,GO,GS,Op>;
00092     // template<class M, typename S, typename GO, typename GS, typename Op>
00093     // friend class Util::get_cxs_helper;
00094 
00095     MatrixAdapter(Teuchos::RCP<Matrix> m);
00096 
00097 
00127     void getCrs(const Teuchos::ArrayView<scalar_t> nzval,
00128     const Teuchos::ArrayView<global_ordinal_t> colind,
00129     const Teuchos::ArrayView<global_size_t> rowptr,
00130     global_size_t& nnz,
00131     const Teuchos::Ptr<const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> > rowmap,
00132     EStorage_Ordering ordering=ARBITRARY) const;
00133 
00139     void getCrs(const Teuchos::ArrayView<scalar_t> nzval,
00140     const Teuchos::ArrayView<global_ordinal_t> colind,
00141     const Teuchos::ArrayView<global_size_t> rowptr,
00142     global_size_t& nnz,
00143     EDistribution distribution,
00144     EStorage_Ordering ordering=ARBITRARY) const;
00145 
00172     void getCcs(const Teuchos::ArrayView<scalar_t> nzval,
00173     const Teuchos::ArrayView<global_ordinal_t> rowind,
00174     const Teuchos::ArrayView<global_size_t> colptr,
00175     global_size_t& nnz,
00176     const Teuchos::Ptr<const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> > colmap,
00177     EStorage_Ordering ordering=ARBITRARY) const;
00178 
00184     void getCcs(const Teuchos::ArrayView<scalar_t> nzval,
00185     const Teuchos::ArrayView<global_ordinal_t> rowind,
00186     const Teuchos::ArrayView<global_size_t> colptr,
00187     global_size_t& nnz,
00188     EDistribution distribution,
00189     EStorage_Ordering ordering=ARBITRARY) const;
00190 
00191 
00193     const Teuchos::RCP<const Teuchos::Comm<int> > getComm() const
00194     {
00195       return comm_;
00196     }
00197 
00199     global_size_t getGlobalNumRows() const;
00200 
00202     global_size_t getGlobalNumCols() const;
00203 
00205     global_size_t getRowIndexBase() const;
00206 
00208     global_size_t getColumnIndexBase() const;
00209 
00211     global_size_t getGlobalNNZ() const;
00212 
00214     size_t getLocalNumRows() const;
00215 
00217     size_t getLocalNumCols() const;
00218 
00220     size_t getLocalNNZ() const;
00221 
00222     Teuchos::RCP<const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> >
00223     getRowMap() const {
00224       return row_map_;
00225     }
00226 
00227     Teuchos::RCP<const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> >
00228     getColMap() const {
00229       return col_map_;
00230     }
00231 
00232     Teuchos::RCP<const type> get(const Teuchos::Ptr<const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> > map) const;
00233 
00235     std::string description() const;
00236 
00238     void describe(Teuchos::FancyOStream &out,
00239       const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const;
00240 
00241 
00242   private:
00243 
00244     void help_getCrs(const Teuchos::ArrayView<scalar_t> nzval,
00245          const Teuchos::ArrayView<global_ordinal_t> colind,
00246          const Teuchos::ArrayView<global_size_t> rowptr,
00247          global_size_t& nnz,
00248          const Teuchos::Ptr<const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> > rowmap,
00249          EStorage_Ordering ordering,
00250          has_special_impl hsi) const;
00251 
00252     void help_getCrs(const Teuchos::ArrayView<scalar_t> nzval,
00253          const Teuchos::ArrayView<global_ordinal_t> colind,
00254          const Teuchos::ArrayView<global_size_t> rowptr,
00255          global_size_t& nnz,
00256          const Teuchos::Ptr<const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> > rowmap,
00257          EStorage_Ordering ordering,
00258          no_special_impl nsi) const;
00259 
00260     void do_getCrs(const Teuchos::ArrayView<scalar_t> nzval,
00261        const Teuchos::ArrayView<global_ordinal_t> colind,
00262        const Teuchos::ArrayView<global_size_t> rowptr,
00263        global_size_t& nnz,
00264        const Teuchos::Ptr<const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> > rowmap,
00265        EStorage_Ordering ordering,
00266        row_access ra) const;
00267 
00268     void do_getCrs(const Teuchos::ArrayView<scalar_t> nzval,
00269        const Teuchos::ArrayView<global_ordinal_t> colind,
00270        const Teuchos::ArrayView<global_size_t> rowptr,
00271        global_size_t& nnz,
00272        const Teuchos::Ptr<const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> > rowmap,
00273        EStorage_Ordering ordering,
00274        col_access ca) const;
00275 
00276     void help_getCcs(const Teuchos::ArrayView<scalar_t> nzval,
00277          const Teuchos::ArrayView<global_ordinal_t> rowind,
00278          const Teuchos::ArrayView<global_size_t> colptr,
00279          global_size_t& nnz,
00280          const Teuchos::Ptr<const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> > colmap,
00281          EStorage_Ordering ordering,
00282          has_special_impl hsi) const;
00283 
00284     void help_getCcs(const Teuchos::ArrayView<scalar_t> nzval,
00285          const Teuchos::ArrayView<global_ordinal_t> rowind,
00286          const Teuchos::ArrayView<global_size_t> colptr,
00287          global_size_t& nnz,
00288          const Teuchos::Ptr<const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> > colmap,
00289          EStorage_Ordering ordering,
00290          no_special_impl nsi) const;
00291 
00292     void do_getCcs(const Teuchos::ArrayView<scalar_t> nzval,
00293        const Teuchos::ArrayView<global_ordinal_t> rowind,
00294        const Teuchos::ArrayView<global_size_t> colptr,
00295        global_size_t& nnz,
00296        const Teuchos::Ptr<const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> > colmap,
00297        EStorage_Ordering ordering,
00298        row_access ra) const;
00299 
00300     void do_getCcs(const Teuchos::ArrayView<scalar_t> nzval,
00301        const Teuchos::ArrayView<global_ordinal_t> rowind,
00302        const Teuchos::ArrayView<global_size_t> colptr,
00303        global_size_t& nnz,
00304        const Teuchos::Ptr<const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> > colmap,
00305        EStorage_Ordering ordering,
00306        col_access ca) const;
00307 
00308   protected:
00309     // These methods will link to concrete implementations, and may
00310     // also be used by them
00311 
00318     void getGlobalRowCopy(global_ordinal_t row,
00319         const Teuchos::ArrayView<global_ordinal_t>& indices,
00320         const Teuchos::ArrayView<scalar_t>& vals,
00321         size_t& nnz) const;
00322 
00329     void getGlobalColCopy(global_ordinal_t col,
00330         const Teuchos::ArrayView<global_ordinal_t>& indices,
00331         const Teuchos::ArrayView<scalar_t>& vals,
00332         size_t& nnz) const;
00333 
00334     size_t getMaxRowNNZ() const;
00335 
00336     size_t getMaxColNNZ() const;
00337 
00338     size_t getGlobalRowNNZ(global_ordinal_t row) const;
00339 
00340     size_t getLocalRowNNZ(local_ordinal_t row) const;
00341 
00342     size_t getGlobalColNNZ(global_ordinal_t col) const;
00343 
00344     size_t getLocalColNNZ(local_ordinal_t col) const;
00345 
00346     bool isLocallyIndexed() const;
00347 
00348     bool isGloballyIndexed() const;
00349 
00350   protected:
00351     const Teuchos::RCP<const Matrix> mat_;
00352 
00353     // only need to be mutable for the initial assignment, is there
00354     // another way to do this?
00355     mutable Teuchos::RCP<const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> > row_map_;
00356 
00357     mutable Teuchos::RCP<const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> > col_map_;
00358 
00359     mutable Teuchos::RCP<const Teuchos::Comm<int> > comm_;
00360     
00361   };        // end class MatrixAdapter
00362 
00363 
00364   // Factory creation method
00365   template <class Matrix>
00366   Teuchos::RCP<MatrixAdapter<Matrix> >
00367   createMatrixAdapter(Teuchos::RCP<Matrix> m);
00368     
00369   template <class Matrix>
00370   Teuchos::RCP<const MatrixAdapter<Matrix> >
00371   createConstMatrixAdapter(Teuchos::RCP<const Matrix> m);
00372 
00373 } // end namespace Amesos2
00374 
00375 #endif  // AMESOS2_MATRIXADAPTER_DECL_HPP