Reference documentation for deal.II version 9.6.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// SPDX-License-Identifier: LGPL-2.1-or-later
4// Copyright (C) 2016 - 2024 by the deal.II authors
5//
6// This file is part of the deal.II library.
7//
8// Part of the source code is dual licensed under Apache-2.0 WITH
9// LLVM-exception OR LGPL-2.1-or-later. Detailed license information
10// governing the source code and code contributions can be found in
11// LICENSE.md and CONTRIBUTING.md at the top level directory of deal.II.
12//
13// ------------------------------------------------------------------------
14
15#ifndef dealii_cuda_vector_h
16#define dealii_cuda_vector_h
17
18#include <deal.II/base/config.h>
19
23
25
26#ifdef DEAL_II_WITH_CUDA
27
29
30// Forward declarations
31# ifndef DOXYGEN
32namespace LinearAlgebra
33{
34 template <typename Number>
35 class ReadWriteVector;
36}
37# endif
38
39namespace LinearAlgebra
40{
44 namespace CUDAWrappers
45 {
54 template <typename Number>
55 class Vector
56 {
57 public:
58 using value_type = Number;
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
113 void
114 swap(Vector<Number> &v);
115
121 void
122 reinit(const size_type n, const bool omit_zeroing_entries = false);
123
128 void
129 reinit(const Vector<Number> &V, const bool omit_zeroing_entries = false);
130
139 void
141 const ReadWriteVector<Number> &V,
142 const VectorOperation::values operation,
143 const std::shared_ptr<const Utilities::MPI::CommunicationPatternBase>
144 &communication_pattern = {});
145
150 import(const ReadWriteVector<Number> &V,
151 VectorOperation::values operation,
152 std::shared_ptr<const Utilities::MPI::CommunicationPatternBase>
153 communication_pattern = {})
154 {
155 import_elements(V, operation, communication_pattern);
156 }
157
163 operator=(const Number s);
164
169 operator*=(const Number factor);
170
175 operator/=(const Number factor);
176
181 operator+=(const Vector<Number> &V);
182
187 operator-=(const Vector<Number> &V);
188
192 Number
193 operator*(const Vector<Number> &V) const;
194
198 void
199 add(const Number a);
200
204 void
205 add(const Number a, const Vector<Number> &V);
206
210 void
211 add(const Number a,
212 const Vector<Number> &V,
213 const Number b,
214 const Vector<Number> &W);
215
220 void
221 sadd(const Number s, const Number a, const Vector<Number> &V);
222
228 void
229 scale(const Vector<Number> &scaling_factors);
230
234 void
235 equ(const Number a, const Vector<Number> &V);
236
240 bool
241 all_zero() const;
242
246 value_type
247 mean_value() const;
248
253 real_type
254 l1_norm() const;
255
260 real_type
261 l2_norm() const;
262
266 real_type
267 norm_sqr() const;
268
273 real_type
274 linfty_norm() const;
275
295 Number
296 add_and_dot(const Number a,
297 const Vector<Number> &V,
298 const Vector<Number> &W);
299
304 Number *
305 get_values() const;
306
310 size_type
311 size() const;
312
319
323 void
324 print(std::ostream &out,
325 const unsigned int precision = 2,
326 const bool scientific = true,
327 const bool across = true) const;
328
332 std::size_t
333 memory_consumption() const;
334
341
342 private:
346 std::unique_ptr<Number[], void (*)(Number *)> val;
347
352 };
353 } // namespace CUDAWrappers
354} // namespace LinearAlgebra
355
356// ---------------------------- Inline functions --------------------------
357
365template <typename Number>
366inline void
372
373namespace LinearAlgebra
374{
375 namespace CUDAWrappers
376 {
377 template <typename Number>
378 inline Number *
380 {
381 return val.get();
382 }
383
384
385
386 template <typename Number>
387 inline typename Vector<Number>::size_type
389 {
390 return n_elements;
391 }
392
393
394 template <typename Number>
395 inline IndexSet
397 {
398 return complete_index_set(n_elements);
399 }
400
401
402
403 template <typename Number>
404 inline void
406 {
407 std::swap(val, v.val);
408 std::swap(n_elements, v.n_elements);
409 }
410 } // namespace CUDAWrappers
411} // namespace LinearAlgebra
412
414
415#endif
416
417#endif
Vector(Vector< Number > &&) noexcept=default
void equ(const Number a, const Vector< Number > &V)
void sadd(const Number s, const Number a, const Vector< Number > &V)
Number add_and_dot(const Number a, const Vector< Number > &V, const Vector< Number > &W)
std::unique_ptr< Number[], void(*)(Number *)> val
typename numbers::NumberTraits< Number >::real_type real_type
Definition cuda_vector.h:60
Vector< Number > & operator*=(const Number factor)
void import_elements(const ReadWriteVector< Number > &V, const VectorOperation::values operation, const std::shared_ptr< const Utilities::MPI::CommunicationPatternBase > &communication_pattern={})
Vector & operator=(const Vector< Number > &v)
Vector< Number > & operator+=(const Vector< Number > &V)
void scale(const Vector< Number > &scaling_factors)
::IndexSet locally_owned_elements() const
void print(std::ostream &out, const unsigned int precision=2, const bool scientific=true, const bool across=true) const
Number operator*(const Vector< Number > &V) const
void swap(Vector< Number > &v)
void reinit(const size_type n, const bool omit_zeroing_entries=false)
Vector< Number > & operator-=(const Vector< Number > &V)
std::size_t memory_consumption() const
Vector< Number > & operator/=(const Number factor)
void swap(LinearAlgebra::CUDAWrappers::Vector< Number > &u, LinearAlgebra::CUDAWrappers::Vector< Number > &v)
#define DEAL_II_DEPRECATED
Definition config.h:207
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:503
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:504
#define DeclException0(Exception0)
Definition exceptions.h:471
static ::ExceptionBase & ExcVectorTypeNotCompatible()
IndexSet complete_index_set(const IndexSet::size_type N)
Definition index_set.h:1204
STL namespace.
unsigned int global_dof_index
Definition types.h:81