Adding the new interface to access comm lib.
authorSameer Kumar <skumar2@uiuc.edu>
Thu, 14 Oct 2004 17:42:19 +0000 (17:42 +0000)
committerSameer Kumar <skumar2@uiuc.edu>
Thu, 14 Oct 2004 17:42:19 +0000 (17:42 +0000)
src/ck-com/ComlibManager.C
src/ck-com/ComlibManager.h
src/ck-com/EachToManyMulticastStrategy.C

index 3ee55f9d4ad39ad320642db8079760177bf19c04..0316a72b843dc258428aef655480a24142246ee9 100644 (file)
@@ -904,12 +904,53 @@ void ComlibManager::lbUpdate(LBMigrateMsg *msg) {
     CkFreeMsg(msg);
 }
 
+CkDelegateData* ComlibManager::ckCopyDelegateData(CkDelegateData *data) {
+    ComlibInstanceHandle *inst = new ComlibInstanceHandle
+        (*((ComlibInstanceHandle *)data));
+    return inst;
+}
+
+
+CkDelegateData * ComlibManager::DelegatePointerPup(PUP::er &p,
+                                                   CkDelegateData *pd) {
+    ComlibInstanceHandle *inst; 
+    if(!p.isUnpacking()) 
+        inst = (ComlibInstanceHandle *) pd;
+    
+    if(p.isUnpacking()) 
+        //Call migrate constructor
+        inst = new ComlibInstanceHandle();
+    
+    inst->pup(p);
+    return inst;
+}    
+
 
 void ComlibDelegateProxy(CProxy *proxy){
     CProxy_ComlibManager cgproxy(CkpvAccess(cmgrID));
     proxy->ckDelegate(cgproxy.ckLocalBranch());
 }
 
+void ComlibAssociateProxy(CharmStrategy *strat, CProxy &proxy) {
+    ComlibInstanceHandle *cinst = new ComlibInstanceHandle
+        (CkGetComlibInstance());
+
+    cinst->setStrategy(strat);
+    
+    CProxy_ComlibManager cgproxy(CkpvAccess(cmgrID));
+    proxy.ckDelegate(cgproxy.ckLocalBranch(), cinst);
+} 
+
+void ComlibBegin(CProxy &proxy) {
+    ComlibInstanceHandle *cinst = (ComlibInstanceHandle *)proxy.ckDelegatedPtr();
+    cinst->beginIteration();
+} 
+
+void ComlibEnd(CProxy &proxy) {
+    ComlibInstanceHandle *cinst = (ComlibInstanceHandle *)proxy.ckDelegatedPtr();
+    cinst->endIteration();
+}
+
 ComlibInstanceHandle CkCreateComlibInstance(){
     return CkGetComlibInstance();
 }
@@ -949,7 +990,7 @@ public:
 };
 
 //Called by user code
