Skip to content

Commit 374907e

Browse files
Migratable collidev701 (#3922)
* Changes attempting to make the collide-lib migratable * Changes to fix reset --------- Co-authored-by: adityakpandare <apandare@lanl.gov>
1 parent c5f1dcd commit 374907e

6 files changed

Lines changed: 144 additions & 16 deletions

File tree

src/libs/ck-libs/collide/collide_util.C

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ void CollideGrid3d::init(const vector3d &Norigin,//Grid voxel corner 0,0,0
4949
sizes[i]=desiredSize[i];
5050
#endif
5151
((double *)scales)[i]=1.0/((double *)sizes)[i];
52-
testMapping(*this,i,((double *)origin)[i],((double *)sizes)[i]);
52+
//testMapping(*this,i,((double *)origin)[i],((double *)sizes)[i]);
5353
}
5454

5555
}

src/libs/ck-libs/collide/collidecharm.C

Lines changed: 87 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*/
55
#include "charm++.h"
66
#include "collidecharm_impl.h"
7+
#include <iostream>
78

89
#define COLLIDE_TRACE 0
910
#if COLLIDE_TRACE
@@ -45,6 +46,17 @@ CkGroupID CollideSerialClient(CkCallback clientCb)
4546
return cl;
4647
}
4748

49+
/// Call this on all procesors at restart, to reinitialize the Collision client
50+
/// with correct clientFn and clientParam
51+
void CollideSerialClientRestart(
52+
CollideHandle h,
53+
CollisionClientFn clientFn,
54+
void *clientParam )
55+
{
56+
CProxy_collideMgr mgr(h);
57+
mgr.ckLocalBranch()->reinitClient(clientFn, clientParam);
58+
}
59+
4860
/// Create a collider group to contribute objects to.
4961
/// Should be called on processor 0.
5062
CollideHandle CollideCreate(const CollideGrid3d &gridMap,
@@ -74,6 +86,7 @@ void CollideBoxesPrio(CollideHandle h,int chunkNo,
7486
int nBox,const bbox3d *boxes,const int *prio)
7587
{
7688
CProxy_collideMgr mgr(h);
89+
std::cout << "CollideBoxesPrio init'ed collideMgr from nBoxes " << nBox << std::endl;
7790
mgr.ckLocalBranch()->contribute(chunkNo,nBox,boxes,prio);
7891
}
7992

@@ -301,7 +314,6 @@ void CollisionAggregator::compact(void)
301314

302315
/********************* syncReductionMgr ******************/
303316
syncReductionMgr::syncReductionMgr()
304-
:thisproxy(thisgroup)
305317
{
306318
stepCount=-1;
307319
stepFinished=true;
@@ -326,16 +338,19 @@ void syncReductionMgr::startStep(int stepNo,bool withProd)
326338
stepFinished=false;
327339
localFinished=false;
328340
childrenCount=0;
329-
if (nChildren>0)
341+
if (nChildren>0) {
342+
CProxy_syncReductionMgr proxy(ckGetGroupID());
330343
for (int i=0;i<TREE_WID;i++)
331344
if (treeChildStart+i<CkNumPes())
332-
thisproxy[treeChildStart+i].childProd(stepCount);
345+
proxy[treeChildStart+i].childProd(stepCount);
346+
}
333347
if (withProd)
334348
pleaseAdvance();//Advise subclass to advance
335349
}
336350

337351
void syncReductionMgr::advance(void)
338352
{
353+
std::cout << "in syncReductionMgr::advance()" << std::endl;
339354
SRM_STATUS("syncReductionMgr::advance");
340355
if (stepFinished) startStep(stepCount+1,false);
341356
localFinished=true;
@@ -347,16 +362,19 @@ void syncReductionMgr::pleaseAdvance(void)
347362

348363
//This is called on PE 0 once the reduction is finished
349364
void syncReductionMgr::reductionFinished(void)
350-
{ /*Child use only */ }
365+
{ /*Child use only */
366+
std::cout << "in syncReductionMgr::reductionFinished()" << std::endl;
367+
}
351368

352369
void syncReductionMgr::tryFinish(void) //Try to finish reduction
353370
{
371+
std::cout << "in syncReductionMgr::tryFinished()" << std::endl;
354372
SRM_STATUS("syncReductionMgr::tryFinish");
355373
if (localFinished && (!stepFinished) && childrenCount==nChildren)
356374
{
357375
stepFinished=true;
358376
if (treeParent!=-1)
359-
thisproxy[treeParent].childDone(stepCount);
377+
CProxy_syncReductionMgr(ckGetGroupID())[treeParent].childDone(stepCount);
360378
else
361379
reductionFinished();
362380
}
@@ -371,12 +389,30 @@ void syncReductionMgr::childProd(int stepCount)
371389
//Called by tree children-- me and my children are finished
372390
void syncReductionMgr::childDone(int stepCount)
373391
{
392+
std::cout << "in syncReductionMgr::childDone()" << std::endl;
374393
SRM_STATUS("syncReductionMgr::childDone");
375394
if (stepFinished) startStep(stepCount,true);
376395
childrenCount++;
377396
tryFinish();
378397
}
379398

399+
syncReductionMgr::syncReductionMgr(CkMigrateMessage* m) :
400+
CBase_syncReductionMgr(m)
401+
{
402+
stepCount=-1;
403+
stepFinished=true;
404+
localFinished=false;
405+
406+
//Set up the reduction tree
407+
onPE=CkMyPe();
408+
if (onPE==0) treeParent=-1;
409+
else treeParent=(onPE-1)/TREE_WID;
410+
treeChildStart=(onPE*TREE_WID)+1;
411+
treeChildEnd=treeChildStart+TREE_WID;
412+
if (treeChildStart>CkNumPes()) treeChildStart=CkNumPes();
413+
if (treeChildEnd>CkNumPes()) treeChildEnd=CkNumPes();
414+
nChildren=treeChildEnd-treeChildStart;
415+
}
380416

381417
/*********************** collideMgr ***********************/
382418
//Extract the (signed) low 23 bits of src--
@@ -402,7 +438,7 @@ static const char * voxName(const CkIndex3D &idx,char *buf) {
402438
collideMgr::collideMgr(const CollideGrid3d &gridMap_,
403439
const CProxy_collideClient &client_,
404440
const CProxy_collideVoxel &voxels)
405-
:thisproxy(thisgroup), voxelProxy(voxels),
441+
:voxelProxy(voxels),
406442
gridMap(gridMap_), client(client_), aggregator(gridMap,this)
407443
{
408444
steps=0;
@@ -411,6 +447,26 @@ collideMgr::collideMgr(const CollideGrid3d &gridMap_,
411447
msgsSent=msgsRecvd=0;
412448
}
413449

450+
collideMgr::collideMgr(CkMigrateMessage* m) :
451+
CBase_collideMgr(m),
452+
gridMap(CollideGrid3d(CkVector3d(0, 0, 0),CkVector3d(2, 100, 2))),
453+
aggregator(gridMap,this)
454+
{
455+
steps=0;
456+
nContrib=0;
457+
contribCount=0;
458+
msgsSent=msgsRecvd=0;
459+
}
460+
461+
// Reinitialize collideClient's state on restart
462+
void collideMgr::reinitClient(
463+
CollisionClientFn clientFn,
464+
void *clientParam )
465+
{
466+
std::cout << "collideMgr::reinitClient from " << thisIndex << std::endl;
467+
client.ckLocalBranch()->setClient(clientFn, clientParam);
468+
}
469+
414470
//Maintain contributor registration count
415471
void collideMgr::registerContributor(int chunkNo)
416472
{
@@ -428,6 +484,7 @@ void collideMgr::contribute(int chunkNo,
428484
int n,const bbox3d *boxes,const int *prio)
429485
{
430486
//printf("[%d] Receiving contribution from %d\n",CkMyPe(), chunkNo);
487+
std::cout << "began contribute() of nBoxes " << n << std::endl;
431488
CM_STATUS("collideMgr::contribute "<<n<<" boxes from "<<chunkNo);
432489
aggregator.aggregate(CkMyPe(),chunkNo,n,boxes,prio);
433490
aggregator.send(); //Deliver all outgoing messages
@@ -437,6 +494,7 @@ void collideMgr::contribute(int chunkNo,
437494
aggregator.compact();//Blow away all the old voxels (saves memory)
438495
tryAdvance();
439496
}
497+
std::cout << "completed contribute() of nBoxes " << n << std::endl;
440498
//printf("[%d] DONE receiving contribution from %d\n",CkMyPe(), chunkNo);
441499
}
442500

@@ -483,6 +541,7 @@ void collideMgr::pleaseAdvance(void)
483541
//Attempt to finish the voxel send/recv step
484542
void collideMgr::tryAdvance(void)
485543
{
544+
std::cout << "in collideMgr::tryAdvance()" << std::endl;
486545
CM_STATUS("tryAdvance: "<<nContrib-contribCount<<" contrib, "<<msgsSent-msgsRecvd<<" msg")
487546
if ((contribCount==nContrib) && (msgsSent==msgsRecvd)) {
488547
CM_STATUS("advancing");
@@ -496,6 +555,7 @@ void collideMgr::tryAdvance(void)
496555
//This is called on PE 0 once the voxel send/recv reduction is finished
497556
void collideMgr::reductionFinished(void)
498557
{
558+
std::cout << "in collideMgr::reductionFinished()" << std::endl;
499559
CM_STATUS("collideMgr::reductionFinished");
500560
//Broadcast Collision start:
501561
voxelProxy.startCollision(steps,gridMap,client);
@@ -613,12 +673,18 @@ void collideVoxel::startCollision(int step,
613673
);
614674
CollisionList colls;
615675
collide(territory,colls);
676+
677+
std::cout << "in collideVoxel::startCollision(), completed local collide" << std::endl;
616678
client.ckLocalBranch()->collisions(this,step,colls);
617679

618680
emptyMessages();
619681
CC_STATUS("} startCollision");
620682
}
621683

684+
collideClient::collideClient() {}
685+
686+
collideClient::collideClient(CkMigrateMessage* m) : Group(m) {}
687+
622688
collideClient::~collideClient() {}
623689

624690
/********************** serialCollideClient *****************/
@@ -629,6 +695,13 @@ serialCollideClient::serialCollideClient(void) {
629695
useCb = false;
630696
}
631697

698+
serialCollideClient::serialCollideClient(CkMigrateMessage* m) : collideClient(m)
699+
{
700+
clientFn = NULL;
701+
clientParam = NULL;
702+
clientCb = CkCallback(CkCallback::ignore);
703+
}
704+
632705
serialCollideClient::serialCollideClient(CkCallback clientCb_) {
633706
clientFn=NULL;
634707
clientParam=NULL;
@@ -638,6 +711,7 @@ serialCollideClient::serialCollideClient(CkCallback clientCb_) {
638711

639712
/// Call this client function on processor 0:
640713
void serialCollideClient::setClient(CollisionClientFn clientFn_,void *clientParam_) {
714+
std::cout << "serialCollideClient::setClient from " << thisIndex << std::endl;
641715
clientFn=clientFn_;
642716
clientParam=clientParam_;
643717
}
@@ -646,22 +720,28 @@ void serialCollideClient::collisions(ArrayElement *src,
646720
int step,CollisionList &colls)
647721
{
648722
if(useCb) { // Use user passed callback as reduction target
723+
std::cout << "in serialCollideClient::collisions(), useCB" << std::endl;
649724
src->contribute(colls.length()*sizeof(Collision),colls.getData(),
650725
CkReduction::concat, clientCb);
651726
} else { // Use client fn with reduction targetted at serialCollideClient::reductionDone
652727
CkCallback cb(CkIndex_serialCollideClient::reductionDone(0),0,thisgroup);
728+
std::cout << "in serialCollideClient::collisions(), NOT useCB " << thisIndex << std::endl;
653729
src->contribute(colls.length()*sizeof(Collision),colls.getData(),
654730
CkReduction::concat,cb);
731+
std::cout << "in serialCollideClient::collisions(), after contribute " << thisIndex << std::endl;
655732
}
656733
}
657734

658735
//This is called after the collideVoxel Collision reduction completes
659736
void serialCollideClient::reductionDone(CkReductionMsg *msg)
660737
{
738+
std::cout << "in serialCollideClient::reductionDone()" << std::endl;
661739
int nColl=msg->getSize()/sizeof(Collision);
662740
CM_STATUS("serialCollideClient with "<<nColl<<" collisions");
663-
if (clientFn!=NULL) //User wants Collisions on node 0
741+
if (clientFn!=NULL) {//User wants Collisions on node 0
742+
std::cout << "in serialCollideClient::reductionDone() in clientFn" << std::endl;
664743
(clientFn)(clientParam,nColl,(Collision *)msg->getData());
744+
}
665745
else //FIXME: never registered a client
666746
CkAbort("Forgot to call serialCollideClient::setClient!\n");
667747
delete msg;

src/libs/ck-libs/collide/collidecharm.ci

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,18 @@ module collidecharm {
33

44
group collideClient {
55
};
6-
group serialCollideClient : collideClient {
6+
group [migratable] serialCollideClient : collideClient {
77
entry serialCollideClient();
88
entry serialCollideClient(CkCallback clientCb_);
99
entry void reductionDone(CkReductionMsg *m);
1010
};
1111

12-
group syncReductionMgr {
12+
group [migratable] syncReductionMgr {
1313
entry syncReductionMgr();
1414
entry void childProd(int stepCount);
1515
entry void childDone(int stepCount);
1616
};
17-
group collideMgr : syncReductionMgr {
17+
group [migratable] collideMgr : syncReductionMgr {
1818
entry collideMgr(CollideGrid3d gridMap,
1919
CProxy_collideClient client,
2020
CkArrayID cells);

src/libs/ck-libs/collide/collidecharm.h

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
#include "collide_util.h"
1010
#include "collidecharm.decl.h"
1111

12+
/// This client function is called on PE 0 with a Collision list
13+
typedef void (*CollisionClientFn)(void *param,int nColl,Collision *colls);
14+
15+
1216
/********************** collideClient *****************
1317
A place for the assembled Collision lists to go.
1418
Each voxel calls this "Collisions" method with their
@@ -22,17 +26,18 @@
2226
*/
2327
class collideClient : public Group {
2428
public:
29+
collideClient();
30+
collideClient(CkMigrateMessage* m);
2531
virtual ~collideClient();
2632
virtual void collisions(ArrayElement *src,
2733
int step,CollisionList &colls) =0;
34+
virtual void setClient(CollisionClientFn clientFn,
35+
void *clientParam) = 0;
2836
};
2937

3038
/********************** serialCollideClient *****************
3139
Reduces the Collision list down to processor 0.
3240
*/
33-
/// This client function is called on PE 0 with a Collision list
34-
typedef void (*CollisionClientFn)(void *param,int nColl,Collision *colls);
35-
3641
/// Call this on processor 0 to build a Collision client that
3742
/// just calls this serial routine on processor 0 with the final,
3843
/// complete Collision list.
@@ -43,9 +48,17 @@ CkGroupID CollideSerialClient(CollisionClientFn clientFn,void *clientParam);
4348
/// complete Collision list.
4449
CkGroupID CollideSerialClient(CkCallback clientCb);
4550

46-
/****************** Collision Interface ******************/
4751
typedef CkGroupID CollideHandle;
4852

53+
/// Call this on all procesors at restart, to reinitialize the Collision client
54+
/// with correct clientFn and clientParam
55+
void CollideSerialClientRestart(
56+
CollideHandle h,
57+
CollisionClientFn clientFn,
58+
void *clientParam );
59+
60+
/****************** Collision Interface ******************/
61+
4962
/// Create a collider group to contribute objects to.
5063
/// Should be called on processor 0.
5164
CollideHandle CollideCreate(const CollideGrid3d &gridMap,

0 commit comments

Comments
 (0)