
00001 #include "charm++.h" 00002 00003 #ifndef X_ARRAY_SECTION_REDUCER_H 00004 #define X_ARRAY_SECTION_REDUCER_H 00005 00006 namespace ck { 00007 namespace impl { 00008 00018 class XArraySectionReducer 00019 { 00020 public: 00022 XArraySectionReducer(int _numSubSections, CkCallback *_finalCB) 00023 : numSubSections(_numSubSections), finalCB(_finalCB), numReceived(0) 00024 { 00025 CkAssert(numSubSections > 0); 00026 msgList = new CkReductionMsg*[numSubSections]; 00027 bzero( msgList, numSubSections*sizeof(CkReductionMsg*) ); 00028 } 00029 00031 ~XArraySectionReducer() 00032 { 00033 delete finalCB; 00034 delete [] msgList; 00035 } 00036 00038 void acceptSectionContribution(CkReductionMsg *msg) 00039 { 00040 msgList[numReceived++] = msg; 00041 if (numReceived >= numSubSections) 00042 finalReducer(); 00043 } 00044 00045 private: 00047 void finalReducer() 00048 { 00049 // Get a handle on the reduction function for this message 00050 CkReduction::reducerFn f = CkReduction::reducerTable[ msgList[0]->reducer ]; 00051 // Perform an extra reduction step on all the subsection reduction msgs 00052 CkReductionMsg *finalMsg = (*f)(numSubSections, msgList); 00053 // Send the final reduced msg to the client 00054 finalCB->send(finalMsg); 00055 // Delete the subsection redn msgs, accounting for any msg reuse 00056 for (int i=0; i < numSubSections; i++) 00057 if (msgList[i] != finalMsg) delete msgList[i]; 00058 // Reset the msg list and counters in preparation for the next redn 00059 bzero( msgList, numSubSections*sizeof(CkReductionMsg*) ); 00060 numReceived = 0; 00061 } 00062 00063 // The number of subsection redn msgs to expect 00064 const int numSubSections; 00065 // The final client callback after all redn are done 00066 const CkCallback *finalCB; 00067 // Counter to track when all subsection redns are complete 00068 int numReceived; 00069 // List of subsection redn msgs 00070 CkReductionMsg **msgList; 00071 }; 00072 00073 00075 void processSectionContribution (void *that, void *msg) 00076 { 00077 CkAssert(that); 00078 reinterpret_cast<XArraySectionReducer*>(that)->acceptSectionContribution(reinterpret_cast<CkReductionMsg*>(msg)); 00079 } 00080 00081 } // end namespace impl 00082 } // end namespace ck 00083 00084 #endif // X_ARRAY_SECTION_REDUCER_H 00085
1.5.5