00001
00002
00003 #ifndef __UIUC_CHARM_TASKGRAPH_H
00004 #define __UIUC_CHARM_TASKGRAPH_H
00005
00006 #include <charm++.h>
00007
00008 class taskGraphSolver;
00009
00010 #include "taskGraph.decl.h"
00011
00012
00013
00014
00015
00016
00017
00018 class taskGraphSolver : public PUP::able {
00019 private:
00020 CkArrayID __taskSet;
00021 CkArrayIndex __taskIndex;
00022 CkVec<CkArrayIndex> __taskDeps;
00023 public:
00024 virtual void dependsOn(int x) { dependsOn(CkArrayIndex1D(x)); }
00025 virtual void dependsOn(int x, int y) { dependsOn(CkArrayIndex2D(x,y)); }
00026 virtual void dependsOn(int x, int y, int z) { dependsOn(CkArrayIndex3D(x,y,z)); }
00027 virtual void dependsOn(CkArrayIndex taskDep) { __taskDeps.push_back(CkArrayIndex(taskDep)); }
00028
00029 static CkArrayID newTaskGraph() { return CProxy_taskGraphArray::ckNew(); }
00030 virtual void startTask() {
00031 CProxy_taskGraphArray array(__taskSet);
00032 array(__taskIndex).insert(__taskDeps, (taskGraphSolver *)this, CkCallback::ignore);
00033 }
00034 virtual void removeTask() {
00035 CProxy_taskGraphArray array(__taskSet);
00036 array(__taskIndex).deleteElement();
00037 }
00038
00039 public:
00040 taskGraphSolver(CkArrayID set, int x)
00041 : __taskSet(set), __taskIndex(CkArrayIndex1D(x)), __taskDeps() {}
00042 taskGraphSolver(CkArrayID set, int x, int y)
00043 : __taskSet(set), __taskIndex(CkArrayIndex2D(x,y)), __taskDeps() {}
00044 taskGraphSolver(CkArrayID set, int x, int y, int z)
00045 : __taskSet(set), __taskIndex(CkArrayIndex3D(x,y,z)), __taskDeps() {}
00046 taskGraphSolver(CkArrayID set, CkArrayIndex taskIndex)
00047 : __taskSet(set), __taskIndex(taskIndex), __taskDeps() {}
00048 taskGraphSolver(CkMigrateMessage *m) : PUP::able(m) {}
00049
00050 virtual void pup(PUP::er &p) {
00051 }
00052 PUPable_abstract(taskGraphSolver);
00053
00054 virtual void solve(int depsCount, taskGraphSolver *data[]) = 0;
00055 virtual void setup() = 0;
00056 };
00057
00058
00059
00060 class callbackMsg : public CMessage_callbackMsg {
00061 public:
00062 PUPable_marshall<taskGraphSolver> Data;
00063 CkArrayIndex Index;
00064 callbackMsg(taskGraphSolver* self, CkArrayIndex ind)
00065 : Data(self), Index(ind) {};
00066 };
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076 CkArrayID taskGraphInit();
00077
00078
00079
00080
00081
00082
00083
00084
00085 template <class T>
00086 void taskGraphAdd(CkArrayID id, T taskID,
00087 CkVec<T> deps,
00088 taskGraphSolver *self,
00089 CkCallback returnResults = CkCallback::ignore) {
00090 CkVec<CkArrayIndex> newDeps;
00091
00092 for ( int i = 0 ; i < deps.length() ; i++ ) {
00093 newDeps.push_back( CkArrayIndex(deps[i]) );
00094 }
00095
00096 CkArrayIndex newTaskID( taskID );
00097 CProxy_taskGraphArray array(id);
00098 array(newTaskID).insert(newDeps, self, returnResults);
00099 }
00100
00101
00102
00103
00104 void taskGraphDelete(CkArrayID id, CkArrayIndex taskID);
00105
00106
00107
00108
00109
00110 class taskGraphArray : public ArrayElementMax {
00111 protected:
00112 taskGraphSolver *Self;
00113 int isSolved;
00114 CkVec<CkArrayIndex> Waiting;
00115
00116 int DepsCount;
00117 taskGraphSolver **DepsData;
00118 int DepsReceived;
00119
00120 CkCallback ReturnResults;
00121
00122 void tryToSolve();
00123
00124 public:
00125 taskGraphArray(CkVec<CkArrayIndex> deps,
00126 taskGraphSolver *data,
00127 CkCallback returnResults);
00128 taskGraphArray(CkMigrateMessage *m) {};
00129 void requestData(CkArrayIndex from);
00130 void depositData(taskGraphSolver *data);
00131 void deleteElement();
00132 };
00133
00134 #endif