Reference documentation for deal.II version 9.5.0
\(\newcommand{\dealvcentcolon}{\mathrel{\mathop{:}}}\) \(\newcommand{\dealcoloneq}{\dealvcentcolon\mathrel{\mkern-1.2mu}=}\) \(\newcommand{\jump}[1]{\left[\!\left[ #1 \right]\!\right]}\) \(\newcommand{\average}[1]{\left\{\!\left\{ #1 \right\}\!\right\}}\)
Loading...
Searching...
No Matches
cuda_vector.h
Go to the documentation of this file.
1// ---------------------------------------------------------------------
2//
3// Copyright (C) 2016 - 2023 by the deal.II authors
4//
5// This file is part of the deal.II library.
6//
7// The deal.II library is free software; you can use it, redistribute
8// it, and/or modify it under the terms of the GNU Lesser General
9// Public License as published by the Free Software Foundation; either
10// version 2.1 of the License, or (at your option) any later version.
11// The full text of the license can be found in the file LICENSE.md at
12// the top level directory of deal.II.
13//
14// ---------------------------------------------------------------------
15
16#ifndef dealii_cuda_vector_h
17#define dealii_cuda_vector_h
18
19#include <deal.II/base/config.h>
20
24
27
28#ifdef DEAL_II_WITH_CUDA
29
31
32// Forward declarations
33# ifndef DOXYGEN
34template <typename Number>
35class ReadWriteVector;
36# endif
37
38namespace LinearAlgebra
39{
43 namespace CUDAWrappers
44 {
54 template <typename Number>
55 class Vector : public VectorSpaceVector<Number>
56 {
57 public:
61
65 Vector();
66
70 Vector(const Vector<Number> &V);
71
75 Vector(Vector<Number> &&) noexcept = default;
76
87 explicit Vector(const size_type n);
88
92 Vector &
93 operator=(const Vector<Number> &v);
94
98 Vector &
99 operator=(Vector<Number> &&v) noexcept = default;
100
116 virtual void
117 swap(Vector<Number> &v);
118
124 void
125 reinit(const size_type n, const bool omit_zeroing_entries = false);
126
131 virtual void
132 reinit(const VectorSpaceVector<Number> &V,
133 const bool omit_zeroing_entries = false) override;
134
143 virtual void
145 const ReadWriteVector<Number> &V,
146 VectorOperation::values operation,
147 std::shared_ptr<const Utilities::MPI::CommunicationPatternBase>
148 communication_pattern = {}) override;
149
153 DEAL_II_DEPRECATED_EARLY virtual void
154 import(const ReadWriteVector<Number> &V,
155 VectorOperation::values operation,
156 std::shared_ptr<const Utilities::MPI::CommunicationPatternBase>
157 communication_pattern = {}) override
158 {
159 import_elements(V, operation, communication_pattern);
160 }
161
166 virtual Vector<Number> &
167 operator=(const Number s) override;
168
172 virtual Vector<Number> &
173 operator*=(const Number factor) override;
174
178 virtual Vector<Number> &
179 operator/=(const Number factor) override;
180
184 virtual Vector<Number> &
185 operator+=(const VectorSpaceVector<Number> &V) override;
186
190 virtual Vector<Number> &
191 operator-=(const VectorSpaceVector<Number> &V) override;
192
196 virtual Number
197 operator*(const VectorSpaceVector<Number> &V) const override;
198
202 virtual void
203 add(const Number a) override;
204
208 virtual void
209 add(const Number a, const VectorSpaceVector<Number> &V) override;
210
214 virtual void
215 add(const Number a,
217 const Number b,
218 const VectorSpaceVector<Number> &W) override;
219
224 virtual void
225 sadd(const Number s,
226 const Number a,
227 const VectorSpaceVector<Number> &V) override;
228
234 virtual void
235 scale(const VectorSpaceVector<Number> &scaling_factors) override;
236
240 virtual void
241 equ(const Number a, const VectorSpaceVector<Number> &V) override;
242
246 virtual bool
247 all_zero() const override;
248
252 virtual value_type
253 mean_value() const override;
254
259 virtual real_type
260 l1_norm() const override;
261
266 virtual real_type
267 l2_norm() const override;
268
273 norm_sqr() const;
274
279 virtual real_type
280 linfty_norm() const override;
281
301 virtual Number
302 add_and_dot(const Number a,
304 const VectorSpaceVector<Number> &W) override;
305
310 Number *
311 get_values() const;
312
316 virtual size_type
317 size() const override;
318
323 virtual ::IndexSet
324 locally_owned_elements() const override;
325
329 virtual void
330 print(std::ostream & out,
331 const unsigned int precision = 2,
332 const bool scientific = true,
333 const bool across = true) const override;
334
338 virtual std::size_t
339 memory_consumption() const override;
340
347
348 private:
352 std::unique_ptr<Number[], void (*)(Number *)> val;
353
358 };
359 } // namespace CUDAWrappers
360} // namespace LinearAlgebra
361
362// ---------------------------- Inline functions --------------------------
363
371template <typename Number>
372inline void
375{
376 u.swap(v);
377}
378
379namespace LinearAlgebra
380{
381 namespace CUDAWrappers
382 {
383 template <typename Number>
384 inline Number *
386 {
387 return val.get();
388 }
389
390
391
392 template <typename Number>
393 inline typename Vector<Number>::size_type
395 {
396 return n_elements;
397 }
398
399
400 template <typename Number>
401 inline IndexSet
403 {
404 return complete_index_set(n_elements);
405 }
406
407
408
409 template <typename Number>
410 inline void
412 {
413 std::swap(val, v.val);
414 std::swap(n_elements, v.n_elements);
415 }
416 } // namespace CUDAWrappers
417} // namespace LinearAlgebra
418
420
421#endif
422
423#endif
virtual value_type mean_value() const override
Vector(Vector< Number > &&) noexcept=default
virtual void scale(const VectorSpaceVector< Number > &scaling_factors) override
typename VectorSpaceVector< Number >::value_type value_type
Definition cuda_vector.h:58
virtual void import_elements(const ReadWriteVector< Number > &V, VectorOperation::values operation, std::shared_ptr< const Utilities::MPI::CommunicationPatternBase > communication_pattern={}) override
std::unique_ptr< Number[], void(*)(Number *)> val
virtual void add(const Number a) override
typename VectorSpaceVector< Number >::size_type size_type
Definition cuda_vector.h:59
virtual Vector< Number > & operator+=(const VectorSpaceVector< Number > &V) override
virtual void sadd(const Number s, const Number a, const VectorSpaceVector< Number > &V) override
virtual Vector< Number > & operator-=(const VectorSpaceVector< Number > &V) override
virtual Vector< Number > & operator*=(const Number factor) override
virtual ::IndexSet locally_owned_elements() const override
virtual Number add_and_dot(const Number a, const VectorSpaceVector< Number > &V, const VectorSpaceVector< Number > &W) override
typename VectorSpaceVector< Number >::real_type real_type
Definition cuda_vector.h:60
virtual void print(std::ostream &out, const unsigned int precision=2, const bool scientific=true, const bool across=true) const override
virtual real_type l2_norm() const override
Vector & operator=(const Vector< Number > &v)
virtual void equ(const Number a, const VectorSpaceVector< Number > &V) override
virtual Number operator*(const VectorSpaceVector< Number > &V) const override
virtual void swap(Vector< Number > &v)
virtual real_type l1_norm() const override
virtual bool all_zero() const override
virtual real_type linfty_norm() const override
virtual Vector< Number > & operator/=(const Number factor) override
void reinit(const size_type n, const bool omit_zeroing_entries=false)
virtual std::size_t memory_consumption() const override
virtual size_type size() const override
typename numbers::NumberTraits< Number >::real_type real_type
void swap(LinearAlgebra::CUDAWrappers::Vector< Number > &u, LinearAlgebra::CUDAWrappers::Vector< Number > &v)
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:472
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:473
#define DeclException0(Exception0)
Definition exceptions.h:465
static ::ExceptionBase & ExcVectorTypeNotCompatible()
IndexSet complete_index_set(const IndexSet::size_type N)
Definition index_set.h:1089
STL namespace.