Chaste Commit::f2ff7ee04e70ac9d06c57344df8d017dbb12b97b
DistributedVectorFactory Class Reference

#include <DistributedVectorFactory.hpp>

+ Collaboration diagram for DistributedVectorFactory:

Public Member Functions

 DistributedVectorFactory (Vec vec)
 
 DistributedVectorFactory (unsigned size, PetscInt local=PETSC_DECIDE)
 
 DistributedVectorFactory (DistributedVectorFactory *pOriginalFactory)
 
 DistributedVectorFactory (unsigned lo, unsigned hi, unsigned size, unsigned numProcs=PetscTools::GetNumProcs())
 
 ~DistributedVectorFactory ()
 
Vec CreateVec ()
 
Vec CreateVec (unsigned stride)
 
DistributedVector CreateDistributedVector (Vec vec, bool readOnly=false)
 
bool IsGlobalIndexLocal (unsigned globalIndex)
 
unsigned GetLocalOwnership () const
 
unsigned GetHigh () const
 
unsigned GetLow () const
 
unsigned GetProblemSize () const
 
unsigned GetNumProcs () const
 
DistributedVectorFactoryGetOriginalFactory ()
 
void SetOriginalFactory (DistributedVectorFactory *pOriginalFactory)
 
void SetFromFactory (DistributedVectorFactory *pFactory)
 
std::vector< unsigned > & rGetGlobalLows ()
 

Static Public Member Functions

static void SetCheckNumberOfProcessesOnLoad (bool checkNumberOfProcessesOnLoad=true)
 
static bool CheckNumberOfProcessesOnLoad ()
 

Private Member Functions

void CheckForPetsc ()
 
void CalculateOwnership (Vec vec)
 
template<class Archive >
void serialize (Archive &archive, const unsigned int version)
 

Private Attributes

unsigned mLo
 
unsigned mHi
 
unsigned mProblemSize
 
unsigned mNumProcs
 
bool mPetscStatusKnown
 
std::vector< unsignedmGlobalLows
 
DistributedVectorFactorympOriginalFactory
 

Static Private Attributes

static bool msCheckNumberOfProcessesOnLoad = true
 

Friends

class boost::serialization::access
 

Detailed Description

Factory for creating PETSc vectors distributed across processes.

Replacement for the vector creation portions of DistributedVector (which was implemented using static methods and data), the factory class allows several patterns of PETSc vector length (and distributions among processes) to co-exist.

All vectors created by a factory instance will have the same base size and parallelisation pattern.

Definition at line 57 of file DistributedVectorFactory.hpp.

Constructor & Destructor Documentation

◆ DistributedVectorFactory() [1/4]

DistributedVectorFactory::DistributedVectorFactory ( Vec  vec)

Set the problem with an existing PETSc vector – must have stride=1.

Parameters
vecis a PETSc vector which we want to use as the pattern for future vectors produced by this factory

Definition at line 81 of file DistributedVectorFactory.cpp.

References CalculateOwnership().

◆ DistributedVectorFactory() [2/4]

DistributedVectorFactory::DistributedVectorFactory ( unsigned  size,
PetscInt  local = PETSC_DECIDE 
)

Set the problem size specifying distribution over local processor.

Parameters
sizethe problem size
localdefaults to PETSc's default

Definition at line 88 of file DistributedVectorFactory.cpp.

References CalculateOwnership(), CheckForPetsc(), PetscTools::CreateVec(), and PetscTools::Destroy().

◆ DistributedVectorFactory() [3/4]

DistributedVectorFactory::DistributedVectorFactory ( DistributedVectorFactory pOriginalFactory)

Constructor for use in archiving. Note that this constructor is only called when the number of processes is different from the original. Therefore, the orignal local node ownership cannot be used, and a new even partition will be applied.

Parameters
pOriginalFactorysee mpOriginalFactory

Definition at line 100 of file DistributedVectorFactory.cpp.

References CalculateOwnership(), PetscTools::CreateVec(), PetscTools::Destroy(), GetProblemSize(), and mpOriginalFactory.

◆ DistributedVectorFactory() [4/4]

DistributedVectorFactory::DistributedVectorFactory ( unsigned  lo,
unsigned  hi,
unsigned  size,
unsigned  numProcs = PetscTools::GetNumProcs() 
)

Constructor intended for use in archiving. Allows complete manual specification of the factory.

Parameters
lofirst index owned by this process
hione beyond last index owned by this process
sizetotal size of vectors
numProcsthe number of processes expected (defaults to the current number)

Definition at line 116 of file DistributedVectorFactory.cpp.

References CheckForPetsc().

