ParGeMSLR
parallel_vector.hpp
Go to the documentation of this file.
1 #ifndef PARGEMSLR_PARALLEL_VECTOR_H
2 #define PARGEMSLR_PARALLEL_VECTOR_H
3 
8 #include <iostream>
9 
10 #include "../utils/utils.hpp"
11 #include "vector.hpp"
12 #include "int_vector.hpp"
13 #include "sequential_vector.hpp"
14 #include "../matrices/parallel_csr_matrix.hpp"
15 
16 namespace pargemslr
17 {
18 
23  template <typename T>
24  class ParallelVectorClass: public VectorClass<T>
25  {
26  private:
27 
32  SequentialVectorClass<T> _data_vec;
33 
38  long int _n_start;
39 
44  long int _n_global;
45 
46  public:
47 
53 
59  ParallelVectorClass(const ParallelVectorClass<T> &vec);
60 
66  ParallelVectorClass( ParallelVectorClass<T> &&vec);
67 
74  ParallelVectorClass<T>& operator= (const ParallelVectorClass<T> &vec);
75 
82  ParallelVectorClass<T>& operator= ( ParallelVectorClass<T> &&vec);
83 
88  virtual ~ParallelVectorClass();
89 
97  int Setup(int n_local, parallel_log &parlog);
98 
107  int Setup(int n_local, bool setzero, parallel_log &parlog);
108 
118  int Setup(int n_local, int location, bool setzero, parallel_log &parlog);
119 
131  int Setup(int n_local, int reserve, int location, bool setzero, parallel_log &parlog);
132 
142  int Setup(int n_local, long int n_start, long int n_global, parallel_log &parlog);
143 
154  int Setup(int n_local, long int n_start, long int n_global, bool setzero, parallel_log &parlog);
155 
167  int Setup(int n_local, long int n_start, long int n_global, int location, bool setzero, parallel_log &parlog);
168 
182  int Setup(int n_local, long int n_start, long int n_global, int reserve, int location, bool setzero, parallel_log &parlog);
183 
191  int SetupPtrStr( ParallelVectorClass<T> &x);
192 
200  int SetupPtrStr( ParallelCsrMatrixClass<T> &A);
201 
209  int UpdatePtr( void* data, int location);
210 
217  virtual T& operator[] (int i);
218 
224  virtual int Clear();
225 
231  virtual T* GetData() const;
232 
238  SequentialVectorClass<T>& GetDataVector();
239 
245  virtual int GetDataLocation() const;
246 
252  virtual int GetLengthLocal() const;
253 
259  virtual long int GetLengthGlobal() const;
260 
266  virtual long int GetStartGlobal() const;
267 
273  bool IsHoldingData() const;
274 
280  int SetHoldingData(bool hold_data);
281 
290  int Plot( int conditiona, int conditionb, int width);
291 
298  int WriteToDisk( const char *datafilename);
299 
306  virtual int Fill(const T &v);
307 
313  virtual int Rand();
314 
321  virtual int Scale( const T &alpha);
322 
331  virtual int Axpy( const T &alpha, const VectorClass<T> &x);
332 
341  virtual int Axpy( const T &alpha, const VectorClass<T> &x, VectorClass<T> &y);
342 
352  virtual int Axpy( const T &alpha, const VectorClass<T> &x, const T &beta, VectorClass<T> &y);
353 
360  virtual int Norm2( float &norm) const;
361 
368  virtual int Norm2( double &norm) const;
369 
376  virtual int NormInf( float &norm);
377 
384  virtual int NormInf( double &norm);
385 
393  virtual int Dot( const VectorClass<T> &y, T &t) const;
394 
400  virtual bool IsParallel() const;
401 
402 #ifdef PARGEMSLR_CUDA
403 #if (PARGEMSLR_CUDA_VERSION == 11)
404 
408  virtual cusparseDnVecDescr_t GetCusparseVec() const;
409 
415  int SetCusparseVec(cusparseDnVecDescr_t cusparse_vec);
416 #endif
417 #endif
418 
425  virtual int MoveData( const int &location);
426 
434  int ReadFromSingleMMFile(const char *vecfile, int idxin);
435 
436  };
437 
438  typedef ParallelVectorClass<float> vector_par_float;
439  typedef ParallelVectorClass<double> vector_par_double;
440  typedef ParallelVectorClass<complexs> vector_par_complexs;
441  typedef ParallelVectorClass<complexd> vector_par_complexd;
442  template<> struct PargemslrIsComplex<ParallelVectorClass<complexs> > : public std::true_type {};
443  template<> struct PargemslrIsComplex<ParallelVectorClass<complexd> > : public std::true_type {};
444  template<> struct PargemslrIsParallel<ParallelVectorClass<complexs> > : public std::true_type {};
445  template<> struct PargemslrIsParallel<ParallelVectorClass<complexd> > : public std::true_type {};
446 
447 }
448 
449 #endif
int_vector.hpp
Integer vector data structure, not a vector_base class.
pargemslr::ParallelVectorClass::Plot
int Plot(int conditiona, int conditionb, int width)
Print the vector.
Definition: parallel_vector.cpp:446
pargemslr::ParallelVectorClass::IsParallel
virtual bool IsParallel() const
Tell if this is a prallel vector.
Definition: parallel_vector.cpp:601
vector.hpp
The virtual vector classes.
pargemslr::ParallelVectorClass::GetData
virtual T * GetData() const
Get the data pointer of the vector.
Definition: parallel_vector.cpp:304
pargemslr::ParallelVectorClass::UpdatePtr
int UpdatePtr(void *data, int location)
Update the data with new memory address. Need to call SetupPtrStr first.
Definition: parallel_vector.cpp:266
pargemslr::ParallelVectorClass::NormInf
virtual int NormInf(float &norm)
Compute the inf-norm of a vector, result is type float.
Definition: parallel_vector.cpp:555
pargemslr::ParallelVectorClass::Norm2
virtual int Norm2(float &norm) const
Compute the 2-norm of a vector, result is type float.
Definition: parallel_vector.cpp:529
pargemslr::PargemslrIsParallel
Tell if a value is a parallel data structure.
Definition: utils.hpp:444
pargemslr::ParallelVectorClass::SetupPtrStr
int SetupPtrStr(ParallelVectorClass< T > &x)
Setup the length information of a vector pointer with the information of a ParallelVectorClass.
Definition: parallel_vector.cpp:214
pargemslr::ParallelVectorClass::Fill
virtual int Fill(const T &v)
Fill the vector with constant value.
Definition: parallel_vector.cpp:462
sequential_vector.hpp
Sequential vector data structure.
pargemslr::ParallelVectorClass::MoveData
virtual int MoveData(const int &location)
Move the data to another memory location.
Definition: parallel_vector.cpp:611
pargemslr::ParallelVectorClass::ParallelVectorClass
ParallelVectorClass()
The constructor of ParallelVectorClass.
Definition: parallel_vector.cpp:22
pargemslr::ParallelVectorClass::Setup
int Setup(int n_local, parallel_log &parlog)
Free the current vector, and malloc memory to initilize the vector on comm.
Definition: parallel_vector.cpp:101
pargemslr::ParallelVectorClass::GetDataLocation
virtual int GetDataLocation() const
Get the data location of the vector.
Definition: parallel_vector.cpp:324
pargemslr::ParallelVectorClass
The class of parallel real/complex vector.
Definition: structs.hpp:14
pargemslr::ParallelVectorClass::GetDataVector
SequentialVectorClass< T > & GetDataVector()
Get the reference of the data vector.
Definition: parallel_vector.cpp:314
pargemslr::ComplexValueClass
The template class complex.
Definition: complex.hpp:24
pargemslr::ParallelVectorClass::IsHoldingData
bool IsHoldingData() const
Check if the vector holding its own data.
Definition: parallel_vector.cpp:364
pargemslr::ParallelVectorClass::Dot
virtual int Dot(const VectorClass< T > &y, T &t) const
Compute the dot product.
Definition: parallel_vector.cpp:587
pargemslr::ParallelVectorClass::Rand
virtual int Rand()
Fill the vector with random value.
Definition: parallel_vector.cpp:472
pargemslr::ParallelVectorClass::Scale
virtual int Scale(const T &alpha)
Scale the vector by x = alpha*x, where x is this vector.
Definition: parallel_vector.cpp:482
pargemslr::ParallelVectorClass::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: parallel_vector.cpp:492
pargemslr::PargemslrIsComplex
Tell if a value is a complex value.
Definition: complex.hpp:684
pargemslr::ParallelVectorClass::WriteToDisk
int WriteToDisk(const char *datafilename)
Write file to disk.
Definition: parallel_vector.cpp:384
pargemslr::ParallelVectorClass::operator[]
virtual T & operator[](int i)
Get the reference of an index in the local vector.
Definition: parallel_vector.cpp:91
pargemslr::ParallelVectorClass::GetStartGlobal
virtual long int GetStartGlobal() const
Get the global start index of the vector.
Definition: parallel_vector.cpp:354
pargemslr::ParallelVectorClass::ReadFromSingleMMFile
int ReadFromSingleMMFile(const char *vecfile, int idxin)
Read vector on the host memory, matrix market format. Note that the vector should be setup already (h...
Definition: parallel_vector.cpp:646
pargemslr::ParallelVectorClass::operator=
ParallelVectorClass< T > & operator=(const ParallelVectorClass< T > &vec)
The operator = of ParallelVectorClass.
Definition: parallel_vector.cpp:59
pargemslr::ParallelVectorClass::SetHoldingData
int SetHoldingData(bool hold_data)
Set if the vector holding its own data.
Definition: parallel_vector.cpp:374
pargemslr::ParallelVectorClass::Clear
virtual int Clear()
Free the current vector.
Definition: parallel_vector.cpp:277
pargemslr::ParallelVectorClass::GetLengthLocal
virtual int GetLengthLocal() const
Get the local length of the vector.
Definition: parallel_vector.cpp:334
pargemslr::ParallelVectorClass::GetLengthGlobal
virtual long int GetLengthGlobal() const
Get the global length of the vector.
Definition: parallel_vector.cpp:344
pargemslr::ParallelVectorClass::~ParallelVectorClass
virtual ~ParallelVectorClass()
The destructor of ParallelVectorClass.
Definition: parallel_vector.cpp:294