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>
111 this->base_type::replaceGlobalValue (globalRow, 0, value);
114 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node, const
bool classic>
119 const bool atomic)
const 121 this->base_type::sumIntoGlobalValue (globalRow, 0, value, atomic);
124 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node, const
bool classic>
128 this->base_type::replaceLocalValue (myRow, 0, value);
131 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node, const
bool classic>
136 const bool atomic)
const 138 this->base_type::sumIntoLocalValue (globalRow, 0, value, atomic);
141 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node, const
bool classic>
145 const size_t lda = this->getLocalLength ();
146 this->get1dCopy (A, lda);
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);
223 const size_t lclNumRows = this->getLocalLength ();
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));
238 ATM::one () /
static_cast<mag_type> (this->getGlobalLength ());
239 RCP<const Comm<int> > comm = this->getMap ().is_null () ?
240 Teuchos::null : this->getMap ()->getComm ();
242 if (! comm.is_null () && this->isDistributed ()) {
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>
261 return this->descriptionImpl (
"Tpetra::Vector");
264 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node, const
bool classic>
267 const Teuchos::EVerbosityLevel verbLevel)
const 269 this->describeImpl (out,
"Tpetra::Vector", verbLevel);
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> >
288 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;
295 typedef Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node, classic> V;
297 const size_t newNumRows = subMap->getNodeNumElements ();
298 const bool tooManyElts = newNumRows + offset > this->getOrigNumLocalRows ();
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> >
318 Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node, classic>::
319 offsetViewNonConst (
const Teuchos::RCP<const map_type>& subMap,
322 typedef Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node, classic> V;
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.
MultiVector< ST, LO, GO, NT, classic > createCopy(const MultiVector< ST, LO, GO, NT, classic > &src)
Return a deep copy of the given MultiVector.
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.
Kokkos::Details::InnerProductSpaceTraits< impl_scalar_type >::dot_type dot_type
Type of an inner ("dot") product result.
base_type::mag_type mag_type
Type of a norm result.
mag_type normInf() const
Compute Inf-norm of this Vector.
mag_type norm1() const
Return 1-norm of this Vector.
size_t getLocalLength() const
Local number of rows on the calling process.
virtual ~Vector()
Destructor.
mag_type norm2() const
Compute 2-norm of this Vector.
dot_type dot(const Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node, classic > &y) const
Computes dot product of this Vector against 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.
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.
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.