Changeset 63a2f8 in git for kernel


Ignore:
Timestamp:
Mar 26, 2010, 2:21:53 PM (14 years ago)
Author:
Martin Monerjan
Branches:
(u'fieker-DuVal', '117eb8c30fc9e991c4decca4832b1d19036c4c65')(u'spielwiese', 'd08f5f0bb3329b8ca19f23b74cb1473686415c3a')
Children:
25d15e8446fc517a57510738439e5916bed4071e
Parents:
b78b73c2edf5c1cdd8c86014f84cb640bf73f3df
Message:
Cleanup in destructors
gcone::setBaseRing
Bugfix in getConeNormals
Removed one nDelete(&nCoeffNom) (Thomas' example)
Hack for guessing memory usage in the local part


git-svn-id: file:///usr/local/Singular/svn/trunk@12681 2c84dea3-7e68-4137-9b89-c4e89433aadc
File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/gfan.cc

    rb78b73 r63a2f8  
    7676//NOTE Defining this will slow things down!
    7777//Only good for very coarse profiling
    78 #define gfanp
     78//#define gfanp
    7979#ifdef gfanp
    8080#include <sys/time.h>
     
    201201{
    202202#ifdef gfan_DEBUG
    203         printf("shallowdel@UCN %i\n", this->getUCN());
     203//      printf("shallowdel@UCN %i\n", this->getUCN());
    204204#endif
    205205        this->fNormal=NULL;
     
    219219{
    220220#ifdef gfan_DEBUG
    221         printf("~facet@UCN %i\n",this->getUCN());
     221//      printf("~facet@UCN %i\n",this->getUCN());
    222222#endif
    223223        if(this->fNormal!=NULL)
     
    226226                delete this->interiorPoint;
    227227        /* Cleanup the codim2-structure */
    228         if(this->codim==2)
    229 //      if(this->codim2Ptr!=NULL)
    230         {
    231                 facet *codim2Ptr;
    232                 codim2Ptr = this->codim2Ptr;
    233                 while(codim2Ptr!=NULL)
    234                 {
    235                         if(codim2Ptr->fNormal!=NULL)
    236                         {
    237                                 delete codim2Ptr->fNormal;//NOTE Do not want this anymore since the rays are now in gcone!
    238                                 codim2Ptr = codim2Ptr->next;
    239                         }
    240                 }
    241 //              delete this->codim2Ptr;
    242         }
     228//      if(this->codim==2)
     229//      {
     230//              facet *codim2Ptr;
     231//              codim2Ptr = this->codim2Ptr;
     232//              while(codim2Ptr!=NULL)
     233//              {
     234//                      if(codim2Ptr->fNormal!=NULL)
     235//                      {
     236//                              delete codim2Ptr->fNormal;//NOTE Do not want this anymore since the rays are now in gcone!
     237//                              codim2Ptr = codim2Ptr->next;
     238//                      }
     239//              }
     240//      }
    243241        //The rays are stored in the cone!
    244 //      if(this->codim2Ptr!=NULL)
    245 //              delete this->codim2Ptr;
    246242        if(this->flipGB!=NULL)
    247243                idDelete((ideal *)&this->flipGB);
    248         if(this->flipRing!=NULL && this->flipRing->idroot!=(idhdl)0xfbfbfbfbfbfbfbfb)
     244//      if(this->flipRing!=NULL && this->flipRing->idroot!=(idhdl)0xfbfbfbfbfbfbfbfb)
    249245//              rDelete(this->flipRing); //See vol II/134
    250246//      this->flipRing=NULL;
     
    735731                                codim2Act = codim2Act->next;
    736732                        }
    737                         printf("UCN = %i",fAct->getUCN());
     733                        printf("UCN = %i\n",fAct->getUCN());
    738734                        fAct = fAct->next;
    739735                }
     
    807803{
    808804        return rCopy(this->baseRing);
     805}
     806
     807inline void gcone::setBaseRing(ring r)
     808{
     809        this->baseRing=rCopy(r);
    809810}
    810811
     
    863864                //simpler version of storing expvect diffs
    864865                int *leadexpv=(int*)omAlloc(((this->numVars)+1)*sizeof(int));
    865 //              int *tailexpv=(int*)omAlloc(((this->numVars)+1)*sizeof(int));
    866866                pGetExpV(aktpoly,leadexpv);
    867                 while(pNext(aktpoly)!=NULL)
    868                 {
    869                         aktpoly=pNext(aktpoly);
     867                poly pNextTerm=aktpoly;
     868                while(pNext(pNextTerm)/*pNext(aktpoly)*/!=NULL)
     869                {
     870                        pNextTerm/*aktpoly*/=pNext(pNextTerm);
    870871                        int *tailexpv=(int*)omAlloc(((this->numVars)+1)*sizeof(int));
    871                         pGetExpV(aktpoly,tailexpv);                     
     872                        pGetExpV(pNextTerm,tailexpv);                   
    872873                        for(int kk=1;kk<=this->numVars;kk++)
    873874                        {                               
     
    924925                                if(P->p!=NULL)  //spoly non zero=?
    925926                                {       
    926                                         poly p=pInit();                 
    927                                         poly q=pInit();
     927                                        poly p;//=pInit(); NOTE Evil memleak if pInit is used                   
     928                                        poly q;//=pInit();
    928929                                        p=pCopy(P->p);
    929930                                        q=pHead(p);     //Monomial q
     
    932933                                        while(p!=NULL)
    933934                                        {
    934                                                 q=pHead(p);                                             
    935 //                                              unsigned long sevSpoly=pGetShortExpVector(q);
    936 //                                              unsigned long not_sevL;                                         
     935                                                q=pHead(p);
    937936                                                for(int ll=0;ll<IDELEMS(L);ll++)
    938937                                                {
    939 //                                                      not_sevL=~pGetShortExpVector(L->m[ll]);//                                       
    940                                                         //if(!(sevSpoly & not_sevL) && pLmDivisibleBy(L->m[ll],q) )//i.e. spoly is in L
    941938                                                        if(pLmEqual(L->m[ll],q) || pDivisibleBy(L->m[ll],q))
    942939                                                        {                                                       
     
    15071504                }
    15081505        }
    1509         assert(iv64isStrictlyPositive(ivIntPointOfCone));
     1506//      assert(iv64isStrictlyPositive(ivIntPointOfCone));
    15101507       
    15111508        this->setIntPoint(ivIntPointOfCone);
     
    15171514        facet *fAct=gc.facetPtr;
    15181515        //Construct an array to hold the extremal rays of the cone
    1519         this->gcRays = (intvec**)omAlloc0(sizeof(intvec*)*P->rowsize);
     1516        this->gcRays = (intvec**)omAlloc0(sizeof(intvec*)*P->rowsize); 
    15201517        for(int ii=0;ii<P->rowsize;ii++)
    15211518        {
     
    15241521                this->gcRays[ii] = ivCopy(rowvec);
    15251522                delete rowvec;
    1526         }
     1523        }       
    15271524        this->numRays=P->rowsize;
    15281525        //Check which rays belong to which facet
     
    31463143          Choose a facet from SearchList, flip it and forget the previous cone
    31473144          We always choose the first facet from SearchList as facet to be flipped
    3148         */                     
     3145        */     
    31493146        while( (SearchListAct!=NULL))//&& counter<490)
    31503147        {//NOTE See to it that the cone is only changed after ALL facets have been flipped!                             
    3151                 fAct = SearchListAct;
    3152                                
     3148                fAct = SearchListAct;           
    31533149                while(fAct!=NULL)
    31543150//              while( (fAct->getUCN() == fAct->next->getUCN()) )               
     
    31583154                        ring rTmp=rCopy(fAct->flipRing);
    31593155//                      ring rTmp=fAct->flipRing; //segfaults
    3160                         rComplete(rTmp);                       
     3156                        rComplete(rTmp);
    31613157                        rChangeCurrRing(rTmp);
    31623158                        gcone *gcTmp = new gcone::gcone(*gcAct,*fAct);//copy constructor!
     
    31713167                        idDelete((ideal *)&fAct->flipGB);
    31723168                        rDelete(fAct->flipRing);
    3173 
     3169                       
    31743170                        gcTmp->getConeNormals(gcTmp->gcBasis/*, FALSE*/);       //TODO FALSE is default, so should not be needed here
    31753171//                      gcTmp->getCodim2Normals(*gcTmp);
    31763172                        gcTmp->getExtremalRays(*gcTmp);
    3177 
    3178 
     3173                       
    31793174//                      //NOTE If flip2 is used we need to get an interior point of gcTmp
    31803175//                      // and replace gcTmp->baseRing with an appropriate ring with only
     
    31893184                        /*add facets to SLA here*/
    31903185#ifdef SHALLOW
    3191                         SearchListRoot=gcTmp->enqueue2/*NewFacets*/(SearchListRoot);
     3186//                      printf("fActUCN before enq2: %i\n",fAct->getUCN());
     3187                        facet *tmp; tmp=gcTmp->enqueue2(SearchListRoot);
     3188//                      printf("\nheadUCN=%i\n",tmp->getUCN());
     3189//                      printf("fActUCN after enq2: %i\n",fAct->getUCN());                     
     3190                        SearchListRoot=tmp;
     3191//                      SearchListRoot=gcTmp->enqueue2/*NewFacets*/(SearchListRoot);
    31923192#else
    31933193                        SearchListRoot=gcTmp->enqueueNewFacets(SearchListRoot);
     
    32133213                        if(fAct->getUCN() == fAct->next->getUCN())
    32143214                        {
    3215                                 fAct=fAct->next;
     3215                                printf("Switching UCN from %i to %i\n",fAct->getUCN(),fAct->next->getUCN());
     3216                                fAct=fAct->next;                               
    32163217                        }
    32173218                        else
     3219                        {
     3220                                //rDelete(gcAct->baseRing);
     3221//                              printf("break\n");
    32183222                                break;
     3223                        }
    32193224//                      fAct=fAct->next;
    32203225                }//while( ( (fAct->next!=NULL) && (fAct->getUCN()==fAct->next->getUCN() ) ) );         
    32213226                //Search for cone with smallest UCN
    3222                 gcNext = gcHead;
    32233227#ifndef NDEBUG
    32243228  #if SIZEOF_LONG==8    //64 bit
     
    32643268                                }                               
    32653269                        }
    3266 //                      else if(gcNext->getUCN() < SearchListRoot->getUCN() )
    3267 //                      {
    3268 //                              idDelete( (ideal*)&gcNext->gcBasis );
    3269 //                              rDelete(gcNext->baseRing);
    3270 //                      }
     3270                        else if(gcNext->getUCN() < SearchListRoot->getUCN() )
     3271                        {
     3272                                idDelete( (ideal*)&gcNext->gcBasis );                           
     3273//                              rDelete(gcNext->baseRing);//TODO Why does this crash?
     3274                        }
    32713275                        /*else
    32723276                        {
     
    32823286                }
    32833287                UCNcounter++;
    3284                 SearchListAct = SearchListRoot;
     3288                SearchListAct = SearchListRoot;         
    32853289        }
    32863290        printf("\nFound %i cones - terminating\n", counter);
     
    36713675                        if(slAct==NULL)
    36723676                        {
     3677                                printf("Zero length SLA\n");
    36733678                                facet *fCopy;
    36743679                                fCopy = fAct;                           
     
    37033708                                        fDeleteMarker=slAct;
    37043709                                        if(slAct==slHead)
    3705                                         {                                               
     3710                                        {
     3711//                                              fDeleteMarker=slHead;
     3712//                                              printf("headUCN@enq=%i\n",slHead->getUCN());
    37063713                                                slHead = slAct->next;                                           
     3714//                                              printf("headUCN@enq=%i\n",slHead->getUCN());
    37073715                                                if(slHead!=NULL)
     3716                                                {
    37083717                                                        slHead->prev = NULL;
     3718                                                }
     3719                                                fDeleteMarker->shallowDelete();
     3720//                                              delete fDeleteMarker;//NOTE this messes up fAct in noRevS!
     3721//                                              printf("headUCN@enq=%i\n",slHead->getUCN());
    37093722                                        }
    37103723                                        else if (slAct==slEnd)
     
    37123725                                                slEnd=slEnd->prev;
    37133726                                                slEnd->next = NULL;
     3727                                                fDeleteMarker->shallowDelete();
     3728//                                              delete(fDeleteMarker);
    37143729                                        }                                                               
    37153730                                        else
     
    37173732                                                slAct->prev->next = slAct->next;
    37183733                                                slAct->next->prev = slAct->prev;
     3734                                                fDeleteMarker->shallowDelete();
     3735//                                              delete(fDeleteMarker);
    37193736                                        }
    37203737                                        removalOccured=TRUE;
    37213738                                        gcone::lengthOfSearchList--;
    37223739#ifdef gfan_DEBUG
    3723 printf("Removing (");fAct->fNormal->show(1,1);printf(") from list");
    3724 #endif
    3725                                         fDeleteMarker->shallowDelete();//Sets everything to NULL
    3726 //                                      delete(marker);
    3727                                         break;
     3740printf("Removing (");fAct->fNormal->show(1,1);printf(") from list\n");
     3741#endif
     3742                                        /*fDeleteMarker->shallowDelete();*///Sets everything to NULL
     3743//                                      delete(fDeleteMarker);
     3744                                        break;//leave the while loop, since we found fAct=slAct thus delete slAct and do not add fAct
    37283745                                }
    3729                                 slAct = slAct->next;
     3746                                slAct = slAct->next;                           
    37303747                        }//while(slAct!=NULL)
    37313748                        if(removalOccured==FALSE)
     
    37403757//                      if(fDeleteMarker!=NULL)
    37413758//                      {
    3742 //                              delete fDeleteMarker;
     3759//                              fDeleteMarker->shallowDelete();
     3760//                              delete(fDeleteMarker);
    37433761//                              fDeleteMarker=NULL;
    37443762//                      }
     
    37523770        time_enqueue += (end.tv_sec - start.tv_sec + 1e-6*(end.tv_usec - start.tv_usec));
    37533771#endif 
     3772//      printf("headUCN@enq=%i\n",slHead->getUCN());
    37543773        return slHead;
    37553774}
     
    38033822        this->baseRing=rCopy(replacementRing);
    38043823        this->gcBasis=idCopy(temporaryGroebnerBasis);
    3805         //FIXME idDelete & rDelete!!! MEMLEAK
     3824        //FIXME idDelete & rDelete!!! DONE!
    38063825        /*And back to where we came from*/
    38073826        rChangeCurrRing(srcRing);
     
    41384157                                        else
    41394158                                                resPoly=pAdd(resPoly,strPoly);//pAdd = p_Add_q, destroys args
    4140                                         nDelete(&nCoeff);
     4159//                                      nDelete(&nCoeff);
    41414160                                        nDelete(&nCoeffNom);
    41424161                                        nDelete(&nCoeffDenom);
     
    41524171                {
    41534172                        facet *fAct=gc->facetPtr;
    4154                         for(int ll=0;ll<this->numFacets;ll++)
     4173                        while(fAct!=NULL)
    41554174                        {
    41564175                                getline(gcInputFile,line);
     
    44024421                        gcAct->noRevS(*gcAct);  //Here we go!
    44034422                        //Switch back to the ring the computation was started in
    4404                         //rChangeCurrRing(inputRing);
     4423//                      rChangeCurrRing(inputRing);
    44054424                        //res=gcAct->gcBasis;
    44064425                        //Below is a workaround, since gcAct->gcBasis gets deleted in noRevS                   
     
    44244443                //Simply return an empty list
    44254444                WerrorS("Ring has non-global ordering.\nThis function requires your current ring to be endowed with a global ordering.\n Now terminating!");
     4445                gcone *gcRoot=new gcone();
     4446                gcone *gcPtr = gcRoot;
     4447                for(int ii=0;ii<10000;ii++)
     4448                {
     4449                        gcPtr->setBaseRing(currRing);
     4450                        facet *fPtr=gcPtr->facetPtr=new facet();
     4451                        for(int jj=0;jj<5;jj++)
     4452                        {
     4453                                intvec *iv=new intvec(pVariables);
     4454                                fPtr->setFacetNormal(iv);                               
     4455                                delete(iv);
     4456                                fPtr->next=new facet();
     4457                                fPtr=fPtr->next;
     4458                        }
     4459                        gcPtr->next=new gcone();
     4460                        gcPtr->next->prev=gcPtr;
     4461                        gcPtr=gcPtr->next;                     
     4462                }
     4463                gcPtr=gcRoot;
     4464                while(gcPtr!=NULL)
     4465                {
     4466                        gcPtr=gcPtr->next;
     4467//                      delete(gcPtr->prev);
     4468                }
    44264469                goto pointOfNoReturn;
    44274470        }
Note: See TracChangeset for help on using the changeset viewer.