Amesos2 - Direct Sparse Solver Interfaces Version of the Day
Amesos2_TpetraMultiVecAdapter_decl.hpp
Go to the documentation of this file.
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 
00053 #ifndef AMESOS2_TPETRA_MULTIVEC_ADAPTER_DECL_HPP
00054 #define AMESOS2_TPETRA_MULTIVEC_ADAPTER_DECL_HPP
00055 
00056 #include <Teuchos_RCP.hpp>
00057 #include <Teuchos_Array.hpp>
00058 #include <Teuchos_as.hpp>
00059 #include <Tpetra_MultiVector.hpp>
00060 
00061 #include "Amesos2_MultiVecAdapter_decl.hpp"
00062 
00063 namespace Amesos2 {
00064 
00070   template< typename Scalar,
00071             typename LocalOrdinal,
00072             typename GlobalOrdinal,
00073             class    Node >
00074   class MultiVecAdapter<Tpetra::MultiVector<Scalar,
00075                                             LocalOrdinal,
00076                                             GlobalOrdinal,
00077                                             Node> >
00078   {
00079   public:
00080     // public type definitions
00081     typedef Tpetra::MultiVector<Scalar,
00082                                 LocalOrdinal,
00083                                 GlobalOrdinal,
00084                                 Node>       multivec_t;
00085     typedef Scalar                          scalar_t;
00086     typedef LocalOrdinal                    local_ordinal_t;
00087     typedef GlobalOrdinal                   global_ordinal_t;
00088     typedef Node                            node_t;
00089     typedef Tpetra::global_size_t           global_size_t;
00090 
00091     friend Teuchos::RCP<MultiVecAdapter<multivec_t> > createMultiVecAdapter<> (Teuchos::RCP<multivec_t>);
00092     friend Teuchos::RCP<const MultiVecAdapter<multivec_t> > createConstMultiVecAdapter<> (Teuchos::RCP<const multivec_t>);
00093 
00094     static const char* name;
00095 
00096   protected:
00097     // Do not allow direct construction of MultiVecAdapter's.  Only
00098     // allow construction throw the non-member friend functions.
00099 
00101     MultiVecAdapter( const MultiVecAdapter<multivec_t>& adapter );
00102 
00108     MultiVecAdapter( const Teuchos::RCP<multivec_t>& m );
00109 
00110 
00111   public:
00112 
00113     ~MultiVecAdapter()
00114     { }
00115 
00116 
00118     bool isLocallyIndexed() const
00119     {
00120       if(getComm()->getSize() == 1){
00121         return true;
00122       } // There may be other conditions to check
00123       return false;
00124     }
00125 
00126     // TODO
00127     bool isGloballyIndexed() const;
00128 
00129 
00130     Teuchos::RCP<const Tpetra::Map<
00131                          local_ordinal_t,
00132                          global_ordinal_t,
00133                          node_t > >
00134     getMap() const
00135     {
00136       return mv_->getMap();
00137     }
00138 
00140     Teuchos::RCP<const Teuchos::Comm<int> > getComm() const
00141     {
00142       return mv_->getMap()->getComm();
00143     }
00144 
00146     size_t getLocalLength() const
00147     {
00148       return Teuchos::as<size_t>(mv_->getLocalLength());
00149     }
00150 
00151 
00153     size_t getLocalNumVectors() const
00154     {
00155       return mv_->getNumVectors();
00156     }
00157 
00158 
00160     global_size_t getGlobalLength() const
00161     {
00162       return mv_->getGlobalLength();
00163       //return getMap()->getMaxAllGlobalIndex() + 1;
00164     }
00165 
00166 
00168     global_size_t getGlobalNumVectors() const
00169     {
00170       return Teuchos::as<global_size_t>(mv_->getNumVectors());
00171     }
00172 
00173 
00175     size_t getStride() const
00176     {
00177       return mv_->getStride();
00178     }
00179 
00180 
00182     bool isConstantStride() const
00183     {
00184       return mv_->isConstantStride();
00185     }
00186 
00187 
00189     Teuchos::RCP<const Tpetra::Vector<scalar_t,local_ordinal_t,global_ordinal_t,node_t> >
00190     getVector( size_t j ) const
00191     {
00192       return mv_->getVector(j);
00193     }
00194 
00195 
00197     Teuchos::RCP<Tpetra::Vector<scalar_t,local_ordinal_t,global_ordinal_t,node_t> >
00198     getVectorNonConst( size_t j )
00199     {
00200       return mv_->getVectorNonConst(j);
00201     }
00202 
00203 
00230     void
00231     get1dCopy (const Teuchos::ArrayView<scalar_t>& A,
00232                size_t lda,
00233                Teuchos::Ptr<const Tpetra::Map<local_ordinal_t,
00234                                               global_ordinal_t,
00235                                               node_t> > distribution_map) const;
00236 
00250     Teuchos::ArrayRCP<scalar_t> get1dViewNonConst (bool local = false);
00251 
00260     void
00261     put1dData (const Teuchos::ArrayView<const scalar_t>& new_data,
00262                size_t lda,
00263                Teuchos::Ptr< const Tpetra::Map<local_ordinal_t,
00264                                         global_ordinal_t,
00265                                         node_t> > source_map );
00266 
00268     std::string description () const;
00269 
00271     void
00272     describe (Teuchos::FancyOStream& os,
00273               const Teuchos::EVerbosityLevel verbLevel =
00274               Teuchos::Describable::verbLevel_default) const;
00275 
00276   private:
00278     Teuchos::RCP<multivec_t> mv_;
00279 
00281     typedef Tpetra::Export<local_ordinal_t, global_ordinal_t, node_t> export_type;
00282 
00284     typedef Tpetra::Import<local_ordinal_t, global_ordinal_t, node_t> import_type;
00285 
00292     mutable Teuchos::RCP<export_type> exporter_;
00293 
00300     mutable Teuchos::RCP<import_type> importer_;
00301   }; // end class MultiVecAdapter<Tpetra::MultiVector>
00302 
00303 } // end namespace Amesos2
00304 
00305 
00306 #endif // AMESOS2_TPETRA_MULTIVEC_ADAPTER_DECL_HPP