19 #ifndef AMESOS2_EPETRA_MULTIVEC_ADAPTER_DEF_HPP
20 #define AMESOS2_EPETRA_MULTIVEC_ADAPTER_DEF_HPP
22 #include <Teuchos_as.hpp>
24 #include <Epetra_SerialComm.h>
26 #include <Epetra_MpiComm.h>
28 #include <Epetra_LocalMap.h>
29 #include <Epetra_Import.h>
30 #include <Epetra_Export.h>
39 , mv_map_(adapter.mv_map_)
45 mv_map_ = Teuchos::rcpFromRef(mv_->Map());
49 Teuchos::RCP<Epetra_MultiVector>
52 Teuchos::RCP<Epetra_MultiVector> Y (
new Epetra_MultiVector(*mv_map_, mv_->NumVectors(),
false));
60 return !mv_->DistributedGlobal();
65 return mv_->DistributedGlobal();
69 const Teuchos::RCP<const Teuchos::Comm<int> >
78 return Teuchos::as<size_t>(mv_->MyLength());
84 return Teuchos::as<size_t>(mv_->NumVectors());
91 return Teuchos::as<global_size_t>(mv_->GlobalLength());
97 return Teuchos::as<size_t>(mv_->NumVectors());
103 return Teuchos::as<size_t>(mv_->Stride());
109 return mv_->ConstantStride();
113 Teuchos::RCP<const Tpetra::Vector<MultiVecAdapter<Epetra_MultiVector>::scalar_t,
121 using Teuchos::ArrayRCP;
122 using Tpetra::MultiVector;
125 typedef local_ordinal_t lot;
126 typedef global_ordinal_t got;
129 RCP<MultiVector<st,lot,got,nt> > vector = rcp(
new MultiVector<st,lot,got,nt>(this->getMap(),1));
132 ArrayRCP<st> it = vector->getDataNonConst(0);
133 double* vector_data = mv_->operator[](Teuchos::as<int>(j));
134 Tpetra::global_size_t
size = vector->getGlobalLength();
136 for( Tpetra::global_size_t i = 0; i <
size; ++i ){
137 *it = vector_data[i];
140 return vector->getVector(j);
145 Teuchos::RCP<Tpetra::Vector<MultiVecAdapter<Epetra_MultiVector>::scalar_t,
153 using Teuchos::ArrayRCP;
154 using Tpetra::MultiVector;
157 typedef local_ordinal_t lot;
158 typedef global_ordinal_t got;
161 RCP<MultiVector<st,lot,got,nt> > vector = rcp(
new MultiVector<st,lot,got,nt>(this->getMap(),1));
164 ArrayRCP<st> it = vector->getDataNonConst(0);
165 double* vector_data = mv_->operator[](Teuchos::as<int>(j));
166 Tpetra::global_size_t
size = vector->getGlobalLength();
168 for( Tpetra::global_size_t i = 0; i <
size; ++i ){
169 *it = vector_data[i];
172 return vector->getVectorNonConst(j);
178 TEUCHOS_TEST_FOR_EXCEPTION( this->getGlobalNumVectors() != 1,
179 std::invalid_argument,
180 "Amesos2_EpetraMultiVectorAdapter: getMVPointer_impl should only be called for case with a single vector and single MPI process" );
182 double* vector_data = mv_->operator[](Teuchos::as<int>(0));
196 using Teuchos::rcpFromPtr;
199 const size_t num_vecs = getGlobalNumVectors();
201 #ifdef HAVE_AMESOS2_DEBUG
202 const size_t requested_vector_length = distribution_map->getLocalNumElements();
203 TEUCHOS_TEST_FOR_EXCEPTION( lda < requested_vector_length,
204 std::invalid_argument,
205 "Given stride is not large enough for local vector length" );
206 TEUCHOS_TEST_FOR_EXCEPTION( as<size_t>(av.size()) < (num_vecs-1) * lda + requested_vector_length,
207 std::invalid_argument,
208 "MultiVector storage not large enough given leading dimension "
209 "and number of vectors" );
213 if ( num_vecs == 1 && mv_->Comm().MyPID() == 0 && mv_->Comm().NumProc() == 1 ) {
214 mv_->ExtractCopy(av.getRawPtr(), lda);
217 Epetra_Map e_dist_map
221 node_t>(*distribution_map);
223 multivec_t redist_mv(e_dist_map, as<int>(num_vecs));
224 const Epetra_Import importer(e_dist_map, *mv_map_);
225 redist_mv.Import(*mv_, importer, Insert);
228 redist_mv.ExtractCopy(av.getRawPtr(), lda);
234 Kokkos::View<scalar_t**, Kokkos::LayoutLeft, Kokkos::HostSpace> & host_view,
242 using Teuchos::rcpFromPtr;
245 const size_t num_vecs = getGlobalNumVectors();
247 #ifdef HAVE_AMESOS2_DEBUG
248 const size_t requested_vector_length = distribution_map->getLocalNumElements();
249 TEUCHOS_TEST_FOR_EXCEPTION( lda < requested_vector_length,
250 std::invalid_argument,
251 "Given stride is not large enough for local vector length" );
255 host_view = Kokkos::View<scalar_t**, Kokkos::LayoutLeft, Kokkos::HostSpace>(
256 Kokkos::ViewAllocateWithoutInitializing(
"get1dCopy_kokkos_view"),
257 distribution_map->getLocalNumElements(), num_vecs);
260 if ( num_vecs == 1 && this->mv_->Comm().MyPID() == 0 && this->mv_->Comm().NumProc() == 1 ) {
261 mv_->ExtractCopy(host_view.data(), lda);
264 Epetra_Map e_dist_map
268 node_t>(*distribution_map);
270 multivec_t redist_mv(e_dist_map, as<int>(num_vecs));
271 const Epetra_Import importer(e_dist_map, *mv_map_);
272 redist_mv.Import(*mv_, importer, Insert);
278 redist_mv.ExtractCopy(host_view.data(), lda);
282 Teuchos::ArrayRCP<MultiVecAdapter<Epetra_MultiVector>::scalar_t>
334 return Teuchos::null;
348 using Teuchos::rcpFromPtr;
351 const size_t num_vecs = getGlobalNumVectors();
353 double* data_ptr =
const_cast<double*
>(new_data.getRawPtr());
356 if ( num_vecs == 1 && mv_->Comm().MyPID() == 0 && mv_->Comm().NumProc() == 1 ) {
362 auto vector = mv_->Pointers();
363 for (
size_t i = 0; i < lda; ++i ) {
364 vector[0][i] = data_ptr[i];
368 const Epetra_BlockMap e_source_map
369 = *Util::tpetra_map_to_epetra_map<local_ordinal_t,global_ordinal_t,global_size_t,node_t>(*source_map);
370 const multivec_t source_mv(Copy, e_source_map, data_ptr, as<int>(lda), as<int>(num_vecs));
371 const Epetra_Import importer(*mv_map_, e_source_map);
373 mv_->Import(source_mv, importer, Insert);
379 Kokkos::View<scalar_t**, Kokkos::LayoutLeft, Kokkos::HostSpace> & host_new_data,
387 using Teuchos::rcpFromPtr;
390 const size_t num_vecs = getGlobalNumVectors();
392 double* data_ptr = host_new_data.data();
395 if ( num_vecs == 1 && mv_->Comm().MyPID() == 0 && mv_->Comm().NumProc() == 1 ) {
396 auto vector = mv_->Pointers();
397 for (
size_t i = 0; i < lda; ++i ) {
398 vector[0][i] = data_ptr[i];
402 const Epetra_BlockMap e_source_map
403 = *Util::tpetra_map_to_epetra_map<local_ordinal_t,global_ordinal_t,global_size_t,node_t>(*source_map);
404 const multivec_t source_mv(Copy, e_source_map, data_ptr, as<int>(lda), as<int>(num_vecs));
405 const Epetra_Import importer(*mv_map_, e_source_map);
407 mv_->Import(source_mv, importer, Insert);
413 std::ostringstream oss;
414 oss <<
"Amesos2 adapter wrapping: Epetra_MultiVector";
420 Teuchos::FancyOStream& os,
421 const Teuchos::EVerbosityLevel verbLevel)
const
424 if(verbLevel != Teuchos::VERB_NONE)
426 os <<
"TODO: implement! ";
431 Teuchos::RCP<const Tpetra::Map<MultiVecAdapter<Epetra_MultiVector>::local_ordinal_t,
436 return Util::epetra_map_to_tpetra_map<local_ordinal_t,global_ordinal_t,global_size_t,node_t>(*mv_map_);
441 =
"Amesos2 adapter for Epetra_MultiVector";
446 #endif // AMESOS2_EPETRA_MULTIVEC_ADAPTER_DEF_HPP
const int size
Definition: klu2_simple.cpp:50
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:725
EDistribution
Definition: Amesos2_TypeDecl.hpp:89
A templated MultiVector class adapter for Amesos2.
Definition: Amesos2_MultiVecAdapter_decl.hpp:142