LAMA
/home/brandes/workspace/LAMA/src/lama/pgas/functor/PGASMaxLocFunctor.hpp
Go to the documentation of this file.
00001 
00033 #ifndef LAMA_PGASMAXLOCFUNCTOR_HPP_
00034 #define LAMA_PGASMAXLOCFUNCTOR_HPP_
00035 
00036 #include <lama/pgas/PGASInterface.hpp>
00037 #include <lama/pgas/PGASFunctor.hpp>
00038 
00039 namespace lama{
00040 template <typename T>
00041 class PGASMaxLocFunctor: public PGASFunctor
00042 {
00043     T* mResult;
00044     T* mWork;
00045     int* mWorkRank;
00046     int* mResultRank;
00047     const PGASInterface* const mInterface;
00048 
00049 public:
00050     PGASMaxLocFunctor(T val);
00051     virtual ~PGASMaxLocFunctor();
00052     virtual void iteration(int partner, bool active);
00053     T getResult();
00054     int getLoc();
00055 };
00056 
00057 template <typename T>
00058 PGASMaxLocFunctor<T>::PGASMaxLocFunctor(T val): mInterface(PGASInterface::getInstance())
00059 {
00060     mResult = static_cast<T*>(mInterface->allocate(sizeof(T)));
00061     mWork = static_cast<T*>(mInterface->allocate(sizeof(T)));
00062     mResultRank = static_cast<int*>(mInterface->allocate(sizeof(int)));
00063     *mWork = val;
00064     *mResult = val;
00065     *mResultRank = mInterface->getRank();
00066 }
00067 template <typename T>
00068 PGASMaxLocFunctor<T>::~PGASMaxLocFunctor()
00069 {
00070     mInterface->free(mWork,sizeof(T));
00071     mInterface->free(mResult,sizeof(T));
00072     mInterface->free(mResultRank,sizeof(int));
00073 }
00074 
00075 template <typename T>
00076 T PGASMaxLocFunctor<T>::getResult()
00077 {
00078     return *mResult;
00079 }
00080 
00081 template <typename T>
00082 int PGASMaxLocFunctor<T>::getLoc()
00083 {
00084     return *mResultRank;
00085 }
00086 
00087 template <typename T>
00088 void PGASMaxLocFunctor<T>::iteration(int partner, bool active)
00089 {
00090     mInterface->syncronizeAll();
00091     *mWork = *mResult;
00092     mInterface->syncronizeAll();
00093     if(active)
00094     {
00095         mInterface->get(mWork,mResult,sizeof(T),partner);
00096 
00097         if(((*mWork)>(*mResult)))
00098         {
00099             *mResult = *mWork;
00100             mInterface->get(mResultRank,mResultRank,sizeof(int),partner);
00101         }
00102     }
00103 }
00104 }//namespace lama
00105 
00106 #endif // LAMA_PGASMAXLOCFUNCTOR_HPP_