◆ ~DistributedVectorFactory()

DistributedVectorFactory::~DistributedVectorFactory ( )

Destructor deletes mpOriginalFactory if it exists.

Definition at line 129 of file DistributedVectorFactory.cpp.

References mpOriginalFactory.

Member Function Documentation

◆ CalculateOwnership()

void DistributedVectorFactory::CalculateOwnership ( Vec  vec)
private

Helper method for the constructors.

Parameters
vecthe sample PETSc vector from which to calculate ownerships

Definition at line 44 of file DistributedVectorFactory.cpp.

References CheckForPetsc(), PetscTools::GetNumProcs(), mGlobalLows, mHi, mLo, mNumProcs, mPetscStatusKnown, and mProblemSize.

Referenced by DistributedVectorFactory(), DistributedVectorFactory(), and DistributedVectorFactory().

◆ CheckForPetsc()

void DistributedVectorFactory::CheckForPetsc ( )
private

Double check (in debug code) that PETSc has been initialised properly.

Definition at line 134 of file DistributedVectorFactory.cpp.

References mPetscStatusKnown.

Referenced by DistributedVectorFactory(), DistributedVectorFactory(), and CalculateOwnership().

◆ CheckNumberOfProcessesOnLoad()

static bool DistributedVectorFactory::CheckNumberOfProcessesOnLoad ( )
inlinestatic

Determine whether, when loading an instance from an archive, to check that the current number of processes matches that used in creating the archive.

Returns
true when check is required

Definition at line 249 of file DistributedVectorFactory.hpp.

References msCheckNumberOfProcessesOnLoad.

◆ CreateDistributedVector()

◆ CreateVec() [1/2]

◆ CreateVec() [2/2]

Vec DistributedVectorFactory::CreateVec ( unsigned  stride)

Create a striped PETSc vector of size: stride * problem size.

Parameters
stride
Returns
new PETSc vector

Definition at line 160 of file DistributedVectorFactory.cpp.

References mHi, mLo, and mProblemSize.

◆ GetHigh()

◆ GetLocalOwnership()

◆ GetLow()

◆ GetNumProcs()

◆ GetOriginalFactory()

DistributedVectorFactory * DistributedVectorFactory::GetOriginalFactory ( )
inline

If msCheckNumberOfProcessesOnLoad is not set, and this factory was loaded from an archive, then return a factory with the settings from the archive, which may not be the same as ours - if running on a different number of processes from the original, we will have used PETSC_DECIDE to set the local ownership on load.

Returns
the original factory

Definition at line 261 of file DistributedVectorFactory.hpp.

References mpOriginalFactory.

Referenced by AbstractTetrahedralMesh< ELEMENT_DIM, SPACE_DIM >::load(), AbstractCardiacTissue< ELEMENT_DIM, SPACE_DIM >::LoadCardiacCells(), ExtendedBidomainTissue< SPACE_DIM >::LoadExtendedBidomainCells(), AbstractCardiacProblem< ELEMENT_DIM, SPACE_DIM, PROBLEM_DIM >::LoadExtraArchive(), ExtendedBidomainTissue< SPACE_DIM >::LoadExtracellularStimulus(), and CardiacSimulationArchiver< PROBLEM_CLASS >::Migrate().

◆ GetProblemSize()

◆ IsGlobalIndexLocal()

bool DistributedVectorFactory::IsGlobalIndexLocal ( unsigned  globalIndex)

Test if the given global index is owned by the current process, i.e. is local to it.

Parameters
globalIndexa global index
Returns
true if the global index can be accessed by this process

Definition at line 149 of file DistributedVectorFactory.cpp.

References mHi, and mLo.

Referenced by SingleTraceOutputModifier::InitialiseAtStart(), AbstractCardiacTissue< ELEMENT_DIM, SPACE_DIM >::LoadCardiacCells(), ExtendedBidomainTissue< SPACE_DIM >::LoadExtendedBidomainCells(), and ExtendedBidomainTissue< SPACE_DIM >::LoadExtracellularStimulus().

◆ rGetGlobalLows()

std::vector< unsigned > & DistributedVectorFactory::rGetGlobalLows ( )
Returns
the mLo value from each process in a vector. This is calculated on the first call and cached for later use.

Definition at line 189 of file DistributedVectorFactory.cpp.

References PetscTools::GetNumProcs(), mGlobalLows, and mLo.

◆ serialize()

template<class Archive >
void DistributedVectorFactory::serialize ( Archive &  archive,
const unsigned int  version 
)
inlineprivate

Archive the member variables.

Parameters
archivethe archive
versionthe current version of this class

