Amesos2 - Direct Sparse Solver Interfaces Version of the Day
Amesos2_TpetraMultiVecAdapter_def.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_DEF_HPP
00054 #define AMESOS2_TPETRA_MULTIVEC_ADAPTER_DEF_HPP
00055 
00056 #include "Amesos2_TpetraMultiVecAdapter_decl.hpp"
00057 
00058 
00059 namespace Amesos2 {
00060 
00061   using Tpetra::MultiVector;
00062 
00063   template <typename Scalar, typename LocalOrdinal, typename GlobalOrdinal, class Node >
00064   MultiVecAdapter<
00065     MultiVector<Scalar,
00066     LocalOrdinal,
00067     GlobalOrdinal,
00068     Node> >::MultiVecAdapter( const Teuchos::RCP<multivec_t>& m )
00069   : mv_(m)
00070   {
00071     mv_map_ = this->getMap();
00072   }
00073 
00074   
00075   template <typename Scalar, typename LocalOrdinal, typename GlobalOrdinal, class Node >
00076   void
00077   MultiVecAdapter<
00078     MultiVector<Scalar,
00079     LocalOrdinal,
00080     GlobalOrdinal,
00081     Node> >::get1dCopy(const Teuchos::ArrayView<scalar_t>& av,
00082            size_t lda,
00083            Teuchos::Ptr<
00084              const Tpetra::Map<LocalOrdinal,
00085                                GlobalOrdinal,
00086                                Node> > distribution_map ) const
00087   {
00088     using Teuchos::rcpFromPtr;
00089     using Teuchos::as;
00090     
00091     size_t num_vecs = getGlobalNumVectors();
00092 
00093 #ifdef HAVE_AMESOS2_DEBUG
00094     size_t requested_vector_length = distribution_map->getNodeNumElements();
00095     TEUCHOS_TEST_FOR_EXCEPTION( lda < requested_vector_length,
00096       std::invalid_argument,
00097       "Given stride is not large enough for local vector length" );
00098     TEUCHOS_TEST_FOR_EXCEPTION( as<size_t>(av.size()) < as<size_t>((num_vecs-1) * lda + requested_vector_length),
00099       std::invalid_argument,
00100       "MultiVector storage not large enough given leading dimension "
00101       "and number of vectors" );
00102 #endif
00103 
00104     multivec_t redist_mv(rcpFromPtr(distribution_map), num_vecs);
00105 
00106     const Tpetra::Import<LocalOrdinal,GlobalOrdinal,Node> importer(mv_map_, rcpFromPtr(distribution_map));
00107     redist_mv.doImport(*mv_, importer, Tpetra::REPLACE);
00108 
00109     // do copy
00110     redist_mv.get1dCopy(av, lda);
00111   }
00112 
00113   template <typename Scalar, typename LocalOrdinal, typename GlobalOrdinal, class Node >
00114   Teuchos::ArrayRCP<Scalar>
00115   MultiVecAdapter<
00116     MultiVector<Scalar,
00117     LocalOrdinal,
00118     GlobalOrdinal,
00119     Node> >::get1dViewNonConst(bool local)
00120   {
00121     // if( local ){
00122     //   this->localize();
00123     //   /* Use the global element list returned by
00124     //    * mv_->getMap()->getNodeElementList() to get a subCopy of mv_ which we
00125     //    * assign to l_l_mv_, then return get1dViewNonConst() of l_l_mv_
00126     //    */
00127     //   if(l_l_mv_.is_null() ){
00128     //  Teuchos::ArrayView<const GlobalOrdinal> nodeElements_go
00129     //    = mv_->getMap()->getNodeElementList();
00130     //  Teuchos::Array<size_t> nodeElements_st(nodeElements_go.size());
00131 
00132     //  // Convert the node element to a list of size_t type objects
00133     //  typename Teuchos::ArrayView<const GlobalOrdinal>::iterator it_go;
00134     //  Teuchos::Array<size_t>::iterator it_st = nodeElements_st.begin();
00135     //  for( it_go = nodeElements_go.begin(); it_go != nodeElements_go.end(); ++it_go ){
00136     //    *(it_st++) = Teuchos::as<size_t>(*it_go);
00137     //  }
00138 
00139     //  // To be consistent with the globalize() function, get a view of the local mv
00140     //  l_l_mv_ = l_mv_->subViewNonConst(nodeElements_st);
00141 
00142     //  return(l_l_mv_->get1dViewNonConst());
00143     //   } else {
00144     //  // We need to re-import values to the local, since changes may have been
00145     //  // made to the global structure that are not reflected in the local
00146     //  // view.
00147     //  Teuchos::ArrayView<const GlobalOrdinal> nodeElements_go
00148     //    = mv_->getMap()->getNodeElementList();
00149     //  Teuchos::Array<size_t> nodeElements_st(nodeElements_go.size());
00150 
00151     //  // Convert the node element to a list of size_t type objects
00152     //  typename Teuchos::ArrayView<const GlobalOrdinal>::iterator it_go;
00153     //  Teuchos::Array<size_t>::iterator it_st = nodeElements_st.begin();
00154     //  for( it_go = nodeElements_go.begin(); it_go != nodeElements_go.end(); ++it_go ){
00155     //    *(it_st++) = Teuchos::as<size_t>(*it_go);
00156     //  }
00157 
00158     //  return l_l_mv_->get1dViewNonConst();
00159     //   }
00160     // } else {
00161     //   if( mv_->isDistributed() ){
00162     //  this->localize();
00163 
00164     //  return l_mv_->get1dViewNonConst();
00165     //   } else {                      // not distributed, no need to import
00166     //  return mv_->get1dViewNonConst();
00167     //   }
00168     // }
00169   }
00170 
00171 
00172   template <typename Scalar, typename LocalOrdinal, typename GlobalOrdinal, class Node>
00173   void
00174   MultiVecAdapter<
00175     MultiVector<Scalar,
00176     LocalOrdinal,
00177     GlobalOrdinal,
00178     Node> >::put1dData(const Teuchos::ArrayView<const scalar_t>& new_data,
00179            size_t lda,
00180            Teuchos::Ptr<
00181              const Tpetra::Map<LocalOrdinal,
00182                                GlobalOrdinal,
00183                                Node> > source_map)
00184   {
00185     using Teuchos::rcpFromPtr;
00186 
00187     const size_t num_vecs  = getGlobalNumVectors();
00188     const multivec_t source_mv(rcpFromPtr(source_map), new_data, lda, num_vecs);
00189     const Tpetra::Import<local_ordinal_t, global_ordinal_t, node_t> importer(rcpFromPtr(source_map), mv_map_);
00190 
00191     mv_->doImport(source_mv, importer, Tpetra::REPLACE);
00192   }
00193 
00194 
00195   template <typename Scalar, typename LocalOrdinal, typename GlobalOrdinal, class Node >
00196   std::string
00197   MultiVecAdapter<
00198     MultiVector<Scalar,
00199     LocalOrdinal,
00200     GlobalOrdinal,
00201     Node> >::description() const
00202   {
00203     std::ostringstream oss;
00204     oss << "Amesos2 adapter wrapping: ";
00205     oss << mv_->description();
00206     return oss.str();
00207   }
00208 
00209 
00211   template <typename Scalar, typename LocalOrdinal, typename GlobalOrdinal, class Node >
00212   void
00213   MultiVecAdapter<
00214     MultiVector<Scalar,
00215     LocalOrdinal,
00216     GlobalOrdinal,
00217     Node> >::describe(Teuchos::FancyOStream& os,
00218           const Teuchos::EVerbosityLevel verbLevel) const
00219   {
00220 
00221   }
00222 
00223 
00224   template <typename Scalar, typename LocalOrdinal, typename GlobalOrdinal, class Node >
00225   const char* MultiVecAdapter<
00226     MultiVector<Scalar,
00227     LocalOrdinal,
00228     GlobalOrdinal,
00229     Node> >::name
00230   = "Amesos2 adapter for Tpetra::MultiVector";
00231 
00232 
00233 } // end namespace Amesos2
00234 
00235 #endif // AMESOS2_TPETRA_MULTIVEC_ADAPTER_DEF_HPP