ParGeMSLR
sequential_vector.hpp
Go to the documentation of this file.
1 #ifndef PARGEMSLR_SEQUENTIAL_VECTOR_H
2 #define PARGEMSLR_SEQUENTIAL_VECTOR_H
3 
8 #include <iostream>
9 
10 #include "../utils/utils.hpp"
11 #include "../utils/structs.hpp"
12 #include "vector.hpp"
13 #include "int_vector.hpp"
14 
15 #ifdef PARGEMSLR_CUDA
16 #include "cusparse.h"
17 #endif
18 
19 namespace pargemslr
20 {
21  template <typename T> class CsrMatrixClass;
22 
27  template <typename T>
28  class SequentialVectorClass: public VectorClass<T>
29  {
30  private:
31 
32  /* variables */
33 #ifdef PARGEMSLR_CUDA
34 #if (PARGEMSLR_CUDA_VERSION == 11)
35 
39  cusparseDnVecDescr_t _cusparse_vec;
40 #endif
41 #endif
42 
47  T* _data;
48 
53  int _length;
54 
59  int _maxlength;
60 
65  bool _hold_data;
66 
71  int _location;
72 
73  public:
74 
80 
86  SequentialVectorClass(const SequentialVectorClass<T> &vec);
87 
93  SequentialVectorClass(SequentialVectorClass<T>&& vec);
94 
101  SequentialVectorClass<T>& operator= (const SequentialVectorClass<T> &vec);
102 
109  SequentialVectorClass<T>& operator= (SequentialVectorClass<T>&& vec);
110 
115  virtual ~SequentialVectorClass();
116 
123  int Setup(int length);
124 
132  int Setup(int length, bool setzero);
133 
142  int Setup(int length, int location, bool setzero);
143 
154  int Setup(int length, int reserve, int location, bool setzero);
155 
163  int SetupPtrStr( SequentialVectorClass<T> &x);
164 
172  int SetupPtrStr( CsrMatrixClass<T> &A);
173 
181  int SetupPtrStr( int length);
182 
190  int UpdatePtr( void* data, int location);
191 
200  int SetupPtr( void* data, int length, int location);
201 
211  int SetupPtr( void* data, int length, int location, bool hold_data);
212 
221  int SetupPtr(const VectorClass<T> &vec, int length, int shift);
222 
232  int SetupPtr(const VectorClass<T> &vec, int length, int shift, bool hold_data);
233 
243  int Copy(const T *data, int length, int loc_from, int loc_to);
244 
252  int PushBack(T v);
253 
262  int Resize(int length, bool keepdata, bool setzero);
263 
273  int Resize(int length, int reserve, bool keepdata, bool setzero);
274 
281  virtual T& operator[] (int i);
282 
288  virtual int Clear();
289 
295  virtual T* GetData() const;
296 
297 #ifdef PARGEMSLR_CUDA
298 #if (PARGEMSLR_CUDA_VERSION == 11)
299 
303  virtual cusparseDnVecDescr_t GetCusparseVec() const;
304 
310  int SetCusparseVec(cusparseDnVecDescr_t cusparse_vec);
311 #endif
312 #endif
313 
319  virtual int GetDataLocation() const;
320 
326  virtual int GetLengthLocal() const;
327 
333  virtual long int GetLengthGlobal() const;
334 
340  virtual long int GetStartGlobal() const;
341 
347  bool IsHoldingData() const;
348 
354  int SetHoldingData(bool hold_data);
355 
362  virtual int Fill(const T &v);
363 
369  virtual int Rand();
370 
377  T Max() const;
378 
385  int MaxIndex() const;
386 
393  T Min() const;
394 
401  int MinIndex() const;
402 
411  int BinarySearch(const T &val, int &idx, bool ascending);
412 
420  int Sort(bool ascending);
421 
432  int Sort(IntVectorClass<int> &order, bool ascending, bool stable);
433 
440  int Perm(IntVectorClass<int> &perm);
441 
450  int Plot( int conditiona, int conditionb, int width);
451 
463  int PlotAbsGnuPlot( const char *datafilename, int conditiona, int conditionb, bool logx, bool logy, int pttype = 0);
464 
471  int WriteToDisk( const char *datafilename);
472 
479  virtual int Scale( const T &alpha);
480 
488  virtual int Axpy( const T &alpha, const VectorClass<T> &x);
489 
498  virtual int Axpy( const T &alpha, const VectorClass<T> &x, VectorClass<T> &z);
499 
509  virtual int Axpy( const T &alpha, const VectorClass<T> &x, const T &beta, VectorClass<T> &z);
510 
517  virtual int Norm2( float &norm) const;
518 
525  virtual int Norm2( double &norm) const;
526 
533  virtual int NormInf( float &norm);
534 
541  virtual int NormInf( double &norm);
542 
550  virtual int Dot( const VectorClass<T> &y, T &t) const;
551 
558  virtual int MoveData( const int &location);
559 
567  int ReadFromMMFile(const char *vecfile, int idxin);
568 
569  };
570 
571  typedef SequentialVectorClass<float> vector_seq_float;
572  typedef SequentialVectorClass<double> vector_seq_double;
573  typedef SequentialVectorClass<complexs> vector_seq_complexs;
574  typedef SequentialVectorClass<complexd> vector_seq_complexd;
575  template<> struct PargemslrIsComplex<SequentialVectorClass<complexs> > : public std::true_type {};
576  template<> struct PargemslrIsComplex<SequentialVectorClass<complexd> > : public std::true_type {};
577 
578 }
579 
580 #endif
int_vector.hpp
Integer vector data structure, not a vector_base class.
pargemslr::SequentialVectorClass::SetupPtr
int SetupPtr(void *data, int length, int location)
Free the current vector, and points the vector to an address in the memory.
Definition: sequential_vector.cpp:327
vector.hpp
The virtual vector classes.
pargemslr::SequentialVectorClass::Scale
virtual int Scale(const T &alpha)
Scale the vector by x = alpha*x, where x is this vector.
Definition: sequential_vector.cpp:1037
pargemslr::SequentialVectorClass::Plot
int Plot(int conditiona, int conditionb, int width)
Print the vector.
Definition: sequential_vector.cpp:904
pargemslr::SequentialVectorClass::Min
T Min() const
Get the min value in the vector.
Definition: sequential_vector.cpp:871
pargemslr::SequentialVectorClass::MoveData
virtual int MoveData(const int &location)
Move the data to another memory location.
Definition: sequential_vector.cpp:1180
pargemslr::SequentialVectorClass::Sort
int Sort(bool ascending)
Sort the current vector.
Definition: sequential_vector.cpp:755
pargemslr::SequentialVectorClass::SetHoldingData
int SetHoldingData(bool hold_data)
Set if the vector holding its own data.
Definition: sequential_vector.cpp:694
pargemslr::SequentialVectorClass::PushBack
int PushBack(T v)
Insert value at the end of the vector, expand the vector when necessary.
Definition: sequential_vector.cpp:473
pargemslr::SequentialVectorClass::GetLengthGlobal
virtual long int GetLengthGlobal() const
Get the global length of the vector.
Definition: sequential_vector.cpp:664
pargemslr::SequentialVectorClass::Resize
int Resize(int length, bool keepdata, bool setzero)
Resize the vector. Re-allocate memory when necessary.
Definition: sequential_vector.cpp:499
pargemslr::SequentialVectorClass::operator=
SequentialVectorClass< T > & operator=(const SequentialVectorClass< T > &vec)
The = operator of SequentialVectorClass.
Definition: sequential_vector.cpp:100
pargemslr::SequentialVectorClass::WriteToDisk
int WriteToDisk(const char *datafilename)
Write file to disk.
Definition: sequential_vector.cpp:984
pargemslr::SequentialVectorClass::Copy
int Copy(const T *data, int length, int loc_from, int loc_to)
Free the current vector, allocate memory, and copy data to initilize this vector.
Definition: sequential_vector.cpp:399
pargemslr::SequentialVectorClass::SetupPtrStr
int SetupPtrStr(SequentialVectorClass< T > &x)
Setup the length information of a vector pointer to be same as another vector.
Definition: sequential_vector.cpp:263
pargemslr::SequentialVectorClass::GetStartGlobal
virtual long int GetStartGlobal() const
Get the global start index of the vector.
Definition: sequential_vector.cpp:674
pargemslr::SequentialVectorClass
The class of sequential real/complex vector.
Definition: structs.hpp:12
pargemslr::SequentialVectorClass::GetData
virtual T * GetData() const
Get the data pointer of the vector.
Definition: sequential_vector.cpp:596
pargemslr::SequentialVectorClass::Setup
int Setup(int length)
Free the current vector, and malloc memory to initilize the vector.
Definition: sequential_vector.cpp:178
pargemslr::SequentialVectorClass::GetDataLocation
virtual int GetDataLocation() const
Get the data location of the vector.
Definition: sequential_vector.cpp:640
pargemslr::SequentialVectorClass::NormInf
virtual int NormInf(float &norm)
Compute the inf-norm of a vector, result is type float.
Definition: sequential_vector.cpp:1110
pargemslr::ComplexValueClass
The template class complex.
Definition: complex.hpp:24
pargemslr::SequentialVectorClass::SequentialVectorClass
SequentialVectorClass()
The constructor of SequentialVectorClass.
Definition: sequential_vector.cpp:21
pargemslr::SequentialVectorClass::Dot
virtual int Dot(const VectorClass< T > &y, T &t) const
Compute the dot product.
Definition: sequential_vector.cpp:1166
pargemslr::SequentialVectorClass::Max
T Max() const
Get the max value in the vector.
Definition: sequential_vector.cpp:853
pargemslr::SequentialVectorClass::MinIndex
int MinIndex() const
Get the index of the min value in the vector.
Definition: sequential_vector.cpp:881
pargemslr::SequentialVectorClass::UpdatePtr
int UpdatePtr(void *data, int location)
Update the Ptr with new memory address, keep the current length information. Need to call SetupPtrStr...
Definition: sequential_vector.cpp:308
pargemslr::SequentialVectorClass::IsHoldingData
bool IsHoldingData() const
Check if the vector holding its own data.
Definition: sequential_vector.cpp:684
pargemslr::SequentialVectorClass::Axpy
virtual int Axpy(const T &alpha, const VectorClass< T > &x)
Compute y = alpha * x + y, where y is this vector. Currenlty we don't support x == y.
Definition: sequential_vector.cpp:1047
pargemslr::SequentialVectorClass::BinarySearch
int BinarySearch(const T &val, int &idx, bool ascending)
Binary search between [s, e] inside an array.
Definition: sequential_vector.cpp:891
pargemslr::SequentialVectorClass::Perm
int Perm(IntVectorClass< int > &perm)
Apply permutation to the current vector v := v(perm).
Definition: sequential_vector.cpp:828
pargemslr::PargemslrIsComplex
Tell if a value is a complex value.
Definition: complex.hpp:684
pargemslr::SequentialVectorClass::GetLengthLocal
virtual int GetLengthLocal() const
Get the local length of the vector.
Definition: sequential_vector.cpp:654
pargemslr::SequentialVectorClass::ReadFromMMFile
int ReadFromMMFile(const char *vecfile, int idxin)
Read vector on the host memory, matrix market format.
Definition: sequential_vector.cpp:1192
pargemslr::SequentialVectorClass::operator[]
virtual T & operator[](int i)
Get the reference of an index in the vector.
Definition: sequential_vector.cpp:166
pargemslr::SequentialVectorClass::MaxIndex
int MaxIndex() const
Get the index of the max value in the vector.
Definition: sequential_vector.cpp:863
pargemslr::SequentialVectorClass::~SequentialVectorClass
virtual ~SequentialVectorClass()
The destructor of SequentialVectorClass.
Definition: sequential_vector.cpp:586
pargemslr::SequentialVectorClass::PlotAbsGnuPlot
int PlotAbsGnuPlot(const char *datafilename, int conditiona, int conditionb, bool logx, bool logy, int pttype=0)
Print the absolute value of this vector using GnuPlot.
Definition: sequential_vector.cpp:920
pargemslr::SequentialVectorClass::Clear
virtual int Clear()
Free the current vector.
Definition: sequential_vector.cpp:431
pargemslr::SequentialVectorClass::Fill
virtual int Fill(const T &v)
Fill the vector with constant value.
Definition: sequential_vector.cpp:706
pargemslr::SequentialVectorClass::Norm2
virtual int Norm2(float &norm) const
Compute the 2-norm of a vector, result is type float.
Definition: sequential_vector.cpp:1084
pargemslr::SequentialVectorClass::Rand
virtual int Rand()
Fill the vector with random value.
Definition: sequential_vector.cpp:739