PARALUTION  1.0.0
PARALUTION
host_vector.hpp
Go to the documentation of this file.
1 #ifndef PARALUTION_HOST_VECTOR_HPP_
2 #define PARALUTION_HOST_VECTOR_HPP_
3 
4 #include "../base_vector.hpp"
5 #include "../base_matrix.hpp"
6 #include "../base_stencil.hpp"
7 
8 #include <complex>
9 
10 namespace paralution {
11 
12 template <typename ValueType>
14 
15 template <typename ValueType>
16 class HostVector : public BaseVector<ValueType> {
17 
18 public:
19 
20  HostVector();
21  HostVector(const Paralution_Backend_Descriptor local_backend);
22  virtual ~HostVector();
23 
24  virtual void info(void) const;
25 
26  virtual bool Check(void) const;
27  virtual void Allocate(const int n);
28  virtual void SetDataPtr(ValueType **ptr, const int size);
29  virtual void LeaveDataPtr(ValueType **ptr);
30  virtual void Clear(void);
31  virtual void Zeros(void);
32  virtual void Ones(void);
33  virtual void SetValues(const ValueType val);
34  virtual void SetRandom(const ValueType a, const ValueType b, const int seed);
35  virtual void Assemble(const int *i, const ValueType *v,
36  int size, const int n);
37 
38  virtual void CopyFrom(const BaseVector<ValueType> &vec);
39  virtual void CopyFromFloat(const BaseVector<float> &vec);
40  virtual void CopyFromDouble(const BaseVector<double> &vec);
41  virtual void CopyTo(BaseVector<ValueType> *vec) const;
42  virtual void CopyFrom(const BaseVector<ValueType> &src,
43  const int src_offset,
44  const int dst_offset,
45  const int size);
46  virtual void CopyFromPermute(const BaseVector<ValueType> &src,
47  const BaseVector<int> &permutation);
48  virtual void CopyFromPermuteBackward(const BaseVector<ValueType> &src,
49  const BaseVector<int> &permutation);
50 
51  virtual void CopyFromData(const ValueType *data);
52  virtual void CopyToData(ValueType *data) const;
53 
54  virtual void Permute(const BaseVector<int> &permutation);
55  virtual void PermuteBackward(const BaseVector<int> &permutation);
56 
57  virtual bool Restriction(const BaseVector<ValueType> &vec_fine, const BaseVector<int> &map);
58  virtual bool Prolongation(const BaseVector<ValueType> &vec_coarse, const BaseVector<int> &map);
59 
61  void ReadFileASCII(const std::string filename);
63  void WriteFileASCII(const std::string filename) const;
65  void ReadFileBinary(const std::string filename);
67  void WriteFileBinary(const std::string filename) const;
68 
69  // this = this + alpha*x
70  virtual void AddScale(const BaseVector<ValueType> &x, const ValueType alpha);
71  // this = alpha*this + x
72  virtual void ScaleAdd(const ValueType alpha, const BaseVector<ValueType> &x);
73  // this = alpha*this + x*beta
74  virtual void ScaleAddScale(const ValueType alpha, const BaseVector<ValueType> &x, const ValueType beta);
75  virtual void ScaleAddScale(const ValueType alpha, const BaseVector<ValueType> &x, const ValueType beta,
76  const int src_offset, const int dst_offset,const int size);
77  // this = alpha*this + x*beta + y*gamma
78  virtual void ScaleAdd2(const ValueType alpha, const BaseVector<ValueType> &x,
79  const ValueType beta, const BaseVector<ValueType> &y,
80  const ValueType gamma);
81  // this = alpha*this
82  virtual void Scale(const ValueType alpha);
83  // Compute partial sum
84  virtual void PartialSum(const BaseVector<ValueType> &x);
85  // this^T x
86  virtual ValueType Dot(const BaseVector<ValueType> &x) const;
87  // this^T x
88  virtual ValueType DotNonConj(const BaseVector<ValueType> &x) const;
89  // srqt(this^T this)
90  virtual ValueType Norm(void) const;
91  // reduce vector
92  virtual ValueType Reduce(void) const;
93  // Compute sum of absolute values of this
94  virtual ValueType Asum(void) const;
95  // Compute absolute value of this
96  virtual int Amax(ValueType &value) const;
97  // point-wise multiplication
98  virtual void PointWiseMult(const BaseVector<ValueType> &x);
99  virtual void PointWiseMult(const BaseVector<ValueType> &x, const BaseVector<ValueType> &y);
100  virtual void Power(const double power);
101 
102 
103 private:
104 
105  ValueType *vec_;
106 
107  // for [] operator in LocalVector
108  friend class LocalVector<ValueType>;
109 
110  friend class HostVector<double>;
111  friend class HostVector<float>;
112  friend class HostVector<std::complex<double> >;
113  friend class HostVector<std::complex<float> >;
114  friend class HostVector<int>;
115 
116  friend class HostMatrix<ValueType>;
117  friend class HostMatrixCSR<ValueType>;
118  friend class HostMatrixCOO<ValueType>;
119  friend class HostMatrixDIA<ValueType>;
120  friend class HostMatrixELL<ValueType>;
121  friend class HostMatrixHYB<ValueType>;
122  friend class HostMatrixDENSE<ValueType>;
123  friend class HostMatrixMCSR<ValueType>;
124  friend class HostMatrixBCSR<ValueType>;
125 
126  friend class HostMatrixCOO<float>;
127  friend class HostMatrixCOO<double>;
128  friend class HostMatrixCOO<std::complex<float> >;
129  friend class HostMatrixCOO<std::complex<double> >;
130 
131  friend class HostMatrixCSR<double>;
132  friend class HostMatrixCSR<float>;
133  friend class HostMatrixCSR<std::complex<float> >;
134  friend class HostMatrixCSR<std::complex<double> >;
135 
136  friend class GPUAcceleratorVector<ValueType>;
137  friend class OCLAcceleratorVector<ValueType>;
138  friend class MICAcceleratorVector<ValueType>;
139 
140  friend class HostStencil<ValueType>;
141  friend class HostStencilLaplace2D<ValueType>;
142 
143 };
144 
145 
146 }
147 
148 #endif // PARALUTION_HOST_VECTOR_HPP_
virtual void CopyFromDouble(const BaseVector< double > &vec)
Copy values from another (double) vector.
Definition: host_vector.cpp:260
IndexType i
Definition: cuda_kernels_coo.hpp:195
virtual void AddScale(const BaseVector< ValueType > &x, const ValueType alpha)
Perform vector update of type this = this + alpha*x.
Definition: host_vector.cpp:528
virtual ValueType DotNonConj(const BaseVector< ValueType > &x) const
Compute non-conjugated dot (scalar) product, return this^T y.
Definition: host_vector.cpp:863
virtual bool Prolongation(const BaseVector< ValueType > &vec_coarse, const BaseVector< int > &map)
Prolongation operator based on restriction(!) mapping vector.
Definition: host_vector.cpp:1373
Definition: base_matrix.hpp:24
Definition: base_stencil.hpp:12
virtual void SetValues(const ValueType val)
Set the values of the vector to given argument.
Definition: host_vector.cpp:315
virtual void PointWiseMult(const BaseVector< ValueType > &x)
Perform point-wise multiplication (element-wise) of type this = this * x.
Definition: host_vector.cpp:1192
void ReadFileASCII(const std::string filename)
Read vector from ASCII file.
Definition: host_vector.cpp:353
virtual void CopyTo(BaseVector< ValueType > *vec) const
Copy values to another vector.
Definition: host_vector.cpp:220
void ReadFileBinary(const std::string filename)
Read vector from binary file.
Definition: host_vector.cpp:415
Definition: base_matrix.hpp:14
virtual ValueType Asum(void) const
Compute sum of absolute values of the vector (L1 norm), return = sum(|this|)
Definition: host_vector.cpp:966
virtual void Permute(const BaseVector< int > &permutation)
Perform inplace permutation (forward) of the vector.
Definition: host_vector.cpp:1259
virtual void LeaveDataPtr(ValueType **ptr)
Get a pointer from the vector data and free the vector object.
Definition: host_vector.cpp:134
virtual void Clear(void)
Clear (free) the vector.
Definition: host_vector.cpp:177
virtual void Zeros(void)
Set the values of the vector to zero.
Definition: host_vector.cpp:293
virtual void Assemble(const int *i, const ValueType *v, int size, const int n)
Assembling.
Definition: host_vector.cpp:1393
virtual void Ones(void)
Set the values of the vector to one.
Definition: host_vector.cpp:304
Definition: base_matrix.hpp:26
virtual void ScaleAdd2(const ValueType alpha, const BaseVector< ValueType > &x, const ValueType beta, const BaseVector< ValueType > &y, const ValueType gamma)
Perform vector update of type this = alpha*this + x*beta + y*gamma.
Definition: host_vector.cpp:608
Backend descriptor - keeps information about the hardware - OpenMP (threads); CUDA (blocksizes...
Definition: backend_manager.hpp:19
ValueType * vec_
Definition: host_vector.hpp:105
Definition: base_vector.hpp:16
virtual ~HostVector()
Definition: host_vector.cpp:52
virtual void PartialSum(const BaseVector< ValueType > &x)
Compute partial sum.
Definition: host_vector.cpp:684
HostVector()
Definition: host_vector.cpp:32
virtual void SetRandom(const ValueType a, const ValueType b, const int seed)
Definition: host_vector.cpp:326
Definition: base_matrix.hpp:28
const IndexType const IndexType const IndexType const ValueType const ValueType const ValueType ValueType * y
Definition: cuda_kernels_coo.hpp:91
virtual void CopyToData(ValueType *data) const
Definition: host_vector.cpp:162
Definition: base_vector.hpp:10
void WriteFileBinary(const std::string filename) const
Write vector to binary file.
Definition: host_vector.cpp:437
virtual void Allocate(const int n)
Allocate a local vector with name and size.
Definition: host_vector.cpp:101
virtual void Scale(const ValueType alpha)
Perform vector scaling this = alpha*this.
Definition: host_vector.cpp:670
virtual void CopyFromPermute(const BaseVector< ValueType > &src, const BaseVector< int > &permutation)
Copy a vector under specified permutation (forward permutation)
Definition: host_vector.cpp:1308
void power(const int mic_dev, const int size, const double val, ValueType *vec)
Definition: mic_vector_kernel.cpp:241
virtual void CopyFromPermuteBackward(const BaseVector< ValueType > &src, const BaseVector< int > &permutation)
Copy a vector under specified permutation (backward permutation)
Definition: host_vector.cpp:1330
virtual ValueType Dot(const BaseVector< ValueType > &x) const
Compute dot (scalar) product, return this^T y.
Definition: host_vector.cpp:785
Definition: base_matrix.hpp:20
Definition: base_matrix.hpp:22
virtual void info(void) const
Shows info about the object.
Definition: host_vector.cpp:62
virtual void ScaleAdd(const ValueType alpha, const BaseVector< ValueType > &x)
Perform vector update of type this = alpha*this + x.
Definition: host_vector.cpp:548
Definition: base_vector.hpp:22
virtual bool Restriction(const BaseVector< ValueType > &vec_fine, const BaseVector< int > &map)
Restriction operator based on restriction mapping vector.
Definition: host_vector.cpp:1352
virtual void PermuteBackward(const BaseVector< int > &permutation)
Perform inplace permutation (backward) of the vector.
Definition: host_vector.cpp:1284
virtual void Power(const double power)
Definition: host_vector.cpp:1482
Definition: base_matrix.hpp:16
Definition: backend_manager.cpp:43
virtual ValueType Norm(void) const
Compute L2 norm of the vector, return = srqt(this^T this)
Definition: host_vector.cpp:1078
virtual int Amax(ValueType &value) const
Compute the absolute max value of the vector, return = max(|this|)
Definition: host_vector.cpp:1021
virtual bool Check(void) const
Check if everything is ok.
Definition: host_vector.cpp:69
virtual void SetDataPtr(ValueType **ptr, const int size)
Initialize a vector with externally allocated data.
Definition: host_vector.cpp:121
virtual void CopyFromData(const ValueType *data)
Definition: host_vector.cpp:147
Definition: backend_manager.hpp:14
const IndexType const IndexType const IndexType const ValueType const ValueType const ValueType * x
Definition: cuda_kernels_coo.hpp:91
Definition: base_stencil.hpp:10
void WriteFileASCII(const std::string filename) const
Write vector to ASCII file.
Definition: host_vector.cpp:389
Definition: base_vector.hpp:19
b(1:n)
Base class for all host/accelerator vectors.
Definition: base_vector.hpp:26
virtual void ScaleAddScale(const ValueType alpha, const BaseVector< ValueType > &x, const ValueType beta)
Perform vector update of type this = alpha*this + x*beta.
Definition: host_vector.cpp:566
Definition: host_vector.hpp:13
virtual void CopyFromFloat(const BaseVector< float > &vec)
Copy values from another (float) vector.
Definition: host_vector.cpp:227
virtual ValueType Reduce(void) const
Reduce vector.
Definition: host_vector.cpp:1137
Definition: base_matrix.hpp:18
virtual void CopyFrom(const BaseVector< ValueType > &vec)
Copy values from another vector.
Definition: host_vector.cpp:190