Fixing memory bugs reported by valgrind.
authorEsteban Meneses <emenese2@illinois.edu>
Sat, 2 Jun 2012 22:22:57 +0000 (17:22 -0500)
committerEsteban Meneses <emenese2@illinois.edu>
Sat, 2 Jun 2012 22:22:57 +0000 (17:22 -0500)
src/ck-core/ckcausalmlog.C

index 5994339443bfac5cf36cab6b92c59d5e05e0dcf1..f98ae7faeefdb07cce0d9b8640e8ce32639a363a 100644 (file)
@@ -121,6 +121,15 @@ int _maxBufferedDets;
 // stores the incarnation number from every other processor
 CpvDeclare(char *, _incarnation);
 
+// storage for remove determinants header
+CpvDeclare(RemoveDeterminantsHeader *, _removeDetsHeader);
+// storage for store determinants header
+CpvDeclare(StoreDeterminantsHeader *, _storeDetsHeader);
+// storage for the sizes in vector-send to store determinants
+CpvDeclare(int *, _storeDetsSizes);
+// storage for the pointers in vector-send to store determinants
+CpvDeclare(char **, _storeDetsPtrs);
+
 /***** *****/
 
 /***** VARIABLES FOR PARALLEL RECOVERY *****/
@@ -231,6 +240,7 @@ double lastRestart=0;
 //update location globals
 int _receiveLocationHandlerIdx;
 
+
 /** 
  * @brief Initialize message logging data structures and register handlers
  */
