SMG2S
Sparse Matrix Generator with Given Spectrum
parVector< T, S > Class Template Reference

A class which defines a vector distributed across 1D MPI grid. More...

#include <parVector.hpp>

Public Member Functions

 parVector (MPI_Comm ncomm, S lbound, S ubound)
 A constructor of `parVector`. More...
 
 parVector (parVectorMap< S > map)
 A constructor of `parVectorMap`. More...
 
 ~parVector ()
 A destructor.
 
parVectorMap< S > GetVecMap ()
 Return parVector::index_map.
 
GetLowerBound ()
 Return the lower_bound on each MPI proc.
 
GetUpperBound ()
 Return the upper_bound on each MPI proc.
 
GetGlobalSize ()
 Return parVector<S>::global_size.
 
GetLocalSize ()
 Return parVector<S>::local_size.
 
GetRank ()
 Return parVector<S>::MyPID.
 
GetUpperNeighbor (S offset)
 For each MPI of rank `i`, get a value from the local vector stored on rank `i-1`. More...
 
GetLowerNeighbor (S offset)
 For each MPI of rank `i`, get a value from the local vector stored on rank `i+1`. More...
 
GetValue (S index)
 Get a value of vector with a given global index. More...
 
GetValueLocal (S lindex)
 Get a value of vector with a given local index on each MPI proc. More...
 
T * GetArray ()
 Get the pointer `*array` which stores the local piece of vector on each MPI proc.
 
MPI_Comm GetComm ()
 Get working MPI communicator.
 
Loc2Glob (S local_index)
 Convert a index of local vector on each MPI proc into its index in the global distributed vector. More...
 
Glob2Loc (S global_index)
 Convert a index of global vector into its index in the local vector on each MPI proc. More...
 
void SetToValue (T value)
 Set all the entries of a vector to a same value. More...
 
void SetToZero ()
 Set all the entries of a vector to zero.
 
void SetValueLocal (S row, T value)
 Set a value on a local index of piece of distributed vector on each MPI proc. More...
 
void SetValuesLocal (S nindex, S *rows, T *values)
 Set multiple values with multiple local indices of piece of distributed vector on each MPI proc. More...
 
void SetValueGlobal (S index, T value)
 Set a value with a global index distributed vector. More...
 
void SetValuesGlobal (S nindex, S *rows, T *values)
 Set multiple values with multiple global indices of distributed vector. More...
 
void AddValueLocal (S row, T value)
 add a value onto the value with a given global index of distributed vector More...
 
void AddValuesLocal (S nindex, S *rows, T *values)
 Add multiple values with multiple global indices onto the related values of distributed vector. More...
 
void VecAdd (parVector v)
 Add with another vector. More...
 
void VecScale (T scale)
 Scale all the elements of a vector with `scale`. More...
 
VecDot (parVector v)
 Compute the dot product with another vector `v`. More...
 
void ReadExtVec (std::string spectrum)
 Read a vector from local text file. More...
 
void writeToTxt (std::string file_name)
 Write a parVector in real scalar to a local file. More...
 
void writeToTxtCmplx (std::string file_name)
 Write a parVector in complex scalar to a local file. More...
 
void VecView ()
 Display the vector in a distributed manner.
 

Private Attributes

T * array
 An array store the local piece of a global vector on each MPI proc.
 
local_size
 The number of elements of vector stored on each MPI proc.
 
global_size
 Global size of this distributed vector.
 
MPI_Comm comm
 The working MPI Communicator.
 
parVectorMap< S > index_map
 A parVectorMap object which shows the distribution scheme of a vector.
 
int MyPID
 rank of each MPI procs within the working MPI communicator parVectorMap::comm
 
int nProcs
 number of MPI procs within the working MPI communicator parVectorMap::comm
 

Detailed Description

template<typename T, typename S>
class parVector< T, S >

A class which defines a vector distributed across 1D MPI grid.

  • This class can be constructed with user-provided of index ranges `[lower_bound, upper_bound)` of vector on each MPI proc.
  • This class can be constructed with a distribution scheme by a given parVectorMap object.
Template Parameters
Tdescribes the scalar types of the entries of vector.
Stype of integer to describes the dimension of vector to be generated.

Constructor & Destructor Documentation

◆ parVector() [1/2]

template<typename T , typename S >
parVector< T, S >::parVector ( MPI_Comm  ncomm,
lbound,
ubound 
)

A constructor of `parVector`.

Parameters
[in]ncommthe working MPI Communicator
[in]lboundthe smallest index of a distributed vector on each MPI proc
[in]ubound`ubound-1 = ` the largest index of a distributed vector on each MPI proc

◆ parVector() [2/2]

template<typename T , typename S >
parVector< T, S >::parVector ( parVectorMap< S >  map)

A constructor of `parVectorMap`.

Parameters
[in]mapthe distribution scheme determined by this object of type parVectorMap

Member Function Documentation

◆ AddValueLocal()

template<typename T , typename S >
void parVector< T, S >::AddValueLocal ( row,
value 
)

add a value onto the value with a given global index of distributed vector

Parameters
[in]rowthe global index
[in]valuethe scalar to be added

◆ AddValuesLocal()

template<typename T , typename S >
void parVector< T, S >::AddValuesLocal ( nindex,
S *  rows,
T *  values 
)

