ParGeMSLR
|
The class of sequential real/complex vector. More...
#include <sequential_vector.hpp>
Public Member Functions | |
SequentialVectorClass () | |
The constructor of SequentialVectorClass. More... | |
SequentialVectorClass (const SequentialVectorClass< T > &vec) | |
The copy constructor of SequentialVectorClass. More... | |
SequentialVectorClass (SequentialVectorClass< T > &&vec) | |
The move constructor of SequentialVectorClass. More... | |
SequentialVectorClass< T > & | operator= (const SequentialVectorClass< T > &vec) |
The = operator of SequentialVectorClass. More... | |
SequentialVectorClass< T > & | operator= (SequentialVectorClass< T > &&vec) |
The = operator of SequentialVectorClass. More... | |
virtual | ~SequentialVectorClass () |
The destructor of SequentialVectorClass. More... | |
int | Setup (int length) |
Free the current vector, and malloc memory to initilize the vector. More... | |
int | Setup (int length, bool setzero) |
Free the current vector, and allocate memory to initilize the vector. More... | |
int | Setup (int length, int location, bool setzero) |
Free the current vector, and allocate memory at give location to initilize the vector. More... | |
int | Setup (int length, int reserve, int location, bool setzero) |
Free the current vector, and allocate memory at give location to initilize the vector. More... | |
int | SetupPtrStr (SequentialVectorClass< T > &x) |
Setup the length information of a vector pointer to be same as another vector. More... | |
int | SetupPtrStr (CsrMatrixClass< T > &A) |
Setup the length information of a vector pointer to be same as the number of rows in a CSR matrix. More... | |
int | SetupPtrStr (int length) |
Setup the length information of a vector pointer. More... | |
int | UpdatePtr (void *data, int location) |
Update the Ptr with new memory address, keep the current length information. Need to call SetupPtrStr first. More... | |
int | SetupPtr (void *data, int length, int location) |
Free the current vector, and points the vector to an address in the memory. More... | |
int | SetupPtr (void *data, int length, int location, bool hold_data) |
Free the current vector, and points the vector to an address in the memory. More... | |
int | SetupPtr (const VectorClass< T > &vec, int length, int shift) |
Free the current vector, and points the vector to a given VectorClass. More... | |
int | SetupPtr (const VectorClass< T > &vec, int length, int shift, bool hold_data) |
Free the current vector, and points the vector to a given VectorClass. More... | |
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. More... | |
int | PushBack (T v) |
Insert value at the end of the vector, expand the vector when necessary. More... | |
int | Resize (int length, bool keepdata, bool setzero) |
Resize the vector. Re-allocate memory when necessary. More... | |
int | Resize (int length, int reserve, bool keepdata, bool setzero) |
Resize the vector. Re-allocate memory when necessary. More... | |
virtual T & | operator[] (int i) |
Get the reference of an index in the vector. More... | |
virtual int | Clear () |
Free the current vector. More... | |
virtual T * | GetData () const |
Get the data pointer of the vector. More... | |
virtual int | GetDataLocation () const |
Get the data location of the vector. More... | |
virtual int | GetLengthLocal () const |
Get the local length of the vector. More... | |
virtual long int | GetLengthGlobal () const |
Get the global length of the vector. More... | |
virtual long int | GetStartGlobal () const |
Get the global start index of the vector. More... | |
bool | IsHoldingData () const |
Check if the vector holding its own data. More... | |
int | SetHoldingData (bool hold_data) |
Set if the vector holding its own data. More... | |
virtual int | Fill (const T &v) |
Fill the vector with constant value. More... | |
virtual int | Rand () |
Fill the vector with random value. More... | |
T | Max () const |
Get the max value in the vector. More... | |
int | MaxIndex () const |
Get the index of the max value in the vector. More... | |
T | Min () const |
Get the min value in the vector. More... | |
int | MinIndex () const |
Get the index of the min value in the vector. More... | |
int | BinarySearch (const T &val, int &idx, bool ascending) |
Binary search between [s, e] inside an array. More... | |
int | Sort (bool ascending) |
Sort the current vector. More... | |
int | Sort (IntVectorClass< int > &order, bool ascending, bool stable) |
Get the order such that v[order] is in ascending or descending order. More... | |
int | Perm (IntVectorClass< int > &perm) |
Apply permutation to the current vector v := v(perm). More... | |
int | Plot (int conditiona, int conditionb, int width) |
Print the vector. More... | |
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. More... | |
int | WriteToDisk (const char *datafilename) |
Write file to disk. More... | |
virtual int | Scale (const T &alpha) |
Scale the vector by x = alpha*x, where x is this vector. More... | |
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. More... | |
virtual int | Axpy (const T &alpha, const VectorClass< T > &x, VectorClass< T > &z) |
Compute z = alpha * x + y, where z is this vector. Currenlty we don't support x == y, x == z or y == z. More... | |
virtual int | Axpy (const T &alpha, const VectorClass< T > &x, const T &beta, VectorClass< T > &z) |
Compute z = alpha * x + beta * y, where z is this vector. Currenlty we don't support x == y, x == z or y == z. More... | |
virtual int | Norm2 (float &norm) const |
Compute the 2-norm of a vector, result is type float. More... | |
virtual int | Norm2 (double &norm) const |
Compute the 2-norm of a vector, result is type double. More... | |
virtual int | NormInf (float &norm) |
Compute the inf-norm of a vector, result is type float. More... | |
virtual int | NormInf (double &norm) |
Compute the inf-norm of a vector, result is type double. More... | |
virtual int | Dot (const VectorClass< T > &y, T &t) const |
Compute the dot product. More... | |
virtual int | MoveData (const int &location) |
Move the data to another memory location. More... | |
int | ReadFromMMFile (const char *vecfile, int idxin) |
Read vector on the host memory, matrix market format. More... | |
The class of sequential real/complex vector.
template pargemslr::SequentialVectorClass< T >::SequentialVectorClass | ( | ) |
The constructor of SequentialVectorClass. The default memory location is the host memory.
pargemslr::SequentialVectorClass< T >::SequentialVectorClass | ( | const SequentialVectorClass< T > & | vec | ) |
The copy constructor of SequentialVectorClass.
[in] | vec | The other vector. |
pargemslr::SequentialVectorClass< T >::SequentialVectorClass | ( | SequentialVectorClass< T > && | vec | ) |
The move constructor of SequentialVectorClass.
[in] | vec | The other vector. |
|
virtual |
The desstructor of seq_vector.
The destructor of SequentialVectorClass. Simply a call to the free function.
The desnstructor of seq_vector. Just call the free function.
|
virtual |
Compute y = alpha * x + y, where y is this vector. Currenlty we don't support x == y.
[in] | alpha | The alpha value. |
[in] | x | The vector. |
|
virtual |
Compute z = alpha * x + beta * y, where z is this vector. Currenlty we don't support x == y, x == z or y == z.
[in] | alpha | The alpha value. |
[in] | x | The first vector. |
[in] | beta | The beta value. |
[in] | y | The second vector. |
|
virtual |
Compute z = alpha * x + y, where z is this vector. Currenlty we don't support x == y, x == z or y == z.
[in] | alpha | The alpha value. |
[in] | x | The first vector. |
[in] | y | The second vector. |
template int pargemslr::SequentialVectorClass< T >::BinarySearch | ( | const T & | val, |
int & | idx, | ||
bool | ascending | ||
) |
Binary search between [s, e] inside an array.
[in] | val | The target value. |
[out] | idx | If found the value, set to the index of the value. Otherwise set to the position to insert, or -1 if s > e. |
[in] | descend | The array is descend or ascend. |
|
virtual |
Free the current vector.
Free the current vector.
template int pargemslr::SequentialVectorClass< T >::Copy | ( | const T * | data, |
int | length, | ||
int | loc_from, | ||
int | loc_to | ||
) |
Free the current vector, allocate memory, and copy data to initilize the vector.
Free the current vector, allocate memory, and copy data to initilize this vector.
[in] | data | The target memory address. |
[in] | length | The new length of this vector. |
[in] | loc_from | The location of the input data. |
[in] | loc_to | The location of the new vector. |
Free the current vector, allocate memory, and copy data to initilize the vector.
[in] | data | The target memory address. |
[in] | length | The length of the vector. |
[in] | loc_from | The location of the input data. |
[in] | loc_to | The location of the new vector. |
|
virtual |
Compute the dot product.
[in] | y | The vector. |
[out] | t | The result. |
|
virtual |
Fill the vector with constant value.
[in] | v | The value to be filled. |
|
virtual |
Get the data pointer of the vector.
|
virtual |
Get the data location of the vector.
|
virtual |
Get the global length of the vector.
|
virtual |
Get the local length of the vector.
|
virtual |
Get the global start index of the vector.
template bool pargemslr::SequentialVectorClass< T >::IsHoldingData | ( | ) | const |
Check if the vector holding its own data.
template double pargemslr::SequentialVectorClass< T >::Max | ( | ) | const |
Get the max value in the vector.
For real vectors only.
template int pargemslr::SequentialVectorClass< T >::MaxIndex | ( | ) | const |
Get the index of the max value in the vector.
For real vectors only.
template double pargemslr::SequentialVectorClass< T >::Min | ( | ) | const |
Get the min value in the vector.
For real vectors only.
template int pargemslr::SequentialVectorClass< T >::MinIndex | ( | ) | const |
Get the index of the min value in the vector.
For real vectors only.
|
virtual |
Move the data to another memory location.
[in] | location | The location move to. |
|
virtual |
Compute the 2-norm of a vector, result is type double.
[out] | norm | The 2-norm. |
|
virtual |
Compute the 2-norm of a vector, result is type float.
[out] | norm | The 2-norm. |
|
virtual |
Compute the inf-norm of a vector, result is type double.
[out] | norm | The inf-norm. |
|
virtual |
Compute the inf-norm of a vector, result is type float.
[out] | norm | The inf-norm. |
SequentialVectorClass< T > & pargemslr::SequentialVectorClass< T >::operator= | ( | const SequentialVectorClass< T > & | vec | ) |
The = operator of SequentialVectorClass.
[in] | vec | The other vector. |
SequentialVectorClass< T > & pargemslr::SequentialVectorClass< T >::operator= | ( | SequentialVectorClass< T > && | vec | ) |
The = operator of SequentialVectorClass.
[in] | vec | The other vector. |
|
virtual |
Get the reference of an index in the vector.
[in] | i | The index. |
template int pargemslr::SequentialVectorClass< T >::Perm | ( | IntVectorClass< int > & | perm | ) |
Apply permutation to the current vector v := v(perm).
[in] | perm | The permutation vector. |
template int pargemslr::SequentialVectorClass< T >::Plot | ( | int | conditiona, |
int | conditionb, | ||
int | width | ||
) |
Print the vector.
[in] | conditiona | First condition. |
[in] | conditionb | Secend condition, only plot when conditiona == conditionb. |
[in] | width | The plot width. |
template int pargemslr::SequentialVectorClass< T >::PlotAbsGnuPlot | ( | const char * | datafilename, |
int | conditiona, | ||
int | conditionb, | ||
bool | logx, | ||
bool | logy, | ||
int | pttype = 0 |
||
) |
Print the absolute value of this vector using GnuPlot.
[in] | datafilename | The filename of the temp file holding the data. |
[in] | conditiona | First condition. |
[in] | conditionb | Secend condition, only plot when conditiona == conditionb. |
[in] | logx | Set to true to plot in log in x. |
[in] | logy | Set to true to plot in log in y. |
[in] | pttype | The dot type in GnuPlot. |
template int pargemslr::SequentialVectorClass< T >::PushBack | ( | T | v | ) |
Insert value at the end of the vector, expand the vector when necessary. Work only when the vector is holding data.
Insert value at the end of the vector, expand the vector when necessary.
Work only when the vector is holding data.
[in] | v | The value to be inserted. |
Insert value at the end of the vector, expand the vector when necessary. Work only when the vector is holding data.
[in] | v | The value to be inserted. |
|
virtual |
Fill the vector with random value.
template int pargemslr::SequentialVectorClass< T >::ReadFromMMFile | ( | const char * | vecfile, |
int | idxin | ||
) |
Read vector on the host memory, matrix market format.
[in] | vecfile | The file. |
[in] | idxin | The index base of the input file. 0-based or 1-based. |
template int pargemslr::SequentialVectorClass< T >::Resize | ( | int | length, |
bool | keepdata, | ||
bool | setzero | ||
) |
Resize the vector. Re-allocate memory when necessary.
[in] | length | The new length of this vector. |
[in] | keepdata | Set to true to keep the data in the current vector. |
[in] | setzero | Set to true to fill the new extra memory with 0 if the vector is expanded. |
Resize the vector. Re-allocate memory when necessary.
[in] | length | The length of the vector. |
[in] | keepdata | Do we keep the data in the current vector. |
[in] | setzero | Do we Fill the new extra memory with 0 if we expand the vector. |
template int pargemslr::SequentialVectorClass< T >::Resize | ( | int | length, |
int | reserve, | ||
bool | keepdata, | ||
bool | setzero | ||
) |
Resize the vector. Re-allocate memory when necessary.
[in] | length | The new length of this vector. |
[in] | reserve | The new reserve length in the memory, should be no less than length. |
[in] | keepdata | Set to true to keep the data in the current vector. |
[in] | setzero | Set to true to fill the new extra memory with 0 if the vector is expanded. |
Resize the vector. Re-allocate memory when necessary.
[in] | length | The length of the vector. |
[in] | reserve | The length allocated in the memory, should be no less than length. |
[in] | keepdata | Do we keep the data in the current vector. |
[in] | setzero | Do we Fill the new extra memory with 0 if we expand the vector. |
|
virtual |
Scale the vector by x = alpha*x, where x is this vector.
[in] | alpha | The scale. |
template int pargemslr::SequentialVectorClass< T >::SetHoldingData | ( | bool | hold_data | ) |
Set if the vector holding its own data.
template int pargemslr::SequentialVectorClass< T >::Setup | ( | int | length | ) |
Free the current vector, and malloc memory to initilize the vector.
[in] | length | The length of the vector. |
template int pargemslr::SequentialVectorClass< T >::Setup | ( | int | length, |
bool | setzero | ||
) |
Free the current vector, and allocate memory to initilize the vector.
[in] | length | The length of the vector. |
[in] | setzero | Call calloc if we need to fill the memory with 0. |
template int pargemslr::SequentialVectorClass< T >::Setup | ( | int | length, |
int | location, | ||
bool | setzero | ||
) |
Free the current vector, and allocate memory at give location to initilize the vector.
[in] | length | The length of the vector. |
[in] | location | The location of the vector. |
[in] | setzero | Call calloc if we need to fill the memory with 0. |
template int pargemslr::SequentialVectorClass< T >::Setup | ( | int | length, |
int | reserve, | ||
int | location, | ||
bool | setzero | ||
) |
Free the current vector, and allocate memory at give location to initilize the vector.
The actual memory size is set by the value reserve, and the vector length is given by the value length.
[in] | length | The length of the vector. |
[in] | reserve | The length allocated in the memory, should be no less than length. |
[in] | location | The location of the vector. |
[in] | setzero | Call calloc if we need to fill the memory with 0. |
int pargemslr::SequentialVectorClass< T >::SetupPtr | ( | const VectorClass< T > & | vec, |
int | length, | ||
int | shift | ||
) |
Free the current vector, and points the vector to a given VectorClass. The memory will not be freed by this vector.
[in] | vec | The target vector. |
[in] | length | The new length of this vector. |
[in] | shift | The shift in the target vector. this->_data = vec.GetData() + shift. |
int pargemslr::SequentialVectorClass< T >::SetupPtr | ( | const VectorClass< T > & | vec, |
int | length, | ||
int | shift, | ||
bool | hold_data | ||
) |
Free the current vector, and points the vector to a given VectorClass.
[in] | vec | The target vector. |
[in] | length | The new length of this vector. |
[in] | shift | The shift in the target vector. this->_data = vec.GetData() + shift. |
[in] | hold_data | Set to true if this vector should free the data. Typically this function should not be used. |
template int pargemslr::SequentialVectorClass< T >::SetupPtr | ( | void * | data, |
int | length, | ||
int | location | ||
) |
Free the current vector, and points the vector to an address in the memory. The memory will not be freed by this vector.
[in] | data | The address of the data. |
[in] | length | The length of the vector. |
[in] | location | The location of the data. |
template int pargemslr::SequentialVectorClass< T >::SetupPtr | ( | void * | data, |
int | length, | ||
int | location, | ||
bool | hold_data | ||
) |
Free the current vector, and points the vector to an address in the memory.
[in] | data | The address of the data. |
[in] | length | The length of the vector. |
[in] | location | The location of the data. |
[in] | hold_data | Set to true if this vector should free the data. |
int pargemslr::SequentialVectorClass< T >::SetupPtrStr | ( | CsrMatrixClass< T > & | A | ) |
Setup the length information of a vector pointer to be same as the number of rows in a CSR matrix.
This will only set the length, need to call UpdatePtr function to set data.
[in] | A | The CsrMatrixClass. |
template int pargemslr::SequentialVectorClass< T >::SetupPtrStr | ( | int | length | ) |
Setup the length information of a vector pointer.
This will only set the length, need to call UpdatePtr function to set data.
[in] | length | The new length. |
int pargemslr::SequentialVectorClass< T >::SetupPtrStr | ( | SequentialVectorClass< T > & | x | ) |
Setup the length information of a vector pointer to be same as another vector.
This will only set the length, need to call UpdatePtr function to set data.
[in] | x | The SequentialVectorClass. |
template int pargemslr::SequentialVectorClass< T >::Sort | ( | bool | ascending | ) |
Sort the current vector.
For real vectors only.
[in] | ascending | Sort in ascending or descending. |
template int pargemslr::SequentialVectorClass< T >::Sort | ( | IntVectorClass< int > & | order, |
bool | ascending, | ||
bool | stable | ||
) |
Get the order such that v[order] is in ascending or descending order.
Without modifying the current vector.
For real vectors only.
[out] | order | The order vector. |
[in] | ascending | Sort in ascending or descending. |
[in] | stable | Use stable sort or not. |
template int pargemslr::SequentialVectorClass< T >::UpdatePtr | ( | void * | data, |
int | location | ||
) |
Update the Ptr with new memory address, keep the current length information. Need to call SetupPtrStr first.
[in] | data | The address of the data. |
[in] | location | The location of the data. |
template int pargemslr::SequentialVectorClass< T >::WriteToDisk | ( | const char * | datafilename | ) |
Write file to disk.
[in] | datafilename | The filename of the file holding the data. |