CEPS  24.01
Cardiac ElectroPhysiology Simulator
DistributedHaloVector Class Reference

Detailed Description

Extended distributed vectors.

This class implements a vector that is essentialy the same as a DistributedVector, but has additional padded values that hold halo values. Consider this example of a partitioned 1d cable:

  0       1       2    |     3       4      5
  o-------o-------o----|-----o-------o------o
          P0           |          P1

P0 owns node 0, 1 and 2.
P1 owns 3 4 and 5.
GeomNode 2 is halo for P1 and node 3 is halo for P0.
In a traditional distributed vector, there is no way for P0 to read the value for node 3, because it is physically located on another process. Similarily, P1 cannot read the value of node 2.
This class has additional memory reserved for these halo nodes:
When the vector is assembled, the halo values are also exchanged, so that each process knows the correct value of each node and halo node.

In short, use this type of vector when you know you need the halo values. The usage is similar to parent DistributedVector class. However, it is a bit slower.

Definition at line 60 of file DistributedHaloVector.hpp.

#include <DistributedHaloVector.hpp>

Inheritance diagram for DistributedHaloVector:
[legend]

Public Member Functions

 DistributedHaloVector ()
 Default constructor. More...
 
 DistributedHaloVector (DistributedHaloVector &v)
 Copy constructor. More...
 
 DistributedHaloVector (CepsIndex M, CepsIndex m, CepsIndex nbHaloRows, CepsIndex *haloRows)
 Constructor. More...
 
 ~DistributedHaloVector () override
 Destructor. More...
 
void getLocalData () override
 Mandatory call before accessing data. More...
 
void releaseLocalData () override
 Mandatory call after accessing data. More...
 
void getStripe (DistributedHaloVector &u, CepsInt component, CepsUInt pbDim)
 Override of DistributedVector::getStripe(...) More...
 
void getValues (CepsReal *values, CepsIndex n, const CepsIndex *indices) override
 Override of parent DistributedVector::getValues(...) More...
 
CepsInt getNbHalo ()
 number of halo values More...
 
CepsRealoperator[] (CepsIndex globalIndex) override
 Array subscription override. More...
 
CepsReal operator[] (CepsIndex globalIndex) const override
 Array subscription override. Const version. More...
 
DistributedHaloVectoroperator= (DistributedHaloVector &v)
 Assignment operator. More...
 
DistributedHaloVectoroperator= (DistributedVector &v)
 Assignment operator. More...
 
void getStripeFromNonHalo (DistributedVector &src, CepsInt component, CepsUInt pbDim)
 Get data from regular dist vector. More...
 
void scale (CepsMathScalar alpha) override
 Multiplies self by alpha. More...
 
void abs () override
 Sets all coeffs to their absolute value. More...
 
- Public Member Functions inherited from DistributedVector
 DistributedVector ()
 Default Constructor. More...
 
 DistributedVector (const DistributedVector &v)
 Copy constructor. More...
 
DistributedVectoroperator= (const DistributedVector &v)
 Assignment operator. More...
 
 DistributedVector (CepsInt M, CepsInt m)
 Constructor with sizes. More...
 
 DistributedVector (DistributedVector &templateVector, CepsBool copyValues, CepsBool isSequential=false)
 Constructor with the same structure as the given vector. More...
 
 DistributedVector (std::shared_ptr< DistributedVector > templateVector, CepsBool copyValues, CepsBool isSequential=false)
 Constructor with the same structure as the given vector. More...
 
 DistributedVector (DMatPtr mat, CepsGlobalIndex row)
 Build vector from a matrix row. More...
 
virtual ~DistributedVector ()
 Destructor. More...
 
CepsString getUnit () const
 Units of data. More...
 
void setUnit (const CepsString &u)
 Units of data. More...
 
CepsMathScalarlocalData ()
 Point on the local data. More...
 
void setSize (CepsInt M, CepsInt m)
 Set distributed vector size. More...
 
void getSize (CepsInt *globalSize) const
 Get the global size of the vector. More...
 
CepsInt getSize () const
 Get the global size of the vector. More...
 
void getLocalSize (CepsInt *localSize) const
 Get the number of rows owned by current process. More...
 
CepsInt getLocalSize () const
 Get the local size of the vector. More...
 
void getLocalRange (CepsGlobalIndex *lo, CepsGlobalIndex *hi) const
 Get the range of rows owned by current process. More...
 
const PetscVector & getVector () const
 The underlying vector. More...
 
void setValue (CepsMathScalar value, CepsGlobalIndex i)
 Sets or replaces a single value. More...
 
void addValue (CepsMathScalar value, CepsGlobalIndex i)
 Adds given scalar to the currently existing value or set it if not. More...
 
void ignoreOffProcEntries (CepsBool ignore)
 Sets whether the values on rows that are not owned by current process will be ignored or not. More...
 
void setValues (const CepsMathScalar *values, CepsInt n, const CepsGlobalIndex *indices)
 Sets n multiple values. More...
 
