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>
129 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
134 const bool atomic)
const 139 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
146 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
151 const bool atomic)
const 156 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
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);
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));
254 RCP<const Comm<int> > comm = this->
getMap ().is_null () ?
255 Teuchos::null : this->
getMap ()->getComm ();
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>
279 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
282 const Teuchos::EVerbosityLevel verbLevel)
const 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 ();
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> >
324 return Teuchos::rcp_const_cast<V> (this->offsetView (subMap, offset));
329 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class 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 lclRow, const size_t col, const impl_scalar_type &value) const
Replace value in host memory, using local (row) index.
void sumIntoGlobalValue(const GlobalOrdinal gblRow, const size_t col, const impl_scalar_type &value, const bool atomic=useAtomicUpdatesByDefault) const
Update (+=) a value in host memory, 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.
global_size_t getGlobalLength() const
Global number of rows in the multivector.
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 describeImpl(Teuchos::FancyOStream &out, const std::string &className, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const
Implementation of describe() for this class, and its subclass Vector.
size_t getOrigNumLocalRows() const
"Original" number of rows in the (local) data.
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.
bool isDistributed() const
Whether this is a globally distributed object.
dual_view_type origView_
The "original view" of the MultiVector's data.
Kokkos::Details::InnerProductSpaceTraits< impl_scalar_type >::dot_type dot_type
Type of an inner ("dot") product result.
dual_view_type view_
The Kokkos::DualView containing the MultiVector's data.
virtual ~Vector()
Destructor.
void replaceGlobalValue(const GlobalOrdinal gblRow, const size_t col, const impl_scalar_type &value) const
Replace value in host memory, using global row index.
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.
std::string descriptionImpl(const std::string &className) const
Implementation of description() for this class, and its subclass 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 sumIntoLocalValue(const LocalOrdinal lclRow, const size_t col, const impl_scalar_type &val, const bool atomic=useAtomicUpdatesByDefault) const
Update (+=) a value in host memory, using local row index.
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.