LAMA
/home/brandes/workspace/LAMA/src/lama/distribution/Distribution.hpp
Go to the documentation of this file.
00001 
00033 #ifndef LAMA_DISTRIBUTION_HPP_
00034 #define LAMA_DISTRIBUTION_HPP_
00035 
00036 // for dll_import
00037 #include <lama/config.hpp>
00038 
00039 // base classes
00040 #include <lama/NonCopyable.hpp>
00041 #include <lama/Printable.hpp>
00042 
00043 // others
00044 #include <lama/LAMATypes.hpp>
00045 #include <lama/Communicator.hpp>
00046 
00047 // logging
00048 #include <logging/logging.hpp>
00049 
00050 // boost
00051 #include <boost/shared_ptr.hpp>
00052 
00053 namespace lama
00054 {
00055 
00056 typedef boost::shared_ptr<const class Distribution> DistributionPtr;
00057 
00065 class LAMA_DLL_IMPORTEXPORT Distribution : public Printable,
00066                                            private NonCopyable
00067 {
00068 public:
00069 
00077     Distribution( const IndexType globalSize,
00078                   const CommunicatorPtr communicator );
00079 
00085     Distribution( const IndexType globalSize );
00086 
00089     virtual ~Distribution();
00090 
00093     const Communicator& getCommunicator() const;
00094 
00097     CommunicatorPtr getCommunicatorPtr() const;
00098 
00101     PartitionId getNumPartitions() const;
00102 
00105     bool isReplicated() const { return getNumPartitions() == 1; }
00106 
00113     virtual bool isLocal( const IndexType index ) const = 0;
00114 
00117     inline IndexType getGlobalSize() const;
00118 
00122     virtual IndexType getLocalSize() const = 0;
00123 
00133     virtual IndexType local2global( const IndexType localIndex ) const = 0;
00134 
00144     virtual IndexType global2local( const IndexType globalIndex ) const = 0;
00145 
00153     virtual void computeOwners(
00154         const std::vector<IndexType>& requiredIndexes,
00155         std::vector<PartitionId>& owners ) const;
00156 
00157     virtual bool isEqual( const Distribution& other ) const = 0;
00158 
00163     virtual void writeAt( std::ostream& stream ) const;
00164 
00173     bool operator==( const Distribution& other ) const;
00174 
00180     bool operator!=( const Distribution& other ) const;
00181 
00182     /* Replication of distributed data, one entry for each element of the global range
00183      *
00184      * @param[out] allValues  array over the global range will contain all values
00185      * @param[in]  localValues  array over the local range has only values for each partition
00186      */
00187 
00188     template<typename T1, typename T2>
00189     void replicate( T1* allValues, const T2* localValues ) const;
00190 
00191     /* Replication of distributed data, one line of n entries for each element of the global range
00192      *
00193      * @param[out] allValues  array over the global range will contain all values
00194      * @param[in]  localValues  array over the local range has only values for each partition
00195      * @param[in]  n is number of entries in each line of data
00196      */
00197 
00198     template<typename T1, typename T2>
00199     void replicateN( T1* allValues, const T2* localValues, const IndexType n) const;
00200 
00201     /* Replication of distributed data, several entries for each element of the global range
00202      *
00203      * @param[out] allValues array with all values from all partitions
00204      * @param[in] allOffsets  contains the offset for each element of the global range
00205      * @param[in] localValues elements available on this partition
00206      *
00207      * Note: the size of allValues must be globalSize + 1, allOffsets[globalSize] is total number of values
00208      *
00209      * The offset array is used like in CSR sparse matrix storage for offsets and number of values.
00210      */
00211 
00212     template<typename T>
00213     void replicate( T* allValues, const IndexType* allOffsets, const T* localValues ) const;
00214 
00220     virtual void printDistributionVector( std::string name ) const = 0;
00221 
00222 protected:
00223 
00224     IndexType mGlobalSize;
00225     CommunicatorPtr mCommunicator;
00226 
00227 private:
00228 
00229     Distribution();   // disable default constructor
00230 
00231     LAMA_LOG_DECL_STATIC_LOGGER( logger );
00232 };
00233 
00234 IndexType Distribution::getGlobalSize() const
00235 {
00236     return mGlobalSize;
00237 }
00238 
00239 }
00240 
00241 #endif // LAMA_DISTRIBUTION_HPP_