53 #ifndef AMESOS2_EPETRA_MULTIVEC_ADAPTER_DEF_HPP
54 #define AMESOS2_EPETRA_MULTIVEC_ADAPTER_DEF_HPP
56 #include <Teuchos_as.hpp>
58 #include <Epetra_SerialComm.h>
60 #include <Epetra_MpiComm.h>
62 #include <Epetra_LocalMap.h>
63 #include <Epetra_Import.h>
64 #include <Epetra_Export.h>
73 , mv_map_(adapter.mv_map_)
79 mv_map_ = Teuchos::rcpFromRef(mv_->Map());
85 return !mv_->DistributedGlobal();
90 return mv_->DistributedGlobal();
94 const Teuchos::RCP<const Teuchos::Comm<int> >
103 return Teuchos::as<size_t>(mv_->MyLength());
109 return Teuchos::as<size_t>(mv_->NumVectors());
116 return Teuchos::as<global_size_t>(mv_->GlobalLength());
122 return Teuchos::as<size_t>(mv_->NumVectors());
128 return Teuchos::as<size_t>(mv_->Stride());
134 return mv_->ConstantStride();
138 Teuchos::RCP<const Tpetra::Vector<MultiVecAdapter<Epetra_MultiVector>::scalar_t,
146 using Teuchos::ArrayRCP;
147 using Tpetra::MultiVector;
150 typedef local_ordinal_t lot;
151 typedef global_ordinal_t got;
154 RCP<MultiVector<st,lot,got,nt> > vector = rcp(
new MultiVector<st,lot,got,nt>(this->getMap(),1));
157 ArrayRCP<st> it = vector->getDataNonConst(0);
158 double* vector_data = mv_->operator[](Teuchos::as<int>(j));
159 Tpetra::global_size_t size = vector->getGlobalLength();
161 for( Tpetra::global_size_t i = 0; i < size; ++i ){
162 *it = vector_data[i];
165 return vector->getVector(j);
170 Teuchos::RCP<Tpetra::Vector<MultiVecAdapter<Epetra_MultiVector>::scalar_t,
178 using Teuchos::ArrayRCP;
179 using Tpetra::MultiVector;
182 typedef local_ordinal_t lot;
183 typedef global_ordinal_t got;
186 RCP<MultiVector<st,lot,got,nt> > vector = rcp(
new MultiVector<st,lot,got,nt>(this->getMap(),1));
189 ArrayRCP<st> it = vector->getDataNonConst(0);
190 double* vector_data = mv_->operator[](Teuchos::as<int>(j));
191 Tpetra::global_size_t size = vector->getGlobalLength();
193 for( Tpetra::global_size_t i = 0; i < size; ++i ){
194 *it = vector_data[i];
197 return vector->getVectorNonConst(j);
203 TEUCHOS_TEST_FOR_EXCEPTION( this->getGlobalNumVectors() != 1,
204 std::invalid_argument,
205 "Amesos2_EpetraMultiVectorAdapter: getMVPointer_impl should only be called for case with a single vector and single MPI process" );
207 double* vector_data = mv_->operator[](Teuchos::as<int>(0));
221 using Teuchos::rcpFromPtr;
224 const size_t num_vecs = getGlobalNumVectors();
226 #ifdef HAVE_AMESOS2_DEBUG
227 const size_t requested_vector_length = distribution_map->getNodeNumElements();
228 TEUCHOS_TEST_FOR_EXCEPTION( lda < requested_vector_length,
229 std::invalid_argument,
230 "Given stride is not large enough for local vector length" );
231 TEUCHOS_TEST_FOR_EXCEPTION( as<size_t>(av.size()) < (num_vecs-1) * lda + requested_vector_length,
232 std::invalid_argument,
233 "MultiVector storage not large enough given leading dimension "
234 "and number of vectors" );
238 if ( num_vecs == 1 && mv_->Comm().MyPID() == 0 && mv_->Comm().NumProc() == 1 ) {
239 mv_->ExtractCopy(av.getRawPtr(), lda);
242 Epetra_Map e_dist_map
246 node_t>(*distribution_map);
248 multivec_t redist_mv(e_dist_map, as<int>(num_vecs));
249 const Epetra_Import importer(e_dist_map, *mv_map_);
250 redist_mv.Import(*mv_, importer, Insert);
253 redist_mv.ExtractCopy(av.getRawPtr(), lda);
259 Teuchos::ArrayRCP<MultiVecAdapter<Epetra_MultiVector>::scalar_t>
311 return Teuchos::null;
325 using Teuchos::rcpFromPtr;
328 const size_t num_vecs = getGlobalNumVectors();
330 double* data_ptr =
const_cast<double*
>(new_data.getRawPtr());
333 if ( num_vecs == 1 && mv_->Comm().MyPID() == 0 && mv_->Comm().NumProc() == 1 ) {
339 auto vector = mv_->Pointers();
340 for (
size_t i = 0; i < lda; ++i ) {
341 vector[0][i] = data_ptr[i];
345 const Epetra_BlockMap e_source_map
346 = *Util::tpetra_map_to_epetra_map<local_ordinal_t,global_ordinal_t,global_size_t,node_t>(*source_map);
347 const multivec_t source_mv(Copy, e_source_map, data_ptr, as<int>(lda), as<int>(num_vecs));
348 const Epetra_Import importer(*mv_map_, e_source_map);
350 mv_->Import(source_mv, importer, Insert);
357 std::ostringstream oss;
358 oss <<
"Amesos2 adapter wrapping: Epetra_MultiVector";
364 Teuchos::FancyOStream& os,
365 const Teuchos::EVerbosityLevel verbLevel)
const
368 if(verbLevel != Teuchos::VERB_NONE)
370 os <<
"TODO: implement! ";
375 Teuchos::RCP<const Tpetra::Map<MultiVecAdapter<Epetra_MultiVector>::local_ordinal_t,
380 return Util::epetra_map_to_tpetra_map<local_ordinal_t,global_ordinal_t,global_size_t,node_t>(*mv_map_);
385 =
"Amesos2 adapter for Epetra_MultiVector";
390 #endif // AMESOS2_EPETRA_MULTIVEC_ADAPTER_DEF_HPP
Utility functions for Amesos2.
const RCP< const Teuchos::Comm< int > > to_teuchos_comm(RCP< const Epetra_Comm > c)
Transform an Epetra_Comm object into a Teuchos::Comm object.
Amesos2::MultiVecAdapter specialization for the Epetra_MultiVector class.
RCP< Epetra_Map > tpetra_map_to_epetra_map(const Tpetra::Map< LO, GO, Node > &map)
Transform a Tpetra::Map object into an Epetra_Map.
Definition: Amesos2_Util.hpp:766
EDistribution
Definition: Amesos2_TypeDecl.hpp:123
A templated MultiVector class adapter for Amesos2.
Definition: Amesos2_MultiVecAdapter_decl.hpp:176