LAMA
|
Derived distribution class for general block distributions. More...
#include <GenBlockDistribution.hpp>
Public Member Functions | |
GenBlockDistribution (const IndexType globalSize, const std::vector< IndexType > &localSizes, const CommunicatorPtr communicator) | |
Construct a general block distribution by a vector of localSizes. | |
GenBlockDistribution (const IndexType globalSize, const IndexType firstGlobalIdx, const IndexType lastGlobalIdx, const CommunicatorPtr communicator) | |
Construct a general block distribution by an interval. | |
GenBlockDistribution (const IndexType globalSize, const IndexType localSize, const CommunicatorPtr communicator) | |
Construct a general block distribution by individual localSize. | |
GenBlockDistribution (const IndexType globalSize, const float weight, const CommunicatorPtr communicator) | |
Construct a general block distribution by a weight so that each partition will have a size corresponding to its weight. | |
virtual | ~GenBlockDistribution () |
void | getLocalRange (IndexType &lb, IndexType &ub) const |
Get the local range of the calling partition. | |
virtual bool | isLocal (const IndexType index) const |
Query if the given global index is local for the calling rank (e.g. | |
virtual PartitionId | getOwner (const IndexType globalIndex) const |
Computes the owner of the passed globalIndex. | |
virtual IndexType | getLocalSize () const |
This method returns the number of local elements on the calling processor. | |
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. | |
virtual void | computeOwners (const std::vector< IndexType > &requiredIndexes, std::vector< PartitionId > &owners) const |
Override Distribution::computeOwners. | |
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. | |
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 Member Functions | |
LAMA_LOG_DECL_STATIC_LOGGER (logger) | |
Protected Attributes | |
IndexType | mGlobalSize |
CommunicatorPtr | mCommunicator |
Private Member Functions | |
void | setOffsets (const IndexType rank, const IndexType numPartitions, const IndexType localSizes[]) |
void | setOffsets (const IndexType rank, const IndexType numPartitions, const IndexType mySize) |
GenBlockDistribution () | |
Private Attributes | |
boost::scoped_array< IndexType > | mOffsets |
offset for each partition | |
IndexType | mLB |
IndexType | mUB |
local range of full size in global values |
Derived distribution class for general block distributions.
For the general block distribution a local block size is given for each partition.
GenBlockDistribution is like all Distribution classes non-copyable. Shared pointers might be used to use the same distribution for several objects.
lama::GenBlockDistribution::GenBlockDistribution | ( | const IndexType | globalSize, |
const std::vector< IndexType > & | localSizes, | ||
const CommunicatorPtr | communicator | ||
) |
Construct a general block distribution by a vector of localSizes.
[in] | globalSize | is the number of elements to distribute |
[in] | localSizes | contains the sizes for each partition |
[in] | communicator | specifies the communicator used for this distribution |
Note: All partitions must call this constructor with the 'same' arguments.
References lama::Distribution::getGlobalSize(), LAMA_ASSERT_EQUAL_ERROR, lama::Distribution::mCommunicator, and setOffsets().
lama::GenBlockDistribution::GenBlockDistribution | ( | const IndexType | globalSize, |
const IndexType | firstGlobalIdx, | ||
const IndexType | lastGlobalIdx, | ||
const CommunicatorPtr | communicator | ||
) |
Construct a general block distribution by an interval.
[in] | globalSize | is the number of elements to distribute |
[in] | firstGlobalIdx | is the smallest global index in partition |
[in] | lastGlobalIdx | is the largest global index in partition |
[in] | communicator | specifies the communicator used for this distribution |
References LAMA_ASSERT_EQUAL_ERROR, lama::Distribution::mCommunicator, mLB, mUB, and setOffsets().
lama::GenBlockDistribution::GenBlockDistribution | ( | const IndexType | globalSize, |
const IndexType | localSize, | ||
const CommunicatorPtr | communicator | ||
) |
Construct a general block distribution by individual localSize.
[in] | globalSize | is the number of elements to distribute |
[in] | localSize | is the number of elements for this partition |
[in] | communicator | specifies the communicator used for this distribution |
References lama::Distribution::mCommunicator, and setOffsets().
lama::GenBlockDistribution::GenBlockDistribution | ( | const IndexType | globalSize, |
const float | weight, | ||
const CommunicatorPtr | communicator | ||
) |
Construct a general block distribution by a weight so that each partition will have a size corresponding to its weight.
globalSize | is the number of elements to distribute |
weight | is the weight of this partition (must be positive) |
communicator | specifies the communicator used for this distribution |
Note: GenBlockDistribution( globalSize, localSize, comm) is the same as GenBlockDistribution( globalSize, (float) localSize, comm )
References lama::Distribution::getGlobalSize(), LAMA_THROWEXCEPTION, lama::Distribution::mCommunicator, mLB, mOffsets, and mUB.
lama::GenBlockDistribution::~GenBlockDistribution | ( | ) | [virtual] |
lama::GenBlockDistribution::GenBlockDistribution | ( | ) | [private] |
void lama::GenBlockDistribution::computeOwners | ( | const std::vector< IndexType > & | requiredIndexes, |
std::vector< PartitionId > & | owners | ||
) | const [virtual] |
Override Distribution::computeOwners.
Each processor knowns the sizes of each partition and can therefore compute owners without any communication.
Reimplemented from lama::Distribution.
References getOwner().
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(), 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().
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(), GenBlockDistribution(), lama::GeneralDistribution::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(), setOffsets(), lama::MatrixStorage< T >::splitHalo(), and lama::Vector::Vector().
void lama::GenBlockDistribution::getLocalRange | ( | IndexType & | lb, |
IndexType & | ub | ||
) | const |
IndexType lama::GenBlockDistribution::getLocalSize | ( | ) | const [virtual] |
This method returns the number of local elements on the calling processor.
Implements lama::Distribution.
Referenced by printDistributionVector().
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().
PartitionId lama::GenBlockDistribution::getOwner | ( | const IndexType | globalIndex | ) | const [virtual] |
Computes the owner of the passed globalIndex.
[in] | globalIndex | the global index to compute the owner for. |
References lama::Distribution::mCommunicator, and mOffsets.
Referenced by computeOwners().
IndexType lama::GenBlockDistribution::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 mLB, mUB, and lama::nIndex.
bool lama::GenBlockDistribution::isEqual | ( | const Distribution & | other | ) | const [virtual] |
Implements lama::Distribution.
References lama::Distribution::getCommunicator(), lama::Distribution::mCommunicator, and mOffsets.
bool lama::GenBlockDistribution::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.
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::GenBlockDistribution::LAMA_LOG_DECL_STATIC_LOGGER | ( | logger | ) | [protected] |
Reimplemented from lama::Distribution.
IndexType lama::GenBlockDistribution::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 mLB.
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.
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::GenBlockDistribution::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 getLocalSize(), and lama::Distribution::mCommunicator.
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::GenBlockDistribution::setOffsets | ( | const IndexType | rank, |
const IndexType | numPartitions, | ||
const IndexType | localSizes[] | ||
) | [private] |
References lama::Distribution::getGlobalSize(), LAMA_ASSERT_EQUAL_ERROR, mLB, mOffsets, and mUB.
Referenced by GenBlockDistribution(), and setOffsets().
void lama::GenBlockDistribution::setOffsets | ( | const IndexType | rank, |
const IndexType | numPartitions, | ||
const IndexType | mySize | ||
) | [private] |
References LAMA_ASSERT_EQUAL_DEBUG, lama::Distribution::mCommunicator, and setOffsets().
void lama::GenBlockDistribution::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::mGlobalSize, mLB, and mUB.
CommunicatorPtr lama::Distribution::mCommunicator [protected, inherited] |
Referenced by lama::CyclicDistribution::allGlobal2local(), lama::BlockDistribution::BlockDistribution(), lama::CyclicDistribution::computeOwners(), lama::Distribution::computeOwners(), lama::Distribution::Distribution(), GenBlockDistribution(), lama::CyclicDistribution::getChunkInfo(), lama::Distribution::getCommunicator(), lama::Distribution::getCommunicatorPtr(), lama::GeneralDistribution::getDistributionVector(), lama::CyclicDistribution::getLocalSize(), lama::CyclicDistribution::getNumLocalChunks(), lama::Distribution::getNumPartitions(), lama::CyclicDistribution::getOwner(), getOwner(), isEqual(), lama::CyclicDistribution::isLocal(), lama::CyclicDistribution::local2global(), lama::NoDistribution::printDistributionVector(), lama::BlockDistribution::printDistributionVector(), lama::GeneralDistribution::printDistributionVector(), lama::CyclicDistribution::printDistributionVector(), printDistributionVector(), setOffsets(), lama::GeneralDistribution::writeAt(), and lama::Distribution::~Distribution().
IndexType lama::Distribution::mGlobalSize [protected, inherited] |
Referenced by lama::CyclicDistribution::CyclicDistribution(), lama::Distribution::Distribution(), lama::GeneralDistribution::GeneralDistribution(), lama::CyclicDistribution::getChunkInfo(), lama::GeneralDistribution::getDistributionVector(), lama::Distribution::getGlobalSize(), lama::NoDistribution::getLocalSize(), lama::CyclicDistribution::getNumTotalChunks(), lama::BlockDistribution::isEqual(), lama::CyclicDistribution::isEqual(), lama::GeneralDistribution::printDistributionVector(), lama::NoDistribution::writeAt(), lama::BlockDistribution::writeAt(), lama::GeneralDistribution::writeAt(), lama::CyclicDistribution::writeAt(), writeAt(), and lama::Distribution::~Distribution().
IndexType lama::GenBlockDistribution::mLB [private] |
Referenced by GenBlockDistribution(), getLocalRange(), getLocalSize(), global2local(), isLocal(), local2global(), setOffsets(), and writeAt().
boost::scoped_array<IndexType> lama::GenBlockDistribution::mOffsets [private] |
offset for each partition
Referenced by GenBlockDistribution(), getOwner(), isEqual(), and setOffsets().
IndexType lama::GenBlockDistribution::mUB [private] |
local range of full size in global values
Referenced by GenBlockDistribution(), getLocalRange(), getLocalSize(), global2local(), isLocal(), setOffsets(), and writeAt().