Changeset: e5765e2ffd41 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=e5765e2ffd41
Modified Files:
        monetdb5/optimizer/opt_prelude.c
        monetdb5/scheduler/mut_pack.c
        monetdb5/scheduler/mut_pack.h
        monetdb5/scheduler/mut_policy.c
        monetdb5/scheduler/mut_select.c
        monetdb5/scheduler/mut_util.c
        monetdb5/scheduler/run_multicore.c
Branch: mutation
Log Message:

Recursively pus mat.pack


diffs (287 lines):

diff --git a/monetdb5/optimizer/opt_prelude.c b/monetdb5/optimizer/opt_prelude.c
--- a/monetdb5/optimizer/opt_prelude.c
+++ b/monetdb5/optimizer/opt_prelude.c
@@ -86,7 +86,7 @@ str tintersectRef;
 str tdiffRef;
 str tinterRef;
 str mergecandRef;
-str mergepack;
+str mergepackRef;
 str intersectcandRef;
 str eqRef;
 str disconnectRef;
@@ -356,7 +356,7 @@ void optimizerInit(void){
                tdiffRef= putName("tdiff",5);
                tinterRef= putName("tinter",6);
                mergecandRef= putName("mergecand",9);
-               mergepack= putName("mergepack",9);
+               mergepackRef= putName("mergepack",9);
                intersectcandRef= putName("intersectcand",13);
                eqRef = putName("==",2);
                disconnectRef= putName("disconnect",10);
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
@@ -26,6 +26,7 @@
 #include "mut_pack.h"
 #include "mut_util.h"
 #include "opt_prelude.h"
+#include "opt_support.h"
 
 /* 
  * A mat.pack propagation aims at simply replacing the pack with the next
@@ -63,6 +64,7 @@ mutationPack(Client cntxt, Mutant m){
        MalBlkPtr mb = m->src;
        MalStkPtr stk= m->stk;
     int pc = m->target, i, j, mvar, limit, packpc=0, pos=0;
+       int newtarget1 = 0, newtarget2= 0;
     InstrPtr p=0, *old= mb->stmt, q, newpack = 0, newpack1=0, newpack2 = 0;
        int profiler=0, modified= 0;
 
@@ -122,9 +124,9 @@ mutationPack(Client cntxt, Mutant m){
                                                q = 
pushArgument(mb,q,newTmpVariable(mb,getArgType(mb,q,0)));
                                                stk->stk[getArg(q,0)].vtype= 
getVarGDKType(mb,getArg(q,0));
                                        }
+                                       packpc = 0;
+                                       newpack = 0;
                                }
-                               packpc = 0;
-                               newpack = 0;
                                modified++;
                        } 
                        m->comment = GDKstrdup("mutationPack");
@@ -173,8 +175,11 @@ mutationPack(Client cntxt, Mutant m){
                                        if ( pos == 2 && getFunctionId(p) == 
subselectRef)
                                                setFunctionId(newpack1, 
putName("mergepack",9));
                                        pushInstruction(mb, newpack1);
-                                       if ( newpack2)
+                                       newtarget1 = mb->stop-1;
+                                       if ( newpack2){
                                                pushInstruction(mb, newpack2);
+                                               newtarget2 = mb->stop-1;
+                                       }
                                        newpack1 = 0;
                                        newpack2 = 0;
                                        modified++;
@@ -195,8 +200,12 @@ mutationPack(Client cntxt, Mutant m){
                                                pushInstruction(mb,q);
                                                mb->profiler[mb->stop-1].trace 
= profiler;
                                        }
-                                       setFunctionId(newpack1, 
putName("mergepack",9));
+                                       if ( getArgType(mb,newpack1,0) == 
TYPE_oid)
+                                               setFunctionId(newpack1, 
putName("mergepack",9));
+                                       else
+                                               setFunctionId(newpack1, 
putName("pack",4));
                                        pushInstruction(mb, newpack1);
+                                       newtarget1 = mb->stop-1;
                                        modified++;
                                        continue;
                        }
@@ -209,6 +218,10 @@ mutationPack(Client cntxt, Mutant m){
                                modified++;
                                continue;
                        }
+                       if ( i  == packpc+1 && newpack){
+                               pushInstruction(mb, newpack);
+                               newpack = 0;
+                       }
                        pushInstruction(mb, p);
                } else 
                if ( newpack && packpc == i-1 && getArgPos(p,mvar) < 0){
@@ -222,5 +235,46 @@ mutationPack(Client cntxt, Mutant m){
        if( newpack)
                freeInstruction(newpack);
     GDKfree(old);
+       mutationMerge(cntxt,m);
+       if ( modified && newtarget1){
+               m->target = newtarget1;
+               mutationPack(cntxt, m);
+               if( newtarget2){
+                       m->target = newtarget2;
+                       mutationPack(cntxt, m);
+               }
+       }
        return modified;
 }
+
+void
+mutationMerge(Client cntxt, Mutant m )
+{
+       int i,j,k,limit;
+       MalBlkPtr mb= m->src;
+       InstrPtr p, q, *old, *pack;
+
+       (void) cntxt;
+       limit = mb->stop;
+       old = mb->stmt;
+    if ( newMalBlkStmt(mb, mb->ssize) < 0)
+        return ;
+       pack = (InstrPtr*) GDKzalloc(mb->vtop * sizeof(InstrPtr));
+       if( pack == NULL)
+               return;
+       for(i = 0; i < limit; i++)
+       if( (p = old[i])){
+               if( getModuleId(p) == matRef  && (getFunctionId(p) == packRef 
|| getFunctionId(p) == mergepackRef) ){
+                       for( j= p->retc; j<p->argc; j++)
+                       if ( (q =pack[getArg(p,j)]) && getFunctionId(p) == 
getFunctionId(q)){
+                               delArgument(p,j);
+                               for( k= q->retc; k< q->argc; k++)
+                                       p= setArgument(mb, p, j, getArg(q,k));
+                       }
+                       pack[getArg(p,0)] = p;
+               }
+               pushInstruction(mb,p);
+       }
+       GDKfree(pack);
+       GDKfree(old);
+}
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
@@ -25,6 +25,7 @@
 #include "run_multicore.h"
 
 run_multicore_export int mutationPack(Client cntxt, Mutant m);
+run_multicore_export void mutationMerge(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
@@ -83,11 +83,13 @@ MUTfindtarget(Client cntxt, Mutant m, in
 
 /*
  * Base line policy is to replace a single, most expensive instruction if you 
can
+
  */
 static int
 MUTpolicyBaseline(Client cntxt, Mutant m) 
 {
        MalBlkPtr mb = m->src;
+
        int i, ssize, target, modified = 0;
        lng threshold = 0;
        InstrPtr p;
@@ -131,7 +133,7 @@ MUTpolicyBaseline(Client cntxt, Mutant m
                if ( getModuleId(p) == aggrRef)
                        modified = mutationSum(cntxt,m);
                else
-               if ( getModuleId(p) == matRef && getFunctionId(p) == packRef)
+               if ( getModuleId(p) == matRef && (getFunctionId(p) == packRef 
|| getFunctionId(p)== mergepackRef))
                                modified = mutationPack(cntxt,m);
                //else
                //if ( getModuleId(p) == sqlRef && ( getFunctionId(p) == 
subdeltaRef || getFunctionId(p) == projectdeltaRef))
@@ -166,7 +168,7 @@ MUTpolicyBaseline(Client cntxt, Mutant m
        chkFlow(cntxt->fdout,mb);
        DEBUG_MULTICORE{
                mnstr_printf(cntxt->fdout,"Final plan to execute, errors 
%d\n",mb->errors);
-               if( mb->errors)
+               //if( mb->errors)
                        printFunction(cntxt->fdout, mb,0,LIST_MAL_ALL);
                mnstr_printf(cntxt->fdout,"\n\n\n");
        }
diff --git a/monetdb5/scheduler/mut_select.c b/monetdb5/scheduler/mut_select.c
--- a/monetdb5/scheduler/mut_select.c
+++ b/monetdb5/scheduler/mut_select.c
@@ -47,16 +47,16 @@
  */
 
 static  int
-mutationSelect_(MalBlkPtr mb, MalStkPtr stk, InstrPtr p, int partitions, int 
slice, int profiler)
+mutationSelect_(MalBlkPtr mb, MalStkPtr stk, InstrPtr p, int arg, int 
partitions, int slice, int profiler)
 {
        int v, b1;
        InstrPtr q;
        
        q= newStmt(mb, batRef, partitionRef);
-       setVarType(mb, getArg(q,0), getArgType(mb, p, p->retc));
+       setVarType(mb, getArg(q,0), getArgType(mb, p, arg));
        stk->stk[getArg(q, 0)].vtype = getVarGDKType(mb, getArg(q,0));
        b1 = getArg(q,0);
-       q = pushArgument(mb,q,getArg(p,1));
+       q = pushArgument(mb,q,getArg(p,arg));
        q = pushInt(mb,q,partitions);
        // update the stack as well, because we are executing
        stk->stk[getArg(q, q->argc-1)].val.ival = partitions;
@@ -66,7 +66,7 @@ mutationSelect_(MalBlkPtr mb, MalStkPtr 
        mb->profiler[mb->stop-1].trace = profiler;
 
        q= copyInstruction(p);
-       getArg(q,1)= b1;
+       getArg(q,arg)= b1;
        v = getArg(q,0)= newTmpVariable(mb,TYPE_any);
        stk->stk[getArg(q,0)].vtype= getVarGDKType(mb,getArg(q,0));
        pushInstruction(mb,q);
@@ -74,25 +74,9 @@ mutationSelect_(MalBlkPtr mb, MalStkPtr 
        return v;
 }
 
-static void
-mutationMergePack(MalBlkPtr mb, int start, int cand)
-{
-       InstrPtr q;
-       int j,k;
-
-       for(j = start; j >0; j--){
-               q= getInstrPtr(mb,j);
-               if ( getFunctionId(q) == packRef && getModuleId(q)== matRef && 
getArg(q,0) == cand){
-                       setFunctionId(q, putName("mergepack",9));
-                       for(k = q->retc; k<q->argc; k++)
-                               mutationMergePack(mb,j-1,getArg(q,k));
-               }
-       }
-}
-
 int 
 mutationSelect(Client cntxt, Mutant m){
-    int pc = m->target, i, limit, v1,v2;
+    int pc = m->target, i, limit, v1,v2,arg;
     InstrPtr p=0, *old= m->src->stmt, q;
        int profiler=0, modified = 0;
 
@@ -104,16 +88,16 @@ mutationSelect(Client cntxt, Mutant m){
     assert( m->src->profiler);
     for (i = 0; i < limit; i++) {
         p= old[i];
-               // check candidate list packing and redo the matpacks
-               if (0  && getModuleId(p) == algebraRef && (getFunctionId(p) == 
subselectRef || getFunctionId(p)== thetasubselectRef) && 
isaBatType(getArgType(m->src,p,2)))
-                       mutationMergePack(m->src,i-1,getArg(p,2));
 
                if ( i == pc){
 
                        profiler = m->src->profiler[i].trace;
+                       // both BAT arguments could be large, so arbitrarely 
split
+                       //arg = 1 + (rand() % 2);
+                       arg=1;
 
-                       v1 = mutationSelect_(m->src, m->stk, p, 2, 0, profiler);
-                       v2 = mutationSelect_(m->src, m->stk, p, 2, 1, profiler);
+                       v1 = mutationSelect_(m->src, m->stk, p, arg, 2, 0, 
profiler);
+                       v2 = mutationSelect_(m->src, m->stk, p, arg, 2, 1, 
profiler);
 
                        q= newStmt(m->src, languageRef, passRef);
                        q = pushArgument(m->src,q,getArg(p, p->retc));
diff --git a/monetdb5/scheduler/mut_util.c b/monetdb5/scheduler/mut_util.c
--- a/monetdb5/scheduler/mut_util.c
+++ b/monetdb5/scheduler/mut_util.c
@@ -189,7 +189,7 @@ mutationPropagate(Mutant m, InstrPtr *ol
        // replace variable use in other mat packs
        for (j = start; j < limit; j++) {
                q= old[j];
-               if ( getModuleId(q) == matRef && getFunctionId(q) == packRef){
+               if ( getModuleId(q) == matRef && (getFunctionId(q) == packRef 
|| getFunctionId(q) == mergepackRef)){
                        for( k= old[j]->retc; k < old[j]->argc; k++)
                                if ( getArg(q,k) == v0){
                                        // replace this argument  by both new 
ones
diff --git a/monetdb5/scheduler/run_multicore.c 
b/monetdb5/scheduler/run_multicore.c
--- a/monetdb5/scheduler/run_multicore.c
+++ b/monetdb5/scheduler/run_multicore.c
@@ -28,6 +28,7 @@
 #include "mal_dataflow.h"
 #include "mut_policy.h"
 #include "mut_util.h"
+#include "mal_stack.h"
 #include "mdb.h"
 
 str
_______________________________________________
checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list

Reply via email to