Changeset: 38f924785ab5 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=38f924785ab5
Added Files:
        monetdb5/extras/crackers/crackers_multicore_unordered.mx
        monetdb5/extras/crackers/crackers_parallelselect_ops.mx
Modified Files:
        monetdb5/extras/crackers/Makefile.ag
        monetdb5/extras/crackers/crackers.mx
        monetdb5/extras/crackers/crackers_selectpl_ops.mx
Branch: holindex
Log Message:

Start implementation of multicore database cracking.


diffs (truncated from 1632 to 300 lines):

diff --git a/monetdb5/extras/crackers/Makefile.ag 
b/monetdb5/extras/crackers/Makefile.ag
--- a/monetdb5/extras/crackers/Makefile.ag
+++ b/monetdb5/extras/crackers/Makefile.ag
@@ -35,6 +35,7 @@ lib_crackers = {
                          crackers_index.mx \
                          crackers_validation.mx \
                          crackers_core_unordered.mx \
+                         crackers_multicore_unordered.mx \
                          crackers_select_ops.mx \
                          crackers_joinselect_ops.mx \
                          crackers_holistic.c \
@@ -46,6 +47,7 @@ lib_crackers = {
                          crackers_selectholst_ops.mx \
                          crackers_selectholpl_ops.mx \
                          crackers_selectpl_ops.mx \
+                         crackers_parallelselect_ops.mx \
                          crackers_updates.mx \
                          crackers_sideways.mx \
                          crackers_sidewayshol.mx \
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
@@ -222,6 +222,17 @@ comment "Retrieve the subset using a cra
         index producing preferably a BATview.";
 
 
+command parallelselect(b:bat[:oid,:@2],l:@2,h:@2,li:bit,hi:bit):bat[:oid,:@2]
+address CRKparallelselectBounds_@2
+comment "Retrieve the subset using a cracker
+        index producing preferably a BATview.";
+
+command 
paralleluselect(b:bat[:any_1,:@2],l:@2,h:@2,li:bit,hi:bit):bat[:any_1,:void]
+address CRKparalleluselectBounds_@2
+comment "Retrieve the subset using a cracker
+        index producing preferably a BATview.";
+
+
 command selectst(b:bat[:oid,:@2],l:@2,h:@2):bat[:oid,:@2]
 address CRKselectst_@2
 comment "Retrieve the subset using a cracker
@@ -895,6 +906,7 @@ comment "Calculate aggregate sum of rang
 #include "crackers_index.h"
 #include "crackers_validation.h"
 #include "crackers_select_ops.h"
+#include "crackers_parallelselect_ops.h"
 #include "crackers_selectst_ops.h"
 #include "crackers_selecthol_ops.h"
 #include "crackers_selectholst_ops.h"
@@ -903,6 +915,7 @@ comment "Calculate aggregate sum of rang
 #include "crackers_holistic.h"
 #include "crackers_holisticsideways.h"
 #include "crackers_core_unordered.h"
+#include "crackers_multicore_unordered.h"
 #include "crackers_AVL_tree.h"
 #include "crackers_updates.h"
 #include "crackers_sideways.h"
diff --git a/monetdb5/extras/crackers/crackers_multicore_unordered.mx 
b/monetdb5/extras/crackers/crackers_multicore_unordered.mx
new file mode 100644
--- /dev/null
+++ b/monetdb5/extras/crackers/crackers_multicore_unordered.mx
@@ -0,0 +1,544 @@
+@/
+The contents of this file are subject to the MonetDB Public License
+Version 1.1 (the "License"); you may not use this file except in
+compliance with the License. You may obtain a copy of the License at
+http://www.monetdb.org/Legal/MonetDBLicense
+
+Software distributed under the License is distributed on an "AS IS"
+basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+License for the specific language governing rights and limitations
+under the License.
+
+The Original Code is the MonetDB Database System.
+
+The Initial Developer of the Original Code is CWI.
+Portions created by CWI are Copyright (C) 1997-July 2008 CWI.
+Copyright August 2008-2013 MonetDB B.V.
+All Rights Reserved.
+@
+
+@f crackers_multicore_unordered
+
+@c
+/*
+ * @a Martin Kersten, Stratos Idreos, Stefan Manegold
+ * @d March 2006 - July 2007
+ * @* MultiCore Cracking (unordered)
+ *
+ *
+ * @+ Interface
+ *
+ *
+ * @- Type expansion
+ */
+@= TypeSwitch
+@:@1(int,simple,,@2)@
+@
+@h
+/*
+ * @- Header file
+ */
+#ifndef _CRACKERS_MULTICORE_UNORDERED_H_
+#define _CRACKERS_MULTICORE_UNORDERED_H_
+
+#ifdef LIBCRACKERS
+
+typedef struct {
+        BAT *array;
+        int *temp_array;
+        int *data_less;
+        int *data_greater;
+        oid* left;
+        oid* right;
+        int tid;
+        int *pivot;
+} thread_data_t;
+
+typedef struct {
+        BAT *array;
+        int *temp_array;
+        int *data_less;
+        int *data_greater;
+        int nthreads; /*number of threads*/
+        int n; /*number of array elements*/
+        oid* left;
+        oid* right;
+        int tid;
+        int *pivot;
+} thread_data_new_t;
+
+
+/* Signatures shared within the crackers module/library */
+@:TypeSwitch(operations,_decl)@
+#endif
+
+/* Exported signatures */
+@:TypeSwitch(MultiCoreUnorderedFunctions_decl,)@
+
+#endif /* _CRACKERS_MULTICORE_UNORDERED_H */
+/*
+ * @- Exported signatures
+ */
+@= MultiCoreUnorderedFunctions_decl
+crackers_export str CRKcrackUnorderedZeroParallel_@1 (int *res, int *bid, @1 
*mid);
+crackers_export str CRKcrackUnorderedThreeParallel_@1 (int *res, int *bid, @1 
*low, @1 *hgh);
+@
+ * @- Signatures shared within the crackers module/library
+@= operations
+@:crackInTwoUnorderedPieces@4(@1,LE,LE,GT,@2,@3)@
+@:crackInTwoUnorderedPieces@4(@1,RE,LT,GE,@2,@3)@
+@:crackInThreeUnorderedPieces@4(@1,LO,RE,LE,GT,LE,GT,@2,@3)@
+@:crackInThreeUnorderedPieces@4(@1,LE,RE,LT,GE,LE,GT,@2,@3)@
+@:crackInThreeUnorderedPieces@4(@1,LO,RO,LE,GT,LT,GE,@2,@3)@
+@:crackInThreeUnorderedPieces@4(@1,LE,RO,LT,GE,LT,GE,@2,@3)@
+@
+@= crackInTwoUnorderedPieces_decl
+str CRKcrackUnorderedZeroParallel_@2_@1( BAT *b, @1 mval, oid first, oid last, 
oid *pos);
+str CRKscanUnorderedZeroParallel_@2_@1( BAT *b, @1 *temp_array, @1 *mval, oid 
first, oid last, int nthreads, int *data_less, int *data_greater);
+void *threadFuncScan_@2_@1(void *arg);
+@
+@= crackInThreeUnorderedPieces_decl
+str CRKcrackUnorderedThreeParallel_@2_@3_@1( BAT *b, @1 low, @1 hgh, oid 
first, oid last, oid *posl, oid *posh);
+str CRKcrackUnorderedThreeCopyParallel_@2_@3_@1( BAT *b, @1 low, @1 hgh, oid 
first, oid last, oid *posl, oid *posh, BAT *bc);
+@
+
+@c
+/*
+ * @+ Implementation
+ *
+ *
+ * @- C file
+ */
+#include "monetdb_config.h"
+#include "crackers.h"
+
+/* Functions shared within the crackers module/library */
+@:TypeSwitch(operations,_impl)@
+
+/* Exported functions */
+@:TypeSwitch(MultiCoreUnorderedFunctions_impl,)@
+/*
+ * @- Exported functions
+ */
+@= MultiCoreUnorderedFunctions_impl
+str
+CRKcrackUnorderedZeroParallel_@1 (int *res, int *bid, @1 *mid){
+        BAT *b;
+        str msg;
+       oid pos;
+
+        if ((b = BATdescriptor(*bid)) == NULL)
+                throw(MAL, "crackers.crack_zeroUnordered", "Cannot access 
descriptor");
+
+        /* set bounds for the iterator */
+       /* if( sizeof(struct SCRATCH{ oid hdummy; @1 tdummy; } ) != BUNsize(b) )
+                throw(MAL, "crackers.crack_zeroUnordered", "Need more clever 
mapping ");
+       */
+        msg = CRKcrackUnorderedZeroParallel_LE_@1( b, *mid,(BUN) 0, 
BATcount(b)-1, &pos);
+
+        BBPkeepref(b->batCacheid);
+        *res = *bid;
+        return msg;
+}
+
+str
+CRKcrackUnorderedThreeParallel_@1 (int *res, int *bid, @1 *low, @1 *hgh){
+        BAT *b;
+        str msg;
+       oid posl, posh;
+
+        if (*(@1 *) low > *(@1 *) hgh)
+                throw(MAL, "crackers.crack_threeUnordered", "illegal range");
+        if ((b = BATdescriptor(*bid)) == NULL)
+                throw(MAL, "crackers.crack_threeUnordered", "Cannot access 
descriptor");
+
+        /* set bounds for the iterator */
+        /*if( sizeof(struct SCRATCH{ oid hdummy; @1 tdummy; } ) != BUNsize(b) )
+                throw(MAL, "crackers.crack_threeUnordered", "Need more clever 
mapping ");
+       */
+        msg = CRKcrackUnorderedThreeParallel_LO_RE_@1( b, *low, *hgh, 0, 
BATcount(b)-1,&posl, &posh);
+
+        BBPkeepref(b->batCacheid);
+        *res = *bid;
+        return msg;
+}
+@
+ * @- Functions shared within the crackers module/library
+@= crackInTwoUnorderedPieces_impl
+str
+CRKcrackUnorderedZeroParallel_@2_@1( BAT *b, @1 mval, BUN first, BUN last, oid 
*pos){
+        @1  *ft, *lt, *t0;
+       oid *fh, *lh;
+        oid hdummy;
+        @1 tdummy;
+       
+
+        /* set bounds for the iterator */
+        t0 = (@1 *)Tloc(b, BUNfirst(b));
+        ft = (@1 *)Tloc(b, BUNfirst(b) + first);
+        lt = (@1 *)Tloc(b, BUNfirst(b) + last);
+        fh = (oid*)Hloc(b, BUNfirst(b) + first);
+        lh = (oid*)Hloc(b, BUNfirst(b) + last);
+
+        while(ft<lt) {
+                if (@5_@3(ft, &mval,@6@1)){
+                        ft++; fh++;
+               }
+                else {
+                        while( @5_@4(lt, &mval,@6@1) && lt>ft){
+                                lt--; lh--;
+                       }
+                        @:shuffle(@1,ft,lt,fh,lh)@
+                        lt--;lh--;
+                        ft++;fh++;
+                }
+        }
+
+       if (lt == ft) {
+               if (@5_@4(lt, &mval,@6@1)){
+                       if (lt==t0) 
+                               *pos = (oid) BUNfirst(b);
+                       else    
+                               *pos = (oid) (lt - t0) - 1; /*works for empty 
left piece also*/
+               }
+               else{
+                       *pos = (oid) (lt - t0); 
+                       if (*pos==last) /*empty right piece*/
+                               *pos = *pos + 1;
+               }
+       }
+       else{
+               if (lt > t0)
+                       *pos = (oid) (lt - t0);
+               else
+                       *pos = (oid) BUNfirst(b);
+       }               
+               
+        return MAL_SUCCEED;
+}
+
+str
+CRKscanUnorderedZeroParallel_@2_@1(BAT *b, @1 *temp_array, @1 *mval, oid 
first, oid last, int nthreads, int *data_less, int *data_greater){
+
+       int i;
+       oid partition_elements;
+       oid *lh;
+        thread_data_t *data;
+
+        pthread_t **thread = (pthread_t **) malloc (sizeof(pthread_t *) * 
nthreads);
+        for (i = 0; i < nthreads; i++)
+                thread[i] = (pthread_t *) malloc (sizeof(pthread_t));
+
+        data = malloc (nthreads * sizeof(thread_data_t));
+
+        lh = (oid*)Hloc(b, BUNfirst(b) + last);
+
+        partition_elements=(last-first+1)/nthreads;
+        for (i = 0; i < nthreads; i++) {
+               data[i].array = b;
+                data[i].temp_array = temp_array;
_______________________________________________
checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list

Reply via email to