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.
5062CollideHandle 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 ******************/
303316syncReductionMgr ::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
337351void 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
349364void syncReductionMgr ::reductionFinished (void )
350- { /*Child use only */ }
365+ { /*Child use only */
366+ std ::cout << "in syncReductionMgr::reductionFinished()" << std ::endl ;
367+ }
351368
352369void 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
372390void 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) {
402438collideMgr ::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
415471void 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
484542void 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
497556void 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+
622688collideClient ::~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+
632705serialCollideClient ::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:
640713void 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
659736void 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 ;
0 commit comments