42 #ifndef TPETRA_VECTOR_DEF_HPP 43 #define TPETRA_VECTOR_DEF_HPP 53 #include "Tpetra_MultiVector.hpp" 54 #include "Tpetra_Details_gathervPrint.hpp" 55 #include "KokkosCompat_View.hpp" 56 #include "KokkosBlas1_nrm2w_squared.hpp" 57 #include "Teuchos_CommHelpers.hpp" 62 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
68 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
70 Vector (
const Teuchos::RCP<const map_type>& map,
75 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
81 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
84 const Teuchos::DataAccess copyOrView)
88 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
90 Vector (
const Teuchos::RCP<const map_type>& map,
91 const Teuchos::ArrayView<const Scalar>& values)
92 :
base_type (map, values, values.size (), 1)
95 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
97 Vector (
const Teuchos::RCP<const map_type>& map,
102 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
104 Vector (
const Teuchos::RCP<const map_type>& map,
110 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
117 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
122 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
126 this->base_type::replaceGlobalValue (globalRow, 0, value);
129 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
134 const bool atomic)
const 136 this->base_type::sumIntoGlobalValue (globalRow, 0, value, atomic);
139 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
143 this->base_type::replaceLocalValue (myRow, 0, value);
146 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
151 const bool atomic)
const 153 this->base_type::sumIntoLocalValue (globalRow, 0, value, atomic);
156 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
160 const size_t lda = this->getLocalLength ();
161 this->get1dCopy (A, lda);
164 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
170 this->dot (y, Teuchos::arrayView (&result, 1));
174 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
180 this->meanValue (Teuchos::arrayView (&mean, 1));
184 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
190 this->norm1 (Teuchos::arrayView (&norm, 1));
194 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
200 this->norm2 (Teuchos::arrayView (&norm, 1));
204 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
210 this->normInf (Teuchos::arrayView (&norm, 1));
214 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
221 using Kokkos::subview;
224 using Teuchos::reduceAll;
225 using Teuchos::REDUCE_SUM;
226 typedef Kokkos::Details::ArithTraits<impl_scalar_type> ATS;
227 typedef Kokkos::Details::ArithTraits<mag_type> ATM;
228 typedef Kokkos::View<mag_type, device_type> norm_view_type;
229 const char tfecfFuncName[] =
"normWeighted: ";
231 #ifdef HAVE_TPETRA_DEBUG 232 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(
233 ! this->getMap ()->isCompatible (*weights.
getMap ()), std::runtime_error,
234 "Vectors do not have compatible Maps:" << std::endl
235 <<
"this->getMap(): " << std::endl << *this->getMap()
236 <<
"weights.getMap(): " << std::endl << *weights.
getMap() << std::endl);
238 const size_t lclNumRows = this->getLocalLength ();
239 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(
241 "Vectors do not have the same local length.");
242 #endif // HAVE_TPETRA_DEBUG 244 norm_view_type lclNrm (
"lclNrm");
247 auto X_lcl = this->
template getLocalView<device_type> ();
248 auto W_lcl = this->
template getLocalView<device_type> ();
249 KokkosBlas::nrm2w_squared (lclNrm,
250 subview (X_lcl, ALL (), 0),
251 subview (W_lcl, ALL (), 0));
253 ATM::one () /
static_cast<mag_type> (this->getGlobalLength ());
254 RCP<const Comm<int> > comm = this->getMap ().is_null () ?
255 Teuchos::null : this->getMap ()->getComm ();
257 if (! comm.is_null () && this->isDistributed ()) {
259 reduceAll<int, mag_type> (*comm, REDUCE_SUM, 1, lclNrm.data (),
261 gblNrm = ATM::sqrt (gblNrm * OneOverN);
264 auto lclNrm_h = Kokkos::create_mirror_view (lclNrm);
266 gblNrm = ATM::sqrt (ATS::magnitude (lclNrm_h()) * OneOverN);
272 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
276 return this->descriptionImpl (
"Tpetra::Vector");
279 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
282 const Teuchos::EVerbosityLevel verbLevel)
const 284 this->describeImpl (out,
"Tpetra::Vector", verbLevel);
287 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
288 Teuchos::RCP<const Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
290 offsetView (
const Teuchos::RCP<const map_type>& subMap,
291 const size_t offset)
const 294 using Kokkos::subview;
298 const size_t newNumRows = subMap->getNodeNumElements ();
299 const bool tooManyElts = newNumRows + offset > this->getOrigNumLocalRows ();
301 const int myRank = this->getMap ()->getComm ()->getRank ();
302 TEUCHOS_TEST_FOR_EXCEPTION(
303 newNumRows + offset > this->getLocalLength (), std::runtime_error,
304 "Tpetra::Vector::offsetView(NonConst): Invalid input Map. The input " 305 "Map owns " << newNumRows <<
" entries on process " << myRank <<
". " 306 "offset = " << offset <<
". Yet, the Vector contains only " 307 << this->getOrigNumLocalRows () <<
" rows on this process.");
310 const std::pair<size_t, size_t> offsetPair (offset, offset + newNumRows);
312 return rcp (
new V (subMap,
313 subview (this->view_, offsetPair, ALL ()),
317 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
318 Teuchos::RCP<Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
319 Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node>::
320 offsetViewNonConst (
const Teuchos::RCP<const map_type>& subMap,
323 typedef Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node> V;
324 return Teuchos::rcp_const_cast<V> (this->offsetView (subMap, offset));
329 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
330 Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node>
336 vec_type dst (src, Teuchos::Copy);
354 #define TPETRA_VECTOR_INSTANT(SCALAR,LO,GO,NODE) \ 355 namespace Classes { \ 356 template class Vector< SCALAR , LO , GO , NODE >; \ 358 template Vector< SCALAR , LO , GO , NODE > createCopy (const Vector< SCALAR , LO , GO , NODE >& src); 360 #endif // TPETRA_VECTOR_DEF_HPP
void sumIntoLocalValue(const LocalOrdinal myRow, const Scalar &value, const bool atomic=base_type::useAtomicUpdatesByDefault) const
Add value to existing value, using local (row) index.
Vector()
Default constructor: makes a Vector with no rows or columns.
Namespace Tpetra contains the class and methods constituting the Tpetra library.
void sumIntoGlobalValue(const GlobalOrdinal globalRow, const Scalar &value, const bool atomic=base_type::useAtomicUpdatesByDefault) const
Add value to existing value, using global (row) index.
void replaceLocalValue(const LocalOrdinal myRow, const Scalar &value) const
Replace current value at the specified location with specified values.
A distributed dense vector.
mag_type TPETRA_DEPRECATED normWeighted(const Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &weights) const
Compute Weighted 2-norm (RMS Norm) of this Vector.
One or more distributed dense vectors.
virtual Teuchos::RCP< const map_type > getMap() const
The Map describing the parallel distribution of this object.
MultiVector< ST, LO, GO, NT > createCopy(const MultiVector< ST, LO, GO, NT > &src)
Return a deep copy of the given MultiVector.
size_t getLocalLength() const
Local number of rows on the calling process.
mag_type normInf() const
Return the infinity-norm of this Vector.
virtual std::string description() const
Return a one-line description of this object.
void deep_copy(MultiVector< DS, DL, DG, DN > &dst, const MultiVector< SS, SL, SG, SN > &src)
Copy the contents of the MultiVector src into dst.
dot_type dot(const Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &y) const
Return the dot product of this Vector and the input Vector x.
Kokkos::DualView< impl_scalar_type **, Kokkos::LayoutLeft, typename execution_space::execution_space > dual_view_type
Kokkos::DualView specialization used by this class.
Kokkos::Details::InnerProductSpaceTraits< impl_scalar_type >::dot_type dot_type
Type of an inner ("dot") product result.
virtual ~Vector()
Destructor.
base_type::dot_type dot_type
Type of an inner ("dot") product result.
Kokkos::Details::ArithTraits< impl_scalar_type >::mag_type mag_type
Type of a norm result.
void get1dCopy(const Teuchos::ArrayView< Scalar > &A) const
Return multi-vector values in user-provided two-dimensional array (using Teuchos memory management cl...
Scalar meanValue() const
Compute mean (average) value of this Vector.
mag_type norm2() const
Return the two-norm of this Vector.
virtual void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const
Describe this object in a human-readable way to the given output stream.
mag_type norm1() const
Return the one-norm of this Vector.
void replaceGlobalValue(const GlobalOrdinal globalRow, const Scalar &value) const
Replace current value at the specified location with specified value.
base_type::mag_type mag_type
Type of a norm result.