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 Kokkos::View<scalar_t**, Kokkos::LayoutLeft, Kokkos::HostSpace> & host_view,
267 using Teuchos::rcpFromPtr;
270 const size_t num_vecs = getGlobalNumVectors();
272 #ifdef HAVE_AMESOS2_DEBUG
273 const size_t requested_vector_length = distribution_map->getNodeNumElements();
274 TEUCHOS_TEST_FOR_EXCEPTION( lda < requested_vector_length,
275 std::invalid_argument,
276 "Given stride is not large enough for local vector length" );
280 host_view = Kokkos::View<scalar_t**, Kokkos::LayoutLeft, Kokkos::HostSpace>(
281 Kokkos::ViewAllocateWithoutInitializing(
"get1dCopy_kokkos_view"),
282 distribution_map->getNodeNumElements(), num_vecs);
285 if ( num_vecs == 1 && this->mv_->Comm().MyPID() == 0 && this->mv_->Comm().NumProc() == 1 ) {
286 mv_->ExtractCopy(host_view.data(), lda);
289 Epetra_Map e_dist_map
293 node_t>(*distribution_map);
295 multivec_t redist_mv(e_dist_map, as<int>(num_vecs));
296 const Epetra_Import importer(e_dist_map, *mv_map_);
297 redist_mv.Import(*mv_, importer, Insert);
303 redist_mv.ExtractCopy(host_view.data(), lda);
307 Teuchos::ArrayRCP<MultiVecAdapter<Epetra_MultiVector>::scalar_t>
359 return Teuchos::null;
373 using Teuchos::rcpFromPtr;
376 const size_t num_vecs = getGlobalNumVectors();
378 double* data_ptr =
const_cast<double*
>(new_data.getRawPtr());
381 if ( num_vecs == 1 && mv_->Comm().MyPID() == 0 && mv_->Comm().NumProc() == 1 ) {
387 auto vector = mv_->Pointers();
388 for (
size_t i = 0; i < lda; ++i ) {
389 vector[0][i] = data_ptr[i];
393 const Epetra_BlockMap e_source_map
394 = *Util::tpetra_map_to_epetra_map<local_ordinal_t,global_ordinal_t,global_size_t,node_t>(*source_map);
395 const multivec_t source_mv(Copy, e_source_map, data_ptr, as<int>(lda), as<int>(num_vecs));
396 const Epetra_Import importer(*mv_map_, e_source_map);
398 mv_->Import(source_mv, importer, Insert);
404 Kokkos::View<scalar_t**, Kokkos::LayoutLeft, Kokkos::HostSpace> & host_new_data,
412 using Teuchos::rcpFromPtr;
415 const size_t num_vecs = getGlobalNumVectors();
417 double* data_ptr = host_new_data.data();
420 if ( num_vecs == 1 && mv_->Comm().MyPID() == 0 && mv_->Comm().NumProc() == 1 ) {
421 auto vector = mv_->Pointers();
422 for (
size_t i = 0; i < lda; ++i ) {
423 vector[0][i] = data_ptr[i];
427 const Epetra_BlockMap e_source_map
428 = *Util::tpetra_map_to_epetra_map<local_ordinal_t,global_ordinal_t,global_size_t,node_t>(*source_map);
429 const multivec_t source_mv(Copy, e_source_map, data_ptr, as<int>(lda), as<int>(num_vecs));
430 const Epetra_Import importer(*mv_map_, e_source_map);
432 mv_->Import(source_mv, importer, Insert);
438 std::ostringstream oss;
439 oss <<
"Amesos2 adapter wrapping: Epetra_MultiVector";
445 Teuchos::FancyOStream& os,
446 const Teuchos::EVerbosityLevel verbLevel)
const
449 if(verbLevel != Teuchos::VERB_NONE)
451 os <<
"TODO: implement! ";
456 Teuchos::RCP<const Tpetra::Map<MultiVecAdapter<Epetra_MultiVector>::local_ordinal_t,
461 return Util::epetra_map_to_tpetra_map<local_ordinal_t,global_ordinal_t,global_size_t,node_t>(*mv_map_);
466 =
"Amesos2 adapter for Epetra_MultiVector";
471 #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:884
EDistribution
Definition: Amesos2_TypeDecl.hpp:123
A templated MultiVector class adapter for Amesos2.
Definition: Amesos2_MultiVecAdapter_decl.hpp:176