Changeset: e30a75d9b5eb for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=e30a75d9b5eb
Modified Files:
monetdb5/extras/crackers/crackers_holistic.c
monetdb5/extras/crackers/crackers_selectholpl_ops.mx
Branch: holindex
Log Message:
Each idle thread does two cracks instead of one.
diffs (truncated from 385 to 300 lines):
diff --git a/monetdb5/extras/crackers/crackers_holistic.c
b/monetdb5/extras/crackers/crackers_holistic.c
--- a/monetdb5/extras/crackers/crackers_holistic.c
+++ b/monetdb5/extras/crackers/crackers_holistic.c
@@ -328,7 +328,6 @@ CRKrandomCrack(int *ret)
{
int bid=0;
FrequencyNode* max_node;
- int change_bat=0;
bit inclusive=TRUE;
FrequencyNode *fs = getFrequencyStruct('A');
@@ -339,8 +338,8 @@ CRKrandomCrack(int *ret)
if(max_node!=NULL && max_node->weight > 0)
{
bid=max_node->bid;
- change_bat = CRKrandomholpl_int(&bid,&inclusive);
- if (change_bat == -1)
+ CRKrandomholpl_int(&bid,&inclusive,&inclusive);
+ /*if (change_bat == -1)
{
MT_lock_set(&frequencylock, "getFrequencyStruct");
max_node=findOtherMax(fs,bid);
@@ -350,7 +349,7 @@ CRKrandomCrack(int *ret)
bid=max_node->bid;
(void) CRKrandomholpl_int(&bid,&inclusive);
}
- }
+ }*/
}
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
@@ -65,7 +65,7 @@ crackers_export str CRKuselectholpl_@1(i
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);
-crackers_export int CRKrandomholpl_@1(int *bid, bit *inclusiveLow);
+crackers_export str CRKrandomholpl_@1(int *bid, bit *inclusiveLow,bit
*inclusiveHgh);
@
@c
@@ -181,46 +181,47 @@ CRKsumholplBounds_@1(int *vid, int *bid,
return CRKRangeSumTree_@1(vid, bid, low, hgh, inclusiveLow,
inclusiveHgh, FALSE);
}
-int
-CRKrandomholpl_@1(int *bid, bit *inclusiveLow){
- BAT *b,*c,*bo;
- int m;
+str
+CRKrandomholpl_@1(int *bid, bit *inclusiveLow, bit *inclusiveHgh){
+
+ BAT *b,*c;
+ int m,temp_val;
int *t;
- @1 *low=NULL;
+ oid p;
+ int gapL = 1;
+ int gapH = 1;
+ @1 *low=NULL, *hgh=NULL;
pthread_rwlock_t *plock=0;
- oid vl=0;
- /* vl and vh are the low and high index values to create the view with
the result */
- oid cl1=0, ch1=0;
- /* index values in the case we have to crack
- |cl1...........ch1|.....................|cl2.........ch2|
- if we have to crack only one piece, i.e., if our range falls
- in one piece only then we crack from cl to ch otherwise we use
- the other indices as it is shown */
- oid _vl=0;
- bit foundLow=0;
- bit LBound=FALSE;
+ oid vl=0, vh=0;
+ oid cl1=0, ch1=0, cl2=0, ch2=0, _vl=0;
+ bit foundLow=0, foundHgh=0;
+ bit LBound=FALSE,HBound=FALSE;
struct Node *lowNode=NULL;
BUN idxFirst;
- int gapL=1;
- oid p;
+ int incr_pieces=0;
struct timeval tv0, tv1;
double wt=0, ct=0;
int countBatElements=0;
- int retryIter=0;
- int incr_pieces=0;
int L1=0; /*Number of elements that can fit into L1 cache (size:
32KB)*/
int mod_bid=0;
FILE *ofp;
char *outputFilename1;
FrequencyNode* FN;
FrequencyNode *FrequencyStructA = getFrequencyStruct('A');
+
gettimeofday(&tv0,0);
+
+ low=(@1*) GDKmalloc(sizeof(@1));
+ hgh=(@1*) GDKmalloc(sizeof(@1));
+ if (low==NULL || hgh==NULL)
+ throw(MAL, "crackers.crackRange", "low or null cannot get
memory");
outputFilename1 = getenv("HOLOUTPUT_ATTRIBUTES");
if (outputFilename1 == NULL){
fprintf(stderr, "Error: HOLOUTPUT_ATTRIBUTES\n");
exit(1);
}
+
L1=32000/ATOMsize(TYPE_@1);
ofp = fopen(outputFilename1,"a");
@@ -228,11 +229,7 @@ CRKrandomholpl_@1(int *bid, bit *inclusi
fprintf(stderr, "Can't open output file!\n");
exit(1);
}
-
- low=(@1*) GDKmalloc(sizeof(@1));
- if (low==NULL)
- return -2;
-
+
mod_bid=ABS(*bid)%LOCKS;
MT_lock_set(&CRKIndexLock[mod_bid],"Cracker Index Lock");
@@ -242,79 +239,17 @@ CRKrandomholpl_@1(int *bid, bit *inclusi
m = existsCrackerIndex(*bid);
/* if this is the first time we selectholpl something from this bat,
we have to create the crack index for it and
- if necessary materialize the head of the bat */
-
- if (m == -1){
- if ((bo = BATdescriptor(*bid)) == NULL)
- return -2;
- b = BATcopy(bo, bo->htype, bo->ttype, TRUE);
- if ( bo->htype == TYPE_void)
- b = BATmaterializeh(b);
- b->hsorted = FALSE;
- b->tsorted = FALSE;
- b->hdense = FALSE;
- b->tdense = FALSE;
- /*BATkey(b,TRUE);*/
- BATkey(BATmirror(b),FALSE);
- b->batRestricted= BAT_READ;
- BATmode(b,PERSISTENT);
- bo->batRestricted= BAT_READ;
+ if necessary materialize the head of the bat */
+ if (m == -1)
+ throw(MAL, "crackers.crackRange", "index should already exist");
- BBPincref(*bid,TRUE);
- m = newCrackerIndex_@1(*bid,b->batCacheid);
-
- countBatElements=BATcount(b);
-
- if ((c = BATdescriptor(CrackerIndex[m].cid)) == NULL)
- return -2;
-
- t = (int *) Tloc(b, BUNfirst(b));
- p=rand()%countBatElements;
- *low=t[p];
- @:crkTwoLTree@5(@1,@5)@
-
- if (IndexSize < IndexStop) {
- if (vl > 0)
- _vl = vl - 1;
- else
- _vl = vl;
- if (gapL>0)
- {
- addCrackerIndex_@1(m, low, *inclusiveLow, _vl,
c);
- incr_pieces++;
-
- }
- if ((vl == 1) && (*t == *low) && (*inclusiveLow ==
TRUE))
- vl = vl - 1;
- }
-
- gettimeofday(&tv1,0); ct+=dt(tv0,tv1); tv0=tv1;
- MT_lock_set(&frequencylock, "getFrequencyStruct");
- gettimeofday(&tv1,0); wt+=dt(tv0,tv1); tv0=tv1;
- FN=searchBAT(FrequencyStructA,*bid);
- FN->c = FN->c + incr_pieces;
- if(FN->weight > 0)
- FN->weight = changeWeight(FN,countBatElements,L1);
- gettimeofday(&tv1,0); ct+=dt(tv0,tv1); tv0=tv1;
- fprintf(ofp,"Idle_Query \t 0 \t Bat_id= \t %d \t Pieces= \t %d
\t Wait_time\t %9.6lf \t Selection_time\t %9.6lf \t Low= \t %d \t Thread_id=
\t" SZFMT "\n",FN->bid,FN->c,wt,ct,(int)*low,MT_getpid());
- fclose(ofp);
- MT_lock_unset(&frequencylock, "getFrequencyStruct");
-
-
- BBPincref(b->batCacheid,TRUE);
- BBPunfix(bo->batCacheid);
-
- MT_lock_unset(&CRKIndexLock[mod_bid],"Cracker Index Lock");
- GDKfree(low);
- return 0;
- }
/* Take the index of the bat */
if ((c = BATdescriptor(CrackerIndex[m].cid)) == NULL)
- return -2;
+ 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)
- return -2;
+ throw(MAL, "crackers.crackRange", "Cannot access crack index");
idxFirst = BUNfirst(c);
@@ -322,12 +257,22 @@ CRKrandomholpl_@1(int *bid, bit *inclusi
gettimeofday(&tv1,0); ct+=dt(tv0,tv1); tv0=tv1;
- countBatElements=BATcount(b);
-
retry:;
+
t = (int *) Tloc(b, BUNfirst(b));
p=rand()%countBatElements;
*low=t[p];
+ p=rand()%countBatElements;
+ *hgh=t[p];
+ if(*low > *hgh)
+ {
+ temp_val=*hgh;
+ *hgh=*low;
+ *low=temp_val;
+ }
+ else if (*low==*hgh)
+ goto retry;
+
pthread_rwlock_rdlock(&CrackerIndex[m].columnRWLock);
@@ -336,68 +281,102 @@ CRKrandomholpl_@1(int *bid, bit *inclusi
/* 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);
+
pthread_rwlock_unlock(&CrackerIndex[m].columnRWLock);
+ gettimeofday(&tv1,0); ct+=dt(tv0,tv1); tv0=tv1;
+
/*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++;
-
- gettimeofday(&tv1,0); ct+=dt(tv0,tv1); tv0=tv1;
+ 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) {
- pthread_rwlock_rdlock(&CrackerIndex[m].columnRWLock);
- gettimeofday(&tv1,0); wt+=dt(tv0,tv1); tv0=tv1;
- lowNode = findNodeL_@1(*low, TRUE, CrackerIndex[m].Tree, c,
idxFirst, NULL);
- plock = (lowNode == NULL)? &CRKFirstPieceRWLock :
&lowNode->pieceLock;
- if (pthread_rwlock_trywrlock(plock)){
+ if (foundLow == 0 || foundHgh == 0) {
+ if (foundLow == 0) {
+ pthread_rwlock_rdlock(&CrackerIndex[m].columnRWLock);
+ gettimeofday(&tv1,0); wt+=dt(tv0,tv1); tv0=tv1;
+ lowNode = findNodeL_@1(*low, TRUE,
CrackerIndex[m].Tree, c, idxFirst, NULL);
+ plock = (lowNode == NULL)? &CRKFirstPieceRWLock :
&lowNode->pieceLock;
+ if (pthread_rwlock_trywrlock(plock)){
+
pthread_rwlock_unlock(&CrackerIndex[m].columnRWLock);
+ gettimeofday(&tv1,0); ct+=dt(tv0,tv1); tv0=tv1;
+ pthread_rwlock_wrlock(plock);
+ gettimeofday(&tv1,0); wt+=dt(tv0,tv1); tv0=tv1;
+ pthread_rwlock_unlock(plock);
+ goto retry;
+ }
pthread_rwlock_unlock(&CrackerIndex[m].columnRWLock);
+ @:crkTwoLTree@5(@1,@5)@
gettimeofday(&tv1,0); ct+=dt(tv0,tv1); tv0=tv1;
- pthread_rwlock_wrlock(plock);
+ pthread_rwlock_wrlock(&CrackerIndex[m].columnRWLock);
gettimeofday(&tv1,0); wt+=dt(tv0,tv1); tv0=tv1;
+ t = (int *) Tloc(b, BUNfirst(b));
+ if (IndexSize < IndexStop) {
+ if (vl > 0)
+ _vl = vl - 1;
+ else
+ _vl = vl;
+ if (gapL>0)
+ {
+ addCrackerIndex_@1(m, low,
*inclusiveLow, _vl, c);
+ incr_pieces++;
+ }
+ if ((vl == 1) && (*t == *low) && (*inclusiveLow
== TRUE))
+ vl = vl - 1;
+ }
+ vh = ch2;
+ pthread_rwlock_unlock(&CrackerIndex[m].columnRWLock);
pthread_rwlock_unlock(plock);
- retryIter++;
- if(retryIter > 2)
- {
+ }
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list