Changeset: 6e3b194739fd for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=6e3b194739fd
Modified Files:
monetdb5/optimizer/opt_mutation.c
monetdb5/scheduler/Tests/mutation00.mal
monetdb5/scheduler/Tests/mutation01.mal
monetdb5/scheduler/Tests/query00.mal
monetdb5/scheduler/mut_transforms.c
monetdb5/scheduler/run_mutation.c
monetdb5/scheduler/run_mutation.h
monetdb5/scheduler/run_mutation.mal
Branch: mutation
Log Message:
Replace dataflow by mutation
Overlaying the dataflow block with the mutation scheduler
provides the easiest way to exploit it in complex SQL queries.
The main issue to keep in mind is that the runtime stack
delivered for parallel execution should be updated/initialized
with the newly introduced partition arguments.
diffs (276 lines):
diff --git a/monetdb5/optimizer/opt_mutation.c
b/monetdb5/optimizer/opt_mutation.c
--- a/monetdb5/optimizer/opt_mutation.c
+++ b/monetdb5/optimizer/opt_mutation.c
@@ -38,9 +38,14 @@ OPTmutationImplementation(Client cntxt,
return 0;
pushInstruction(mb, old[0]);
- (void) newStmt(mb,schedulerRef, mutationRef);
- for (i = 1; i < limit; i++)
+
+ for (i = 1; i < limit; i++) {
+ if ( getModuleId(old[i]) == languageRef &&
getFunctionId(old[i]) == dataflowRef){
+ setModuleId(old[i], schedulerRef);
+ setFunctionId(old[i], mutationRef);
+ }
pushInstruction(mb,old[i]);
+ }
for(; i<slimit; i++)
if( old[i])
freeInstruction(old[i]);
diff --git a/monetdb5/scheduler/Tests/mutation00.mal
b/monetdb5/scheduler/Tests/mutation00.mal
--- a/monetdb5/scheduler/Tests/mutation00.mal
+++ b/monetdb5/scheduler/Tests/mutation00.mal
@@ -40,8 +40,9 @@ exit z;
end query;
#multiple calls should produce more parallel plans.
-scheduler.mutation("user","query");
-scheduler.mutation("user","query");
-scheduler.mutation("user","query");
-scheduler.mutation("user","query");
-scheduler.mutation("user","query");
+optimizer.mutation("user","query");
+user.query();
+user.query();
+user.query();
+user.query();
+user.query();
diff --git a/monetdb5/scheduler/Tests/mutation01.mal
b/monetdb5/scheduler/Tests/mutation01.mal
--- a/monetdb5/scheduler/Tests/mutation01.mal
+++ b/monetdb5/scheduler/Tests/mutation01.mal
@@ -39,6 +39,8 @@ exit z;
end query;
#multiple calls should produce more parallel plans.
-scheduler.mutation("user","query");
-scheduler.mutation("user","query");
-scheduler.mutation("user","query");
+optimizer..mutation("user","query");
+user.query();
+user.query();
+user.query();
+
diff --git a/monetdb5/scheduler/Tests/query00.mal
b/monetdb5/scheduler/Tests/query00.mal
--- a/monetdb5/scheduler/Tests/query00.mal
+++ b/monetdb5/scheduler/Tests/query00.mal
@@ -24,7 +24,6 @@ function initialize{unsafe}():bat[:oid,:
end initialize;
function query(b:bat[:oid,:lng]);
- scheduler.mutation();
t0:= alarm.usec();
barrier z:= language.dataflow();
s1 := algebra.subselect(b,1:lng,99:lng,true,false,false);
@@ -37,6 +36,7 @@ exit z;
end query;
b:= initialize();
+optimizer.mutation("user","query");
user.query(b);
user.query(b);
user.query(b);
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
@@ -18,10 +18,9 @@
*/
/*
- * @f run_mutation
- * @a M. Kersten, M. Gawade
- * Run mutated query plans
+ * M. Kersten, M. Gawade
* The infrastructure to adapatively create multi-processor parallel plans.
+ * Be careful in handling the stk, because it is also used by the caller
functions.
*/
#include "monetdb_config.h"
#include "mut_transforms.h"
@@ -60,19 +59,26 @@ mutationSelect(Client cntxt, Mutant m){
Also initialize the corresponding stk, which may
actually
have to be extended.
*/
+ m->stk = (MalStkPtr) GDKrealloc(m->stk,
stackSize(m->src->vtop + 4));
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,1));
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,1));
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 = 0;
q= copyInstruction(p);
getArg(q,1)= b1;
diff --git a/monetdb5/scheduler/run_mutation.c
b/monetdb5/scheduler/run_mutation.c
--- a/monetdb5/scheduler/run_mutation.c
+++ b/monetdb5/scheduler/run_mutation.c
@@ -27,6 +27,7 @@
#include "run_mutation.h"
#include "mal_profiler.h"
#include "opt_prelude.h"
+#include "mal_dataflow.h"
#include "mut_transforms.h"
#include "mut_policy.h"
@@ -39,72 +40,41 @@ mutationPrint(Client cntxt, Mutant m)
mutationPrint(cntxt, m->next);
}
-static void
-RUNtoggleMutation(MalBlkPtr mb)
-{
- int i;
- InstrPtr p;
- for ( i =0; i < mb->stop; i++){
- p = getInstrPtr(mb,i);
- if ( getModuleId(p) == schedulerRef && getFunctionId(p) ==
mutationRef){
- if ( p->token == REMsymbol)
- p->token = PATcall;
- else
- p->token = REMsymbol;
- }
- }
-}
-
-static str
-RUNmutationInternal(Client cntxt, MalStkPtr stk, str modnme, str fcnnme)
+str
+RUNmutation(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
{
Mutant mutant;
- MalBlkPtr src=0;
- Symbol s= 0;
str msg;
lng clk;
+ int *ret = (int*) getArgReference(stk,pci,0);
- DEBUG_MUTATION{
- mnstr_printf(cntxt->fdout,"#mutation %s.%s\n",modnme,fcnnme);
- } else
- (void) cntxt;
-
- s = findSymbol(cntxt->nspace, modnme, fcnnme);
- if (s == NULL || (src= s->def) == NULL)
- throw(MAL, "scheduler.mutation", SEMANTIC_OPERATION_MISSING);
- src = s->def;
+ (void) cntxt;
// if called the first time, just execute the call
- if ( src->calls == 0 || src->runtime == 0){
- initProfiler(src);
+ if ( mb->calls == 0 || mb->runtime == 0){
+ initProfiler(mb);
setFilterAll();
mutant = (Mutant) GDKzalloc(sizeof(struct MUTANT));
- mutant->src = src;
+ mutant->src = mb;
mutant->stk = stk;
- src->mutants = (void*) mutant;
-
- // turn off the scheduler call
- RUNtoggleMutation(src);
+ mb->mutants = (void*) mutant;
clk = GDKusec();
- // assume scheduler call is at line 1
- //msg = runMALsequence(cntxt, src, 2,mutant->src->stop,stk,0,0);
- msg = runMAL(cntxt, src, 0, 0);
+ msg = runMALdataflow(cntxt, mb, getPC(mb,pci), pci->jump, stk);
mutant->calls++;
mutant->runtime += GDKusec()- clk;
// turn on the scheduler call
- RUNtoggleMutation(src);
return msg;
}
// Keep old version in the history
// and collect the mutation arguments
mutant = (Mutant) GDKzalloc(sizeof(struct MUTANT));
- mutant->next = ((Mutant)src->mutants);
- mutant->src = src;
+ mutant->next = ((Mutant)mb->mutants);
+ mutant->src = mb;
mutant->stk = stk;
- ((Mutant) src->mutants)->src = copyMalBlk(src);
- src->mutants = (void *) mutant;
+ ((Mutant) mb->mutants)->src = copyMalBlk(mb);
+ mb->mutants = (void *) mutant;
// Find an expensive instruction to replace
msg = MUTpolicy(cntxt,mutant);
@@ -112,35 +82,10 @@ RUNmutationInternal(Client cntxt, MalStk
/* remove mutation record? */
return msg;
- // turn off the scheduler call
- RUNtoggleMutation(src);
-
clk = GDKusec();
- // assume scheduler call is at line 1
- //msg = runMALsequence(cntxt, src, 2,mutant->src->stop,mutant->stk,0,
0);
- msg = runMAL(cntxt, src, 0, 0);
+ msg = runMALdataflow(cntxt, mb, getPC(mb,pci), pci->jump, mutant->stk);
mutant->runtime += GDKusec()- clk;
- // turn on the scheduler call
- RUNtoggleMutation(src);
+ *ret = 0;
return msg;
}
-
-str
-RUNmutationInline(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr p)
-{
- p = getInstrPtr(mb,0);
-
- (void) stk;
- return RUNmutationInternal(cntxt, 0, getModuleId(p), getFunctionId(p));
-}
-
-str
-RUNmutation(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr p)
-{
- str modnme = *(str*) getArgReference(stk,p,1);
- str fcnnme = *(str*) getArgReference(stk,p,2);
-
- (void) mb;
- return RUNmutationInternal(cntxt,0, modnme,fcnnme);
-}
diff --git a/monetdb5/scheduler/run_mutation.h
b/monetdb5/scheduler/run_mutation.h
--- a/monetdb5/scheduler/run_mutation.h
+++ b/monetdb5/scheduler/run_mutation.h
@@ -50,7 +50,6 @@ typedef struct MUTANT{
} *Mutant;
#define DEBUG_MUTATION if(1)
run_mutation_export str RUNmutation(Client cntxt, MalBlkPtr mb, MalStkPtr stk,
InstrPtr p);
-run_mutation_export str RUNmutationInline(Client cntxt, MalBlkPtr mb,
MalStkPtr stk, InstrPtr p);
run_mutation_export void mutationPrint(Client cntxt, Mutant m);
#endif /* MAL_RUN_MUTATION */
diff --git a/monetdb5/scheduler/run_mutation.mal
b/monetdb5/scheduler/run_mutation.mal
--- a/monetdb5/scheduler/run_mutation.mal
+++ b/monetdb5/scheduler/run_mutation.mal
@@ -15,10 +15,6 @@
# Copyright August 2008-2013 MonetDB B.V.
# All Rights Reserved.
-pattern scheduler.mutation(mod:str, fcn:str)
+pattern scheduler.mutation():bit
address RUNmutation
comment "Generate an adaptive plan and execute it";
-
-pattern scheduler.mutation()
-address RUNmutationInline
-comment "Generate an adaptive plan and execute it";
_______________________________________________
checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list