Changeset: da41db51ae37 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=da41db51ae37
Modified Files:
monetdb5/mal/mal_recycle.c
monetdb5/scheduler/run_memo.c
Branch: sciql
Log Message:
merged from default
diffs (truncated from 322 to 300 lines):
diff --git a/monetdb5/mal/mal_recycle.c b/monetdb5/mal/mal_recycle.c
--- a/monetdb5/mal/mal_recycle.c
+++ b/monetdb5/mal/mal_recycle.c
@@ -69,6 +69,7 @@
#include "mal_interpreter.h"
#include "mal_function.h"
#include "mal_listing.h"
+#include "mal_runtime.h"
static MT_Lock recycleLock ;
MalBlkPtr recycleBlk = NULL;
diff --git a/monetdb5/scheduler/run_memo.c b/monetdb5/scheduler/run_memo.c
--- a/monetdb5/scheduler/run_memo.c
+++ b/monetdb5/scheduler/run_memo.c
@@ -31,25 +31,25 @@
* The arguments of the second dictate which instructions to consider
* for cost evaluation.
* @example
- * ...
- * scheduler.choice("getVolume");
- * T1:= algebra.join(A,B);
- * T2:= algebra.join(B,C);
- * T3:= algebra.join(C,D);
- * scheduler.choice("getVolume",T1,T2,T3);
- * T4:= algebra.join(T1,C);
- * T5:= algebra.join(A,T2);
- * T6:= algebra.join(T2,D);
- * T7:= algebra.join(B,T3);
- * T8:= algebra.join(C,D);
- * scheduler.choice("getVolume",T4,T5,T6,T7,T8);
- * T9:= algebra.join(T4,D);
- * T10:= algebra.join(T5,D);
- * T11:= algebra.join(A,T6);
- * T12:= algebra.join(A,T7);
- * T13:= algebra.join(T1,T8);
- * scheduler.choice("getVolume",T9,T10,T11,T12,T13);
- * answer:= scheduler.pick(T9, T10, T11, T12, T13);
+ * ...
+ * scheduler.choice("getVolume");
+ * T1:= algebra.join(A,B);
+ * T2:= algebra.join(B,C);
+ * T3:= algebra.join(C,D);
+ * scheduler.choice("getVolume",T1,T2,T3);
+ * T4:= algebra.join(T1,C);
+ * T5:= algebra.join(A,T2);
+ * T6:= algebra.join(T2,D);
+ * T7:= algebra.join(B,T3);
+ * T8:= algebra.join(C,D);
+ * scheduler.choice("getVolume",T4,T5,T6,T7,T8);
+ * T9:= algebra.join(T4,D);
+ * T10:= algebra.join(T5,D);
+ * T11:= algebra.join(A,T6);
+ * T12:= algebra.join(A,T7);
+ * T13:= algebra.join(T1,T8);
+ * scheduler.choice("getVolume",T9,T10,T11,T12,T13);
+ * answer:= scheduler.pick(T9, T10, T11, T12, T13);
* @end example
*
* The @code{scheduler.choice()} operator calls a builtin @code{getVolume}
@@ -84,17 +84,17 @@
* part of the plan as well. Then you don't have to
* include a hardwired cost function.
* @example
- * Acost:= aggr.count(A);
- * Bcost:= aggr.count(B);
- * Ccost:= aggr.count(C);
- * T1cost:= Acost+Bcost;
- * T2cost:= Bcost+Ccost;
- * T3cost:= Ccost+Dcost;
- * scheduler.choice(T1cost,T1, T2cost,T2, T3cost,T3);
- * T1:= algebra.join(A,B);
- * T2:= algebra.join(B,C);
- * T3:= algebra.join(C,D);
- * ...
+ * Acost:= aggr.count(A);
+ * Bcost:= aggr.count(B);
+ * Ccost:= aggr.count(C);
+ * T1cost:= Acost+Bcost;
+ * T2cost:= Bcost+Ccost;
+ * T3cost:= Ccost+Dcost;
+ * scheduler.choice(T1cost,T1, T2cost,T2, T3cost,T3);
+ * T1:= algebra.join(A,B);
+ * T2:= algebra.join(B,C);
+ * T3:= algebra.join(C,D);
+ * ...
* @end example
* The current implementation assumes a regular plan
* and unique use of variables.
@@ -106,27 +106,28 @@
*/
#include "monetdb_config.h"
#include "run_memo.h"
+#include "mal_runtime.h"
static void
-propagateNonTarget(MalBlkPtr mb, int pc){
+propagateNonTarget(MalBlkPtr mb, int pc)
+{
int i;
InstrPtr p;
- str scheduler= putName("scheduler",9);
+ str scheduler = putName("scheduler", 9);
- for(; pc< mb->stop; pc++){
- p= getInstrPtr(mb,pc);
- if( getModuleId(p)== scheduler)
+ for (; pc < mb->stop; pc++) {
+ p = getInstrPtr(mb, pc);
+ if (getModuleId(p) == scheduler)
continue;
- for(i=0; i<p->argc; i++)
- if( isVarDisabled(mb,getArg(p,i)) && p->token >=0 )
- p->token = -p->token; /* temporary NOOP */
- if( p->token<0)
- for(i=0; i<p->retc; i++)
- setVarDisabled(mb,getArg(p,i));
+ for (i = 0; i < p->argc; i++)
+ if (isVarDisabled(mb, getArg(p, i)) && p->token >= 0)
+ p->token = -p->token; /* temporary NOOP */
+ if (p->token < 0)
+ for (i = 0; i < p->retc; i++)
+ setVarDisabled(mb, getArg(p, i));
}
}
/*
- * @-
* THe choice operator first searches the next one to identify
* the fragment to be optimized and to gain access to the variables
* without the need to declare them upfront.
@@ -136,127 +137,129 @@ RUNchoice(Client cntxt, MalBlkPtr mb, Ma
{
int target;
lng cost, mincost;
- int i,j,pc;
+ int i, j, pc;
char *nme;
InstrPtr q;
- pc= getPC(mb,p);
- for(i=pc+1; i<mb->stop; i++){
- q= getInstrPtr(mb,i);
- if( getModuleId(p)== getModuleId(q) &&
- getFunctionId(p) == getFunctionId(q)){
- p=q;
+ pc = getPC(mb, p);
+ for (i = pc + 1; i < mb->stop; i++) {
+ q = getInstrPtr(mb, i);
+ if (getModuleId(p) == getModuleId(q) &&
+ getFunctionId(p) == getFunctionId(q)) {
+ p = q;
break;
}
}
- if( i == mb->stop)
+ if (i == mb->stop)
return MAL_SUCCEED;
- target= getArg(p,2);
- if( getArgType(mb,p,1)== TYPE_int && p->argc>=3 && (p->argc-1)%2 ==0){
+ target = getArg(p, 2);
+ if (getArgType(mb, p, 1) == TYPE_int && p->argc >= 3 && (p->argc - 1) %
2 == 0) {
/* choice pairs */
- mincost= *(int*) getArgReference(stk,p,1);
- for(i=3; i<p->argc; i+= 2){
- cost= *(int*) getArgReference(stk,p,i);
- if( cost <mincost && !isVarDisabled(mb,getArg(p,i+1))){
- mincost= cost;
- target= getArg(p,i+1);
+ mincost = *(int *) getArgReference(stk, p, 1);
+ for (i = 3; i < p->argc; i += 2) {
+ cost = *(int *) getArgReference(stk, p, i);
+ if (cost < mincost && !isVarDisabled(mb, getArg(p, i +
1))) {
+ mincost = cost;
+ target = getArg(p, i + 1);
}
}
- } else
- if( getArgType(mb,p,1)== TYPE_str){
- nme= *(str*) getArgReference(stk,p,1);
+ } else if (getArgType(mb, p, 1) == TYPE_str) {
+ nme = *(str *) getArgReference(stk, p, 1);
/* should be generalized to allow an arbitrary user defined
function */
- if( strcmp(nme,"getVolume")!= 0)
- throw(MAL,"scheduler.choice",ILLEGAL_ARGUMENT "Illegal
cost function");
+ if (strcmp(nme, "getVolume") != 0)
+ throw(MAL, "scheduler.choice", ILLEGAL_ARGUMENT
"Illegal cost function");
- mincost= -1;
- for(j=2;j<p->argc; j++){
- if( !isVarDisabled(mb,getArg(p,j)) )
- for(i= pc+1; i<mb->stop; i++){
- InstrPtr q= getInstrPtr(mb,i);
- if(p->token >=0 && getArg(q,0)== getArg(p,j)){
- cost= getVolume(stk,q,1);
- if( cost>0 && (cost<mincost ||
mincost== -1)){
- mincost= cost;
- target= getArg(p,j);
+ mincost = -1;
+ for (j = 2; j < p->argc; j++) {
+ if (!isVarDisabled(mb, getArg(p, j)))
+ for (i = pc + 1; i < mb->stop; i++) {
+ InstrPtr q = getInstrPtr(mb, i);
+ if (p->token >= 0 && getArg(q, 0) ==
getArg(p, j)) {
+ cost = getVolume(stk, q, 1);
+ if (cost > 0 && (cost < mincost
|| mincost == -1)) {
+ mincost = cost;
+ target = getArg(p, j);
+ }
+ break;
}
- break;
}
- }
+
}
}
#ifdef DEBUG_RUN_MEMORUN
- mnstr_printf(cntxt->fdout,"#function target %s cost
%d\n",getVarName(mb,target),mincost);
+ mnstr_printf(cntxt->fdout, "#function target %s cost %d\n",
getVarName(mb, target), mincost);
#else
(void) cntxt;
#endif
/* remove non-qualifying variables */
- for(i=2; i<p->argc; i+= 2)
- if( getArg(p,i) != target){
- setVarDisabled(mb,getArg(p,i-1));
- setVarDisabled(mb,getArg(p,i));
+ for (i = 2; i < p->argc; i += 2)
+ if (getArg(p, i) != target) {
+ setVarDisabled(mb, getArg(p, i - 1));
+ setVarDisabled(mb, getArg(p, i));
}
- propagateNonTarget(mb,pc+1);
+
+ propagateNonTarget(mb, pc + 1);
#ifdef DEBUG_RUN_MEMORUN
- mnstr_printf(cntxt->fdout,"#cost choice selected %s %d\n",
- getVarName(mb,target),mincost);
- printFunction(cntxt->fdout,mb,1);
+ mnstr_printf(cntxt->fdout, "#cost choice selected %s %d\n",
+ getVarName(mb, target), mincost);
+ printFunction(cntxt->fdout, mb, 1);
#endif
return MAL_SUCCEED;
}
/*
- * @-
* At the end of the query plan we save the result in
* a separate variable.
*/
str
RUNpickResult(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr p)
{
- ValPtr lhs,rhs;
+ ValPtr lhs, rhs;
int i;
(void) cntxt;
- lhs= &stk->stk[getArg(p,0)];
- for(i=p->retc; i<p->argc; i++)
- if( !isVarDisabled(mb,getArg(p,i))){
- rhs= &stk->stk[getArg(p,i)];
- if( (rhs)->vtype < TYPE_str)
+ lhs = &stk->stk[getArg(p, 0)];
+ for (i = p->retc; i < p->argc; i++)
+ if (!isVarDisabled(mb, getArg(p, i))) {
+ rhs = &stk->stk[getArg(p, i)];
+ if ((rhs)->vtype < TYPE_str)
*lhs = *rhs;
- else VALcopy(lhs,rhs);
- if( lhs->vtype == TYPE_bat)
+ else
+ VALcopy(lhs, rhs);
+ if (lhs->vtype == TYPE_bat)
BBPincref(lhs->val.bval, TRUE);
return MAL_SUCCEED;
}
- throw(MAL,"scheduler.pick", OPERATION_FAILED "No result available");
+
+ throw(MAL, "scheduler.pick", OPERATION_FAILED "No result available");
}
/*
- * @-
* The routine below calculates a cost based on the BAT volume in bytes.
* The MAL compiler ensures that all arguments have been
* assigned a value.
*/
str
-RUNvolumeCost(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr p){
- lng *cost= (lng*) getArgReference(stk,p,0);
+RUNvolumeCost(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr p)
+{
+ lng *cost = (lng *) getArgReference(stk, p, 0);
(void) mb;
(void) cntxt;
- *cost = getVolume(stk,p,0); /* calculate total input size */
+ *cost = getVolume(stk, p, 0); /* calculate total input size */
return MAL_SUCCEED;
}
/*
_______________________________________________
Checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list