Changeset: 4516bd2b02ba for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=4516bd2b02ba
Added Files:
        monetdb5/scheduler/Tests/matpack04.mal
Modified Files:
        monetdb5/scheduler/mut_aggr.c
        monetdb5/scheduler/mut_aggr.h
        monetdb5/scheduler/mut_join.c
        monetdb5/scheduler/mut_join.h
        monetdb5/scheduler/mut_leftjoin.c
        monetdb5/scheduler/mut_leftjoin.h
        monetdb5/scheduler/mut_pack.c
        monetdb5/scheduler/mut_pack.h
        monetdb5/scheduler/mut_policy.c
        monetdb5/scheduler/mut_policy.h
        monetdb5/scheduler/mut_select.c
        monetdb5/scheduler/mut_select.h
        monetdb5/scheduler/mut_util.c
        monetdb5/scheduler/run_multicore.c
        monetdb5/scheduler/run_multicore.h
Branch: mutation
Log Message:

Retry when mutation fails
Introduce framework to select slower targets
when the best is not feasible.


diffs (truncated from 501 to 300 lines):

diff --git a/monetdb5/scheduler/Tests/matpack04.mal 
b/monetdb5/scheduler/Tests/matpack04.mal
new file mode 100644
--- /dev/null
+++ b/monetdb5/scheduler/Tests/matpack04.mal
@@ -0,0 +1,55 @@
+# example framework to obtain insight in behavior of
+# a single MAL primitive
+
+function initialize{unsafe}(limit:lng):bat[:oid,:lng];
+       b:= bat.new(:oid,:lng);
+
+       r:= mmath.srand(0);
+       barrier i:= 0:lng;
+               k:= mmath.rand();
+               l:= calc.lng(k);
+               bat.append(b,l);
+               redo i:= iterator.next(1:lng,limit);
+       exit i;
+       return b;
+end initialize;
+
+function query(b:bat[:oid,:lng],c:bat[:oid,:lng],d:bat[:oid,:lng]):lng;
+       t0:= alarm.usec();
+       z:= bat.new(:oid,:lng);
+       m:= mat.pack(c,c,d);
+       b1:= bat.partition(m,2,0);
+       b2:= bat.partition(m,2,1);
+       (s1,v1):= algebra.join(b1,z);
+       (s2,v2):= algebra.join(b2,z);
+       s:= mat.pack(s1,s2);
+       t:= mat.pack(v1,v2);
+       t1:= alarm.usec();
+       return query := t1-t0;
+end query;
+
+optimizer.multicore("user","query");
+function testrun(limit:lng);
+       t0:= alarm.usec();
+       b:= initialize(limit);
+       bat.setReadMode(b);
+       t1:= alarm.usec();
+       t1:= t1-t0;
+       max:= aggr.max(b);
+       min:= aggr.min(b);
+       step := max-min;
+       step := step/10;
+       io.printf(" max %d min %d step %d\n",max,min,step);
+
+       barrier i:=0;
+               t2:= user.query(b,b,b);
+               mdb.list("user","query");
+               io.printf("#run %d %d %d\n",limit,i,t2);
+               redo i:= iterator.next(1,8);
+       exit i;
+
+end testrun;
+
+# runs based on sizes
+testrun(100000:lng);   #400K
+#testrun(1000000:lng);  #4MB
diff --git a/monetdb5/scheduler/mut_aggr.c b/monetdb5/scheduler/mut_aggr.c
--- a/monetdb5/scheduler/mut_aggr.c
+++ b/monetdb5/scheduler/mut_aggr.c
@@ -31,25 +31,27 @@
 /* Sample plan mutation actions
  * The aggr.sum operation performs parallel sums and consolidates the result
  */
-void 
+int 
 mutationSum(Client cntxt, Mutant m){
-    int pc = m->target, i, limit;
+    int pc = m->target, i, limit, modified=0;
     InstrPtr p=0, *old= m->src->stmt;
 
        (void) cntxt;
     limit= m->src->stop;
     if ( newMalBlkStmt(m->src, m->src->ssize) < 0)
-        return;
+        return -1;
 
     for (i = 0; i < limit; i++) {
         p= old[i];
                if ( i == pc){
                        /* replace the instruction, e.g. with a partioned one */
                        pushInstruction(m->src,p);
+                       modified++;
                        m->comment = GDKstrdup("mutationSum");
                } else
                        pushInstruction(m->src,p);
        }
     GDKfree(old);
+       return modified;
 }
 
