Fixed a memory leak and a added some other code optimizations.
authorSameer Kumar <skumar2@uiuc.edu>
Tue, 31 Aug 2004 18:09:49 +0000 (18:09 +0000)
committerSameer Kumar <skumar2@uiuc.edu>
Tue, 31 Aug 2004 18:09:49 +0000 (18:09 +0000)
src/conv-com/convcomlibmanager.C
src/conv-com/convcomlibstrategy.h
src/conv-com/gridrouter.C
src/conv-com/gridrouter.h
src/conv-com/petable.C
src/conv-com/routerstrategy.C

index b2d9112b6eef42ee70d378665732a65f3a8d552e..c12b3b6d6f83d40680bc93b2635aa94b2c024406 100644 (file)
@@ -59,7 +59,7 @@ void initComlibManager(){
     CkpvInitialize(ConvComlibManager *, conv_comm_ptr);
     CkpvAccess(conv_comm_ptr) = conv_com;
 
-    comm_debug = 0;
+    //comm_debug = 1;
     ComlibPrintf("Init Call\n");
 
     CkpvInitialize(int, RecvmsgHandle);
index d68cc420e016c6dc6967ce0830aaa02d3b34ee82..7978749a4da6647f50146957b65dd0d989ac105b 100644 (file)
@@ -55,6 +55,14 @@ class MessageHolder : public PUP::able {
       return size;
     }
 
+    inline void * operator new(size_t size) {
+        return CmiAlloc(size);
+    }
+
+    inline void operator delete (void *buf) {
+        CmiFree(buf);
+    }
+
     virtual void pup(PUP::er &p);
     PUPable_decl(MessageHolder);
 };
@@ -90,8 +98,8 @@ class Strategy : public PUP::able{
        higherLevel = this;
     }
 
-    void setBracketed(){isStrategyBracketed = 1;}
-    int isBracketed(){return isStrategyBracketed;}
+    inline void setBracketed(){isStrategyBracketed = 1;}
+    inline int isBracketed(){return isStrategyBracketed;}
 
     //Called for each message
     virtual void insertMessage(MessageHolder *msg) {}
