Reference documentation for deal.II version 9.0.0
cuda_vector.h
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2016 - 2018 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 at
12 // the top level of the deal.II distribution.
13 //
14 // ---------------------------------------------------------------------
15 
16 #ifndef dealii_cuda_vector_h
17 #define dealii_cuda_vector_h
18 
19 #include <deal.II/base/config.h>
20 #include <deal.II/base/exceptions.h>
21 #include <deal.II/base/index_set.h>
22 #include <deal.II/lac/vector_space_vector.h>
23 #include <deal.II/lac/vector_operation.h>
24 
25 #ifdef DEAL_II_WITH_CUDA
26 
27 DEAL_II_NAMESPACE_OPEN
28 
29 class CommunicationPatternBase;
30 template <typename Number> class ReadWriteVector;
31 
32 namespace LinearAlgebra
33 {
37  namespace CUDAWrappers
38  {
49  template <typename Number>
50  class Vector: public VectorSpaceVector<Number>
51  {
52  public:
53  typedef typename VectorSpaceVector<Number>::value_type value_type;
54  typedef typename VectorSpaceVector<Number>::size_type size_type;
55  typedef typename VectorSpaceVector<Number>::real_type real_type;
56 
60  Vector();
61 
65  Vector(const Vector<Number> &V);
66 
77  explicit Vector(const size_type n);
78 
82  ~Vector();
83 
89  void reinit(const size_type n,
90  const bool omit_zeroing_entries = false);
91 
96  virtual void reinit(const VectorSpaceVector<Number> &V,
97  const bool omit_zeroing_entries = false) override;
98 
107  virtual void import(const ReadWriteVector<Number> &V,
108  VectorOperation::values operation,
109  std::shared_ptr<const CommunicationPatternBase> communication_pattern =
110  std::shared_ptr<const CommunicationPatternBase> ()) override;
111 
116  virtual Vector<Number> &operator= (const Number s) override;
117 
121  virtual Vector<Number> &operator*= (const Number factor) override;
122 
126  virtual Vector<Number> &operator/= (const Number factor) override;
127 
131  virtual Vector<Number> &operator+= (const VectorSpaceVector<Number> &V) override;
132 
136  virtual Vector<Number> &operator-= (const VectorSpaceVector<Number> &V) override;
137 
141  virtual Number operator* (const VectorSpaceVector<Number> &V) const override;
142 
146  virtual void add(const Number a) override;
147 
151  virtual void add(const Number a, const VectorSpaceVector<Number> &V) override;
152 
156  virtual void add(const Number a, const VectorSpaceVector<Number> &V,
157  const Number b, const VectorSpaceVector<Number> &W) override;
158 
163  virtual void sadd(const Number s, const Number a,
164  const VectorSpaceVector<Number> &V) override;
165 
171  virtual void scale(const VectorSpaceVector<Number> &scaling_factors) override;
172 
176  virtual void equ(const Number a, const VectorSpaceVector<Number> &V) override;
177 
181  virtual bool all_zero() const override;
182 
186  virtual value_type mean_value() const override;
187 
192  virtual real_type l1_norm() const override;
193 
198  virtual real_type l2_norm() const override;
199 
204  virtual real_type linfty_norm() const override;
205 
225  virtual Number add_and_dot(const Number a,
226  const VectorSpaceVector<Number> &V,
227  const VectorSpaceVector<Number> &W) override;
228 
232  Number *get_values() const;
233 
237  virtual size_type size() const override;
238 
243  virtual ::IndexSet locally_owned_elements() const override;
244 
248  virtual void print(std::ostream &out,
249  const unsigned int precision=2,
250  const bool scientific=true,
251  const bool across=true) const override;
252 
256  virtual std::size_t memory_consumption() const override;
257 
264 
265  private:
269  Number *val;
270 
274  size_type n_elements;
275  };
276 
277 
278 
279  // ------------------------------ Inline functions -----------------------------
280  template <typename Number>
281  inline
283  {
284  return val;
285  }
286 
287 
288 
289  template <typename Number>
290  inline
291  typename Vector<Number>::size_type Vector<Number>::size() const
292  {
293  return n_elements;
294  }
295 
296 
297  template <typename Number>
298  inline
300  {
301  return complete_index_set(n_elements);
302  }
303  }
304 }
305 
306 DEAL_II_NAMESPACE_CLOSE
307 
308 #endif
309 
310 #endif
virtual Number add_and_dot(const Number a, const VectorSpaceVector< Number > &V, const VectorSpaceVector< Number > &W) override
virtual void equ(const Number a, const VectorSpaceVector< Number > &V) override
void reinit(const size_type n, const bool omit_zeroing_entries=false)
virtual Vector< Number > & operator-=(const VectorSpaceVector< Number > &V) override
virtual real_type l1_norm() const override
virtual value_type mean_value() const override
virtual ::IndexSet locally_owned_elements() const override
Definition: cuda_vector.h:299
virtual void add(const Number a) override
#define DeclException0(Exception0)
Definition: exceptions.h:323
static ::ExceptionBase & ExcVectorTypeNotCompatible()
virtual Vector< Number > & operator*=(const Number factor) override
virtual bool all_zero() const override
virtual Number operator*(const VectorSpaceVector< Number > &V) const override
virtual Vector< Number > & operator/=(const Number factor) override
virtual std::size_t memory_consumption() const override
virtual real_type l2_norm() const override
virtual Vector< Number > & operator+=(const VectorSpaceVector< Number > &V) override
virtual void scale(const VectorSpaceVector< Number > &scaling_factors) override
virtual Vector< Number > & operator=(const Number s) override
virtual void sadd(const Number s, const Number a, const VectorSpaceVector< Number > &V) override
virtual void print(std::ostream &out, const unsigned int precision=2, const bool scientific=true, const bool across=true) const override
virtual size_type size() const override
Definition: cuda_vector.h:291
virtual real_type linfty_norm() const override