@@ -307,12 +317,20 @@ void _messageLoggingInit(){
        CpvInitialize(char *, _localDets);
        CpvInitialize((CkHashtableT<CkHashtableAdaptorT<CkObjID>, CkVec<Determinant> *> *),_remoteDets);
        CpvInitialize(char *, _incarnation);
+       CpvInitialize(RemoveDeterminantsHeader *, _removeDetsHeader);
+       CpvInitialize(StoreDeterminantsHeader *, _storeDetsHeader);
+       CpvInitialize(int *, _storeDetsSizes);
+       CpvInitialize(char **, _storeDetsPtrs);
        CpvAccess(_localDets) = (char *) CmiAlloc(_maxBufferedDets * sizeof(Determinant));
        CpvAccess(_remoteDets) = new CkHashtableT<CkHashtableAdaptorT<CkObjID>, CkVec<Determinant> *>(100, 0.4);
        CpvAccess(_incarnation) = (char *) CmiAlloc(CmiNumPes() * sizeof(int));
        for(int i=0; i<CmiNumPes(); i++){
                CpvAccess(_incarnation)[i] = 0;
        }
+       CpvAccess(_removeDetsHeader) = (RemoveDeterminantsHeader *) CmiAlloc(sizeof(RemoveDeterminantsHeader));
+       CpvAccess(_storeDetsHeader) = (StoreDeterminantsHeader *) CmiAlloc(sizeof(StoreDeterminantsHeader));
+       CpvAccess(_storeDetsSizes) = (int *) CmiAlloc(sizeof(int) * 2);
+       CpvAccess(_storeDetsPtrs) = (char **) CmiAlloc(sizeof(char *) * 2);
 
        // Cpv variables for parallel recovery
        CpvInitialize(CkVec<LocationID *> *, _emigrantRecObjs);
@@ -686,9 +704,6 @@ void sendMsg(CkObjID &sender,CkObjID &recver,int destPE,MlogEntry *entry,MCount
        DEBUG_NOW(char senderString[100]);
 
        int totalSize;
-       StoreDeterminantsHeader header;
-       int sizes[2];
-       char *ptrs[2];
 
        envelope *env = entry->env;
        DEBUG_PE(3,printf("[%d] Sending message to %s from %s PE %d SN %d time %.6lf \n",CkMyPe(),env->recver.toString(recverString),env->sender.toString(senderString),destPE,env->SN,CkWallTimer()));
@@ -716,19 +731,19 @@ void sendMsg(CkObjID &sender,CkObjID &recver,int destPE,MlogEntry *entry,MCount
        if(_numBufferedDets > 0){
 
                // modifying the actual number of determinants sent in message
-               header.number = _numBufferedDets;
-               header.index = _indexBufferedDets;
-               header.phase = _phaseBufferedDets;
-               header.PE = CmiMyPe();
+               CpvAccess(_storeDetsHeader)->number = _numBufferedDets;
+               CpvAccess(_storeDetsHeader)->index = _indexBufferedDets;
+               CpvAccess(_storeDetsHeader)->phase = _phaseBufferedDets;
+               CpvAccess(_storeDetsHeader)->PE = CmiMyPe();
        
                // sending the message
-               sizes[0] = sizeof(StoreDeterminantsHeader);
-               sizes[1] = _numBufferedDets * sizeof(Determinant);
-               ptrs[0] = (char *) &header;
-               ptrs[1] = CpvAccess(_localDets) + (_indexBufferedDets - _numBufferedDets) * sizeof(Determinant);
+               CpvAccess(_storeDetsSizes)[0] = sizeof(StoreDeterminantsHeader);
+               CpvAccess(_storeDetsSizes)[1] = _numBufferedDets * sizeof(Determinant);
+               CpvAccess(_storeDetsPtrs)[0] = (char *) CpvAccess(_storeDetsHeader);
+               CpvAccess(_storeDetsPtrs)[1] = CpvAccess(_localDets) + (_indexBufferedDets - _numBufferedDets) * sizeof(Determinant);
                DEBUG(CkPrintf("[%d] Sending %d determinants\n",CkMyPe(),_numBufferedDets));
-               CmiSetHandler(&header, _storeDeterminantsHandlerIdx);
-               CmiSyncVectorSend(destPE, 2, &sizes[0], &ptrs[0]);
+               CmiSetHandler(CpvAccess(_storeDetsHeader), _storeDeterminantsHandlerIdx);
+               CmiSyncVectorSend(destPE, 2, CpvAccess(_storeDetsSizes), CpvAccess(_storeDetsPtrs));
        }
 
        // updating its message log entry
@@ -860,12 +875,10 @@ void _removeDeterminantsHandler(char *buffer){
  */
 void _storeDeterminantsHandler(char *buffer){
        StoreDeterminantsHeader *header;
-       RemoveDeterminantsHeader removeHeader;
-       Determinant *detPtr, *det;
+       Determinant *detPtr, det;
        int i, n, index, phase, destPE;
        CkVec<Determinant> *vec;
 
-
        // getting the header from the message and pointing to the first determinant
        header = (StoreDeterminantsHeader *)buffer;
        n = header->number;
@@ -879,22 +892,21 @@ void _storeDeterminantsHandler(char *buffer){
 
        // going through all determinants and storing them into _remoteDets
        for(i = 0; i < n; i++){
-               det = new Determinant();
-               det->sender = detPtr->sender;
-               det->receiver = detPtr->receiver;
-               det->SN = detPtr->SN;
-               det->TN = detPtr->TN;
+               det.sender = detPtr->sender;
+               det.receiver = detPtr->receiver;
+               det.SN = detPtr->SN;
+               det.TN = detPtr->TN;
 
                // getting the determinant array
-               vec = CpvAccess(_remoteDets)->get(det->receiver);
+               vec = CpvAccess(_remoteDets)->get(det.receiver);
                if(vec == NULL){
                        vec = new CkVec<Determinant>();
-                       CpvAccess(_remoteDets)->put(det->receiver) = vec;
+                       CpvAccess(_remoteDets)->put(det.receiver) = vec;
                }
 #if COLLECT_STATS_DETS
 #if COLLECT_STATS_DETS_DUP
                for(int j=0; j<vec->size(); j++){
-                       if(isSameDet(&(*vec)[j],det)){
+                       if(isSameDet(&(*vec)[j],&det)){
                                numDupDets++;
                                break;
                        }
@@ -904,7 +916,7 @@ void _storeDeterminantsHandler(char *buffer){
 #if COLLECT_STATS_MEMORY
                storedDetsSize++;
 #endif
-               vec->push_back(*det);
+               vec->push_back(det);
                detPtr = detPtr++;
        }
 
@@ -914,10 +926,10 @@ void _storeDeterminantsHandler(char *buffer){
        CmiFree(buffer);
 
        // sending the ACK back to the sender
-       removeHeader.index = index;
-       removeHeader.phase = phase;
-       CmiSetHandler(&removeHeader,_removeDeterminantsHandlerIdx);
-       CmiSyncSend(destPE, sizeof(RemoveDeterminantsHeader), (char *)&removeHeader);
+       CpvAccess(_removeDetsHeader)->index = index;
+       CpvAccess(_removeDetsHeader)->phase = phase;
+       CmiSetHandler(CpvAccess(_removeDetsHeader),_removeDeterminantsHandlerIdx);
+       CmiSyncSend(destPE, sizeof(RemoveDeterminantsHeader), (char *)CpvAccess(_removeDetsHeader));
        
 }