Changeset: 788094fa199b for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=788094fa199b
Modified Files:
        monetdb5/extras/crackers/crackers.mx
        monetdb5/extras/crackers/crackers_core_unordered.mx
        monetdb5/extras/crackers/crackers_select_ops.mx
        monetdb5/extras/crackers/crackers_selecthol_ops.mx
        monetdb5/extras/crackers/crackers_selectholpl_ops.mx
        monetdb5/extras/crackers/crackers_selectholst_ops.mx
        monetdb5/extras/crackers/crackers_selectpl_ops.mx
        monetdb5/extras/crackers/crackers_selectst_ops.mx
        monetdb5/extras/crackers/crackers_selectstpl_ops.mx
        monetdb5/modules/kernel/bat5.mal
Branch: holindex
Log Message:

Parallel vectorized cracking.


diffs (truncated from 1295 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
@@ -226,7 +226,7 @@ comment "Retrieve the subset using a cra
 
 # new multi-threaded versions
 
-command select(b:bat[:oid,:@2],l:@2,h:@2, nthreads:int):bat[:oid,:@2]
+command select(b:bat[:oid,:@2],l:@2,h:@2, nthreads:int, 
vector_elements:int):bat[:oid,:@2]
 address CRKselect_@2_MT
 comment "Retrieve the subset using a cracker
         index producing preferably a BATview;
@@ -235,7 +235,7 @@ comment "Retrieve the subset using a cra
         nthreads <  0    ->  1st (inferior) version of new multi-threaded 
implementation,
         nthreads >  0    ->  2nd (superior) version of new multi-threaded 
implementation.";
 
-command select(b:bat[:oid,:@2],l:@2, nthreads:int):bat[:oid,:@2]
+command select(b:bat[:oid,:@2],l:@2, nthreads:int, 
vector_elements:int):bat[:oid,:@2]
 address CRKselectValue_@2_MT
 comment "Retrieve the subset using a cracker
         index producing preferably a BATview;
@@ -244,7 +244,7 @@ comment "Retrieve the subset using a cra
         nthreads <  0    ->  1st (inferior) version of new multi-threaded 
implementation,
         nthreads >  0    ->  2nd (superior) version of new multi-threaded 
implementation.";
 
-command select(b:bat[:oid,:@2],l:@2,h:@2,li:bit,hi:bit, 
nthreads:int):bat[:oid,:@2]
+command select(b:bat[:oid,:@2],l:@2,h:@2,li:bit,hi:bit, nthreads:int, 
vector_elements:int):bat[:oid,:@2]
 address CRKselectBounds_@2_MT
 comment "Retrieve the subset using a cracker
         index producing preferably a BATview;
@@ -253,7 +253,7 @@ comment "Retrieve the subset using a cra
         nthreads <  0    ->  1st (inferior) version of new multi-threaded 
implementation,
         nthreads >  0    ->  2nd (superior) version of new multi-threaded 
implementation.";
 
-command uselect(b:bat[:any_1,:@2],l:@2,h:@2, nthreads:int):bat[:any_1,:void]
+command uselect(b:bat[:any_1,:@2],l:@2,h:@2, nthreads:int, 
vector_elements:int):bat[:any_1,:void]
 address CRKuselect_@2_MT
 comment "Retrieve the subset using a cracker
         index producing preferably a BATview;
@@ -262,7 +262,7 @@ comment "Retrieve the subset using a cra
         nthreads <  0    ->  1st (inferior) version of new multi-threaded 
implementation,
         nthreads >  0    ->  2nd (superior) version of new multi-threaded 
implementation.";
 
-command uselect(b:bat[:any_1,:@2],l:@2, nthreads:int):bat[:any_1,:void]
+command uselect(b:bat[:any_1,:@2],l:@2, nthreads:int, 
vector_elements:int):bat[:any_1,:void]
 address CRKuselectValue_@2_MT
 comment "Retrieve the subset using a cracker
         index producing preferably a BATview;
@@ -271,7 +271,7 @@ comment "Retrieve the subset using a cra
         nthreads <  0    ->  1st (inferior) version of new multi-threaded 
implementation,
         nthreads >  0    ->  2nd (superior) version of new multi-threaded 
implementation.";
 
-command uselect(b:bat[:any_1,:@2],l:@2,h:@2,li:bit,hi:bit, 
nthreads:int):bat[:any_1,:void]
+command uselect(b:bat[:any_1,:@2],l:@2,h:@2,li:bit,hi:bit, nthreads:int, 
vector_elements:int):bat[:any_1,:void]
 address CRKuselectBounds_@2_MT
 comment "Retrieve the subset using a cracker
         index producing preferably a BATview;
@@ -280,7 +280,7 @@ comment "Retrieve the subset using a cra
         nthreads <  0    ->  1st (inferior) version of new multi-threaded 
implementation,
         nthreads >  0    ->  2nd (superior) version of new multi-threaded 
implementation.";
 
-command thetauselect(b:bat[:any_1,:@2],v:@2,op:str, 
nthreads:int):bat[:any_1,:void]
+command thetauselect(b:bat[:any_1,:@2],v:@2,op:str, nthreads:int, 
vector_elements:int):bat[:any_1,:void]
 address CRKthetauselect_@2_MT
 comment "Retrieve the subset using a cracker
         index producing preferably a BATview;
@@ -289,7 +289,7 @@ comment "Retrieve the subset using a cra
         nthreads <  0    ->  1st (inferior) version of new multi-threaded 
implementation,
         nthreads >  0    ->  2nd (superior) version of new multi-threaded 
implementation.";
 
-command thetaselect(b:bat[:any_1,:@2],v:@2,op:str, 
nthreads:int):bat[:any_1,:@2]
+command thetaselect(b:bat[:any_1,:@2],v:@2,op:str, nthreads:int, 
vector_elements:int):bat[:any_1,:@2]
 address CRKthetaselect_@2_MT
 comment "Retrieve the subset using a cracker
         index producing preferably a BATview;
@@ -352,7 +352,7 @@ comment "Retrieve the subset using a cra
 
 # new multi-threaded stochastic versions
 
-command selectst(b:bat[:oid,:@2],l:@2,h:@2, nthreads:int):bat[:oid,:@2]
+command selectst(b:bat[:oid,:@2],l:@2,h:@2, nthreads:int, 
vector_elements:int):bat[:oid,:@2]
 address CRKselectst_@2_MT
 comment "Retrieve the subset using a cracker
         index producing preferably a BATview;
@@ -361,7 +361,7 @@ comment "Retrieve the subset using a cra
         nthreads <  0    ->  1st (inferior) version of new multi-threaded 
implementation,
         nthreads >  0    ->  2nd (superior) version of new multi-threaded 
implementation.";
 
-command selectst(b:bat[:oid,:@2],l:@2, nthreads:int):bat[:oid,:@2]
+command selectst(b:bat[:oid,:@2],l:@2, nthreads:int, 
vector_elements:int):bat[:oid,:@2]
 address CRKselectstValue_@2_MT
 comment "Retrieve the subset using a cracker
         index producing preferably a BATview;
@@ -370,7 +370,7 @@ comment "Retrieve the subset using a cra
         nthreads <  0    ->  1st (inferior) version of new multi-threaded 
implementation,
         nthreads >  0    ->  2nd (superior) version of new multi-threaded 
implementation.";
 
-command selectst(b:bat[:oid,:@2],l:@2,h:@2,li:bit,hi:bit, 
nthreads:int):bat[:oid,:@2]
+command selectst(b:bat[:oid,:@2],l:@2,h:@2,li:bit,hi:bit, nthreads:int, 
vector_elements:int):bat[:oid,:@2]
 address CRKselectstBounds_@2_MT
 comment "Retrieve the subset using a cracker
         index producing preferably a BATview;
@@ -379,7 +379,7 @@ comment "Retrieve the subset using a cra
         nthreads <  0    ->  1st (inferior) version of new multi-threaded 
implementation,
         nthreads >  0    ->  2nd (superior) version of new multi-threaded 
implementation.";
 
-command uselectst(b:bat[:any_1,:@2],l:@2,h:@2, nthreads:int):bat[:any_1,:void]
+command uselectst(b:bat[:any_1,:@2],l:@2,h:@2, nthreads:int, 
vector_elements:int):bat[:any_1,:void]
 address CRKuselectst_@2_MT
 comment "Retrieve the subset using a cracker
         index producing preferably a BATview;
@@ -388,7 +388,7 @@ comment "Retrieve the subset using a cra
         nthreads <  0    ->  1st (inferior) version of new multi-threaded 
implementation,
         nthreads >  0    ->  2nd (superior) version of new multi-threaded 
implementation.";
 
-command uselectst(b:bat[:any_1,:@2],l:@2, nthreads:int):bat[:any_1,:void]
+command uselectst(b:bat[:any_1,:@2],l:@2, nthreads:int, 
vector_elements:int):bat[:any_1,:void]
 address CRKuselectstValue_@2_MT
 comment "Retrieve the subset using a cracker
         index producing preferably a BATview;
@@ -397,7 +397,7 @@ comment "Retrieve the subset using a cra
         nthreads <  0    ->  1st (inferior) version of new multi-threaded 
implementation,
         nthreads >  0    ->  2nd (superior) version of new multi-threaded 
implementation.";
 
-command uselectst(b:bat[:any_1,:@2],l:@2,h:@2,li:bit,hi:bit, 
nthreads:int):bat[:any_1,:void]
+command uselectst(b:bat[:any_1,:@2],l:@2,h:@2,li:bit,hi:bit, nthreads:int, 
vector_elements:int):bat[:any_1,:void]
 address CRKuselectstBounds_@2_MT
 comment "Retrieve the subset using a cracker
         index producing preferably a BATview;
@@ -406,7 +406,7 @@ comment "Retrieve the subset using a cra
         nthreads <  0    ->  1st (inferior) version of new multi-threaded 
implementation,
         nthreads >  0    ->  2nd (superior) version of new multi-threaded 
implementation.";
 
-command thetauselectst(b:bat[:any_1,:@2],v:@2,op:str, 
nthreads:int):bat[:any_1,:void]
+command thetauselectst(b:bat[:any_1,:@2],v:@2,op:str, nthreads:int, 
vector_elements:int):bat[:any_1,:void]
 address CRKthetauselectst_@2_MT
 comment "Retrieve the subset using a cracker
         index producing preferably a BATview;
@@ -415,7 +415,7 @@ comment "Retrieve the subset using a cra
         nthreads <  0    ->  1st (inferior) version of new multi-threaded 
implementation,
         nthreads >  0    ->  2nd (superior) version of new multi-threaded 
implementation.";
 
-command thetaselectst(b:bat[:any_1,:@2],v:@2,op:str, 
nthreads:int):bat[:any_1,:@2]
+command thetaselectst(b:bat[:any_1,:@2],v:@2,op:str, nthreads:int, 
vector_elements:int):bat[:any_1,:@2]
 address CRKthetaselectst_@2_MT
 comment "Retrieve the subset using a cracker
         index producing preferably a BATview;
diff --git a/monetdb5/extras/crackers/crackers_core_unordered.mx 
b/monetdb5/extras/crackers/crackers_core_unordered.mx
--- a/monetdb5/extras/crackers/crackers_core_unordered.mx
+++ b/monetdb5/extras/crackers/crackers_core_unordered.mx
@@ -96,7 +96,7 @@ All Rights Reserved.
  * @- Exported signatures
  */
 @= CoreUnorderedFunctions_decl
-crackers_export str CRKcrackUnorderedZero_@1 (int *res, int *bid, @1 *mid, int 
nthreads);
+crackers_export str CRKcrackUnorderedZero_@1 (int *res, int *bid, @1 *mid, int 
nthreads, int vector_elements);
 crackers_export str CRKcrackUnorderedThree_@1 (int *res, int *bid, @1 *low, @1 
*hgh);
 @
  * @- Signatures shared within the crackers module/library
@@ -109,7 +109,7 @@ crackers_export str CRKcrackUnorderedThr
 @:crackInThreeUnorderedPieces@4(@1,LE,RO,LT,GE,LT,GE,@2,@3)@
 @
 @= crackInTwoUnorderedPieces_decl
-str CRKcrackUnorderedZero_@2_@1( BAT *b, @1 mval, oid first, oid last, oid 
*pos, int nthreads);
+str CRKcrackUnorderedZero_@2_@1( BAT *b, @1 mval, oid first, oid last, oid 
*pos, int nthreads, int vector_elements);
 @
 @= crackInThreeUnorderedPieces_decl
 str CRKcrackUnorderedThree_@2_@3_@1( BAT *b, @1 low, @1 hgh, oid first, oid 
last, oid *posl, oid *posh);
@@ -153,7 +153,7 @@ str CRKcrackUnorderedThreeSideways_@3_@4
  */
 #include "monetdb_config.h"
 #include "crackers.h"
-
+#include<math.h>
 //#define CRACK_MUTLI_THREAD_DEBUG
 
 /* argument struct for countThread & crackThread functions */
@@ -168,8 +168,14 @@ typedef struct {
        BUN pos_r;         /* first(!) pos of right(!) piece */
        const char *msg;   /* error message */
        BUN m;             /* size of half slice */
+       BUN ml;             /* size of left slice */
+       BUN mr;             /* size of right slice */
 } c_Thread_t;
 
+typedef struct {
+       BUN left, right;
+} cursorDeltas;
+
 /* Functions shared within the crackers module/library */
 @:TypeSwitch(operations,_impl)@
 @:TypeSwitch_4(operationsSideways,_impl)@
@@ -182,7 +188,7 @@ typedef struct {
  */
 @= CoreUnorderedFunctions_impl
 str
-CRKcrackUnorderedZero_@1 (int *res, int *bid, @1 *mid, int nthreads){
+CRKcrackUnorderedZero_@1 (int *res, int *bid, @1 *mid, int nthreads, int 
vector_elements){
         BAT *b;
         str msg;
        oid pos;
@@ -194,7 +200,7 @@ CRKcrackUnorderedZero_@1 (int *res, int 
        /* if( sizeof(struct SCRATCH{ oid hdummy; @1 tdummy; } ) != BUNsize(b) )
                 throw(MAL, "crackers.crack_zeroUnordered", "Need more clever 
mapping ");
        */
-        msg = CRKcrackUnorderedZero_LE_@1( b, *mid,(BUN) 0, BATcount(b)-1, 
&pos, nthreads);
+        msg = CRKcrackUnorderedZero_LE_@1( b, *mid,(BUN) 0, BATcount(b)-1, 
&pos, nthreads, vector_elements);
 
         BBPkeepref(b->batCacheid);
         *res = *bid;
@@ -574,7 +580,7 @@ CRKcrackUnorderedZero_@2_@1_MT_crackThre
 
 /* new multi-threaded crack code; Alternative 2 */
 static str
-CRKcrackUnorderedZero_@2_@1_MT ( const BAT *b, const @1 mval, const BUN first, 
const BUN last, oid *pos, int nthreads, int alt )
+CRKcrackUnorderedZero_@2_@1_MT ( const BAT *b, const @1 mval, const BUN first, 
const BUN last, oid *pos, int nthreads, int alt)
 {
        BUN n = last - first + 1; /* total # tuples / values */
        BUN m;                    /* # tuples / values per slice */
@@ -835,57 +841,492 @@ CRKcrackUnorderedZero_@2_@1_MT ( const B
 
        return MAL_SUCCEED;
 }
+static cursorDeltas performCrackOnVectors_@2_@1(const @1* input, @1* 
leftOutput, @1* rightOutput, const @1 pivot, const oid* inputPayload, oid* 
leftOutputPayload, oid* rightOutputPayload, int vector_elements){
+       BUN rightOutI = 0, leftOutI = 0, inI;
+       unsigned int  isLessThan;
 
+       for (inI = 0; inI < (BUN)vector_elements; inI++){
+               rightOutput[rightOutI] = input[inI];
+               rightOutputPayload[rightOutI] = inputPayload[inI];
+               isLessThan = (input[inI] @7 pivot);
+               rightOutI -= (~isLessThan)&1;
+               leftOutput[leftOutI] = input[inI];
+               leftOutputPayload[leftOutI] = inputPayload[inI];
+               leftOutI += isLessThan;
+       }
+       return (cursorDeltas){.left = leftOutI, .right = rightOutI};
+}
+static cursorDeltas performCrackOnVectors_left_@2_@1(const @1* input, @1* 
leftOutput, @1* rightOutput, const @1 pivot, const oid* inputPayload, oid* 
leftOutputPayload, oid* rightOutputPayload, BUN max, BUN skip, int 
vector_elements){
+       BUN rightOutI = 0, leftOutI = 0, inI;
+       unsigned int  isLessThan;
+
+       for (inI = 0; inI < (BUN)vector_elements; inI++){
+               rightOutput[rightOutI] = input[inI];
+               rightOutputPayload[rightOutI] = inputPayload[inI];
+               isLessThan = (input[inI] @7 pivot);
+               rightOutI -= (~isLessThan)&1;
+               leftOutput[leftOutI] = input[inI];
+               leftOutputPayload[leftOutI] = inputPayload[inI];
+               leftOutI += isLessThan;
+               leftOutI += (leftOutI == max) * skip;
+       }
+       return (cursorDeltas){.left = leftOutI, .right = rightOutI};
+}
+
+static cursorDeltas performCrackOnVectors_right_@2_@1(const @1* input, @1* 
leftOutput, @1* rightOutput, const @1 pivot, const oid* inputPayload, oid* 
leftOutputPayload, oid* rightOutputPayload, BUN min, BUN skip, int 
vector_elements){
+       BUN rightOutI = 0, leftOutI = 0, inI;
+       unsigned int  isLessThan;
+
+       for (inI = 0; inI < (BUN)vector_elements; inI++){
+               rightOutput[rightOutI] = input[inI];
+               rightOutputPayload[rightOutI] = inputPayload[inI];
+               isLessThan = (input[inI] @7 pivot);
+               rightOutI -= (~isLessThan)&1;
+               rightOutI -= (rightOutI == min) * skip;
+               leftOutput[leftOutI] = input[inI];
+               leftOutputPayload[leftOutI] = inputPayload[inI];
+               leftOutI += isLessThan;
+       }
+       return (cursorDeltas){.left = leftOutI, .right = rightOutI};
+}
+
+static cursorDeltas performCrackOnVectors_left_right_@2_@1(const @1* input, 
@1* leftOutput, @1* rightOutput, const @1 pivot, const oid* inputPayload, oid* 
leftOutputPayload, oid* rightOutputPayload, BUN max, BUN min, BUN skip, int 
vector_elements){
+       BUN rightOutI = 0, leftOutI = 0, inI;
+       unsigned int  isLessThan;
+
+       for (inI = 0; inI < (BUN)vector_elements; inI++){
+               rightOutput[rightOutI] = input[inI];
+               rightOutputPayload[rightOutI] = inputPayload[inI];
+               isLessThan = (input[inI] @7 pivot);
+               rightOutI -= (~isLessThan)&1;
+               rightOutI -= (rightOutI == min) * skip;
+               leftOutput[leftOutI] = input[inI];
+               leftOutputPayload[leftOutI] = inputPayload[inI];
+               leftOutI += isLessThan;
+               leftOutI += (leftOutI == max) * skip;
+       }
+       return (cursorDeltas){.left = leftOutI, .right = rightOutI};
+}
+
+static str CRKvectorized_x_@2_@1 (
+       /* input */
+       const BAT* buffer,      /* attribute (array) */
+       const @1 pivot, /* pivot value for attribute*/
+       BUN first_left,  /* first position of to-be-cracked piece */
+       BUN last_right,  /* last position of to-be-cracked piece */
+       BUN ml, 
+       BUN mr, 
+       BUN *pos_r, /*return position*/
+       int vector_elements
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to