void setValuesLocal (DistributedVector &values, CepsInt n, const CepsGlobalIndex *indices=nullptr)
 Sets n multiple local values. More...
 
void setValuesLocal (const CepsMathScalar *values, CepsInt n, const CepsGlobalIndex *indices=nullptr)
 Sets n multiple local values. More...
 
void setValuesLocal (const CepsVector< CepsMathScalar > &values, const CepsVector< CepsGlobalIndex > &indices)
 Sets multiple local values, PetscVector version. More...
 
void addValues (const CepsMathScalar *values, CepsInt n, const CepsGlobalIndex *indices)
 Add multiple values to already existing values. More...
 
void addValuesLocal (DistributedVector &values, CepsInt n, const CepsGlobalIndex *indices=nullptr)
 Add multiple local values to already existing values. More...
 
void addValuesLocal (const CepsMathScalar *values, CepsInt n, const CepsGlobalIndex *indices=nullptr)
 Add multiple local values to already existing values. More...
 
void addSubVector (const CepsMathDynamic1D &subVector, const CepsVector< CepsGlobalIndex > &rowIndices)
 Adds a vector in a distributed vector. More...
 
void insertSubVector (const CepsMathDynamic1D &subVector, const CepsVector< CepsGlobalIndex > &rowIndices)
 Insert (i.e. set) a vector in a distributed vector. More...
 
CepsVector< CepsMathScalargetSubVector (const CepsVector< CepsGlobalIndex > &rowIndices)
 Get some local data from the distributed vector. More...
 
void zero ()
 Fills vector with zeros. More...
 
void fill (CepsMathScalar value)
 Fills vector with given value. More...
 
void duplicate (DistributedVector &dest, CepsBool copyValues) const
 Shares the non-zero structure, and optionally values. More...
 
void beginAssembly ()
 Start distributed vector assembly. More...
 
void endAssembly ()
 Wait for the distributed vector assembly to finish. More...
 
void finalize ()
 Calls both beginAssembly() and endAssembly() More...
 
CepsBool isAssembled () const
 true if vector has been assembled More...
 
CepsBool sameSize (const DistributedVector &vec) const
 Compares global sizes. More...
 
CepsBool sameLocalRange (const DistributedVector &vec) const
 Compares local ranges. More...
 
CepsBool equals (const DistributedVector &vec, CepsMathScalar errorFactor=1.0) const
 Whether two vector have the (exact!) same values on all process. More...
 
CepsBool approxEquals (const DistributedVector &vec, CepsMathScalar epsilon) const
 Whether two vector have the approximately the same values on all process, with epsilon tolerance. More...
 
void checkNanOrInf (CepsString message="")
 Stops if there are coefficients that are nan or inf. More...
 
void add (const DistributedVector &x)
 Adds x to current vector. More...
 
void addScaled (const DistributedVector &x, CepsMathScalar alpha)
 Adds alpha*x to current vector. More...
 
virtual void pointWiseScale (const DistributedVector &x, CepsBool divide=false)
 Perform a point wise multiplication or division on this vector by another vector. More...
 
virtual void mult (const DistributedMatrix &A, const DistributedVector &x)
 Sets current vector to result of product A*x. More...
 
CepsMathScalar dot (DistributedVector &x)
 Computes the inner product of current vector by x. More...
 
CepsMathScalar lInfNorm () const
 $l^inf$-norm of vector More...
 
CepsMathScalar l1Norm () const
 $l^1$-norm of vector More...
 
CepsMathScalar l2Norm () const
 $l^2$-norm of vector More...
 
void view () const
 Display vector on standard output. More...
 
DistributedVectoroperator+= (const DistributedVector &v)
 Short addition with other vector. More...
 
DistributedVectoroperator+= (const CepsMathScalar &scalar)
 Short addition with scalar. More...
 
DistributedVectoroperator-= (const DistributedVector &v)
 Short substraction with other vector. More...
 
DistributedVectoroperator-= (const CepsMathScalar &scalar)
 Short substraction with scalar. More...
 
DistributedVectoroperator*= (const CepsMathScalar &scalar)
 Short mult by scalar. More...
 
void fillFromVector (const CepsVector< CepsMathScalar > &data)
 Fills the distributed vector with data stored in a vector on process 0. More...
 

Protected Attributes

std::map< CepsIndex, CepsIndexm_globalToLocalMapping
 Index mapping. More...
 
CepsIndex m_nbHaloRows
 Number of halo values that will be received. More...
 
- Protected Attributes inherited from DistributedVector
CepsString m_unit
 Unit of the data. More...
 
PetscVector m_v
 The underlying vector. More...
 
CepsGlobalIndex m_lo
 Index of first owned row. More...
 
CepsGlobalIndex m_hi
 Index of row right after last owned row. More...
 
CepsInt m_globalSize
 Global size of vector. More...
 
CepsInt m_localSize
 Local size of vector. More...
 
CepsMathScalarm_localData
 
CepsBool m_mayReadData
 
CepsBool m_isAssembled
 Whether this vector is assembled or not. More...
 
CepsBool m_initialized
 Whether this vector is ready to be used or not. More...
 
