Changeset: 86f2271d0faa for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=86f2271d0faa
Modified Files:
        monetdb5/extras/crackers/crackers.mx
        monetdb5/extras/crackers/crackers_selecthol_ops.mx
        monetdb5/extras/crackers/crackers_selectholpl_ops.mx
Branch: holindex
Log Message:

Implement sum as a separate operator (just for result verification).


diffs (truncated from 464 to 300 lines):

diff --git a/monetdb5/extras/crackers/crackers.mx 
b/monetdb5/extras/crackers/crackers.mx
--- a/monetdb5/extras/crackers/crackers.mx
+++ b/monetdb5/extras/crackers/crackers.mx
@@ -159,6 +159,8 @@ module crackers;
 @:TypeSwitch_1(Updates)@
 @:TypeSwitch_2(Sideways)@
 @:TypeSwitch_1(JoinSelect)@
+@:TypeSwitch_1(Aggregation)@
+
 
 command getTotalStorage( ):void
 address CRKgetTotalStorage
@@ -816,8 +818,16 @@ command fmcreateMaphol(b:bat[:oid,:@1],b
 address CRKcreateFullMaphol_@1_@2
 comment "make new map for debugging";
 @
+@= Aggregation
+command sumhol(b:bat[:any_1,:@2],l:@2,h:@2,li:bit,hi:bit):@2
+address CRKsumholBounds_@2
+comment "Calculate aggregate sum of range l-h.";
 
- 
+command sumholpl(b:bat[:any_1,:@2],l:@2,h:@2,li:bit,hi:bit):@2
+address CRKsumholplBounds_@2
+comment "Calculate aggregate sum of range l-h.";
+@
+
 @h
 /*
  * @- Header file
diff --git a/monetdb5/extras/crackers/crackers_selecthol_ops.mx 
b/monetdb5/extras/crackers/crackers_selecthol_ops.mx
--- a/monetdb5/extras/crackers/crackers_selecthol_ops.mx
+++ b/monetdb5/extras/crackers/crackers_selecthol_ops.mx
@@ -62,6 +62,7 @@ crackers_export str CRKselecthol_@1(int 
 crackers_export str CRKuselecthol_@1(int *vid, int *bid, @1 *low, @1 *hgh);
 crackers_export str CRKthetaselecthol_@1(int *vid, int *bid, @1 *val, str *op);
 crackers_export str CRKthetauselecthol_@1(int *vid, int *bid, @1 *val, str 
*op);
+crackers_export str CRKsumholBounds_@1(int *vid, int *bid, @1 *low, @1 *hgh, 
bit *inclusiveLow, bit *inclusiveHgh);
 @
 
 @c
@@ -180,7 +181,10 @@ CRKthetauselecthol_@1(int *vid, int *bid
 
        return CRKuselectholBounds_@1(vid, bid, low, high, &lin, &rin, 
&isIdleQuery);
 }
-
+str
+CRKsumholBounds_@1(int *vid, int *bid, @1 *low, @1 *hgh, bit *inclusiveLow, 
bit *inclusiveHgh){
+       return CRKRangeSumTree_@1(vid, bid, low, hgh, inclusiveLow, 
inclusiveHgh, FALSE);
+}
 
 @
 
@@ -282,9 +286,9 @@ createView:
 @
 @= RangeSelectBody
 
-       @1 *t0;
+
        BAT *b,*c,*bo;
-       //BAT *view;
+       BAT *view;
        int  m;
        int *t;
        int createIndex=0;
@@ -303,19 +307,17 @@ createView:
        int gapL = 1;
        int gapH = 1;
        bit rippledDeletions = FALSE;
-       struct Node *lowNode=NULL, *hghNode=NULL, *lowNodeNext=NULL, *temp, 
*stopNode;
+       struct Node *lowNode=NULL, *hghNode=NULL, *lowNodeNext=NULL, *temp;
        BUN idxFirst;
        struct timeval tv0, tv1;
-       double wt=0, ct=0,st=0;
+       double wt=0, ct=0;
        bit copy=TRUE;
-       unsigned long long sum = 0;     
        int countBatElements=0;
        int L1=0; /*Number of elements that can fit into L1 cache (size: 32KB)*/
        /*FILE *ofp;
        char outputFilename1[] = 
"/export/scratch2/petraki/experiments_1st_paper/experiments/stochastic/idle_time_2/pieces_holistic.txt";*/
        FrequencyNode* FN;
        FrequencyNode *FrequencyStructA = getFrequencyStruct('A');
-       (void) tail;
 
        gettimeofday(&tv0,0);
 
@@ -395,8 +397,6 @@ createView:
                        BBPincref(b->batCacheid,TRUE);
                        BBPunfix(bo->batCacheid);
                        
-                       gettimeofday(&tv1,0); ct+=dt(tv0,tv1); tv0=tv1;
-                       fprintf(stderr,"Wait time: %9.6lf Selection time: 
%9.6lf\n",wt,ct);
                        goto tempcreateView;
                }
                else{
@@ -638,13 +638,86 @@ createView:
 
        /*fprintf(ofp,"%d\n",FN->c);
        fclose(ofp);*/
-
-       //gettimeofday(&tv1,0); ct+=dt(tv0,tv1); tv0=tv1;
-       //fprintf(stderr,"Wait time: %9.6lf Selection time: %9.6lf\n",wt,ct);
+       
        /*@:CreateResult()@*/
 
        tempcreateView:;
 
+       if (!tail)
+               view = BATslice(VIEWhead_(b, BAT_READ), vl, vh+1);
+       else
+               view = BATslice(b, vl, vh+1);
+       
+       *vid = view->batCacheid;
+       BBPkeepref(*vid);
+       BBPunfix(b->batCacheid);
+       BBPunfix(c->batCacheid);
+       if (createIndex==1)
+       {
+               MT_lock_unset(&CRKIndexLock,"Cracker Index Lock");
+               createIndex=0;  
+       }
+       else
+               MT_lock_unset(&CrackerIndex[m].columnLock,"Lock Attribute");    
+
+       gettimeofday(&tv1,0); ct+=dt(tv0,tv1); tv0=tv1;
+       if(*isIdleQuery==FALSE)
+               fprintf(stderr,"Wait time: %9.6lf Selection time: 
%9.6lf\n",wt,ct);
+
+       return MAL_SUCCEED;
+@
+@= RangeSumBody
+       int m;
+       @1 *t0;
+       BAT *b,*c;
+       int *t;
+       bit foundLow=0, foundHgh=0;
+       bit LBound=FALSE;
+       oid vl=0, vh=0, posh;
+       BUN idxFirst;
+       unsigned long long sum = 0;     
+       /* vl and vh are the low and high index values to create the view with 
the result */
+       oid cl1=0, ch1=0, cl2=0, ch2=0;
+       struct Node *lowNode=NULL, *hghNode=NULL, *lowNodeNext=NULL, *temp, 
*stopNode;
+       (void) tail;
+
+       m = existsCrackerIndex(*bid);
+       
+       if(m == -1)
+               throw(MAL, "crackers.crackRange", "Index does not exist");
+
+       /* Take the index of the bat */
+       if ((c = BATdescriptor(CrackerIndex[m].cid)) == NULL)
+               throw(MAL, "crackers.crackRange", "Cannot access crack index");
+
+       /* Take the copy of the bat for which we maintain the index */
+       if ((b = BATdescriptor(CrackerIndex[m].cbid)) == NULL)
+               throw(MAL, "crackers.crackRange", "Cannot access crack index");
+
+       MT_lock_set(&CrackerIndex[m].columnLock,"Lock Attribute");
+
+       /* find out where in the index the low falls */
+       foundLow = GetLow_@1(*low, *inclusiveLow, CrackerIndex[m].Tree, c, 
BUNfirst(c), &cl1, &ch1, 0, BUNlast(b)-(oid)1,&LBound);
+
+       /* find out where in the index the high falls */
+       foundHgh = GetHgh_@1(*hgh, *inclusiveHgh, CrackerIndex[m].Tree, c, 
BUNfirst(c), &cl2, &ch2, 0, BUNlast(b)-(oid)1);
+
+       /*need to increase one position for the low bound only since we always 
store the previous position in the index*/
+       if (cl1 != 0 && LBound==FALSE) cl1++;
+       if (cl2 != 0) cl2++;
+       
+       /* If one or both of the result view bounds were not found using the
+       index then we have to crack */
+       if (foundLow == 0 || foundHgh == 0) {
+               throw(MAL, "crackers.crackRange", "Range is not found in 
index.");
+       } else {
+               t = (int *) Tloc(b, BUNfirst(b));
+               vl = cl1;
+               if ((vl == 0) && (*t < *low) && (*inclusiveLow == TRUE))
+                       vl = vl + 1;
+               vh = ch2;
+       }
+
        t0   = (@1 *)Tloc(b, BUNfirst(b));
        *vid = 0;
        
@@ -670,7 +743,6 @@ createView:
 
        stopNode = findNodeH_@1(*hgh, *inclusiveHgh, CrackerIndex[m].Tree, c, 
idxFirst, NULL);
 
-       gettimeofday(&tv1,0); ct+=dt(tv0,tv1); tv0=tv1;
        
        while (1){
                hghNode = (lowNode == NULL)? lowNodeNext : 
findNextPiece(lowNode);
@@ -687,7 +759,6 @@ createView:
                lowNode = hghNode;
                vl = vh+1;
        }
-       gettimeofday(&tv1,0); st+=dt(tv0,tv1); tv0=tv1;
        
        // verify the result
        if (!(sum == ((unsigned long long) *hgh - *low) * ((unsigned long long) 
*hgh + *low - 1)/ 2)){
@@ -697,23 +768,11 @@ createView:
                assert(0);
        }
        
+       fprintf(stderr,"sum=%llu \n",(unsigned long long) sum);
+
        BBPunfix(b->batCacheid);
        BBPunfix(c->batCacheid);
-
-       if(*isIdleQuery==FALSE)
-               fprintf(stderr,"wt=%9.6lf ct=%9.6lf st=%9.6lf lo=%d, hi=%d 
sum=%llu\n",wt,ct,st,(int) *low, (int) *hgh,(unsigned long long) sum);
-       
-       //fprintf(out,"%9.6lf %9.6lf %9.6lf\n",wt,ct,st);
-       //fclose(out);
-
-       if (createIndex==1)
-       {
-               MT_lock_unset(&CRKIndexLock,"Cracker Index Lock");
-               createIndex=0;  
-       }
-       else
-               MT_lock_unset(&CrackerIndex[m].columnLock,"Lock Attribute");    
-
+       MT_lock_unset(&CrackerIndex[m].columnLock,"Lock Attribute");
        return MAL_SUCCEED;
 @
 @= crackOperations
@@ -1006,6 +1065,10 @@ static str
 CRKRangeTree_@1(int *vid, int *bid, @1 *low, @1 *hgh, bit *inclusiveLow, bit 
*inclusiveHgh, bit tail, bit *isIdleQuery){       
        @:RangeSelectBody(@1,@2,@3,@4,)@
 }
+static str
+CRKRangeSumTree_@1(int *vid, int *bid, @1 *low, @1 *hgh, bit *inclusiveLow, 
bit *inclusiveHgh, bit tail){      
+       @:RangeSumBody(@1,@2,@3,@4,)@
+}
 
 static str
 CRKRangeLeftNilTree_@1(int *vid, int *bid, @1 *hgh, bit *inclusiveHgh, bit 
tail, bit *isIdleQuery){
diff --git a/monetdb5/extras/crackers/crackers_selectholpl_ops.mx 
b/monetdb5/extras/crackers/crackers_selectholpl_ops.mx
--- a/monetdb5/extras/crackers/crackers_selectholpl_ops.mx
+++ b/monetdb5/extras/crackers/crackers_selectholpl_ops.mx
@@ -64,6 +64,7 @@ crackers_export str CRKselectholpl_@1(in
 crackers_export str CRKuselectholpl_@1(int *vid, int *bid, @1 *low, @1 *hgh);
 crackers_export str CRKthetaselectholpl_@1(int *vid, int *bid, @1 *val, str 
*op);
 crackers_export str CRKthetauselectholpl_@1(int *vid, int *bid, @1 *val, str 
*op);
+crackers_export str CRKsumholplBounds_@1(int *vid, int *bid, @1 *low, @1 *hgh, 
bit *inclusiveLow, bit *inclusiveHgh);
 @
 
 @c
@@ -180,6 +181,10 @@ CRKthetauselectholpl_@1(int *vid, int *b
 
        return CRKuselectholplBounds_@1(vid, bid, low, high, &lin, &rin, 
&isIdleQuery);
 }
+str
+CRKsumholplBounds_@1(int *vid, int *bid, @1 *low, @1 *hgh, bit *inclusiveLow, 
bit *inclusiveHgh){
+       return CRKRangeSumTree_@1(vid, bid, low, hgh, inclusiveLow, 
inclusiveHgh, FALSE);
+}
 
 
 @
@@ -279,10 +284,9 @@ createView:
 
 @
 @= RangeSelectBody
-       @1 *t0;
-       unsigned long long sum = 0;
+
        BAT *b,*c,*bo;
-       //BAT *view;
+       BAT *view;
        int  m;
        int *t;
        int createIndex=0;
@@ -302,11 +306,11 @@ createView:
        int gapL = 1;
        int gapH = 1;
        bit rippledDeletions = FALSE;
-       struct Node *lowNode=NULL, *hghNode=NULL, *lowNodeNext=NULL, *temp, 
*stopNode=NULL;
+       struct Node *lowNode=NULL, *hghNode=NULL, *lowNodeNext=NULL, *temp;
        BUN idxFirst;
        int firstRetry=0;
        struct timeval tv0, tv1;
-       double wt=0, ct=0, st=0;
+       double wt=0, ct=0;
        bit copy=TRUE;  
        int countBatElements=0;
        int L1=0; /*Number of elements that can fit into L1 cache (size: 
32KB)*/        
@@ -314,7 +318,6 @@ createView:
        char outputFilename1[] = 
"/export/scratch2/petraki/experiments_1st_paper/experiments/stochastic/idle_time_2/pieces_holistic.txt";*/
        FrequencyNode* FN;
        FrequencyNode *FrequencyStructA = getFrequencyStruct('A');
-       (void) tail;
 
        gettimeofday(&tv0,0);
        
@@ -683,14 +686,9 @@ createView:
        
        tempcreateView:;
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
http://mail.monetdb.org/mailman/listinfo/checkin-list

Reply via email to