@@ -100,24 +108,24 @@ class Strategy : public PUP::able{
     //messages on that processor.
     virtual void doneInserting() {}
 
-    void setInstance(int instid){myInstanceID = instid;}
-    int getInstance(){return myInstanceID;}
-    int getType() {return type;}
-    void setType(int t) {type = t;}
+    inline void setInstance(int instid){myInstanceID = instid;}
+    inline int getInstance(){return myInstanceID;}
+    inline int getType() {return type;}
+    inline void setType(int t) {type = t;}
 
-    void setDestination(int handler) {destinationHandler = handler;}
-    int getDestination() {return destinationHandler;}
+    inline void setDestination(int handler) {destinationHandler = handler;}
+    inline int getDestination() {return destinationHandler;}
 
-    void setConverseStrategy(Strategy *s){
+    inline void setConverseStrategy(Strategy *s){
         converseStrategy = s;
     }
 
-    Strategy * getConverseStrategy() {
+    inline Strategy * getConverseStrategy() {
         return converseStrategy;
     }
 
-    void setHigherLevel(Strategy *s) {
-      higherLevel = s;
+    inline void setHigherLevel(Strategy *s) {
+        higherLevel = s;
     }
 
     Strategy * getHigherLevel() {
index 3b4c073fbd589833065d282017e9c6d4ae541568..6d42c5c579a76998ccb73b7329902984d0286f0f 100644 (file)
@@ -12,6 +12,7 @@
  *
  * Grid (mesh) based router
  ***********************************************************/
+
 #include "gridrouter.h"
 
 #define gmap(pe) {if (gpes) pe=gpes[pe];}
@@ -45,8 +46,8 @@ GridRouter::GridRouter(int n, int me)
   LPMsgExpected = Expect(MyPe, NumPes);
   recvExpected = 0;
 
-  int myrow=MyPe/COLLEN;
-  int mycol=MyPe%COLLEN;  
+  myrow=MyPe/COLLEN;
+  mycol=MyPe%COLLEN;  
   int lastrow = (NumPes - 1)/COLLEN;
   
   if(myrow < lastrow) 
@@ -180,15 +181,15 @@ void GridRouter::EachToManyMulticast(comID id, int size, void *msg, int numpes,
   }
 
   //Send the messages
-  int MYROW=MyPe/COLLEN;
-  int MYCOL = MyPe%COLLEN;
-  int myrep=MYROW*COLLEN;
-  
+  //int MYROW  =MyPe/COLLEN;
+  //int MYCOL = MyPe%COLLEN;
+  int myrep= myrow*COLLEN; 
+  int length = (NumPes - 1)/COLLEN + 1;
   for (int colcount = 0; colcount < rvecSize; ++colcount) {
       int nextpe = rowVector[colcount];
       i = nextpe % COLLEN;
       
-      int length = (NumPes - 1)/COLLEN + 1;
       if((length - 1)* COLLEN + i >= NumPes)
           length --;
       
@@ -221,9 +222,6 @@ void GridRouter::RecvManyMsg(comID id, char *msg)
   if (recvCount == recvExpected) {
       ComlibPrintf("%d recvcount=%d recvexpected = %d\n", MyPe, recvCount, recvExpected);
       
-      int myrow=MyPe/COLLEN;
-      int mycol=MyPe%COLLEN;
-      
       char *a2amsg;
       int a2a_len;
       if(id.isAllToAll) {
index c1287a5a079fd0cc22c7ef111ecc8f052464f236..d475bd76f9f46b62861600402651545fe8bbbf67 100644 (file)
@@ -47,6 +47,7 @@ class GridRouter : public Router
             *rowVector, *colVector, 
             *growVector, *gcolVector;
 
+        int myrow, mycol;
         int rvecSize, cvecSize;
        int MyPe, NumPes, COLLEN;
        int LPMsgCount, LPMsgExpected;
index 610ce4b4ea9e33e751578f58c92068cc59c06c93..cba0b03adac465dd185547ea50d63e0d64bb4710 100644 (file)
@@ -231,8 +231,7 @@ char * PeTable ::ExtractAndPack(comID id, int ufield, int npe,
                                 int *pelist, int *length)
 {
     char *junk;
-    int mask=~7;
-    int nummsgs, offset, actual_msgsize=0, num_distinctmsgs;
+    int nummsgs, offset, num_distinctmsgs;
     
     ComlibPrintf("In ExtractAndPack %d\n", npe); 
     
@@ -241,27 +240,19 @@ char * PeTable ::ExtractAndPack(comID id, int ufield, int npe,
        *length=0;
         
         ComlibPrintf("Returning NULL\n");
-
        return(NULL);
     }
     
-    //int ave_msgsize=(tot_msgsize>MSGSIZETHRESHOLD) ? 
-    //  tot_msgsize/(num_distinctmsgs):tot_msgsize;
-    
     int msg_offset = CmiReservedHeaderSize + sizeof(comID) 
         + (npe + 4 + nummsgs) * sizeof(int);  
 
     msg_offset = ALIGN8(msg_offset);
     
-    int headersize=msg_offset;
-    
     *length = tot_msgsize;
     *length += msg_offset;
     char *p;
     p=(char *)CmiAlloc(*length);
-    
-    int l1 = *length;
-    
+
     char *t = p + CmiReservedHeaderSize;
     int i, j;
     if (!p) CmiAbort("Big time problem\n");
@@ -288,48 +279,29 @@ char * PeTable ::ExtractAndPack(comID id, int ufield, int npe,
         register int newval=-1*pelist[i];
         PACKINT(newval); 
         for (j=0;j<msgnum[index];j++) {
-            if (PeList[index][j]->magic != magic) {
-               int tmpms=actual_msgsize+PeList[index][j]->msgsize;
-               if (tmpms >= MSGSIZETHRESHOLD 
-                    /*|| (PeList[index][j]->msgsize>=ave_msgsize)*/ ) {
-                    
-                    CmiPrintf("%d sending directly\n", CkMyPe());
-                    if (--(PeList[index][j]->refCount) <=0) {
-                        CmiSyncSendAndFree(index, PeList[index][j]->msgsize, 
-                                           (char*)PeList[index][j]->msg);
-                       //ComlibPrintf("%d Freeing msg\n", CkMyPe());
-                        PTFREE(PeList[index][j]);
-                       }
-                    else
-                        CmiSyncSend(index, PeList[index][j]->msgsize, 
-                                    (char*)PeList[index][j]->msg);
-                    PeList[index][j]=NULL;
-                    continue;
-               }
-               
+            if (PeList[index][j]->magic == magic) {
+                offset=(PeList[index][j]->offset);
+            }
+            else {
                npacked ++;
                 
                offset=msg_offset;
                PeList[index][j]->magic=magic;
                PeList[index][j]->offset=msg_offset;
                PTinfo *tempmsg=PeList[index][j];
-               PACKMSG((&(tempmsg->msgsize)), sizeof(int));
-               actual_msgsize += tempmsg->msgsize;
-               int nullptr=-1;
-               PACKMSG(&nullptr, sizeof(int));
-
+               
+                CmiChunkHeader hdr;
+                hdr.size = tempmsg->msgsize;
+                hdr.ref = -1;
+                PACKMSG(&hdr, sizeof(CmiChunkHeader));
                PACKMSG(tempmsg->msg, tempmsg->msgsize);
 
                 msg_offset = ALIGN8(msg_offset);
-                actual_msgsize = ALIGN8(actual_msgsize);                
-               actual_msgsize += 2*sizeof(int);
-            }
-            else {
-               offset=(PeList[index][j]->offset);
             }
             
             //ComlibPrintf("%d Packing msg_offset=%d\n", CkMyPe(), offset);
             PACKINT(offset); 
+
             if (--(PeList[index][j]->refCount) <=0) {
                 CmiFree(PeList[index][j]->msg);
                 
@@ -347,14 +319,7 @@ char * PeTable ::ExtractAndPack(comID id, int ufield, int npe,
        npe=npe-lesspe;
        PACK(int, npe);
     }
-    if (!actual_msgsize) {
-        if (l1 >= MAXBUFSIZE) 
-            CmiFree(p);
-        *length=0;
-        return(NULL);
-    }
-    
-    *length=actual_msgsize+headersize;
+
     return(p);
 } 
 
@@ -402,6 +367,7 @@ int PeTable :: UnpackAndInsert(void *in)
                 UNPACK(int, offset);
                 continue;
             }
+            
             PTinfo *temp;
             PTALLOC(temp);
             temp->msgsize=tempmsgsize;
@@ -512,78 +478,3 @@ void PeTable :: GarbageCollect()
 {
 }
 
-GList :: GList()
-{
-  InList=(InNode *)CmiAlloc(10*sizeof(InNode));
-  InListIndex=0;
-}
-
-GList :: ~GList()
-{
-  CmiFree(InList);
-}
-
-int GList :: AddWholeMsg(void *ptr)
-{
-  InList[InListIndex].flag=0;
-  InList[InListIndex++].ptr=ptr;
-  return(InListIndex-1);
-}
-
-void GList :: setRefcount(int indx, int ref)
-{
-  //ComlibPrintf("setting InList[%d]=%d\n", indx, ref);
-  InList[indx].refCount=ref;
-}
-
-void GList :: DeleteWholeMsg(int indx)
-{
-  //ComlibPrintf("DeleteWholeMsg indx=%d\n", indx);
-  InList[indx].refCount--;
-  if ((InList[indx].refCount <=0) && (InList[indx].flag==0)) {
-       //ComlibPrintf("Deleting msgwhole\n");
-       CmiFree(InList[indx].ptr);
-  }
-}
-void GList :: DeleteWholeMsg(int indx, int flag)
-{
-  InList[indx].refCount--;
-  InList[indx].flag=flag;
-} 
-/*
-void GList :: DeleteWholeMsg(int indx, void *p)
-{
-  int *rc=(int *)((char *)p-sizeof(int));
-  *rc=(int)((char *)p-(char *)(InList[indx].ptr)+2*sizeof(int));
-}
-*/
-
-void GList :: GarbageCollect()
-{
-  for (int i=0;i<InListIndex;i++) {
-       if ((InList[i].refCount <= 0) && (InList[i].flag >0))
-               CmiFree(InList[i].ptr);
-  }
-}
-
-void GList :: Add(void *ptr )
-{
-  InList[InListIndex].ptr=ptr;
-  InList[InListIndex++].refCount=0;
-}
-
-void GList :: Delete()
-{
-  InListIndex=0;
-  /******
-  int counter=0;
-  for (int i=0;i< InListIndex;i++) {
-       if (InList[i].refCount <=0)  {
-               counter++;
-               CmiFree(InList[i].ptr);
-       }
-  }
-  if (counter == InListIndex) InListIndex=0;
-****/
-}
-
index 7c824430232b347f29bcb158497fede1db153db3..54efd82de778803368b4bd0f7cde08cf298d7533 100644 (file)
@@ -11,11 +11,17 @@ CkpvDeclare(int, DummyHandle);
 //Correspods to Router::ProcManyMsg
 void procManyCombinedMsg(char *msg)
 {
-    comID id;
+    //comID id;
+    int instance_id;
+
     ComlibPrintf("In Recv combined message at %d\n", CkMyPe());
-    memcpy(&id,(msg+CmiReservedHeaderSize+sizeof(int)), sizeof(comID));
-    
-    Strategy *s = ConvComlibGetStrategy(id.instanceID);
+    //memcpy(&id,(msg+CmiReservedHeaderSize+sizeof(int)), sizeof(comID));
+
+    //Comid specific
+    memcpy(&instance_id, (char*) msg + CmiReservedHeaderSize + 2*sizeof(int)
+           , sizeof(int));
+
+    Strategy *s = ConvComlibGetStrategy(instance_id);
     ((RouterStrategy *)s)->ProcManyMsg(msg);
 }
 
@@ -30,11 +36,16 @@ void dummyEP(DummyMsg *m)
 //Correspods to Router::RecvManyMsg
 void recvManyCombinedMsg(char *msg)
 {
-    comID id;
+    //comID id;
+    int instance_id;
     ComlibPrintf("In Recv combined message at %d\n", CkMyPe());
-    memcpy(&id,(msg+CmiReservedHeaderSize+sizeof(int)), sizeof(comID));
+    //memcpy(&id,(msg+CmiReservedHeaderSize+sizeof(int)), sizeof(comID));
     
-    Strategy *s = ConvComlibGetStrategy(id.instanceID);
+    //Comid specific
+    memcpy(&instance_id, (char*) msg + CmiReservedHeaderSize + 2*sizeof(int)
+           , sizeof(int));
+
+    Strategy *s = ConvComlibGetStrategy(instance_id);
     ((RouterStrategy *)s)->RecvManyMsg(msg);
 }
 
@@ -142,7 +153,7 @@ void RouterStrategy::insertMessage(MessageHolder *cmsg){
         delete cmsg;
     }
     else
-        msgQ.enq(cmsg);
+        msgQ.push(cmsg);
 }
 
 void RouterStrategy::doneInserting(){
@@ -180,7 +191,7 @@ void RouterStrategy::doneInserting(){
                                                      CkMyPe(), 
                                                      sizeof(DummyMsg));
         cmsg->isDummy = 1;
-        msgQ.enq(cmsg);
+        msgQ.push(cmsg);
     }
 
     int numToDeposit = msgQ.length();
@@ -209,7 +220,8 @@ void RouterStrategy::doneInserting(){
             router->EachToManyMulticast(id, cmsg->size, msg, 1, &myPe, 
                                         numToDeposit > 1);
         
-        numToDeposit --;        
+        numToDeposit --;
+        delete cmsg;        
     }
 
     while(!recvQ.isEmpty()) {
@@ -253,26 +265,36 @@ void RouterStrategy::pup(PUP::er &p){}
 //Call the router functions
 void RouterStrategy::RecvManyMsg(char *msg) {
 
-    comID new_id;
-    ComlibPrintf("In RecvManyMsg at %d\n", CkMyPe());
-    memcpy(&new_id,(msg+CmiReservedHeaderSize+sizeof(int)), sizeof(comID));
+    //comID new_id;
+    int new_refno =0;
 
-    ComlibPrintf("REFNO = %d, %d\n", new_id.refno, id.refno);
+    //FOO BAR when structure of comid changes this will break !!!!!
+    ComlibPrintf("In RecvManyMsg at %d\n", CkMyPe());
+    //memcpy(&new_id,(msg+CmiReservedHeaderSize+sizeof(int)), sizeof(comID));
+    //ComlibPrintf("REFNO = %d, %d\n", new_id.refno, id.refno);
+    
+    //First int in comid is refno
+    memcpy(&new_refno, (char*) msg + CmiReservedHeaderSize + sizeof(int), 
+           sizeof(int)); 
 
-    if(new_id.refno != id.refno)
-        recvQ.enq(msg);
+    if(new_refno != id.refno)
+        recvQ.push(msg);
     else
         router->RecvManyMsg(id, msg);
 }
 
 void RouterStrategy::ProcManyMsg(char *msg) {    
 
-    comID new_id;
+    //comID new_id;
+    int new_refno =0;
     ComlibPrintf("In ProcManyMsg at %d\n", CkMyPe());
-    memcpy(&new_id,(msg+CmiReservedHeaderSize+sizeof(int)), sizeof(comID));
-
-    if(new_id.refno != id.refno)
-        procQ.enq(msg);
+    //memcpy(&new_id,(msg+CmiReservedHeaderSize+sizeof(int)), sizeof(comID));
+    //First int in comid is refno
+    memcpy(&new_refno, (char*) msg + CmiReservedHeaderSize + sizeof(int), 
+           sizeof(int)); 
+    
+    if(new_refno != id.refno)
+        procQ.push(msg);
     else
         router->ProcManyMsg(id, msg);
 }
@@ -280,7 +302,7 @@ void RouterStrategy::ProcManyMsg(char *msg) {
 void RouterStrategy::DummyEP(DummyMsg *m) {
 
     if(id.refno != m->id.refno)
-        dummyQ.enq(m);
+        dummyQ.push(m);
     else {
         router->DummyEP(m->id, m->magic);
         CmiFree(m);