LAMA
lama::CyclicDistribution Class Reference

For a block cyclic distribution the range is partitioned into chunks of a certain block size and these chunks are assigned in a round-robin manner to the available partitions. More...

#include <CyclicDistribution.hpp>

Inheritance diagram for lama::CyclicDistribution:

Public Member Functions

 CyclicDistribution (const IndexType globalSize, const IndexType chunkSize, const CommunicatorPtr communicator)
 Construct a new object for a block-cyclic distribution.
virtual ~CyclicDistribution ()
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.
IndexType chunkSize () const
IndexType getNumLocalChunks () const
 getNumChunks() returns the number of local chunks
IndexType getNumChunks (const PartitionId partition) const
 getNumChunks() returns the number of chunks for a given partition
IndexType getNumTotalChunks () const
 get the global number of chunks
IndexType getPartitionSize (const PartitionId partition) const
 gets the size of the passed partition
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
 Method to compute directly the owners of global indexes without any communication.
void printDistributionVector (std::string problem) const
 Master process prints out the distribution vector to file named "name.part".
const CommunicatorgetCommunicator () 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 Attributes

IndexType mGlobalSize
CommunicatorPtr mCommunicator

Private Member Functions

 CyclicDistribution ()
IndexType allGlobal2local (const IndexType globalIndex) const
void getChunkInfo (IndexType &localChunks, IndexType &extra, const PartitionId rank) const
 Help routine to get the number of local chunks and info about rmemaining elements.
 LAMA_LOG_DECL_STATIC_LOGGER (logger)

Private Attributes

IndexType mChunkSize

Detailed Description

For a block cyclic distribution the range is partitioned into chunks of a certain block size and these chunks are assigned in a round-robin manner to the available partitions.


Constructor & Destructor Documentation

lama::CyclicDistribution::CyclicDistribution ( const IndexType  globalSize,
const IndexType  chunkSize,
const CommunicatorPtr  communicator 
)

Construct a new object for a block-cyclic distribution.

Parameters:
[in]globalSizenumber of elements to distribution
[in]chunkSizeis the size of the chunk block.

References mChunkSize, and lama::Distribution::mGlobalSize.


Member Function Documentation

IndexType lama::CyclicDistribution::allGlobal2local ( const IndexType  globalIndex) const [private]
void lama::CyclicDistribution::computeOwners ( const std::vector< IndexType > &  requiredIndexes,
std::vector< PartitionId > &  owners 
) const [virtual]

Method to compute directly the owners of global indexes without any communication.

Reimplemented from lama::Distribution.

References mChunkSize, and lama::Distribution::mCommunicator.

void lama::CyclicDistribution::getChunkInfo ( IndexType localChunks,
IndexType extra,
const PartitionId  rank 
) const [private]

Help routine to get the number of local chunks and info about rmemaining elements.

References mChunkSize, lama::Distribution::mCommunicator, and lama::Distribution::mGlobalSize.

Referenced by getNumChunks(), and getPartitionSize().

Getter routine for the communicator as shared pointer.

References lama::Distribution::mCommunicator.

Referenced by lama::DenseMatrix< T >::invert().

This method returns the number of local elements on the calling processor.

Implements lama::Distribution.

References getPartitionSize(), and lama::Distribution::mCommunicator.

getNumChunks() returns the number of chunks for a given partition

Returns:
number of chunks for any partition, includes the remaining chunk that might have less elements than chunkSize

References getChunkInfo().

Referenced by getNumLocalChunks().

getNumChunks() returns the number of local chunks

Returns:
number of chunks, also included the remaining chunk that might have less elements than chunkSize

References getNumChunks(), and lama::Distribution::mCommunicator.

Referenced by writeAt().

get the global number of chunks

Returns:
number of chunks, also included the remaining chunk that might have less elements than chunkSize

References mChunkSize, and lama::Distribution::mGlobalSize.

Referenced by printDistributionVector().

PartitionId lama::CyclicDistribution::getOwner ( const IndexType  globalIndex) const [virtual]

Computes the owner of the passed globalIndex.

Parameters:
[in]globalIndexthe global index to compute the owner for.
Returns:
the owner of the passed globalIndex.

References mChunkSize, and lama::Distribution::mCommunicator.

Referenced by isLocal().

gets the size of the passed partition

Returns:
size of the passed partition

References getChunkInfo(), and mChunkSize.

Referenced by getLocalSize().

IndexType lama::CyclicDistribution::global2local ( const IndexType  globalIndex) const [virtual]

Abstract method that translates a global index into a local index.

Parameters:
[in]globalIndexwith 0 <= globalIndex < getGlobalSize
Returns:
localIndex with 0 <= localIndex < getLocalSize() if local, nIndex otherwise

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 allGlobal2local(), isLocal(), and lama::nIndex.

bool lama::CyclicDistribution::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

Parameters:
[in]indexthe global index to query for locality to the calling rank
Returns:
if the passed global index is local to the calling rank

Implements lama::Distribution.

References getOwner(), and lama::Distribution::mCommunicator.

Referenced by global2local().

IndexType lama::CyclicDistribution::local2global ( const IndexType  localIndex) const [virtual]

Abstract method that translates a local index back to a global index.

Parameters:
[in]localIndexis the local index, 0 <= localIndex < getLocalSize()
Returns:
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 mChunkSize, and lama::Distribution::mCommunicator.

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::CyclicDistribution::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 getNumTotalChunks(), mChunkSize, and lama::Distribution::mCommunicator.

void lama::CyclicDistribution::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 getNumLocalChunks(), mChunkSize, and lama::Distribution::mGlobalSize.


Field Documentation


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