-ComlibInstanceHandle::ComlibInstanceHandle(){
+ComlibInstanceHandle::ComlibInstanceHandle() : CkDelegateData() {
     _instid = -1;
     _dmid.setZero();
     _srcPe = -1;
@@ -957,21 +998,28 @@ ComlibInstanceHandle::ComlibInstanceHandle(){
 }
 
 //Called by user code
-ComlibInstanceHandle::ComlibInstanceHandle(const ComlibInstanceHandle &h){
+ComlibInstanceHandle::ComlibInstanceHandle(const ComlibInstanceHandle &h) 
+    : CkDelegateData() {
     _instid = h._instid;
     _dmid = h._dmid;
-    toForward = h.toForward;
+    toForward = h.toForward;        
 
     ComlibPrintf("In Copy Constructor\n");
-
-    //We DO NOT copy the source processor
-    //Source PE is initialized here
     _srcPe = h._srcPe;
+
+    reset();
+    ref();
 }
 
-void ComlibInstanceHandle::init(){
-    CProxy_ComlibManager cgproxy(CkpvAccess(cmgrID));    
-    *this = (cgproxy.ckLocalBranch())->createInstance();
+ComlibInstanceHandle& ComlibInstanceHandle::operator=(ComlibInstanceHandle &h) {
+    _instid = h._instid;
+    _dmid = h._dmid;
+    toForward = h.toForward;
+    _srcPe = h._srcPe;
+    
+    reset();
+    ref();
+    return *this;
 }
 
 //Called by the communication library
@@ -985,7 +1033,7 @@ ComlibInstanceHandle::ComlibInstanceHandle(int instid, CkGroupID dmid){
 void ComlibInstanceHandle::beginIteration() { 
     CProxy_ComlibManager cgproxy(_dmid);
 
-    ComlibPrintf("Instance Handle beginIteration %d, %d\n", CkMyPe(), _srcPe);
+    ComlibPrintf("Instance Handle beginIteration %d, %d, %d\n", CkMyPe(), _srcPe, _instid);
 
     //User forgot to make the instance handle a readonly or pass it
     //into the constructor of an array and is using it directly from
index d9af80b5a9c4e77ee6bc805a24e1cca891c25d61..563503a0c149413ee4da4677fa0f1907d2c078d0 100644 (file)
@@ -56,9 +56,8 @@ class ComlibMulticastMsg : public CkMcastBaseMsg,
 class ComlibManager;
 
 //An Instance of the communication library.
-class ComlibInstanceHandle {
+class ComlibInstanceHandle : public CkDelegateData {
  private:    
-    
     int _instid;
     CkGroupID _dmid;
     int _srcPe;
@@ -69,8 +68,9 @@ class ComlibInstanceHandle {
     ComlibInstanceHandle(const ComlibInstanceHandle &h);
     ComlibInstanceHandle(int instid, CkGroupID dmid);    
    
+    ComlibInstanceHandle &operator=(ComlibInstanceHandle &h);
+
     void setForwardingOnMigration(){toForward = 1;} 
-    void init();
     void beginIteration();
     void endIteration();
     
@@ -83,6 +83,10 @@ class ComlibInstanceHandle {
 
     friend class ComlibManager;
     void pup(PUP::er &p) {
+
+        if(p.isUnpacking())
+             reset();        
+
         p | _instid;
         p | _dmid;
         p | _srcPe;
@@ -222,35 +226,23 @@ class ComlibManager: public CkDelegateMgr {
     //Returns the processor on which the comlib sees the array element
     //belonging to
     inline int getLastKnown(CkArrayID a, CkArrayIndexMax &idx) {
-        /*
-        ClibGlobalArrayIndex cidx;
-        cidx.aid = a;
-        cidx.idx = idx;
-        int pe = locationTable->get(cidx);
-
-        if(pe == 0) {
-            //Array element does not exist in the table
-
-            CkArray *array = CkArrayID::CkLocalBranch(a);
-            pe = array->lastKnown(idx) + CkNumPes();
-            locationTable->put(cidx) = pe;
-        }
-        //CkPrintf("last pe = %d \n", pe - CkNumPes());
-
-        return pe - CkNumPes();
-        */
         return ComlibGetLastKnown(a, idx);
     }
+
+    CkDelegateData* ckCopyDelegateData(CkDelegateData *data); 
+    CkDelegateData *DelegatePointerPup(PUP::er &p,CkDelegateData *pd);
 };
 
 void ComlibDelegateProxy(CProxy *proxy);
+void ComlibAssociateProxy(CharmStrategy *strat, CProxy &proxy); 
+void ComlibBegin(CProxy &proxy);    
+void ComlibEnd(CProxy &proxy);    
 
 ComlibInstanceHandle CkCreateComlibInstance();
 ComlibInstanceHandle CkGetComlibInstance();
 ComlibInstanceHandle CkGetComlibInstance(int id);
 void ComlibResetSectionProxy(CProxySection_ArrayBase *sproxy);
 
-
 //Only Called when the strategies are not being created in main::main
 void ComlibDoneCreating(); 
 
index 0a652496811d32ae85281baf76cdd4f18a07adbf..d3a89689658ebd2f3daa890755e4fd0d7f4f07fa 100644 (file)
@@ -235,7 +235,7 @@ void EachToManyMulticastStrategy::pup(PUP::er &p){
 
     int count = 0;
     ComlibPrintf("[%d] Each To many::pup %s\n", CkMyPe(), 
-                 ((p.isPacking()==0)?("UnPacking"):("Packing")));
+                 ((!p.isUnpacking() == 0)?("UnPacking"):("Packing")));
 
     CharmStrategy::pup(p);