00001
00002
00003
00004
00005 #ifndef __UIUC_CHARM_COLLIDECHARM_IMPL_H
00006 #define __UIUC_CHARM_COLLIDECHARM_IMPL_H
00007
00008 #include "collide_serial.h"
00009 #include "collide_buffers.h"
00010 #include "collidecharm.decl.h"
00011 #include "collidecharm.h"
00012
00013
00014
00015
00016
00017
00018
00019 class objListMsg : public CMessage_objListMsg
00020 {
00021 public:
00022 class returnReceipt {
00023 CkGroupID gid;
00024 public:
00025 int onPE;
00026 returnReceipt() {}
00027 returnReceipt(CkGroupID gid_,int onPE_) :gid(gid_),onPE(onPE_) {}
00028 void send(void);
00029 };
00030 private:
00031 bool isHeapAllocated;
00032 returnReceipt receipt;
00033
00034 int n;
00035 CollideObjRec *obj;
00036
00037 void freeHeapAllocated();
00038 public:
00039 objListMsg() :isHeapAllocated(false) {}
00040
00041
00042
00043 objListMsg(int n_,CollideObjRec *obj_,
00044 const returnReceipt &receipt_);
00045 ~objListMsg() {freeHeapAllocated();}
00046
00047 int getSource(void) {return receipt.onPE;}
00048 void sendReceipt(void) {receipt.send();}
00049
00050 int getObjects(void) const {return n;}
00051 const CollideObjRec &getObj(int i) const {return obj[i];}
00052 const bbox3d &bbox(int i) const {return obj[i].box;}
00053
00054 static void *pack(objListMsg *m);
00055 static objListMsg *unpack(void *m);
00056 };
00057
00058
00059
00060 #include "ckhashtable.h"
00061
00062 class collideMgr;
00063 class voxelAggregator;
00064
00065
00066
00067
00068 class CollisionAggregator {
00069 CollideGrid3d gridMap;
00070 CkHashtableT<CollideLoc3d,voxelAggregator *> voxels;
00071 collideMgr *mgr;
00072
00073
00074 voxelAggregator *addAccum(const CollideLoc3d &dest);
00075 public:
00076 CollisionAggregator(const CollideGrid3d &gridMap_,collideMgr *mgr_);
00077 ~CollisionAggregator();
00078
00079
00080 void aggregate(int pe,int chunk,
00081 int n,const bbox3d *boxes,const int *prio);
00082
00083
00084 void send(void);
00085
00086
00087 void compact(void);
00088 };
00089
00090
00091
00092
00093
00094
00095
00096
00097 class syncReductionMgr : public CBase_syncReductionMgr
00098 {
00099 CProxy_syncReductionMgr thisproxy;
00100 void status(const char *msg) {
00101 CkPrintf("SRMgr pe %d> %s\n",CkMyPe(),msg);
00102 }
00103
00104 int onPE;
00105 enum {TREE_WID=4};
00106 int treeParent;
00107 int treeChildStart,treeChildEnd;
00108 int nChildren;
00109 void startStep(int stepNo,bool withProd);
00110
00111
00112 int stepCount;
00113 bool stepFinished;
00114 bool localFinished;
00115 int childrenCount;
00116 void tryFinish(void);
00117
00118 protected:
00119
00120 void advance(void);
00121
00122 virtual void pleaseAdvance(void);
00123
00124 virtual void reductionFinished(void);
00125 public:
00126 int getStepCount(void) const {return stepCount;}
00127 syncReductionMgr();
00128
00129
00130 void childProd(int stepCount);
00131
00132 void childDone(int stepCount);
00133 };
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147 class collideMgr : public CBase_collideMgr
00148 {
00149 CProxy_collideMgr thisproxy;
00150 private:
00151 void status(const char *msg) {
00152 CkPrintf("CMgr pe %d> %s\n",CkMyPe(),msg);
00153 }
00154 int steps;
00155 CProxy_collideVoxel voxelProxy;
00156 CollideGrid3d gridMap;
00157 CProxy_collideClient client;
00158
00159 int nContrib;
00160 int contribCount;
00161
00162 CollisionAggregator aggregator;
00163 int msgsSent;
00164 int msgsRecvd;
00165 void tryAdvance(void);
00166 protected:
00167
00168 virtual void pleaseAdvance(void);
00169
00170 virtual void reductionFinished(void);
00171 public:
00172 collideMgr(const CollideGrid3d &gridMap,
00173 const CProxy_collideClient &client,
00174 const CProxy_collideVoxel &voxels);
00175
00176
00177 void registerContributor(int chunkNo);
00178 void unregisterContributor(int chunkNo);
00179
00180
00181 void contribute(int chunkNo,
00182 int n,const bbox3d *boxes,const int *prio);
00183
00184
00185 void sendVoxelMessage(const CollideLoc3d &dest,
00186 int n,CollideObjRec *obj);
00187
00188
00189 void voxelMessageRecvd(void);
00190 };
00191
00192
00193
00194
00195
00196
00197
00198 class collideVoxel : public CBase_collideVoxel
00199 {
00200 growableBufferT<objListMsg *> msgs;
00201 void status(const char *msg);
00202 void emptyMessages();
00203 void collide(const bbox3d &territory,CollisionList &dest);
00204 public:
00205 collideVoxel(void);
00206 collideVoxel(CkMigrateMessage *m);
00207 ~collideVoxel();
00208 void pup(PUP::er &p);
00209
00210 void add(objListMsg *msg);
00211 void startCollision(int step,
00212 const CollideGrid3d &gridMap,
00213 const CProxy_collideClient &client);
00214 };
00215
00216
00217
00218
00219
00220 class serialCollideClient : public collideClient {
00221 CollisionClientFn clientFn;
00222 void *clientParam;
00223 public:
00224 serialCollideClient(void);
00225
00227 void setClient(CollisionClientFn clientFn,void *clientParam);
00228
00230 virtual void collisions(ArrayElement *src,
00231 int step,CollisionList &colls);
00232
00234 virtual void reductionDone(CkReductionMsg *m);
00235 };
00236
00237 #if CMK_TRACE_ENABLED
00238
00239 static const char *funclist[] = {"COLLIDE_Init", "COLLIDE_Boxes",
00240 "COLLIDE_Boxes_prio", "COLLIDE_Count", "COLLIDE_List",
00241 "COLLIDE_Destroy"};
00242
00243 #endif // CMK_TRACE_ENABLED
00244
00245 #endif //def(thisHeader)