45 #ifndef AMESOS2_MULTIVECADAPTER_DEF_HPP
46 #define AMESOS2_MULTIVECADAPTER_DEF_HPP
61 template <
typename MV,
typename V>
62 typename vector_pointer_helper<MV, V>::ptr_return_type *
63 vector_pointer_helper<MV, V>::get_pointer_to_vector (
const Teuchos::Ptr< MV > &mv ) {
64 return mv->getMVPointer_impl();
67 template <
typename MV,
typename V>
68 typename vector_pointer_helper<MV, V>::ptr_return_type *
69 vector_pointer_helper<MV, V>::get_pointer_to_vector ( Teuchos::Ptr< MV > &mv ) {
70 return mv->getMVPointer_impl();
73 template <
typename MV,
typename V>
74 typename vector_pointer_helper<MV, V>::ptr_return_type *
75 vector_pointer_helper<MV, V>::get_pointer_to_vector (
const Teuchos::Ptr< const MV > &mv ) {
76 return mv->getMVPointer_impl();
79 template <
typename MV,
typename V>
80 typename vector_pointer_helper<MV, V>::ptr_return_type *
81 vector_pointer_helper<MV, V>::get_pointer_to_vector ( Teuchos::Ptr< const MV > &mv ) {
82 return mv->getMVPointer_impl();
94 template <
typename MV>
95 void same_type_get_copy<MV>::apply(
const Teuchos::Ptr<const MV>& mv,
96 const Teuchos::ArrayView<typename MV::scalar_t>& v,
98 Teuchos::Ptr<
const Tpetra::Map<typename MV::local_ordinal_t, typename MV::global_ordinal_t, typename MV::node_t> > distribution_map,
101 mv->get1dCopy (v, ldx, distribution_map, distribution);
110 template <
typename MV,
typename S>
111 void diff_type_get_copy<MV,S>::
112 apply (
const Teuchos::Ptr<const MV>& mv,
113 const Teuchos::ArrayView<S>& v,
115 Teuchos::Ptr<
const Tpetra::Map<typename MV::local_ordinal_t, typename MV::global_ordinal_t, typename MV::node_t> > distribution_map,
118 typedef typename MV::scalar_t mv_scalar_t;
119 typedef typename Teuchos::Array<mv_scalar_t>::size_type size_type;
121 TEUCHOS_TEST_FOR_EXCEPTION(
122 mv.getRawPtr () == NULL, std::invalid_argument,
123 "Amesos2::diff_type_get_copy::apply: mv is null.");
124 TEUCHOS_TEST_FOR_EXCEPTION(
125 distribution_map.getRawPtr () == NULL, std::invalid_argument,
126 "Amesos2::diff_type_get_copy::apply: distribution_map is null.");
128 const size_type vals_length = v.size ();
129 Teuchos::Array<mv_scalar_t> vals_tmp (vals_length);
131 mv->get1dCopy (vals_tmp (), ldx, distribution_map, distribution);
132 for (size_type i = 0; i < vals_length; ++i) {
133 v[i] = Teuchos::as<S> (vals_tmp[i]);
143 template <
class MV,
typename S>
145 do_get (
const Teuchos::Ptr<const MV>& mv,
146 const Teuchos::ArrayView<S>& vals,
148 Teuchos::Ptr<
const Tpetra::Map<typename MV::local_ordinal_t, typename MV::global_ordinal_t, typename MV::node_t> > distribution_map,
152 if_then_else<is_same<typename MV::scalar_t,S>::value,
153 same_type_get_copy<MV>,
154 diff_type_get_copy<MV,S> >::type::apply (mv, vals, ldx, distribution_map, distribution);
157 template <
class MV,
typename S>
159 do_get (
const Teuchos::Ptr<const MV>& mv,
160 const Teuchos::ArrayView<S>& vals,
163 typename MV::global_ordinal_t indexBase)
165 typedef typename MV::local_ordinal_t lo_t;
166 typedef typename MV::global_ordinal_t go_t;
167 typedef typename MV::global_size_t gs_t;
168 typedef typename MV::node_t node_t;
170 TEUCHOS_TEST_FOR_EXCEPTION(
171 mv.getRawPtr () == NULL, std::invalid_argument,
172 "Amesos2::get_1d_copy_helper::do_get(5 args): mv is null.");
174 Teuchos::RCP<const Tpetra::Map<lo_t,go_t,node_t> > map
175 = Amesos2::Util::getDistributionMap<lo_t,go_t,gs_t,node_t> (distribution,
176 mv->getGlobalLength (),
181 do_get (mv, vals, ldx, Teuchos::ptrInArg (*map), distribution);
184 template <
class MV,
typename S>
186 const Teuchos::ArrayView<S>& vals,
189 typedef Tpetra::Map<
typename MV::local_ordinal_t,
190 typename MV::global_ordinal_t,
191 typename MV::node_t> map_type;
192 TEUCHOS_TEST_FOR_EXCEPTION(
193 mv.getRawPtr () == NULL, std::invalid_argument,
194 "Amesos2::get_1d_copy_helper::do_get(3 args): mv is null.");
196 Teuchos::RCP<const map_type> map = mv->getMap ();
197 TEUCHOS_TEST_FOR_EXCEPTION(
198 map.is_null (), std::invalid_argument,
199 "Amesos2::get_1d_copy_helper::do_get(3 args): mv->getMap() is null.");
202 do_get (mv, vals, ldx, Teuchos::ptrInArg (*map), ROOTED);
210 template <
typename MV>
211 void same_type_data_put<MV>::apply(
const Teuchos::Ptr<MV>& mv,
212 const Teuchos::ArrayView<typename MV::scalar_t>& data,
214 Teuchos::Ptr<
const Tpetra::Map<typename MV::local_ordinal_t, typename MV::global_ordinal_t, typename MV::node_t> > distribution_map,
217 mv->put1dData (data, ldx, distribution_map, distribution);
226 template <
typename MV,
typename S>
227 void diff_type_data_put<MV,S>::apply(
const Teuchos::Ptr<MV>& mv,
228 const Teuchos::ArrayView<S>& data,
230 Teuchos::Ptr<
const Tpetra::Map<typename MV::local_ordinal_t, typename MV::global_ordinal_t, typename MV::node_t> > distribution_map,
233 typedef typename MV::scalar_t mv_scalar_t;
234 typedef typename Teuchos::Array<mv_scalar_t>::size_type size_type;
236 TEUCHOS_TEST_FOR_EXCEPTION(
237 mv.getRawPtr () == NULL, std::invalid_argument,
238 "Amesos2::diff_type_data_put(4 args): mv is null.");
240 const size_type vals_length = data.size ();
241 Teuchos::Array<mv_scalar_t> data_tmp (vals_length);
243 for (size_type i = 0; i < vals_length; ++i) {
244 data_tmp[i] = Teuchos::as<mv_scalar_t> (data[i]);
247 mv->put1dData (data_tmp (), ldx, distribution_map, distribution);
257 template <
class MV,
typename S>
259 const Teuchos::ArrayView<S>& data,
261 Teuchos::Ptr<
const Tpetra::Map<typename MV::local_ordinal_t, typename MV::global_ordinal_t, typename MV::node_t> > distribution_map,
265 if_then_else<is_same<typename MV::scalar_t,S>::value,
266 same_type_data_put<MV>,
267 diff_type_data_put<MV,S> >::type::apply(mv, data, ldx, distribution_map, distribution);
270 template <
class MV,
typename S>
272 const Teuchos::ArrayView<S>& data,
274 EDistribution distribution,
typename MV::global_ordinal_t indexBase)
276 typedef typename MV::local_ordinal_t lo_t;
277 typedef typename MV::global_ordinal_t go_t;
278 typedef typename MV::global_size_t gs_t;
279 typedef typename MV::node_t node_t;
281 const Teuchos::RCP<const Tpetra::Map<lo_t,go_t,node_t> > map
282 = Amesos2::Util::getDistributionMap<lo_t,go_t,gs_t,node_t>(distribution,
283 mv->getGlobalLength(),
288 do_put(mv, data, ldx, Teuchos::ptrInArg(*map), distribution);
291 template <
class MV,
typename S>
293 const Teuchos::ArrayView<S>& data,
296 const Teuchos::RCP<
const Tpetra::Map<
typename MV::local_ordinal_t,
297 typename MV::global_ordinal_t,
298 typename MV::node_t> > map
300 do_put (mv, data, ldx, Teuchos::ptrInArg (*map), ROOTED);
307 #endif // AMESOS2_EPETRAMULTIVECADAPTER_DEF
Utility functions for Amesos2.
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:145
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:258
EDistribution
Definition: Amesos2_TypeDecl.hpp:123