CepsBool m_vecCreated
 Underlying vec created. More...
 

Private Member Functions

void initialize ()
 

Private Attributes

PetscVector m_localV
 Local representation of the halo vector. More...
 

Additional Inherited Members

- Protected Member Functions inherited from DistributedVector
void checkAndSetSizes (CepsInt gSize, CepsInt lSize)
 Check if calling vector has had its sizes set. If not, set sizes. More...
 
void createEmptyVector ()
 Inits the underlying vector. Use setSize afterwards. More...
 

Constructor & Destructor Documentation

◆ DistributedHaloVector() [1/3]

DistributedHaloVector::DistributedHaloVector ( )

Default constructor.

◆ DistributedHaloVector() [2/3]

DistributedHaloVector::DistributedHaloVector ( DistributedHaloVector v)

Copy constructor.

◆ DistributedHaloVector() [3/3]

DistributedHaloVector::DistributedHaloVector ( CepsIndex  M,
CepsIndex  m,
CepsIndex  nbHaloRows,
CepsIndex haloRows 
)

Constructor.

Parameters
[in]Mtotal vector size
[in]mlocal size
[in]nbHaloRowsnumber of additional rows
[in]haloRowsglobal indices of halo rows

◆ ~DistributedHaloVector()

DistributedHaloVector::~DistributedHaloVector ( )
override

Destructor.

Member Function Documentation

◆ abs()

void DistributedHaloVector::abs ( )
overridevirtual

Sets all coeffs to their absolute value.

Reimplemented from DistributedVector.

◆ getLocalData()

void DistributedHaloVector::getLocalData ( )
overridevirtual

Mandatory call before accessing data.

Reimplemented from DistributedVector.

◆ getNbHalo()

CepsInt DistributedHaloVector::getNbHalo ( )

number of halo values

◆ getStripe()

void DistributedHaloVector::getStripe ( DistributedHaloVector u,
CepsInt  component,
CepsUInt  pbDim 
)

Override of DistributedVector::getStripe(...)

Has the same functionality, but works from halo vector to halo vector. Moreover, the destination vector u must already be properly initialized (of correct size and memory allocation).

Parameters
[out]udestination halo vector
[in]componentwhich component to copy. 0 <= component < DIM
[in]pbDimnumber of unknowns per dof

◆ getStripeFromNonHalo()

void DistributedHaloVector::getStripeFromNonHalo ( DistributedVector src,
CepsInt  component,
CepsUInt  pbDim 
)

Get data from regular dist vector.

◆ getValues()

void DistributedHaloVector::getValues ( CepsReal values,
CepsIndex  n,
const CepsIndex indices 
)
overridevirtual

Override of parent DistributedVector::getValues(...)

Users must still call DistributedHaloVector::getLocalData(...) before reading any values, and then DistributedHaloVector::releaseLocalData() when reading is done.

Parameters
[out]valueswhere the read values will be stored
[in]nnumber of values to read
[in]indicesglobal row indices to read. May hold halo rows.

Reimplemented from DistributedVector.

◆ initialize()

void DistributedHaloVector::initialize ( )
private

◆ operator=() [1/2]

DistributedHaloVector& DistributedHaloVector::operator= ( DistributedHaloVector v)

Assignment operator.

◆ operator=() [2/2]

DistributedHaloVector& DistributedHaloVector::operator= ( DistributedVector v)

Assignment operator.

◆ operator[]() [1/2]

CepsReal DistributedHaloVector::operator[] ( CepsIndex  globalIndex) const
overridevirtual

Array subscription override. Const version.

Much slower than parent's class operator.

Parameters
[in]globalIndexglobal row to read. May be halo.
Returns
value at globalIndex

Reimplemented from DistributedVector.

◆ operator[]() [2/2]

CepsReal& DistributedHaloVector::operator[] ( CepsIndex  globalIndex)
overridevirtual

Array subscription override.

Much slower than parent's class operator.

Parameters
[in]globalIndexglobal row to read. May be halo.
Returns
value at globalIndex

Reimplemented from DistributedVector.

◆ releaseLocalData()

void DistributedHaloVector::releaseLocalData ( )
overridevirtual

Mandatory call after accessing data.

Reimplemented from DistributedVector.

◆ scale()

void DistributedHaloVector::scale ( CepsMathScalar  alpha)
overridevirtual

Multiplies self by alpha.

Parameters
[in]alphascale factor

Reimplemented from DistributedVector.

Field Documentation

◆ m_globalToLocalMapping

std::map<CepsIndex, CepsIndex> DistributedHaloVector::m_globalToLocalMapping
protected

Index mapping.

Definition at line 173 of file DistributedHaloVector.hpp.

◆ m_localV

PetscVector DistributedHaloVector::m_localV
private

Local representation of the halo vector.

Definition at line 178 of file DistributedHaloVector.hpp.

◆ m_nbHaloRows

CepsIndex DistributedHaloVector::m_nbHaloRows
protected

Number of halo values that will be received.

Definition at line 174 of file DistributedHaloVector.hpp.


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