45 #ifndef AMESOS2_MULTIVECADAPTER_DEF_HPP
46 #define AMESOS2_MULTIVECADAPTER_DEF_HPP
62 template <
typename MV,
typename V>
63 typename vector_pointer_helper<MV, V>::ptr_return_type *
64 vector_pointer_helper<MV, V>::get_pointer_to_vector (
const Teuchos::Ptr< MV > &mv ) {
65 return mv->getMVPointer_impl();
68 template <
typename MV,
typename V>
69 typename vector_pointer_helper<MV, V>::ptr_return_type *
70 vector_pointer_helper<MV, V>::get_pointer_to_vector ( Teuchos::Ptr< MV > &mv ) {
71 return mv->getMVPointer_impl();
74 template <
typename MV,
typename V>
75 typename vector_pointer_helper<MV, V>::ptr_return_type *
76 vector_pointer_helper<MV, V>::get_pointer_to_vector (
const Teuchos::Ptr< const MV > &mv ) {
77 return mv->getMVPointer_impl();
80 template <
typename MV,
typename V>
81 typename vector_pointer_helper<MV, V>::ptr_return_type *
82 vector_pointer_helper<MV, V>::get_pointer_to_vector ( Teuchos::Ptr< const MV > &mv ) {
83 return mv->getMVPointer_impl();
95 template <
typename MV>
96 void same_type_get_copy<MV>::apply(
const Teuchos::Ptr<const MV> mv,
97 const Teuchos::ArrayView<typename MV::scalar_t>& v,
99 Teuchos::Ptr<
const Tpetra::Map<typename MV::local_ordinal_t, typename MV::global_ordinal_t, typename MV::node_t> > distribution_map,
102 mv->get1dCopy (v, ldx, distribution_map, distribution);
111 template <
typename MV,
typename S>
112 void diff_type_get_copy<MV,S>::
113 apply (
const Teuchos::Ptr<const MV> mv,
114 const Teuchos::ArrayView<S>& v,
116 Teuchos::Ptr<
const Tpetra::Map<typename MV::local_ordinal_t, typename MV::global_ordinal_t, typename MV::node_t> > distribution_map,
119 typedef typename MV::scalar_t mv_scalar_t;
120 typedef typename Teuchos::Array<mv_scalar_t>::size_type size_type;
122 TEUCHOS_TEST_FOR_EXCEPTION(
123 mv.getRawPtr () == NULL, std::invalid_argument,
124 "Amesos2::diff_type_get_copy::apply: mv is null.");
125 TEUCHOS_TEST_FOR_EXCEPTION(
126 distribution_map.getRawPtr () == NULL, std::invalid_argument,
127 "Amesos2::diff_type_get_copy::apply: distribution_map is null.");
129 const size_type vals_length = v.size ();
130 Teuchos::Array<mv_scalar_t> vals_tmp (vals_length);
132 mv->get1dCopy (vals_tmp (), ldx, distribution_map, distribution);
133 for (size_type i = 0; i < vals_length; ++i) {
134 v[i] = Teuchos::as<S> (vals_tmp[i]);
144 template <
class MV,
typename S>
146 do_get (
const Teuchos::Ptr<const MV>& mv,
147 const Teuchos::ArrayView<S>& vals,
149 Teuchos::Ptr<
const Tpetra::Map<typename MV::local_ordinal_t, typename MV::global_ordinal_t, typename MV::node_t> > distribution_map,
153 if_then_else<is_same<typename MV::scalar_t,S>::value,
154 same_type_get_copy<MV>,
155 diff_type_get_copy<MV,S> >::type::apply (mv, vals, ldx, distribution_map, distribution);
158 template <
class MV,
typename S>
160 do_get (
const Teuchos::Ptr<const MV>& mv,
161 const Teuchos::ArrayView<S>& vals,
164 typename MV::global_ordinal_t indexBase)
166 typedef typename MV::local_ordinal_t lo_t;
167 typedef typename MV::global_ordinal_t go_t;
168 typedef typename MV::global_size_t gs_t;
169 typedef typename MV::node_t node_t;
171 TEUCHOS_TEST_FOR_EXCEPTION(
172 mv.getRawPtr () == NULL, std::invalid_argument,
173 "Amesos2::get_1d_copy_helper::do_get(5 args): mv is null.");
175 Teuchos::RCP<const Tpetra::Map<lo_t,go_t,node_t> > map
176 = Amesos2::Util::getDistributionMap<lo_t,go_t,gs_t,node_t> (distribution,
177 mv->getGlobalLength (),
182 do_get (mv, vals, ldx, Teuchos::ptrInArg (*map), distribution);
185 template <
class MV,
typename S>
187 const Teuchos::ArrayView<S>& vals,
190 typedef Tpetra::Map<
typename MV::local_ordinal_t,
191 typename MV::global_ordinal_t,
192 typename MV::node_t> map_type;
193 TEUCHOS_TEST_FOR_EXCEPTION(
194 mv.getRawPtr () == NULL, std::invalid_argument,
195 "Amesos2::get_1d_copy_helper::do_get(3 args): mv is null.");
197 Teuchos::RCP<const map_type> map = mv->getMap ();
198 TEUCHOS_TEST_FOR_EXCEPTION(
199 map.is_null (), std::invalid_argument,
200 "Amesos2::get_1d_copy_helper::do_get(3 args): mv->getMap() is null.");
203 do_get (mv, vals, ldx, Teuchos::ptrInArg (*map), ROOTED);
206 template <
class MV,
typename KV>
207 void get_1d_copy_helper_kokkos_view<MV,KV>::
208 do_get (
const Teuchos::Ptr<const MV>& mv,
211 Teuchos::Ptr<
const Tpetra::Map<typename MV::local_ordinal_t, typename MV::global_ordinal_t, typename MV::node_t> > distribution_map,
214 mv->get1dCopy_kokkos_view(kokkos_vals, ldx, distribution_map, distribution);
217 template <
class MV,
typename KV>
218 void get_1d_copy_helper_kokkos_view<MV,KV>::
219 do_get (
const Teuchos::Ptr<const MV>& mv,
223 typename MV::global_ordinal_t indexBase)
225 typedef typename MV::local_ordinal_t lo_t;
226 typedef typename MV::global_ordinal_t go_t;
227 typedef typename MV::global_size_t gs_t;
228 typedef typename MV::node_t node_t;
230 TEUCHOS_TEST_FOR_EXCEPTION(
231 mv.getRawPtr () == NULL, std::invalid_argument,
232 "Amesos2::get_1d_copy_helper_kokkos_view::do_get(5 args): mv is null.");
234 Teuchos::RCP<const Tpetra::Map<lo_t,go_t,node_t> > map
235 = Amesos2::Util::getDistributionMap<lo_t,go_t,gs_t,node_t> (distribution,
236 mv->getGlobalLength (),
241 do_get (mv, kokkos_vals, ldx, Teuchos::ptrInArg (*map), distribution);
244 template <
class MV,
typename KV>
245 void get_1d_copy_helper_kokkos_view<MV,KV>::do_get(
const Teuchos::Ptr<const MV>& mv,
249 typedef Tpetra::Map<
typename MV::local_ordinal_t,
250 typename MV::global_ordinal_t,
251 typename MV::node_t> map_type;
252 TEUCHOS_TEST_FOR_EXCEPTION(
253 mv.getRawPtr () == NULL, std::invalid_argument,
254 "Amesos2::get_1d_copy_helper::do_get(3 args): mv is null.");
256 Teuchos::RCP<const map_type> map = mv->getMap ();
257 TEUCHOS_TEST_FOR_EXCEPTION(
258 map.is_null (), std::invalid_argument,
259 "Amesos2::get_1d_copy_helper_kokkos_view::do_get(3 args): mv->getMap() is null.");
261 do_get (mv, kokkos_vals, ldx, Teuchos::ptrInArg (*map), ROOTED);
269 template <
typename MV>
270 void same_type_data_put<MV>::apply(
const Teuchos::Ptr<MV>& mv,
271 const Teuchos::ArrayView<typename MV::scalar_t>& data,
273 Teuchos::Ptr<
const Tpetra::Map<typename MV::local_ordinal_t, typename MV::global_ordinal_t, typename MV::node_t> > distribution_map,
276 mv->put1dData (data, ldx, distribution_map, distribution);
285 template <
typename MV,
typename S>
286 void diff_type_data_put<MV,S>::apply(
const Teuchos::Ptr<MV>& mv,
287 const Teuchos::ArrayView<S>& data,
289 Teuchos::Ptr<
const Tpetra::Map<typename MV::local_ordinal_t, typename MV::global_ordinal_t, typename MV::node_t> > distribution_map,
292 typedef typename MV::scalar_t mv_scalar_t;
293 typedef typename Teuchos::Array<mv_scalar_t>::size_type size_type;
295 TEUCHOS_TEST_FOR_EXCEPTION(
296 mv.getRawPtr () == NULL, std::invalid_argument,
297 "Amesos2::diff_type_data_put(4 args): mv is null.");
299 const size_type vals_length = data.size ();
300 Teuchos::Array<mv_scalar_t> data_tmp (vals_length);
302 for (size_type i = 0; i < vals_length; ++i) {
303 data_tmp[i] = Teuchos::as<mv_scalar_t> (data[i]);
306 mv->put1dData (data_tmp (), ldx, distribution_map, distribution);
316 template <
class MV,
typename S>
318 const Teuchos::ArrayView<S>& data,
320 Teuchos::Ptr<
const Tpetra::Map<typename MV::local_ordinal_t, typename MV::global_ordinal_t, typename MV::node_t> > distribution_map,
324 if_then_else<is_same<typename MV::scalar_t,S>::value,
325 same_type_data_put<MV>,
326 diff_type_data_put<MV,S> >::type::apply(mv, data, ldx, distribution_map, distribution);
329 template <
class MV,
typename S>
331 const Teuchos::ArrayView<S>& data,
333 EDistribution distribution,
typename MV::global_ordinal_t indexBase)
335 typedef typename MV::local_ordinal_t lo_t;
336 typedef typename MV::global_ordinal_t go_t;
337 typedef typename MV::global_size_t gs_t;
338 typedef typename MV::node_t node_t;
340 const Teuchos::RCP<const Tpetra::Map<lo_t,go_t,node_t> > map
341 = Amesos2::Util::getDistributionMap<lo_t,go_t,gs_t,node_t>(distribution,
342 mv->getGlobalLength(),
347 do_put(mv, data, ldx, Teuchos::ptrInArg(*map), distribution);
350 template <
class MV,
typename S>
352 const Teuchos::ArrayView<S>& data,
355 const Teuchos::RCP<
const Tpetra::Map<
typename MV::local_ordinal_t,
356 typename MV::global_ordinal_t,
357 typename MV::node_t> > map
359 do_put (mv, data, ldx, Teuchos::ptrInArg (*map), ROOTED);
362 template <
class MV,
typename KV>
363 void put_1d_data_helper_kokkos_view<MV,KV>::do_put(
const Teuchos::Ptr<MV>& mv,
366 Teuchos::Ptr<
const Tpetra::Map<typename MV::local_ordinal_t, typename MV::global_ordinal_t, typename MV::node_t> > distribution_map,
369 mv->put1dData_kokkos_view(kokkos_data, ldx, distribution_map, distribution);
372 template <
class MV,
typename KV>
373 void put_1d_data_helper_kokkos_view<MV,KV>::do_put(
const Teuchos::Ptr<MV>& mv,
376 EDistribution distribution,
typename MV::global_ordinal_t indexBase)
378 typedef typename MV::local_ordinal_t lo_t;
379 typedef typename MV::global_ordinal_t go_t;
380 typedef typename MV::global_size_t gs_t;
381 typedef typename MV::node_t node_t;
383 const Teuchos::RCP<const Tpetra::Map<lo_t,go_t,node_t> > map
384 = Amesos2::Util::getDistributionMap<lo_t,go_t,gs_t,node_t>(distribution,
385 mv->getGlobalLength(),
390 do_put(mv, kokkos_data, ldx, Teuchos::ptrInArg(*map), distribution);
393 template <
class MV,
typename KV>
394 void put_1d_data_helper_kokkos_view<MV,KV>::do_put (
const Teuchos::Ptr<MV>& mv,
398 const Teuchos::RCP<
const Tpetra::Map<
typename MV::local_ordinal_t,
399 typename MV::global_ordinal_t,
400 typename MV::node_t> > map
402 do_put (mv, kokkos_data, ldx, Teuchos::ptrInArg (*map), ROOTED);
409 #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:146
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:317
EDistribution
Definition: Amesos2_TypeDecl.hpp:123