Definition at line 115 of file DistributedVectorFactory.hpp.

◆ SetCheckNumberOfProcessesOnLoad()

static void DistributedVectorFactory::SetCheckNumberOfProcessesOnLoad ( bool  checkNumberOfProcessesOnLoad = true)
inlinestatic

Set whether, when loading an instance from an archive, to check that the current number of processes matches that used in creating the archive.

Parameters
checkNumberOfProcessesOnLoad

Definition at line 239 of file DistributedVectorFactory.hpp.

References msCheckNumberOfProcessesOnLoad.

Referenced by CardiacSimulationArchiver< PROBLEM_CLASS >::Migrate().

◆ SetFromFactory()

void DistributedVectorFactory::SetFromFactory ( DistributedVectorFactory pFactory)

Set mLo and mHi from another vector factory. Used by archiving.

Parameters
pFactorythe factory to set from.

Definition at line 66 of file DistributedVectorFactory.cpp.

References EXCEPTION, GetHigh(), GetLow(), GetNumProcs(), GetProblemSize(), mGlobalLows, mHi, mLo, mNumProcs, and mProblemSize.

Referenced by AbstractTetrahedralMesh< ELEMENT_DIM, SPACE_DIM >::load().

◆ SetOriginalFactory()

void DistributedVectorFactory::SetOriginalFactory ( DistributedVectorFactory pOriginalFactory)
inline

Set method for mpOriginalFactory, used by archiving (load_construct_data).

Parameters
pOriginalFactorysee mpOriginalFactory

Definition at line 270 of file DistributedVectorFactory.hpp.

References mpOriginalFactory.

Friends And Related Symbol Documentation

◆ boost::serialization::access

friend class boost::serialization::access
friend

Needed for serialization.

Definition at line 106 of file DistributedVectorFactory.hpp.

Member Data Documentation

◆ mGlobalLows

std::vector<unsigned> DistributedVectorFactory::mGlobalLows
private

A cached vector of mLo values from each process.

Definition at line 79 of file DistributedVectorFactory.hpp.

Referenced by CalculateOwnership(), rGetGlobalLows(), and SetFromFactory().

◆ mHi

unsigned DistributedVectorFactory::mHi
private

One above the last entry owned by the current processor.

Definition at line 67 of file DistributedVectorFactory.hpp.

Referenced by CalculateOwnership(), CreateVec(), CreateVec(), GetHigh(), GetLocalOwnership(), IsGlobalIndexLocal(), and SetFromFactory().

◆ mLo

unsigned DistributedVectorFactory::mLo
private

The first entry owned by the current processor.

Definition at line 64 of file DistributedVectorFactory.hpp.

Referenced by CalculateOwnership(), CreateVec(), CreateVec(), GetLocalOwnership(), GetLow(), IsGlobalIndexLocal(), rGetGlobalLows(), and SetFromFactory().

◆ mNumProcs

unsigned DistributedVectorFactory::mNumProcs
private

How many processes this factory is expecting.

Definition at line 73 of file DistributedVectorFactory.hpp.

Referenced by CalculateOwnership(), GetNumProcs(), and SetFromFactory().

◆ mPetscStatusKnown

bool DistributedVectorFactory::mPetscStatusKnown
private

Whether we've checked that PETSc is initialised.

Definition at line 76 of file DistributedVectorFactory.hpp.

Referenced by CalculateOwnership(), and CheckForPetsc().

◆ mpOriginalFactory

DistributedVectorFactory* DistributedVectorFactory::mpOriginalFactory
private

If this instance was loaded from an archive, this points to a factory with the settings from the archive, which may not be the same as this instance.

Definition at line 91 of file DistributedVectorFactory.hpp.

Referenced by DistributedVectorFactory(), ~DistributedVectorFactory(), GetOriginalFactory(), and SetOriginalFactory().

◆ mProblemSize

unsigned DistributedVectorFactory::mProblemSize
private

The problem size, i.e. the number of nodes in the mesh (the number of unknowns may be larger in a Stripe).

Definition at line 70 of file DistributedVectorFactory.hpp.

Referenced by CalculateOwnership(), CreateVec(), CreateVec(), GetProblemSize(), and SetFromFactory().

◆ msCheckNumberOfProcessesOnLoad

bool DistributedVectorFactory::msCheckNumberOfProcessesOnLoad = true
staticprivate

Whether, when loading an instance from an archive, to check that the current number of processes matches that used in creating the archive.

Definition at line 85 of file DistributedVectorFactory.hpp.

Referenced by CheckNumberOfProcessesOnLoad(), and SetCheckNumberOfProcessesOnLoad().


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