Changeset: 8ff58e45c317 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=8ff58e45c317
Modified Files:
        monetdb5/scheduler/mut_policy.c
        monetdb5/scheduler/mut_transforms.c
        monetdb5/scheduler/mut_transforms.h
        monetdb5/scheduler/run_multicore.c
Branch: mutation
Log Message:

added join operator mutation and fixed bug in the first call to mutation 
operator mb->runtime==0


diffs (225 lines):

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
@@ -39,6 +39,11 @@ mutationCandidate(MalBlkPtr mb, InstrPtr
                if (getFunctionId(p) == subselectRef)
                        return 1;
        }
+       if ( getModuleId(p) == algebraRef) {
+               if (getFunctionId(p) == joinRef)
+                       return 1;
+       }
+
 /*
        if ( getModuleId(p) == aggrRef){
                return 1;
@@ -70,6 +75,7 @@ MUTpolicy(Client cntxt, Mutant m)
                        continue;
                DEBUG_MULTICORE
                        mnstr_printf(cntxt->fdout,"#mutation candidate %d cost 
"LLFMT"\n", i, src->profiler[i].ticks/src->calls);
+//                     mnstr_printf(GDKstdout,"#mutation candidate %d cost 
"LLFMT"\n", i, src->profiler[i].ticks/src->calls);
 
                if ( m->target == 0)
                        m->target = i;
@@ -77,10 +83,15 @@ MUTpolicy(Client cntxt, Mutant m)
                if ( src->profiler[i].ticks/src->calls > 
src->profiler[m->target].ticks/src->calls)
                        m->target = i;
        }
-       DEBUG_MULTICORE if ( src->profiler && m->target) {
+       DEBUG_MULTICORE 
+               if ( src->profiler && m->target) {
                mnstr_printf(cntxt->fdout,"#mutation calls %d cost "LLFMT"\n", 
src->calls, src->runtime/src->calls);
+//             mnstr_printf(GDKstdout,"#mutation calls %d cost "LLFMT"\n", 
src->calls, src->runtime/src->calls);
+               
                mnstr_printf(cntxt->fdout,"#mutation target instruction %d cost 
"LLFMT"\n", m->target, src->profiler[m->target].ticks/src->calls);
+//             mnstr_printf(GDKstdout,"#mutation target instruction %d cost 
"LLFMT"\n", m->target, src->profiler[m->target].ticks/src->calls);
                
printInstruction(cntxt->fdout,src,0,getInstrPtr(src,m->target),LIST_MAL_ALL);
+//             
printInstruction(GDKstdout,src,0,getInstrPtr(src,m->target),LIST_MAL_ALL);
        }
        /* At this point we have a target instruction to be replaced */
        /* safe the previous version in the history list */
@@ -89,7 +100,13 @@ MUTpolicy(Client cntxt, Mutant m)
 
                /* apply heuristics */
                if ( getModuleId(p) && strncmp(getModuleId(p), "algebra",7)== 0)
-                       mutationSelect(cntxt,m);
+               {
+                       if(getFunctionId(p) == joinRef)
+                               mutationJoin(cntxt,m);
+                       else if(getFunctionId(p) == subselectRef)
+                               mutationSelect(cntxt,m);
+
+               }
                if ( getModuleId(p) && strncmp(getModuleId(p), "aggr",4)== 0)
                        mutationSum(cntxt,m);
 
@@ -107,6 +124,7 @@ MUTpolicy(Client cntxt, Mutant m)
                chkFlow(cntxt->fdout,src);
                DEBUG_MULTICORE
                        printFunction(cntxt->fdout, src,0,LIST_MAL_ALL);
+//                     printFunction(GDKstdout, src,0,LIST_MAL_ALL);
                if ( src->errors)
                        throw(MAL,"run_mutation","Internal error");
        } 
