LAMA
/home/brandes/workspace/LAMA/src/lama/distribution/Halo.hpp
Go to the documentation of this file.
00001 
00033 #ifndef LAMA_HALO_HPP_
00034 #define LAMA_HALO_HPP_
00035 
00036 // for dll_import
00037 #include <lama/config.hpp>
00038 
00039 // base classes
00040 #include <lama/Printable.hpp>
00041 
00042 // others
00043 #include <lama/LAMAArray.hpp>
00044 #include <lama/CommunicationPlan.hpp>
00045 
00046 #include <lama/exception/LAMAAssert.hpp>
00047 
00048 #include <map>
00049 
00050 namespace lama
00051 {
00052 
00061 class LAMA_DLL_IMPORTEXPORT Halo : public Printable
00062 {
00063     friend class HaloBuilder;
00064 
00065 public:
00066 
00069     Halo();
00070 
00073     Halo( const Halo& halo );
00074 
00075     virtual ~Halo();
00076 
00079     void clear();
00080 
00081     Halo& operator=( const Halo& other );
00082 
00083     inline const CommunicationPlan& getRequiredPlan() const;
00084 
00085     inline const CommunicationPlan& getProvidesPlan() const;
00086 
00087     inline IndexType global2halo(const IndexType globalIndex) const;
00088 
00089     inline const LAMAArray<IndexType>& getProvidesIndexes() const;
00090 
00091     inline const LAMAArray<IndexType>& getRequiredIndexes() const;
00092 
00095     inline IndexType getHaloSize() const;
00096 
00102     inline bool isEmpty() const;
00103 
00104     inline const std::map<IndexType, IndexType>& getMap() const { return mGlobal2Halo; }
00105 
00109     virtual void writeAt( std::ostream& stream ) const;
00110 
00111 protected:
00112 
00113     inline void setGlobal2Halo(IndexType globalIndex, IndexType haloIndex);
00114 
00115 private:
00116 
00117     CommunicationPlan mRequiredPlan;
00118     CommunicationPlan mProvidesPlan;
00119 
00120     // Indexes for required values and values to provide are stored in LAMAArrays
00121     // so they might be used in different contexts, especially also on GPU 
00122 
00123     LAMAArray<IndexType> mRequiredIndexes;
00124     LAMAArray<IndexType> mProvidesIndexes;
00125 
00126     std::map<IndexType, IndexType> mGlobal2Halo;
00127 
00128     LAMA_LOG_DECL_STATIC_LOGGER(logger);
00129 };
00130 
00131 const CommunicationPlan& Halo::getRequiredPlan() const
00132 {
00133     return mRequiredPlan;
00134 }
00135 
00136 const CommunicationPlan& Halo::getProvidesPlan() const
00137 {
00138     return mProvidesPlan;
00139 }
00140 
00141 const LAMAArray<IndexType>& Halo::getProvidesIndexes() const
00142 {
00143     return mProvidesIndexes;
00144 }
00145 
00146 const LAMAArray<IndexType>& Halo::getRequiredIndexes() const
00147 {
00148     return mRequiredIndexes;
00149 }
00150 
00151 void Halo::setGlobal2Halo(IndexType globalIndex, IndexType haloIndex)
00152 {
00153     LAMA_ASSERT_DEBUG( 0 <= haloIndex && haloIndex < getHaloSize(),
00154            "illegal halo index " << haloIndex << ", halo size = " << getHaloSize());
00155     mGlobal2Halo[globalIndex] = haloIndex;
00156 }
00157 
00158 IndexType Halo::global2halo(const IndexType globalIndex) const
00159 {
00160     const std::map<IndexType, IndexType>::const_iterator elem = mGlobal2Halo.find(globalIndex);
00161 
00162     if (elem == mGlobal2Halo.end())
00163     {
00164         return nIndex;
00165     }
00166 
00167     return elem->second;
00168 }
00169 
00170 IndexType Halo::getHaloSize() const
00171 {
00172     return mRequiredPlan.totalQuantity();
00173 }
00174 
00175 bool Halo::isEmpty() const
00176 {
00177     return ( mRequiredPlan.totalQuantity() == 0 ) && ( mProvidesPlan.totalQuantity() == 0 );
00178 }
00179 
00180 }
00181 
00182 #endif // LAMA_HALO_HPP_