Add multiple values with multiple global indices onto the related values of distributed vector.

Parameters
[in]nindexnumber of values to be set
[in]rowsan pointer stores all the values to be set
[in]valuesan pointer stores all the indices to be set

◆ GetLowerNeighbor()

template<typename T , typename S >
T parVector< T, S >::GetLowerNeighbor ( offset)

For each MPI of rank `i`, get a value from the local vector stored on rank `i+1`.

Parameters
[in]offsetget the value from local vector on rank `i+1` with index `offset`.
  • Attention, for the MPI rank `nProcs-1`, the value is obtained from the MPI proc of rank `0`.

◆ GetUpperNeighbor()

template<typename T , typename S >
T parVector< T, S >::GetUpperNeighbor ( offset)

For each MPI of rank `i`, get a value from the local vector stored on rank `i-1`.

Parameters
[in]offsetget the value from local vector on rank `i-1` with index `upper_bound-1-offset`.
  • Attention, for the MPI rank `0`, the value is obtained from the MPI proc of rank `nProcs-1`.

◆ GetValue()

template<typename T , typename S >
T parVector< T, S >::GetValue ( index)
inline

Get a value of vector with a given global index.

Parameters
[in]indexthe querying global index
  • Attention, this function is naturally distributed, so each MPI proc can only query the value within its range `[lower_bound, upper_bound)`.

◆ GetValueLocal()

template<typename T , typename S >
T parVector< T, S >::GetValueLocal ( lindex)
inline

Get a value of vector with a given local index on each MPI proc.

Parameters
[in]lindexthe querying local index

◆ Glob2Loc()

template<typename T , typename S >
S parVector< T, S >::Glob2Loc ( global_index)
inline

Convert a index of global vector into its index in the local vector on each MPI proc.

Parameters
[in]global_indexthe index global vector to be converted
  • Attention, this function is in distributed manner, each MPI proc can only convert the global index of vector in the range `[lower_bound, upper_bound)`.

◆ Loc2Glob()

template<typename T , typename S >
S parVector< T, S >::Loc2Glob ( local_index)
inline

Convert a index of local vector on each MPI proc into its index in the global distributed vector.

Parameters
[in]local_indexthe index local vector to be converted
  • Attention, this function is in distributed manner, each MPI proc can only convert the local index of vector stored on itself.

◆ ReadExtVec()

template<typename T , typename S >
void parVector< T, S >::ReadExtVec ( std::string  spectrum)

Read a vector from local text file.

Parameters
[in]spectruma `std::string` indicates the path+filename of local text file

◆ SetToValue()

template<typename T , typename S >
void parVector< T, S >::SetToValue ( value)

Set all the entries of a vector to a same value.

Parameters
[in]valuethe value to be set

◆ SetValueGlobal()

template<typename T , typename S >
void parVector< T, S >::SetValueGlobal ( index,
value 
)

Set a value with a global index distributed vector.

Parameters
[in]indexthe global index
[in]valuethe scalar to be set

◆ SetValueLocal()

template<typename T , typename S >
void parVector< T, S >::SetValueLocal ( row,
value 
)

Set a value on a local index of piece of distributed vector on each MPI proc.

Parameters
[in]rowthe local index
[in]valuethe scalar to be set

◆ SetValuesGlobal()

template<typename T , typename S >
void parVector< T, S >::SetValuesGlobal ( nindex,
S *  rows,
T *  values 
)

Set multiple values with multiple global indices of distributed vector.

Parameters
[in]nindexnumber of values to be set
[in]rowsan pointer stores all the values to be set
[in]valuesan pointer stores all the indices to be set

◆ SetValuesLocal()

template<typename T , typename S >
void parVector< T, S >::SetValuesLocal ( nindex,
S *  rows,
T *  values 
)

Set multiple values with multiple local indices of piece of distributed vector on each MPI proc.

Parameters
[in]nindexnumber of values to be set
[in]rowsan pointer stores all the values to be set
[in]valuesan pointer stores all the indices to be set

◆ VecAdd()

template<typename T , typename S >
void parVector< T, S >::VecAdd ( parVector< T, S >  v)

Add with another vector.

Parameters
[in]vthe parVector object used to be added

◆ VecDot()

template<typename T , typename S >
T parVector< T, S >::VecDot ( parVector< T, S >  v)

Compute the dot product with another vector `v`.

Parameters
[in]vthe parVector object used to perform a dot product
  • Attention, the results of dot product is stored rebundantly across all MPI procs

◆ VecScale()

template<typename T , typename S >
void parVector< T, S >::VecScale ( scale)

Scale all the elements of a vector with `scale`.

Parameters
[in]scalethe value used for scaling on the vector

◆ writeToTxt()

template<typename T , typename S >
void parVector< T, S >::writeToTxt ( std::string  file_name)

Write a parVector in real scalar to a local file.

Parameters
[in]file_namea `std::string` indicates the path+filename to write into

◆ writeToTxtCmplx()

template<typename T , typename S >
void parVector< T, S >::writeToTxtCmplx ( std::string  file_name)

Write a parVector in complex scalar to a local file.

Parameters
[in]file_namea `std::string` indicates the path+filename to write into

The documentation for this class was generated from the following file: