LAMA
/home/brandes/workspace/LAMA/src/lama/pgas/PGASCommunicator.hpp
Go to the documentation of this file.
00001 
00033 #ifndef LAMA_PGASCOMMUNICATOR_H_
00034 #define LAMA_PGASCOMMUNICATOR_H_
00035 
00036 #include <lama/Communicator.hpp>
00037 
00038 #include <lama/pgas/PGASInterface.hpp>
00039 
00040 namespace lama
00041 {
00042 
00043 class PGASCommunicator : public lama::Communicator
00044 {
00045 
00046     // Only PGASCommunicatorManager is allowed to create PGAS communicator
00047 
00048     friend class PGASCommunicatorManager;
00049     PGASCommunicator( int& argc, char** & argv );
00050 
00051 public:
00052     virtual ~PGASCommunicator();
00053 
00054     virtual bool isEqual( const Communicator& other ) const;
00055 
00056     virtual ThreadSafetyLevel getThreadSafetyLevel() const;
00057 
00058     virtual PartitionId getSize() const;
00059 
00060     virtual PartitionId getRank() const;
00061 
00070     virtual void all2all( int* recvValues, const int* sendValues ) const;
00071 
00080     virtual void exchangeByPlan(
00081         int* const recvData,
00082         const CommunicationPlan& recvPlan,
00083         const int* const sendData,
00084         const CommunicationPlan& sendPlan ) const;
00085 
00086     virtual void exchangeByPlan(
00087         float* const recvData,
00088         const CommunicationPlan& recvPlan,
00089         const float* const sendData,
00090         const CommunicationPlan& sendPlan ) const;
00091 
00092     virtual void exchangeByPlan(
00093         double* const recvData,
00094         const CommunicationPlan& recvPlan,
00095         const double* const sendData,
00096         const CommunicationPlan& sendPlan ) const;
00097 
00098     virtual std::auto_ptr<SyncToken> exchangeByPlanAsync(
00099         int* const recvData,
00100         const CommunicationPlan& recvPlan,
00101         const int* const sendData,
00102         const CommunicationPlan& sendPlan ) const;
00103 
00104     virtual std::auto_ptr<SyncToken> exchangeByPlanAsync(
00105         float* const recvData,
00106         const CommunicationPlan& recvPlan,
00107         const float* const sendData,
00108         const CommunicationPlan& sendPlan ) const;
00109 
00110     virtual std::auto_ptr<SyncToken> exchangeByPlanAsync(
00111         double* const recvData,
00112         const CommunicationPlan& recvPlan,
00113         const double* const sendData,
00114         const CommunicationPlan& sendPlan ) const;
00115 
00116     virtual float sum( const float value ) const;
00117 
00118     virtual double sum( const double value ) const;
00119 
00120     virtual int sum( const int value ) const;
00121 
00122     virtual float min( const float value ) const;
00123 
00124     virtual size_t sum( const size_t value ) const;
00125 
00126     virtual float max( const float value ) const;
00127 
00128     virtual double min( const double value ) const;
00129 
00130     virtual double max( const double value ) const;
00131 
00132     virtual int min( const int value ) const;
00133 
00134     virtual int max( const int value ) const;
00135 
00136     virtual void gather( std::vector<float>& values, float value ) const;
00137 
00138     virtual void synchronize() const;
00139 
00140     virtual IndexType shift( double newVals[], const IndexType newSize,
00141                              const double oldVals[], const IndexType oldSize,
00142                              const int direction ) const;
00143 
00144     virtual IndexType shift( float newVals[], const IndexType newSize,
00145                              const float oldVals[], const IndexType oldSize,
00146                              const int direction ) const;
00147 
00148     virtual IndexType shift( int newVals[], const IndexType newSize,
00149                              const int oldVals[], const IndexType oldSize,
00150                              const int direction ) const;
00151 
00152     virtual std::auto_ptr<SyncToken> shiftAsync( double newVals[], const double oldVals[],
00153                                                  const IndexType size, const int direction ) const;
00154 
00155     virtual std::auto_ptr<SyncToken> shiftAsync( float newVals[], const float oldVals[],
00156                                                  const IndexType size, const int direction ) const;
00157 
00158     virtual std::auto_ptr<SyncToken> shiftAsync( int newVals[], const int oldVals[],
00159                                                  const IndexType size, const int direction ) const;
00160 
00163     virtual void bcast ( double val[], const IndexType n, const PartitionId root ) const;
00164 
00167     virtual void bcast ( int val[], const IndexType n, const PartitionId root ) const;
00168 
00171     virtual void bcast ( float val[], const IndexType n, const PartitionId root ) const;
00172 
00175     virtual void scatter ( double myvals[], const IndexType n, const PartitionId root, const double allvals[] ) const;
00176     virtual void scatter ( float myvals[], const IndexType n, const PartitionId root, const float allvals[] ) const;
00177     virtual void scatter ( int myvals[], const IndexType n, const PartitionId root, const int allvals[] ) const;
00178 
00179     virtual void scatter ( double myvals[], const IndexType n, const PartitionId root,
00180                            const double allvals[], const IndexType sizes[] ) const;
00181     virtual void scatter ( float myvals[], const IndexType n, const PartitionId root,
00182                            const float allvals[], const IndexType sizes[] ) const;
00183     virtual void scatter ( int myvals[], const IndexType n, const PartitionId root,
00184                            const int allvals[], const IndexType sizes[] ) const;
00185 
00188     virtual void gather ( double allvals[], const IndexType n, const PartitionId root, const double myvals[] ) const;
00189     virtual void gather ( float allvals[], const IndexType n, const PartitionId root, const float myvals[] ) const;
00190     virtual void gather ( int allvals[], const IndexType n, const PartitionId root, const int myvals[] ) const;
00191 
00192     virtual void gather ( double allvals[], const IndexType n, const PartitionId root,
00193                           const double myvals[], const IndexType sizes[] ) const;
00194     virtual void gather ( float allvals[], const IndexType n, const PartitionId root,
00195                           const float myvals[], const IndexType sizes[] ) const;
00196     virtual void gather ( int allvals[], const IndexType n, const PartitionId root,
00197                           const int myvals[], const IndexType sizes[] ) const;
00198 
00207     virtual void maxloc( double& val, int& location, const PartitionId root ) const;
00208 
00209     virtual void maxloc( float& val, int& location, const PartitionId root ) const;
00210 
00211     virtual void maxloc( int& val, int& location, const PartitionId root ) const;
00212 
00215     virtual void swap( double val[], const IndexType n, const PartitionId partner ) const;
00216 
00217     virtual void swap( float val[], const IndexType n, const PartitionId partner ) const;
00218 
00219     virtual void swap( int val[], const IndexType n, const PartitionId partner ) const;
00220 
00221     virtual void writeAt( std::ostream& stream ) const;
00222 private:
00223 
00224 
00225 
00226 
00227     template<typename T>
00228     inline void send( const T* buffer, int count, int target ) const;
00229 
00230     template<typename T>
00231     void scatterImpl ( T myvals[], const IndexType n, const PartitionId root,
00232                        const T allvals[] ) const;
00233 
00234     template<typename T>
00235     void scatterImpl ( T myvals[], const IndexType n, const PartitionId root,
00236                        const T allvals[], const IndexType sizes[] ) const;
00237 
00238     template<typename T>
00239     void gatherImpl( T allvals[], const IndexType n, const PartitionId root,
00240                      const T myvals[] ) const;
00241 
00242     template<typename T>
00243     void gatherImpl( T allvals[], const IndexType n, const PartitionId root,
00244                      const T myvals[], const IndexType sizes[] ) const;
00245 
00246     template <typename T>
00247     IndexType shiftImpl(
00248         T newvals[], const IndexType newSize, const PartitionId source,
00249         const T oldVals[], const IndexType oldSize, const PartitionId dest ) const;
00250 
00251     template <typename T>
00252     std::auto_ptr<SyncToken> shiftAsyncImpl(
00253         T newvals[], const PartitionId source,
00254         const T oldVals[], const PartitionId dest, const IndexType size ) const;
00255 
00256     template<typename T>
00257     void swapImpl( T val[], const IndexType n, PartitionId partner ) const;
00258 
00259     template<typename T>
00260     void maxlocImpl( T& val, int& location, PartitionId root ) const;
00261 
00262     template<typename T>
00263     void exchangeByPlanImpl(
00264         T* const recvData,
00265         const CommunicationPlan& recvPlan,
00266         const T* const sendData,
00267         const CommunicationPlan& sendPlan ) const;
00268 
00269     template<typename T>
00270     std::auto_ptr<SyncToken> exchangeByPlanAsyncImpl(
00271         T* const recvData,
00272         const CommunicationPlan& recvPlan,
00273         const T* const sendData,
00274         const CommunicationPlan& sendPlan ) const;
00275 
00276 
00277 
00278 
00279 
00280 
00281     const PGASInterface* mPGASInterface;
00282     Communicator::ThreadSafetyLevel mThreadSafetyLevel;
00283 
00284     LAMA_LOG_DECL_STATIC_LOGGER( logger );
00285 
00286     static const int defaultTag;
00287 
00288 
00289     virtual ContextPtr getCommunicationContext() const;
00290 };
00291 }
00292 
00293 #endif // LAMA_PGASCOMMUNICATOR_H_