11 #ifndef AMESOS2_MULTIVECADAPTER_DEF_HPP
12 #define AMESOS2_MULTIVECADAPTER_DEF_HPP
28 template <
typename MV,
typename V>
29 typename vector_pointer_helper<MV, V>::ptr_return_type *
30 vector_pointer_helper<MV, V>::get_pointer_to_vector (
const Teuchos::Ptr< MV > &mv ) {
31 return mv->getMVPointer_impl();
34 template <
typename MV,
typename V>
35 typename vector_pointer_helper<MV, V>::ptr_return_type *
36 vector_pointer_helper<MV, V>::get_pointer_to_vector ( Teuchos::Ptr< MV > &mv ) {
37 return mv->getMVPointer_impl();
40 template <
typename MV,
typename V>
41 typename vector_pointer_helper<MV, V>::ptr_return_type *
42 vector_pointer_helper<MV, V>::get_pointer_to_vector (
const Teuchos::Ptr< const MV > &mv ) {
43 return mv->getMVPointer_impl();
46 template <
typename MV,
typename V>
47 typename vector_pointer_helper<MV, V>::ptr_return_type *
48 vector_pointer_helper<MV, V>::get_pointer_to_vector ( Teuchos::Ptr< const MV > &mv ) {
49 return mv->getMVPointer_impl();
61 template <
typename MV>
62 void same_type_get_copy<MV>::apply(
const Teuchos::Ptr<const MV> mv,
63 const Teuchos::ArrayView<typename MV::scalar_t>& v,
65 Teuchos::Ptr<
const Tpetra::Map<typename MV::local_ordinal_t, typename MV::global_ordinal_t, typename MV::node_t> > distribution_map,
68 mv->get1dCopy (v, ldx, distribution_map, distribution);
77 template <
typename MV,
typename S>
78 void diff_type_get_copy<MV,S>::
79 apply (
const Teuchos::Ptr<const MV> mv,
80 const Teuchos::ArrayView<S>& v,
82 Teuchos::Ptr<
const Tpetra::Map<typename MV::local_ordinal_t, typename MV::global_ordinal_t, typename MV::node_t> > distribution_map,
85 typedef typename MV::scalar_t mv_scalar_t;
86 typedef typename Teuchos::Array<mv_scalar_t>::size_type size_type;
88 TEUCHOS_TEST_FOR_EXCEPTION(
89 mv.getRawPtr () == NULL, std::invalid_argument,
90 "Amesos2::diff_type_get_copy::apply: mv is null.");
91 TEUCHOS_TEST_FOR_EXCEPTION(
92 distribution_map.getRawPtr () == NULL, std::invalid_argument,
93 "Amesos2::diff_type_get_copy::apply: distribution_map is null.");
95 const size_type vals_length = v.size ();
96 Teuchos::Array<mv_scalar_t> vals_tmp (vals_length);
98 mv->get1dCopy (vals_tmp (), ldx, distribution_map, distribution);
99 for (size_type i = 0; i < vals_length; ++i) {
100 v[i] = Teuchos::as<S> (vals_tmp[i]);
110 template <
class MV,
typename S>
112 do_get (
const Teuchos::Ptr<const MV>& mv,
113 const Teuchos::ArrayView<S>& vals,
115 Teuchos::Ptr<
const Tpetra::Map<typename MV::local_ordinal_t, typename MV::global_ordinal_t, typename MV::node_t> > distribution_map,
119 std::conditional_t<std::is_same_v<typename MV::scalar_t,S>,
120 same_type_get_copy<MV>,
121 diff_type_get_copy<MV,S> >::apply (mv, vals, ldx, distribution_map, distribution);
124 template <
class MV,
typename S>
126 do_get (
const Teuchos::Ptr<const MV>& mv,
127 const Teuchos::ArrayView<S>& vals,
130 typename MV::global_ordinal_t indexBase)
132 typedef typename MV::local_ordinal_t lo_t;
133 typedef typename MV::global_ordinal_t go_t;
134 typedef typename MV::global_size_t gs_t;
135 typedef typename MV::node_t node_t;
137 TEUCHOS_TEST_FOR_EXCEPTION(
138 mv.getRawPtr () == NULL, std::invalid_argument,
139 "Amesos2::get_1d_copy_helper::do_get(5 args): mv is null.");
141 Teuchos::RCP<const Tpetra::Map<lo_t,go_t,node_t> > map
142 = Amesos2::Util::getDistributionMap<lo_t,go_t,gs_t,node_t> (distribution,
143 mv->getGlobalLength (),
148 do_get (mv, vals, ldx, Teuchos::ptrInArg (*map), distribution);
151 template <
class MV,
typename S>
153 const Teuchos::ArrayView<S>& vals,
156 typedef Tpetra::Map<
typename MV::local_ordinal_t,
157 typename MV::global_ordinal_t,
158 typename MV::node_t> map_type;
159 TEUCHOS_TEST_FOR_EXCEPTION(
160 mv.getRawPtr () == NULL, std::invalid_argument,
161 "Amesos2::get_1d_copy_helper::do_get(3 args): mv is null.");
163 Teuchos::RCP<const map_type> map = mv->getMap ();
164 TEUCHOS_TEST_FOR_EXCEPTION(
165 map.is_null (), std::invalid_argument,
166 "Amesos2::get_1d_copy_helper::do_get(3 args): mv->getMap() is null.");
169 do_get (mv, vals, ldx, Teuchos::ptrInArg (*map), ROOTED);
172 template <
class MV,
typename KV>
173 bool get_1d_copy_helper_kokkos_view<MV,KV>::
174 do_get (
bool bInitialize,
175 const Teuchos::Ptr<const MV>& mv,
178 Teuchos::Ptr<
const Tpetra::Map<typename MV::local_ordinal_t, typename MV::global_ordinal_t, typename MV::node_t> > distribution_map,
181 return mv->get1dCopy_kokkos_view(bInitialize, kokkos_vals, ldx, distribution_map, distribution);
184 template <
class MV,
typename KV>
185 bool get_1d_copy_helper_kokkos_view<MV,KV>::
186 do_get (
bool bInitialize,
187 const Teuchos::Ptr<const MV>& mv,
191 typename MV::global_ordinal_t indexBase)
193 typedef typename MV::local_ordinal_t lo_t;
194 typedef typename MV::global_ordinal_t go_t;
195 typedef typename MV::global_size_t gs_t;
196 typedef typename MV::node_t node_t;
198 TEUCHOS_TEST_FOR_EXCEPTION(
199 mv.getRawPtr () == NULL, std::invalid_argument,
200 "Amesos2::get_1d_copy_helper_kokkos_view::do_get(5 args): mv is null.");
202 Teuchos::RCP<const Tpetra::Map<lo_t,go_t,node_t> > map
203 = Amesos2::Util::getDistributionMap<lo_t,go_t,gs_t,node_t> (distribution,
204 mv->getGlobalLength (),
209 return do_get (bInitialize, mv, kokkos_vals, ldx, Teuchos::ptrInArg (*map), distribution);
212 template <
class MV,
typename KV>
213 bool get_1d_copy_helper_kokkos_view<MV,KV>::
214 do_get (
bool bInitialize,
215 const Teuchos::Ptr<const MV>& mv,
219 typedef Tpetra::Map<
typename MV::local_ordinal_t,
220 typename MV::global_ordinal_t,
221 typename MV::node_t> map_type;
222 TEUCHOS_TEST_FOR_EXCEPTION(
223 mv.getRawPtr () == NULL, std::invalid_argument,
224 "Amesos2::get_1d_copy_helper::do_get(3 args): mv is null.");
226 Teuchos::RCP<const map_type> map = mv->getMap ();
227 TEUCHOS_TEST_FOR_EXCEPTION(
228 map.is_null (), std::invalid_argument,
229 "Amesos2::get_1d_copy_helper_kokkos_view::do_get(3 args): mv->getMap() is null.");
231 return do_get (bInitialize, mv, kokkos_vals, ldx, Teuchos::ptrInArg (*map), ROOTED);
239 template <
typename MV>
240 void same_type_data_put<MV>::apply(
const Teuchos::Ptr<MV>& mv,
241 const Teuchos::ArrayView<typename MV::scalar_t>& data,
243 Teuchos::Ptr<
const Tpetra::Map<typename MV::local_ordinal_t, typename MV::global_ordinal_t, typename MV::node_t> > distribution_map,
246 mv->put1dData (data, ldx, distribution_map, distribution);
255 template <
typename MV,
typename S>
256 void diff_type_data_put<MV,S>::apply(
const Teuchos::Ptr<MV>& mv,
257 const Teuchos::ArrayView<S>& data,
259 Teuchos::Ptr<
const Tpetra::Map<typename MV::local_ordinal_t, typename MV::global_ordinal_t, typename MV::node_t> > distribution_map,
262 typedef typename MV::scalar_t mv_scalar_t;
263 typedef typename Teuchos::Array<mv_scalar_t>::size_type size_type;
265 TEUCHOS_TEST_FOR_EXCEPTION(
266 mv.getRawPtr () == NULL, std::invalid_argument,
267 "Amesos2::diff_type_data_put(4 args): mv is null.");
269 const size_type vals_length = data.size ();
270 Teuchos::Array<mv_scalar_t> data_tmp (vals_length);
272 for (size_type i = 0; i < vals_length; ++i) {
273 data_tmp[i] = Teuchos::as<mv_scalar_t> (data[i]);
276 mv->put1dData (data_tmp (), ldx, distribution_map, distribution);
286 template <
class MV,
typename S>
288 const Teuchos::ArrayView<S>& data,
290 Teuchos::Ptr<
const Tpetra::Map<typename MV::local_ordinal_t, typename MV::global_ordinal_t, typename MV::node_t> > distribution_map,
294 std::conditional_t<std::is_same_v<typename MV::scalar_t,S>,
295 same_type_data_put<MV>,
296 diff_type_data_put<MV,S> >::apply(mv, data, ldx, distribution_map, distribution);
299 template <
class MV,
typename S>
301 const Teuchos::ArrayView<S>& data,
303 EDistribution distribution,
typename MV::global_ordinal_t indexBase)
305 typedef typename MV::local_ordinal_t lo_t;
306 typedef typename MV::global_ordinal_t go_t;
307 typedef typename MV::global_size_t gs_t;
308 typedef typename MV::node_t node_t;
310 const Teuchos::RCP<const Tpetra::Map<lo_t,go_t,node_t> > map
311 = Amesos2::Util::getDistributionMap<lo_t,go_t,gs_t,node_t>(distribution,
312 mv->getGlobalLength(),
317 do_put(mv, data, ldx, Teuchos::ptrInArg(*map), distribution);
320 template <
class MV,
typename S>
322 const Teuchos::ArrayView<S>& data,
325 const Teuchos::RCP<
const Tpetra::Map<
typename MV::local_ordinal_t,
326 typename MV::global_ordinal_t,
327 typename MV::node_t> > map
329 do_put (mv, data, ldx, Teuchos::ptrInArg (*map), ROOTED);
332 template <
class MV,
typename KV>
333 void put_1d_data_helper_kokkos_view<MV,KV>::do_put(
const Teuchos::Ptr<MV>& mv,
336 Teuchos::Ptr<
const Tpetra::Map<typename MV::local_ordinal_t, typename MV::global_ordinal_t, typename MV::node_t> > distribution_map,
339 mv->put1dData_kokkos_view(kokkos_data, ldx, distribution_map, distribution);
342 template <
class MV,
typename KV>
343 void put_1d_data_helper_kokkos_view<MV,KV>::do_put(
const Teuchos::Ptr<MV>& mv,
346 EDistribution distribution,
typename MV::global_ordinal_t indexBase)
348 typedef typename MV::local_ordinal_t lo_t;
349 typedef typename MV::global_ordinal_t go_t;
350 typedef typename MV::global_size_t gs_t;
351 typedef typename MV::node_t node_t;
353 const Teuchos::RCP<const Tpetra::Map<lo_t,go_t,node_t> > map
354 = Amesos2::Util::getDistributionMap<lo_t,go_t,gs_t,node_t>(distribution,
355 mv->getGlobalLength(),
360 do_put(mv, kokkos_data, ldx, Teuchos::ptrInArg(*map), distribution);
363 template <
class MV,
typename KV>
364 void put_1d_data_helper_kokkos_view<MV,KV>::do_put (
const Teuchos::Ptr<MV>& mv,
368 const Teuchos::RCP<
const Tpetra::Map<
typename MV::local_ordinal_t,
369 typename MV::global_ordinal_t,
370 typename MV::node_t> > map
372 do_put (mv, kokkos_data, ldx, Teuchos::ptrInArg (*map), ROOTED);
379 #endif // AMESOS2_EPETRAMULTIVECADAPTER_DEF
Utility functions for Amesos2.
Amesos2::MultiVecAdapter specialization for the Kokkos::View class.
static void do_get(const Teuchos::Ptr< const MV > &mv, const Teuchos::ArrayView< S > &vals, const size_t ldx, Teuchos::Ptr< const Tpetra::Map< typename MV::local_ordinal_t, typename MV::global_ordinal_t, typename MV::node_t > > distribution_map, EDistribution distribution=ROOTED)
Helper class for getting 1-D copies of multivectors.
Definition: Amesos2_MultiVecAdapter_def.hpp:112
Amesos2::MultiVecAdapter specialization for the Tpetra::MultiVector class.
static void do_put(const Teuchos::Ptr< MV > &mv, const Teuchos::ArrayView< S > &data, const size_t ldx, Teuchos::Ptr< const Tpetra::Map< typename MV::local_ordinal_t, typename MV::global_ordinal_t, typename MV::node_t > > distribution_map, EDistribution distribution=ROOTED)
Helper class for putting 1-D data arrays into multivectors.
Definition: Amesos2_MultiVecAdapter_def.hpp:287
EDistribution
Definition: Amesos2_TypeDecl.hpp:89