diff --git a/monetdb5/scheduler/mut_aggr.h b/monetdb5/scheduler/mut_aggr.h
--- a/monetdb5/scheduler/mut_aggr.h
+++ b/monetdb5/scheduler/mut_aggr.h
@@ -23,7 +23,7 @@
 #include "mal_interpreter.h"
 #include "run_multicore.h"
 
-run_multicore_export void mutationSum(Client cntxt, Mutant m);
+run_multicore_export int mutationSum(Client cntxt, Mutant m);
 
 
 #endif /* _MUT_AGGR_ */
diff --git a/monetdb5/scheduler/mut_join.c b/monetdb5/scheduler/mut_join.c
--- a/monetdb5/scheduler/mut_join.c
+++ b/monetdb5/scheduler/mut_join.c
@@ -73,16 +73,16 @@ mutationJoin_(MalBlkPtr mb, MalStkPtr st
        mb->profiler[mb->stop-1].trace = profiler;
 }
 
-void 
+int 
 mutationJoin(Client cntxt, Mutant m){
     int pc = m->target, i, limit, v1,v2, z1,z2;
     InstrPtr p=0, *old= m->src->stmt, q;
-    int profiler, arg;
+    int profiler, arg, modified=0;
 
     (void) cntxt;
     limit= m->src->stop;
     if ( newMalBlkStmt(m->src, m->src->ssize) < 0)
-        return;
+        return -1;
 
     for (i = 0; i < limit; i++) {
         p= old[i];
@@ -103,8 +103,10 @@ mutationJoin(Client cntxt, Mutant m){
                        q = pushArgument(m->src,q,getArg(p,arg));
                        m->src->profiler[m->src->stop-1].trace = profiler;
                        m->comment = GDKstrdup("mutationJoin");
+                       modified++;
                } else
                        pushInstruction(m->src,p);
        }
     GDKfree(old);
+       return modified;
 }
diff --git a/monetdb5/scheduler/mut_join.h b/monetdb5/scheduler/mut_join.h
--- a/monetdb5/scheduler/mut_join.h
+++ b/monetdb5/scheduler/mut_join.h
@@ -24,7 +24,7 @@
 #include "mal_client.h"
 #include "run_multicore.h"
 
-run_multicore_export void mutationJoin(Client cntxt, Mutant m);
+run_multicore_export int mutationJoin(Client cntxt, Mutant m);
 
 #endif /* _MUT_JOIN_ */
 
diff --git a/monetdb5/scheduler/mut_leftjoin.c 
b/monetdb5/scheduler/mut_leftjoin.c
--- a/monetdb5/scheduler/mut_leftjoin.c
+++ b/monetdb5/scheduler/mut_leftjoin.c
@@ -64,17 +64,17 @@ mutationLeftFetchJoin_(MalBlkPtr mb, Mal
        return getArg(q,0);
 }
 
-void 
+int 
 mutationLeftFetchJoin(Client cntxt, Mutant m){
     int pc = m->target, i, limit, v1,v2;
     InstrPtr p=0, *old= m->src->stmt,q;
-    int profiler;
+    int profiler, modified = 0;
       
 
     (void) cntxt;
     limit= m->src->stop;
     if ( newMalBlkStmt(m->src, m->src->ssize) < 0)
-        return;
+        return -1;
 
     for (i = 0; i < limit; i++) {
         p= old[i];
@@ -92,11 +92,11 @@ mutationLeftFetchJoin(Client cntxt, Muta
                        q= newStmt(m->src, languageRef, passRef);
                        q = pushArgument(m->src,q,getArg(p,p->retc));
                        m->src->profiler[m->src->stop-1].trace = profiler;
-                       
+                       modified++;
                        m->comment = GDKstrdup("mutationLeftFetchJoin");
                } else
                        pushInstruction(m->src,p);
        }
     GDKfree(old);
+       return modified;
 }
-
diff --git a/monetdb5/scheduler/mut_leftjoin.h 
b/monetdb5/scheduler/mut_leftjoin.h
--- a/monetdb5/scheduler/mut_leftjoin.h
+++ b/monetdb5/scheduler/mut_leftjoin.h
@@ -25,8 +25,7 @@
 #include "mal_client.h"
 #include "run_multicore.h"
 
