LAMA
lama::GeneralDistribution Class Reference

A general distribution allows to map a global range of values to the partitions of a communicator completely arbitrarily. More...

#include <GeneralDistribution.hpp>

Inheritance diagram for lama::GeneralDistribution:

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 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.
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< IndexTypemLocal2Global
IndexType mGlobalSize
CommunicatorPtr mCommunicator

Private Member Functions

 GeneralDistribution ()
GeneralDistributionoperator= (const GeneralDistribution &other)
 LAMA_LOG_DECL_STATIC_LOGGER (logger)

Detailed Description

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.


Member Typedef Documentation


Constructor & Destructor Documentation

lama::GeneralDistribution::GeneralDistribution ( const IndexType  globalSize,
const std::vector< IndexType > &  myGlobalIndexes,
const CommunicatorPtr  communicator 
)

Construcor of a general distribution.

Parameters:
globalSizeis the size of the distributed range
myGlobalIndexescontains all indexes of range owned by this partition
communicatorpartitions 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 IndexType  globalSize,
const CommunicatorPtr  communicator 
) [protected]

Member Function Documentation

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().

Getter routine for the communicator as shared pointer.

References lama::Distribution::mCommunicator.

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

std::vector< IndexType > & lama::GeneralDistribution::getLocalRows ( ) [virtual]

References mLocal2Global.

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

Implements lama::Distribution.

References mLocal2Global.

IndexType lama::GeneralDistribution::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 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

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 mGlobal2Local.

IndexType lama::GeneralDistribution::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 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::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.


Field Documentation


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