diff --git a/monetdb5/scheduler/mut_transforms.c 
b/monetdb5/scheduler/mut_transforms.c
--- a/monetdb5/scheduler/mut_transforms.c
+++ b/monetdb5/scheduler/mut_transforms.c
@@ -28,11 +28,127 @@
 #include "opt_prelude.h"
 
 /* Sample plan mutation actions
+ * The join mutation simply splits the target instruction
+ * and glues the result using matpack.
+ * If the target is already input to a mat.pack, then we should add
+ * the pieces produced to that instruction instead of making a new mat.pack.
+ */
+
+void 
+mutationJoin(Client cntxt, Mutant m){
+    int pc = m->target, i, j, k, limit, b1,b2, v1,v2, z1,z2, mp;
+    InstrPtr p=0, *old= m->src->stmt, q;
+       int matpc = 0;
+
+       (void) cntxt;
+    limit= m->src->stop;
+    if ( newMalBlkStmt(m->src, m->src->ssize) < 0)
+        return;
+
+    pushInstruction(m->src, old[0]);
+    for (i = 1; i < limit; i++) {
+        p= old[i];
+               if ( i == pc){
+                       /* replace the instruction, e.g. with a partioned one.
+                          Dont use any partition intelligence, simple half 
split
+                          v := algebra.select(b,l,h) =>
+                               b1 := bat.partition(b,2,0);
+                               b2 := bat.partition(b,2,1);
+                               v1,z1:= algebra.join(b1,Y);
+                               v2,z2:= algebra.join(b2,Y);
+                               v:= mat.pack(v1,v2);
+                         Be careful not to change the size of the stack,
+                         for we can not easily pass it back to the 
+                         current interpreter call sequence
+                       */
+                       if ( m->stk->stksize < m->src->vtop + 4){
+                               pushInstruction(m->src,p);
+                               continue;
+                       }
+                       q= newStmt(m->src, batRef, partitionRef);
+                       setVarType(m->src, getArg(q,0), getArgType(m->src, p, 
p->retc));
+                       b1 = getArg(q,0);
+                       q = pushArgument(m->src,q,getArg(p,2));
+                       q = pushInt(m->src,q,2);
+                       // update the stack as well, because we are executing
+                       m->stk->stk[getArg(q, q->argc-1)].val.ival = 2;
+                       q = pushInt(m->src,q,0);
+                       m->stk->stk[getArg(q, q->argc-1)].val.ival = 0;
+
+                       q= newStmt(m->src, batRef, partitionRef);
+                       setVarType(m->src, getArg(q,0), getArgType(m->src, p, 
p->retc));
+                       b2 = getArg(q,0);
+                       q = pushArgument(m->src,q,getArg(p,2));
+                       q = pushInt(m->src,q,2);
+                       // update the stack as well, because we are executing
+                       m->stk->stk[getArg(q, q->argc-1)].val.ival = 2;
+                       q = pushInt(m->src,q,1);
+                       m->stk->stk[getArg(q, q->argc-1)].val.ival = 1;
+
+                       q= copyInstruction(p);
+                       getArg(q,2)= b1;
+                       v1 = getArg(q,0)= newTmpVariable(m->src,TYPE_any);
+                       z1 = getArg(q,1)= newTmpVariable(m->src,TYPE_any);
+                       pushInstruction(m->src,q);
+                       q= copyInstruction(p);
+                       getArg(q,2)= b2;
+                       v2 = getArg(q,0)= newTmpVariable(m->src,TYPE_any);
+                       z2 = getArg(q,1)= newTmpVariable(m->src,TYPE_any);
+                       pushInstruction(m->src,q);
+
+                       (void)z1;
+                       (void)z2;
+
+                       // replace its use in other mat packs
+                       for (j = i+1; j < limit; j++) {
+                               q= old[j];
+                               if ( getModuleId(q) == matRef && 
getFunctionId(q) == packRef){
+                                       for( k= old[j]->retc; k < old[j]->argc; 
k++)
+                                               if ( getArg(q,k) == 
getArg(p,0)){
+                                                       /* replace this 
argument */
+                                                       matpc++;
+                                                       delArgument(old[j],k);
+                                                       old[j] = 
setArgument(m->src,old[j],k, v2);
+                                                       old[j] = 
setArgument(m->src,old[j],k, v1);
+                                               }
+                               }
+                       }
+
+                       if ( matpc == 0){
+                               q= newStmt(m->src,matRef,packRef);
+                               mp= getArg(q,0)= getArg(p,0);
+                               q= pushArgument(m->src,q,v1);
+                               q= pushArgument(m->src,q,v2);
+
+                               (void)mp;
+                       
+                               // getBatSize to verify the size of the join 
bat result
+                               // k1 := bat.getSize(s1);
+                               // io.print(k1);
+//                             q= newStmt(m->src, batRef,getSizeRef);
+//                             k1= getArg(q, 0)= newTmpVariable(m->src, 
TYPE_any);
+//                             q= pushArgument(m->src, q, mp);
+
+//                             q= newStmt(m->src, ioRef, printRef);
+//                             pushArgument(m->src, q, k1);                    
        
+                       }
+
+                       //pushInstruction(m->src,p);
+                       m->target = pc;
+                       m->comment = GDKstrdup("mutationJoin");
+               } else
+                       pushInstruction(m->src,p);
+       }
+    GDKfree(old);
+}
+
+/* Sample plan mutation actions
  * The select mutation simply splits the target instruction
  * and glues the result using matpack.
  * If the target is already input to a mat.pack, then we should add
  * the pieces produced to that instruction instead of making a new mat.pack.
  */
+
 void 
 mutationSelect(Client cntxt, Mutant m){
     int pc = m->target, i, j, k, limit, b1,b2, v1,v2;
diff --git a/monetdb5/scheduler/mut_transforms.h 
b/monetdb5/scheduler/mut_transforms.h
--- a/monetdb5/scheduler/mut_transforms.h
+++ b/monetdb5/scheduler/mut_transforms.h
@@ -25,6 +25,7 @@
 #include "mal_client.h"
 #include "run_multicore.h"
 
+run_multicore_export void mutationJoin(Client cntxt, Mutant m);
 run_multicore_export void mutationSelect(Client cntxt, Mutant m);
 run_multicore_export void mutationSum(Client cntxt, Mutant m);
 
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
@@ -51,7 +51,7 @@ RUNmulticore(Client cntxt, MalBlkPtr mb,
        (void) cntxt;
 
        // if called the first time, just execute the call
-       if ( mb->calls == 0 || mb->runtime == 0){
+       if ( mb->calls == 0) { // || mb->runtime == 0){
                initProfiler(mb);
                setFilterAll();
                mutant = (Mutant) GDKzalloc(sizeof(struct MUTANT));
@@ -63,6 +63,7 @@ RUNmulticore(Client cntxt, MalBlkPtr mb,
                msg = runMALdataflow(cntxt, mb, getPC(mb,pci), stk);
                mutant->calls++;
                mutant->runtime += GDKusec()- clk;
+               mnstr_printf(GDKstdout,"\nEntering the first loop");
                return msg;
        }
        
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
http://mail.monetdb.org/mailman/listinfo/checkin-list

Reply via email to