-run_multicore_export void mutationLeftFetchJoin(Client cntxt, Mutant m);
-
+run_multicore_export int mutationLeftFetchJoin(Client cntxt, Mutant m);
 
 #endif /* _MUT_LEFTJOIN_ */
 
diff --git a/monetdb5/scheduler/mut_pack.c b/monetdb5/scheduler/mut_pack.c
--- a/monetdb5/scheduler/mut_pack.c
+++ b/monetdb5/scheduler/mut_pack.c
@@ -58,12 +58,12 @@ validswitch(InstrPtr p, InstrPtr q)
        return 1;
 }
 
-void 
+int 
 mutationPack(Client cntxt, Mutant m){
        MalBlkPtr mb = m->src;
     int pc = m->target, i, j, mvar, limit, packpc=0;
     InstrPtr p=0, *old= mb->stmt, q, newpack = 0, newpack1=0, newpack2 = 0;
-       int profiler=0;
+       int profiler=0, modified= 0;
 
        DEBUG_MULTICORE {
                mnstr_printf(cntxt->fdout,"#MUTATIONPACK\n");
@@ -72,7 +72,7 @@ mutationPack(Client cntxt, Mutant m){
     (void) cntxt;
     limit= mb->stop;
     if ( newMalBlkStmt(mb, mb->ssize) < 0)
-        return;
+        return -1;
        pushInstruction(mb,old[0]);//needed for debugging
 
        // first phase, see if we need to undo a bat.partition
@@ -123,6 +123,7 @@ mutationPack(Client cntxt, Mutant m){
                                }
                                packpc = 0;
                                newpack = 0;
+                               modified++;
                        } 
                        m->comment = GDKstrdup("mutationPack");
                } 
@@ -171,6 +172,7 @@ mutationPack(Client cntxt, Mutant m){
                                                pushInstruction(mb, newpack2);
                                        newpack1 = 0;
                                        newpack2 = 0;
+                                       modified++;
                                        continue;
                                } 
                        }
@@ -182,6 +184,8 @@ mutationPack(Client cntxt, Mutant m){
        if ( packpc == i )
                pushInstruction(mb,newpack);
        DEBUG_MULTICORE
+       if( modified)
                printFunction(cntxt->fdout, mb, 0, LIST_MAL_ALL);
     GDKfree(old);
+       return modified;
 }
diff --git a/monetdb5/scheduler/mut_pack.h b/monetdb5/scheduler/mut_pack.h
--- a/monetdb5/scheduler/mut_pack.h
+++ b/monetdb5/scheduler/mut_pack.h
@@ -24,7 +24,7 @@
 #include "mal_interpreter.h"
 #include "run_multicore.h"
 
-run_multicore_export void mutationPack(Client cntxt, Mutant m);
+run_multicore_export int mutationPack(Client cntxt, Mutant m);
 
 #endif /* _MUT_PACK_ */
 
diff --git a/monetdb5/scheduler/mut_policy.c b/monetdb5/scheduler/mut_policy.c
--- a/monetdb5/scheduler/mut_policy.c
+++ b/monetdb5/scheduler/mut_policy.c
@@ -87,65 +87,79 @@ MUTfindtarget(Client cntxt, Mutant m, in
 static int
 MUTpolicyBaseline(Client cntxt, Mutant m) 
 {
-       MalBlkPtr src = m->src;
-       int i, ssize, target;
+       MalBlkPtr mb = m->src;
+       int i, ssize, target, modified = 0;
+       lng threshold = 0;
        InstrPtr p;
 
-       // Find the most expensive instruction to replace
-       m->target = 0;
-       target = MUTfindtarget(cntxt,m,m->threshold,0);
-       if ( target < 0)
+       do {
+               modified = 0;
+               // Find the next most expensive instruction to replace
+               m->target = 0;
+               target = MUTfindtarget(cntxt,m,m->threshold,threshold);
+               if ( target < 0)
+                       return 0;
+
+               m->target = target;
+               threshold= mb->profiler[target].ticks/mb->calls;
+               p = copyInstruction( getInstrPtr(mb, m->target));
+               DEBUG_MULTICORE{
+                       if ( mb->profiler && m->target) {
+                               mnstr_printf(cntxt->fdout,"#mutation winner %s 
%d calls %d cost "LLFMT"\n", 
+                                       getFunctionId(p),m->target, mb->calls, 
mb->profiler[m->target].ticks/mb->calls);
_______________________________________________
checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list

Reply via email to