LAMA
|
00001 00033 #ifndef LAMA_PGASSUMFUNCTOR_HPP_ 00034 #define LAMA_PGASSUMFUNCTOR_HPP_ 00035 00036 #include <lama/pgas/PGASInterface.hpp> 00037 #include <lama/pgas/PGASFunctor.hpp> 00038 00039 namespace lama{ 00040 template <typename T> 00041 class PGASSumFunctor: public PGASFunctor 00042 { 00043 T* mResult; 00044 T* mWork; 00045 const PGASInterface* const mInterface; 00046 00047 public: 00048 PGASSumFunctor(T val); 00049 virtual ~PGASSumFunctor(); 00050 virtual void iteration(int partner, bool active); 00051 T getResult(); 00052 }; 00053 00054 template <typename T> 00055 PGASSumFunctor<T>::PGASSumFunctor(T val): mInterface(PGASInterface::getInstance()) 00056 { 00057 mResult = static_cast<T*>(mInterface->allocate(sizeof(T))); 00058 mWork = static_cast<T*>(mInterface->allocate(sizeof(T))); 00059 //*mWork = val; 00060 *mResult = val; 00061 } 00062 template <typename T> 00063 PGASSumFunctor<T>::~PGASSumFunctor() 00064 { 00065 mInterface->free(mWork,sizeof(T)); 00066 mInterface->free(mResult,sizeof(T)); 00067 } 00068 00069 template <typename T> 00070 T PGASSumFunctor<T>::getResult() 00071 { 00072 return *mResult; 00073 } 00074 00075 template <typename T> 00076 void PGASSumFunctor<T>::iteration(int partner, bool active) 00077 { 00078 mInterface->syncronizeAll(); 00079 *mWork = *mResult; 00080 mInterface->syncronizeAll(); 00081 if(active) 00082 { 00083 mInterface->get(mResult,mWork,sizeof(T),partner); 00084 *mResult += *mWork; 00085 } 00086 } 00087 }//namespace lama 00088 00089 #endif // LAMA_PGASSUMFUNCTOR_HPP_