LAMA
|
A general distribution allows to map a global range of values to the partitions of a communicator completely arbitrarily. More...
#include <GeneralDistribution.hpp>
Public Member Functions | |
GeneralDistribution (const IndexType globalSize, const std::vector< IndexType > &myGlobalIndexes, const CommunicatorPtr communicator) | |
Construcor of a general distribution. | |
GeneralDistribution (const Distribution &other) | |
virtual | ~GeneralDistribution () |
virtual bool | isLocal (const IndexType index) const |
Query if the given global index is local for the calling rank (e.g. | |
virtual IndexType | getLocalSize () const |
This method returns the number of local elements on the calling processor. | |
virtual std::vector< IndexType > & | getLocalRows () |
virtual IndexType | local2global (const IndexType localIndex) const |
Abstract method that translates a local index back to a global index. | |
virtual IndexType | global2local (const IndexType globalIndex) const |
Abstract method that translates a global index into a local index. | |
virtual bool | isEqual (const Distribution &other) const |
virtual void | writeAt (std::ostream &stream) const |
This method writes info about the distribution into an output stream. | |
void | getDistributionVector (std::vector< IndexType > &row2Partition) const |
void | printDistributionVector (std::string name) const |
Master process prints out the distribution vector to file named "name.part". | |
const Communicator & | getCommunicator () const |
Getter routine for the communicator of the distribution. | |
CommunicatorPtr | getCommunicatorPtr () const |
Getter routine for the communicator as shared pointer. | |
PartitionId | getNumPartitions () const |
Query for the number of partitions onto which the distribution is done. | |
bool | isReplicated () const |
Query whether the distribution is a replication. | |
IndexType | getGlobalSize () const |
Getter for the global number of elements that are distributed. | |
virtual void | computeOwners (const std::vector< IndexType > &requiredIndexes, std::vector< PartitionId > &owners) const |
Compute ownership for required indexes. | |
bool | operator== (const Distribution &other) const |
Check for equality of two distributions. | |
bool | operator!= (const Distribution &other) const |
Check for inequality. | |
template<typename T1 , typename T2 > | |
void | replicate (T1 *allValues, const T2 *localValues) const |
template<typename T > | |
void | replicate (T *allValues, const IndexType *allOffsets, const T *localValues) const |
template<typename T1 , typename T2 > | |
void | replicateN (T1 *allValues, const T2 *localValues, const IndexType n) const |
Protected Types | |
typedef std::map< IndexType, IndexType > | Global2LocalMapType |
Protected Member Functions | |
GeneralDistribution (const IndexType globalSize, const CommunicatorPtr communicator) | |
Protected Attributes | |
Global2LocalMapType | mGlobal2Local |
std::vector< IndexType > | mLocal2Global |
IndexType | mGlobalSize |
CommunicatorPtr | mCommunicator |
Private Member Functions | |
GeneralDistribution () | |
GeneralDistribution & | operator= (const GeneralDistribution &other) |
LAMA_LOG_DECL_STATIC_LOGGER (logger) |
A general distribution allows to map a global range of values to the partitions of a communicator completely arbitrarily.
Each partition has the information which values it holds. A partition has no information where to find values not owned by itself.
typedef std::map<IndexType, IndexType> lama::GeneralDistribution::Global2LocalMapType [protected] |
lama::GeneralDistribution::GeneralDistribution | ( | const IndexType | globalSize, |
const std::vector< IndexType > & | myGlobalIndexes, | ||
const CommunicatorPtr | communicator | ||
) |
Construcor of a general distribution.
globalSize | is the size of the distributed range |
myGlobalIndexes | contains all indexes of range owned by this partition |
communicator | partitions on which the range is distributed. |
Important: each global index from 0 to globalSize-1 must appear exactly once in the vector myGlobalIndexes on one partition.
References LAMA_ASSERT, mGlobal2Local, lama::Distribution::mGlobalSize, and mLocal2Global.
lama::GeneralDistribution::GeneralDistribution | ( | const Distribution & | other | ) | [explicit] |
lama::GeneralDistribution::~GeneralDistribution | ( | ) | [virtual] |
lama::GeneralDistribution::GeneralDistribution | ( | const IndexType | globalSize, |
const CommunicatorPtr | communicator | ||
) | [protected] |
lama::GeneralDistribution::GeneralDistribution | ( | ) | [private] |
void lama::Distribution::computeOwners | ( | const std::vector< IndexType > & | requiredIndexes, |
std::vector< PartitionId > & | owners | ||
) | const [virtual, inherited] |
Compute ownership for required indexes.
The default solution is to communicate required indexes around all partitions and each partition marks indexes with its id if it is local. If ownership can be computed without communication, this routine might be implemented more efficiently.
Reimplemented in lama::GenBlockDistribution, lama::CyclicDistribution, and lama::BlockDistribution.
References lama::Distribution::mCommunicator.
Referenced by lama::DenseMatrix< T >::computeOwners().
const Communicator & lama::Distribution::getCommunicator | ( | ) | const [inherited] |
Getter routine for the communicator of the distribution.
References lama::Distribution::mCommunicator.
Referenced by lama::HaloBuilder::build(), lama::Communicator::computeOwners(), lama::DenseMatrix< T >::DenseMatrix(), lama::MatrixCreator< T >::fillRandom(), lama::DenseMatrix< T >::getValue(), lama::SparseMatrix< T >::getValue(), lama::GenBlockDistribution::isEqual(), lama::SpecializedJacobi::iterateTyped(), lama::SparseMatrix< T >::matrixTimesMatrixImpl(), lama::DenseMatrix< T >::matrixTimesVectorImpl(), lama::Redistributor::Redistributor(), lama::Distribution::replicate(), lama::StorageMethods< T >::replicateCSR(), and lama::Distribution::replicateN().
CommunicatorPtr lama::Distribution::getCommunicatorPtr | ( | ) | const [inherited] |
Getter routine for the communicator as shared pointer.
References lama::Distribution::mCommunicator.
Referenced by lama::DenseMatrix< T >::invert().
void lama::GeneralDistribution::getDistributionVector | ( | std::vector< IndexType > & | row2Partition | ) | const |
References LAMA_ASSERT, MASTER, lama::Distribution::mCommunicator, lama::Distribution::mGlobalSize, and mLocal2Global.
Referenced by printDistributionVector().
IndexType lama::Distribution::getGlobalSize | ( | ) | const [inline, inherited] |
Getter for the global number of elements that are distributed.
References lama::Distribution::mGlobalSize.
Referenced by lama::BlockDistribution::BlockDistribution(), lama::MatrixStorage< T >::buildHalo(), lama::GenBlockDistribution::GenBlockDistribution(), GeneralDistribution(), lama::NoDistribution::isEqual(), lama::BlockDistribution::isEqual(), lama::CyclicDistribution::isEqual(), lama::MatrixStorage< T >::joinHalo(), lama::_MatrixStorage::localize(), lama::DenseMatrix< T >::localize(), lama::MatrixStorage< T >::localize(), lama::StorageMethods< T >::localizeCSR(), lama::Distribution::operator==(), lama::Redistributor::Redistributor(), lama::Distribution::replicate(), lama::MatrixStorage< T >::replicate(), lama::replicate(), lama::StorageMethods< T >::replicateCSR(), lama::Distribution::replicateN(), lama::GenBlockDistribution::setOffsets(), lama::MatrixStorage< T >::splitHalo(), and lama::Vector::Vector().
std::vector< IndexType > & lama::GeneralDistribution::getLocalRows | ( | ) | [virtual] |
References mLocal2Global.
IndexType lama::GeneralDistribution::getLocalSize | ( | ) | const [virtual] |
This method returns the number of local elements on the calling processor.
Implements lama::Distribution.
References mLocal2Global.
PartitionId lama::Distribution::getNumPartitions | ( | ) | const [inherited] |
Query for the number of partitions onto which the distribution is done.
References LAMA_ASSERT, and lama::Distribution::mCommunicator.
Referenced by lama::HaloBuilder::build(), lama::DenseMatrix< T >::DenseMatrix(), lama::MatrixCreator< T >::fillRandom(), lama::DenseMatrix< T >::getValue(), lama::DenseMatrix< T >::matrixTimesVectorImpl(), and lama::LUSolver::solve().
IndexType lama::GeneralDistribution::global2local | ( | const IndexType | globalIndex | ) | const [virtual] |
Abstract method that translates a global index into a local index.
[in] | globalIndex | with 0 <= globalIndex < getGlobalSize |
This method must be implemented by all base classes. It should throw an exception if the argument is not in the valid range.
Implements lama::Distribution.
References mGlobal2Local, and lama::nIndex.
bool lama::GeneralDistribution::isEqual | ( | const Distribution & | other | ) | const [virtual] |
Implements lama::Distribution.
bool lama::GeneralDistribution::isLocal | ( | const IndexType | index | ) | const [virtual] |
Query if the given global index is local for the calling rank (e.g.
process for an MPI Communicator
[in] | index | the global index to query for locality to the calling rank |
Implements lama::Distribution.
References mGlobal2Local.
bool lama::Distribution::isReplicated | ( | ) | const [inline, inherited] |
Query whether the distribution is a replication.
Referenced by lama::DenseMatrix< T >::assignSparse(), lama::SparseMatrix< T >::getRow(), lama::DenseMatrix< T >::getRow(), lama::MatrixStorage< T >::localize(), lama::DenseMatrix< T >::matrixTimesMatrix(), lama::SparseMatrix< T >::matrixTimesMatrixImpl(), lama::SparseMatrix< T >::maxDiffNorm(), lama::SparseMatrix< T >::maxDiffNormImpl(), lama::Distribution::operator==(), lama::MatrixStorage< T >::redistribute(), lama::MatrixStorage< T >::replicate(), and lama::MatrixStorage< T >::splitHalo().
lama::GeneralDistribution::LAMA_LOG_DECL_STATIC_LOGGER | ( | logger | ) | [private] |
Reimplemented from lama::Distribution.
IndexType lama::GeneralDistribution::local2global | ( | const IndexType | localIndex | ) | const [virtual] |
Abstract method that translates a local index back to a global index.
[in] | localIndex | is the local index, 0 <= localIndex < getLocalSize() |
This method must be implemented by all base classes. It should throw an exception if the argument is not in the valid range.
Implements lama::Distribution.
References mLocal2Global.
bool lama::Distribution::operator!= | ( | const Distribution & | other | ) | const [inherited] |
Check for inequality.
Even if two distributions are not equal it might be the case that the mapping of elements to partititons is the same.
GeneralDistribution& lama::GeneralDistribution::operator= | ( | const GeneralDistribution & | other | ) | [private] |
bool lama::Distribution::operator== | ( | const Distribution & | other | ) | const [inherited] |
Check for equality of two distributions.
As verification of same distribution can be rather expensive, the operator might return false.
Attention: The operator must be conservative and only return true if the distributions are really equal.
References lama::Distribution::getGlobalSize(), lama::Distribution::isEqual(), and lama::Distribution::isReplicated().
void lama::GeneralDistribution::printDistributionVector | ( | std::string | name | ) | const [virtual] |
Master process prints out the distribution vector to file named "name.part".
Every row contains a single number: the index of the process, where the row is local.
Implements lama::Distribution.
References getDistributionVector(), MASTER, lama::Distribution::mCommunicator, lama::Distribution::mGlobalSize, and mLocal2Global.
void lama::Distribution::replicate | ( | T1 * | allValues, |
const T2 * | localValues | ||
) | const [inherited] |
References lama::Distribution::getCommunicator(), lama::Distribution::getGlobalSize(), lama::Distribution::getLocalSize(), lama::Communicator::getSize(), LAMA_ASSERT_EQUAL_DEBUG, lama::Distribution::local2global(), lama::Communicator::max(), and lama::Communicator::shift().
Referenced by lama::StorageMethods< T >::replicateCSR().
void lama::Distribution::replicate | ( | T * | allValues, |
const IndexType * | allOffsets, | ||
const T * | localValues | ||
) | const [inherited] |
template LAMA_DLL_IMPORTEXPORT void lama::Distribution::replicateN | ( | T1 * | allValues, |
const T2 * | localValues, | ||
const IndexType | n | ||
) | const [inherited] |
References lama::Distribution::getCommunicator(), lama::Distribution::getGlobalSize(), lama::Distribution::getLocalSize(), lama::Communicator::getSize(), LAMA_ASSERT_EQUAL_DEBUG, lama::Distribution::local2global(), lama::Communicator::max(), and lama::Communicator::shift().
Referenced by lama::replicate().
void lama::GeneralDistribution::writeAt | ( | std::ostream & | stream | ) | const [virtual] |
This method writes info about the distribution into an output stream.
The method should be overwritten by base classes to give more specific information about the object.
Reimplemented from lama::Distribution.
References lama::Distribution::mCommunicator, lama::Distribution::mGlobalSize, and mLocal2Global.
CommunicatorPtr lama::Distribution::mCommunicator [protected, inherited] |
Referenced by lama::CyclicDistribution::allGlobal2local(), lama::BlockDistribution::BlockDistribution(), lama::CyclicDistribution::computeOwners(), lama::Distribution::computeOwners(), lama::Distribution::Distribution(), lama::GenBlockDistribution::GenBlockDistribution(), lama::CyclicDistribution::getChunkInfo(), lama::Distribution::getCommunicator(), lama::Distribution::getCommunicatorPtr(), getDistributionVector(), lama::CyclicDistribution::getLocalSize(), lama::CyclicDistribution::getNumLocalChunks(), lama::Distribution::getNumPartitions(), lama::CyclicDistribution::getOwner(), lama::GenBlockDistribution::getOwner(), lama::GenBlockDistribution::isEqual(), lama::CyclicDistribution::isLocal(), lama::CyclicDistribution::local2global(), lama::NoDistribution::printDistributionVector(), lama::BlockDistribution::printDistributionVector(), printDistributionVector(), lama::CyclicDistribution::printDistributionVector(), lama::GenBlockDistribution::printDistributionVector(), lama::GenBlockDistribution::setOffsets(), writeAt(), and lama::Distribution::~Distribution().
Referenced by GeneralDistribution(), global2local(), and isLocal().
IndexType lama::Distribution::mGlobalSize [protected, inherited] |
Referenced by lama::CyclicDistribution::CyclicDistribution(), lama::Distribution::Distribution(), GeneralDistribution(), lama::CyclicDistribution::getChunkInfo(), getDistributionVector(), lama::Distribution::getGlobalSize(), lama::NoDistribution::getLocalSize(), lama::CyclicDistribution::getNumTotalChunks(), lama::BlockDistribution::isEqual(), lama::CyclicDistribution::isEqual(), printDistributionVector(), lama::NoDistribution::writeAt(), lama::BlockDistribution::writeAt(), writeAt(), lama::CyclicDistribution::writeAt(), lama::GenBlockDistribution::writeAt(), and lama::Distribution::~Distribution().
std::vector<IndexType> lama::GeneralDistribution::mLocal2Global [protected] |
Referenced by GeneralDistribution(), getDistributionVector(), getLocalRows(), getLocalSize(), local2global(), printDistributionVector(), and writeAt().