Amesos2 - Direct Sparse Solver Interfaces  Version of the Day
Amesos2_TpetraMultiVecAdapter_def.hpp
Go to the documentation of this file.
1 // @HEADER
2 //
3 // ***********************************************************************
4 //
5 // Amesos2: Templated Direct Sparse Solver Package
6 // Copyright 2011 Sandia Corporation
7 //
8 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
9 // the U.S. Government retains certain rights in this software.
10 //
11 // Redistribution and use in source and binary forms, with or without
12 // modification, are permitted provided that the following conditions are
13 // met:
14 //
15 // 1. Redistributions of source code must retain the above copyright
16 // notice, this list of conditions and the following disclaimer.
17 //
18 // 2. Redistributions in binary form must reproduce the above copyright
19 // notice, this list of conditions and the following disclaimer in the
20 // documentation and/or other materials provided with the distribution.
21 //
22 // 3. Neither the name of the Corporation nor the names of the
23 // contributors may be used to endorse or promote products derived from
24 // this software without specific prior written permission.
25 //
26 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 //
38 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
39 //
40 // ***********************************************************************
41 //
42 // @HEADER
43 
53 #ifndef AMESOS2_TPETRA_MULTIVEC_ADAPTER_DEF_HPP
54 #define AMESOS2_TPETRA_MULTIVEC_ADAPTER_DEF_HPP
55 
57 
58 
59 namespace Amesos2 {
60 
61  using Tpetra::MultiVector;
62 
63  template <typename Scalar, typename LocalOrdinal, typename GlobalOrdinal, class Node >
64  MultiVecAdapter<
65  MultiVector<Scalar,
66  LocalOrdinal,
67  GlobalOrdinal,
68  Node> >::MultiVecAdapter( const Teuchos::RCP<multivec_t>& m )
69  : mv_(m)
70  {
71  mv_map_ = this->getMap();
72  }
73 
74 
75  template <typename Scalar, typename LocalOrdinal, typename GlobalOrdinal, class Node >
76  void
77  MultiVecAdapter<
78  MultiVector<Scalar,
79  LocalOrdinal,
80  GlobalOrdinal,
81  Node> >::get1dCopy(const Teuchos::ArrayView<scalar_t>& av,
82  size_t lda,
83  Teuchos::Ptr<
84  const Tpetra::Map<LocalOrdinal,
85  GlobalOrdinal,
86  Node> > distribution_map ) const
87  {
88  using Teuchos::rcpFromPtr;
89  using Teuchos::as;
90 
91  size_t num_vecs = getGlobalNumVectors();
92 
93 #ifdef HAVE_AMESOS2_DEBUG
94  size_t requested_vector_length = distribution_map->getNodeNumElements();
95  TEUCHOS_TEST_FOR_EXCEPTION( lda < requested_vector_length,
96  std::invalid_argument,
97  "Given stride is not large enough for local vector length" );
98  TEUCHOS_TEST_FOR_EXCEPTION( as<size_t>(av.size()) < as<size_t>((num_vecs-1) * lda + requested_vector_length),
99  std::invalid_argument,
100  "MultiVector storage not large enough given leading dimension "
101  "and number of vectors" );
102 #endif
103 
104  multivec_t redist_mv(rcpFromPtr(distribution_map), num_vecs);
105 
106  const Tpetra::Import<LocalOrdinal,GlobalOrdinal,Node> importer(mv_map_, rcpFromPtr(distribution_map));
107  redist_mv.doImport(*mv_, importer, Tpetra::REPLACE);
108 
109  // do copy
110  redist_mv.get1dCopy(av, lda);
111  }
112 
113  template <typename Scalar, typename LocalOrdinal, typename GlobalOrdinal, class Node >
114  Teuchos::ArrayRCP<Scalar>
115  MultiVecAdapter<
116  MultiVector<Scalar,
117  LocalOrdinal,
118  GlobalOrdinal,
119  Node> >::get1dViewNonConst(bool local)
120  {
121  // if( local ){
122  // this->localize();
123  // /* Use the global element list returned by
124  // * mv_->getMap()->getNodeElementList() to get a subCopy of mv_ which we
125  // * assign to l_l_mv_, then return get1dViewNonConst() of l_l_mv_
126  // */
127  // if(l_l_mv_.is_null() ){
128  // Teuchos::ArrayView<const GlobalOrdinal> nodeElements_go
129  // = mv_->getMap()->getNodeElementList();
130  // Teuchos::Array<size_t> nodeElements_st(nodeElements_go.size());
131 
132  // // Convert the node element to a list of size_t type objects
133  // typename Teuchos::ArrayView<const GlobalOrdinal>::iterator it_go;
134  // Teuchos::Array<size_t>::iterator it_st = nodeElements_st.begin();
135  // for( it_go = nodeElements_go.begin(); it_go != nodeElements_go.end(); ++it_go ){
136  // *(it_st++) = Teuchos::as<size_t>(*it_go);
137  // }
138 
139  // // To be consistent with the globalize() function, get a view of the local mv
140  // l_l_mv_ = l_mv_->subViewNonConst(nodeElements_st);
141 
142  // return(l_l_mv_->get1dViewNonConst());
143  // } else {
144  // // We need to re-import values to the local, since changes may have been
145  // // made to the global structure that are not reflected in the local
146  // // view.
147  // Teuchos::ArrayView<const GlobalOrdinal> nodeElements_go
148  // = mv_->getMap()->getNodeElementList();
149  // Teuchos::Array<size_t> nodeElements_st(nodeElements_go.size());
150 
151  // // Convert the node element to a list of size_t type objects
152  // typename Teuchos::ArrayView<const GlobalOrdinal>::iterator it_go;
153  // Teuchos::Array<size_t>::iterator it_st = nodeElements_st.begin();
154  // for( it_go = nodeElements_go.begin(); it_go != nodeElements_go.end(); ++it_go ){
155  // *(it_st++) = Teuchos::as<size_t>(*it_go);
156  // }
157 
158  // return l_l_mv_->get1dViewNonConst();
159  // }
160  // } else {
161  // if( mv_->isDistributed() ){
162  // this->localize();
163 
164  // return l_mv_->get1dViewNonConst();
165  // } else { // not distributed, no need to import
166  // return mv_->get1dViewNonConst();
167  // }
168  // }
169  }
170 
171 
172  template <typename Scalar, typename LocalOrdinal, typename GlobalOrdinal, class Node>
173  void
174  MultiVecAdapter<
175  MultiVector<Scalar,
176  LocalOrdinal,
177  GlobalOrdinal,
178  Node> >::put1dData(const Teuchos::ArrayView<const scalar_t>& new_data,
179  size_t lda,
180  Teuchos::Ptr<
181  const Tpetra::Map<LocalOrdinal,
182  GlobalOrdinal,
183  Node> > source_map)
184  {
185  using Teuchos::rcpFromPtr;
186 
187  const size_t num_vecs = getGlobalNumVectors();
188  const multivec_t source_mv(rcpFromPtr(source_map), new_data, lda, num_vecs);
189  const Tpetra::Import<local_ordinal_t, global_ordinal_t, node_t> importer(rcpFromPtr(source_map), mv_map_);
190 
191  mv_->doImport(source_mv, importer, Tpetra::REPLACE);
192  }
193 
194 
195  template <typename Scalar, typename LocalOrdinal, typename GlobalOrdinal, class Node >
196  std::string
197  MultiVecAdapter<
198  MultiVector<Scalar,
199  LocalOrdinal,
200  GlobalOrdinal,
201  Node> >::description() const
202  {
203  std::ostringstream oss;
204  oss << "Amesos2 adapter wrapping: ";
205  oss << mv_->description();
206  return oss.str();
207  }
208 
209 
211  template <typename Scalar, typename LocalOrdinal, typename GlobalOrdinal, class Node >
212  void
213  MultiVecAdapter<
214  MultiVector<Scalar,
215  LocalOrdinal,
216  GlobalOrdinal,
217  Node> >::describe(Teuchos::FancyOStream& os,
218  const Teuchos::EVerbosityLevel verbLevel) const
219  {
220  mv_->describe(os, verbLevel);
221 
222  }
223 
224 
225  template <typename Scalar, typename LocalOrdinal, typename GlobalOrdinal, class Node >
226  const char* MultiVecAdapter<
227  MultiVector<Scalar,
228  LocalOrdinal,
229  GlobalOrdinal,
230  Node> >::name
231  = "Amesos2 adapter for Tpetra::MultiVector";
232 
233 
234 } // end namespace Amesos2
235 
236 #endif // AMESOS2_TPETRA_MULTIVEC_ADAPTER_DEF_HPP
Definition: Amesos2_AbstractConcreteMatrixAdapter.hpp:48
Amesos2::MultiVecAdapter specialization for the Tpetra::MultiVector class.