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 "Kokkos_Blas1_MV.hpp" 60 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node, const
bool classic>
62 Vector (
const Teuchos::RCP<const map_type>& map,
67 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node, const
bool classic>
73 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node, const
bool classic>
76 const Teuchos::DataAccess copyOrView)
80 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node, const
bool classic>
82 Vector (
const Teuchos::RCP<const map_type>& map,
83 const Teuchos::ArrayView<const Scalar>& values)
84 :
base_type (map, values, values.size (), 1)
87 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node, const
bool classic>
89 Vector (
const Teuchos::RCP<const map_type>& map,
94 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node, const
bool classic>
96 Vector (
const Teuchos::RCP<const map_type>& map,
102 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node, const
bool classic>
107 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node, const
bool classic>
114 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node, const
bool classic>
119 const bool atomic)
const 124 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node, const
bool classic>
131 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node, const
bool classic>
136 const bool atomic)
const 141 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node, const
bool classic>
149 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node, const
bool classic>
155 this->
dot (y, Teuchos::arrayView (&result, 1));
159 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node, const
bool classic>
165 this->
meanValue (Teuchos::arrayView (&mean, 1));
169 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node, const
bool classic>
175 this->
norm1 (Teuchos::arrayView (&norm, 1));
179 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node, const
bool classic>
185 this->
norm2 (Teuchos::arrayView (&norm, 1));
189 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node, const
bool classic>
195 this->
normInf (Teuchos::arrayView (&norm, 1));
199 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node, const
bool classic>
206 using Kokkos::subview;
209 using Teuchos::reduceAll;
210 using Teuchos::REDUCE_SUM;
211 typedef Kokkos::Details::ArithTraits<impl_scalar_type> ATS;
212 typedef Kokkos::Details::ArithTraits<mag_type> ATM;
213 typedef Kokkos::View<mag_type, device_type> norm_view_type;
214 const char tfecfFuncName[] =
"normWeighted: ";
216 #ifdef HAVE_TPETRA_DEBUG 217 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(
218 ! this->
getMap ()->isCompatible (*weights.
getMap ()), std::runtime_error,
219 "Vectors do not have compatible Maps:" << std::endl
220 <<
"this->getMap(): " << std::endl << *this->
getMap()
221 <<
"weights.getMap(): " << std::endl << *weights.
getMap() << std::endl);
224 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(
226 "Vectors do not have the same local length.");
227 #endif // HAVE_TPETRA_DEBUG 229 norm_view_type lclNrm (
"lclNrm");
232 auto X_lcl = this->
template getLocalView<device_type> ();
233 auto W_lcl = this->
template getLocalView<device_type> ();
234 KokkosBlas::nrm2w_squared (lclNrm,
235 subview (X_lcl, ALL (), 0),
236 subview (W_lcl, ALL (), 0));
239 RCP<const Comm<int> > comm = this->
getMap ().is_null () ?
240 Teuchos::null : this->
getMap ()->getComm ();
244 reduceAll<int, mag_type> (*comm, REDUCE_SUM, 1, lclNrm.ptr_on_device (),
246 gblNrm = ATM::sqrt (gblNrm * OneOverN);
249 auto lclNrm_h = Kokkos::create_mirror_view (lclNrm);
251 gblNrm = ATM::sqrt (ATS::magnitude (lclNrm_h()) * OneOverN);
257 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node, const
bool classic>
264 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node, const
bool classic>
267 const Teuchos::EVerbosityLevel verbLevel)
const 272 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node, const
bool classic>
286 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node, const
bool classic>
287 Teuchos::RCP<const Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node, classic> >
289 offsetView (
const Teuchos::RCP<const map_type>& subMap,
290 const size_t offset)
const 293 using Kokkos::subview;
297 const size_t newNumRows = subMap->getNodeNumElements ();
300 const int myRank = this->
getMap ()->getComm ()->getRank ();
301 TEUCHOS_TEST_FOR_EXCEPTION(
302 newNumRows + offset > this->
getLocalLength (), std::runtime_error,
303 "Tpetra::Vector::offsetView(NonConst): Invalid input Map. The input " 304 "Map owns " << newNumRows <<
" entries on process " << myRank <<
". " 305 "offset = " << offset <<
". Yet, the Vector contains only " 306 << this->getOrigNumLocalRows () <<
" rows on this process.");
309 const std::pair<size_t, size_t> offsetPair (offset, offset + newNumRows);
311 return rcp (
new V (subMap,
312 subview (this->
view_, offsetPair, ALL ()),
316 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node, const
bool classic>
317 Teuchos::RCP<Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node, classic> >
323 return Teuchos::rcp_const_cast<V> (this->offsetView (subMap, offset));
336 #define TPETRA_VECTOR_INSTANT(SCALAR,LO,GO,NODE) \ 337 template class Vector< SCALAR , LO , GO , NODE >; \ 338 template Vector< SCALAR , LO , GO , NODE > createCopy (const Vector< SCALAR , LO , GO , NODE >& src); 340 #endif // TPETRA_VECTOR_DEF_HPP Vector(const Teuchos::RCP< const map_type > &map, const bool zeroOut=true)
Basic constructor.
Namespace Tpetra contains the class and methods constituting the Tpetra library.
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.
virtual std::string description() const
Return a one-line description of this object.
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.
base_type::dot_type dot_type
Type of an inner ("dot") product result.
void deep_copy(MultiVector< DS, DL, DG, DN, dstClassic > &dst, const MultiVector< SS, SL, SG, SN, srcClassic > &src)
Copy the contents of the MultiVector src into dst.
dual_view_type view_
The Kokkos::DualView containing the MultiVector's data.
Kokkos::Details::InnerProductSpaceTraits< impl_scalar_type >::dot_type dot_type
Type of an inner ("dot") product result.
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.
base_type::mag_type mag_type
Type of a norm result.
mag_type normInf() const
Return the infinity-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.
mag_type norm1() const
Return the one-norm of this Vector.
size_t getLocalLength() const
Local number of rows on the calling process.
virtual ~Vector()
Destructor.
mag_type norm2() const
Return the two-norm of this Vector.
void replaceLocalValue(const LocalOrdinal lclRow, const size_t col, const impl_scalar_type &value) const
Replace value in host memory, using local (row) index.
global_size_t getGlobalLength() const
Global number of rows in the multivector.
dot_type dot(const Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node, classic > &y) const
Return the dot product of this Vector and the input Vector x.
virtual Teuchos::RCP< const map_type > getMap() const
The Map describing the parallel distribution of this object.
void sumIntoLocalValue(const LocalOrdinal myRow, const Scalar &value, const bool atomic=base_type::useAtomicUpdatesByDefault) const
Add value to existing value, using local (row) index.
void get1dCopy(const Teuchos::ArrayView< Scalar > &A) const
Return multi-vector values in user-provided two-dimensional array (using Teuchos memory management cl...
void replaceGlobalValue(const GlobalOrdinal globalRow, const Scalar &value) const
Replace current value at the specified location with specified value.
Kokkos::Details::ArithTraits< impl_scalar_type >::mag_type mag_type
Type of a norm result.
void replaceLocalValue(const LocalOrdinal myRow, const Scalar &value) const
Replace current value at the specified location with specified values.
Kokkos::DualView< impl_scalar_type **, Kokkos::LayoutLeft, typename execution_space::execution_space > dual_view_type
Kokkos::DualView specialization used by this class.
Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node, classic > createCopy(const Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node, classic > &src)
Return a deep copy of the given Vector.
void sumIntoGlobalValue(const GlobalOrdinal globalRow, const Scalar &value, const bool atomic=base_type::useAtomicUpdatesByDefault) const
Add value to existing value, using global (row) index.
A distributed dense vector.
size_t getOrigNumLocalRows() const
"Original" number of rows in the (local) data.
bool isDistributed() const
Whether this is a globally distributed object.
mag_type TPETRA_DEPRECATED normWeighted(const Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node, classic > &weights) const
Compute Weighted 2-norm (RMS Norm) of this Vector.
Scalar meanValue() const
Compute mean (average) value of this Vector.
dual_view_type origView_
The "original view" of the MultiVector's data.
std::string descriptionImpl(const std::string &className) const
Implementation of description() for this class, and its subclass Vector.
void replaceGlobalValue(const GlobalOrdinal gblRow, const size_t col, const impl_scalar_type &value) const
Replace value in host memory, using global row index.