Changeset: 5e6005a8c257 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=5e6005a8c257
Added Files:
monetdb5/scheduler/mut_pack.c
monetdb5/scheduler/mut_pack.h
Modified Files:
monetdb5/scheduler/Makefile.ag
monetdb5/scheduler/mut_aggr.c
monetdb5/scheduler/mut_join.c
monetdb5/scheduler/mut_leftjoin.c
monetdb5/scheduler/mut_select.c
monetdb5/scheduler/run_multicore.c
Branch: mutation
Log Message:
Minor typos and new code
Added the alternative solution to mat.pack,
strictly running on a double pass over the code base.
(incomplete and untested)
diffs (273 lines):
diff --git a/monetdb5/scheduler/Makefile.ag b/monetdb5/scheduler/Makefile.ag
--- a/monetdb5/scheduler/Makefile.ag
+++ b/monetdb5/scheduler/Makefile.ag
@@ -36,6 +36,7 @@ lib_scheduler = {
mut_join.c mut_join.h \
mut_leftjoin.c mut_leftjoin.h \
mut_aggr.c mut_aggr.h \
+ mut_pack.c mut_pack.h \
mut_matpack.c mut_matpack.h \
mut_policy.c mut_policy.h \
run_memo.c run_memo.h \
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
@@ -41,8 +41,7 @@ mutationSum(Client cntxt, Mutant m){
if ( newMalBlkStmt(m->src, m->src->ssize) < 0)
return;
- pushInstruction(m->src, old[0]);
- for (i = 1; i < limit; i++) {
+ for (i = 0; i < limit; i++) {
p= old[i];
if ( i == pc){
/* replace the instruction, e.g. with a partioned one */
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
@@ -85,8 +85,7 @@ mutationJoin(Client cntxt, Mutant m){
if ( newMalBlkStmt(m->src, m->src->ssize) < 0)
return;
- pushInstruction(m->src, old[0]);
- for (i = 1; i < limit; i++) {
+ for (i = 0; i < limit; i++) {
p= old[i];
if ( i == pc){
if ( m->stk->stksize < m->src->vtop + 7){
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
@@ -76,8 +76,7 @@ mutationLeftFetchJoin(Client cntxt, Muta
if ( newMalBlkStmt(m->src, m->src->ssize) < 0)
return;
- pushInstruction(m->src, old[0]);
- for (i = 1; i < limit; i++) {
+ for (i = 0; i < limit; i++) {
p= old[i];
if ( i == pc){
if ( m->stk->stksize < m->src->vtop + 7){
diff --git a/monetdb5/scheduler/mut_pack.c b/monetdb5/scheduler/mut_pack.c
new file mode 100644
--- /dev/null
+++ b/monetdb5/scheduler/mut_pack.c
@@ -0,0 +1,149 @@
+/*
+ * The contents of this file are subject to the MonetDB Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.monetdb.org/Legal/MonetDBLicense
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * The Original Code is the MonetDB Database System.
+ *
+ * The Initial Developer of the Original Code is CWI.
+ * Portions created by CWI are Copyright (C) 1997-July 2008 CWI.
+ * Copyright August 2008-2013 MonetDB B.V.
+ * All Rights Reserved.
+ */
+
+/*
+ * (c) 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_pack.h"
+#include "mut_util.h"
+#include "opt_prelude.h"
+
+/*
+ * A mat.pack propagation aims at simply replacing the pack with the next
+ * instruction. If that instruction happens to be a bat.partition, it has
+ * to be removed first.
+ */
+
+static int
+getArgPos(InstrPtr p, int var)
+{
+ int i;
+ for ( i=0; i<p->argc; i++)
+ if ( getArg(p,0) == var)
+ return i;
+ return -1;
+}
+
+static int
+validswitch(InstrPtr p, InstrPtr q)
+{
+ int i,j;
+ if ( p->barrier || q->barrier ||
+ hasSideEffects(p,TRUE) || hasSideEffects(q,TRUE))
+ return 0;
+ // check for flow dependency
+ for( i = 0; i< p->retc; i++)
+ for( j = q->retc; j<q->argc; j++)
+ if( getArg(p,i) == getArg(q,j))
+ return 0;
+ return 1;
+}
+
+void
+mutationPack(Client cntxt, Mutant m){
+ int pc = m->target, i, j, mvar, svar, dvar, limit;
+ InstrPtr p=0, *old= m->src->stmt, q, qq, newpack = 0;
+ //int profiler=0;
+
+ (void) cntxt;
+ limit= m->src->stop;
+ if ( newMalBlkStmt(m->src, m->src->ssize) < 0)
+ return;
+
+ // first phase, see if we need to undo a bat.partition
+ svar = -1; mvar = -1; dvar = -1;
+ for (j = i = 0; i < limit; i++) {
+ p= old[i];
+ if ( i == pc){
+ if ( m->stk->stksize < m->src->vtop + p->argc){
+ old[j++] = p;
+ continue;
+ }
+ mvar = getArg(p,0);
+
+ // move ahead to first candidate for consolidation
+ j= i;
+ for(i++ ; i < limit && validswitch(old[pc],old[i]); i++)
+ old[j++]= old[i];
+ q = old[i];
+
+ if (getModuleId(q) == batRef && getFunctionId(q) ==
partitionRef && getArgPos(p,mvar) >=0){
+ // we found a partition to be removed
+ svar = getArg(q,0);
+ freeInstruction(p);
+ } else old[j++] = q;
+ newpack = p;
+ qq = q;
+ m->comment = GDKstrdup("mutationPack");
+ } else
+ // rollback all but one partitioned instruction
+ if (svar >= 0 && getArgPos(p,mvar) >= 0){
+ if (dvar == -1){
+ getArg(p, getArgPos(p,svar)) = mvar;
+ dvar = getArg(p,0);
+ old[j++] = p;
+ } else
+ freeInstruction(p);
+ } else
+ old[j++] = p;
+ }
+ limit = j;
+
+ DEBUG_MULTICORE {
+ mnstr_printf(cntxt->fdout,"#mutationPack mvar %d svar %d dvar
%d leftover %d\n", mvar,svar,dvar,limit);
+ for( i= 0; i< limit; i++)
+ printInstruction(cntxt->fdout, m->src, m->stk, old[i],
LIST_MAL_ALL);
+ }
+
+ // second phase, replace matpack with its successor
+ for (i = 0; i < limit; i++) {
+ p= old[i];
+ //profiler = m->src->profiler[i].trace;
+
+ if (qq == p && newpack && getArgPos(p, mvar) >=0 )
+ {
+ if ( getModuleId(q) == algebraRef)
+ {
+ if (getFunctionId(q) == joinRef ||
getFunctionId(q)== leftjoinRef || getFunctionId(q) == selectRef){
+ for( j= newpack->retc; j
<newpack->argc; j++){
+ qq= copyInstruction(q);
+ getArg(qq,getArgPos(qq,svar)) =
getArg(newpack,j);
+ getArg(qq,0) =
newTmpVariable(m->src, getArgType(m->src, qq,0));
+ getArg(newpack,j)= getArg(qq,0);
+ pushInstruction(m->src,qq);
+ }
+ freeInstruction(q);
+ pushInstruction(m->src,newpack);
+ newpack = 0;
+ continue;
+ }
+ }
+ }
+ if ( qq == p){
+ // handle non-partitioned operators
+ if (getFunctionId(q) == joinRef || getFunctionId(q)==
leftjoinRef || getFunctionId(q) == selectRef){
+ }
+ } else
+ pushInstruction(m->src,p);
+ }
+ GDKfree(old);
+}
diff --git a/monetdb5/scheduler/mut_pack.h b/monetdb5/scheduler/mut_pack.h
new file mode 100644
--- /dev/null
+++ b/monetdb5/scheduler/mut_pack.h
@@ -0,0 +1,30 @@
+/*
+ * The contents of this file are subject to the MonetDB Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.monetdb.org/Legal/MonetDBLicense
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * The Original Code is the MonetDB Database System.
+ *
+ * The Initial Developer of the Original Code is CWI.
+ * Portions created by CWI are Copyright (C) 1997-July 2008 CWI.
+ * Copyright August 2008-2013 MonetDB B.V.
+ * All Rights Reserved.
+ */
+
+#ifndef _MUT_PACK_
+#define _MUT_PACK_
+#include "mal.h"
+#include "mal_instruction.h"
+#include "mal_interpreter.h"
+#include "run_multicore.h"
+
+run_multicore_export void mutationPack(Client cntxt, Mutant m);
+
+#endif /* _MUT_PACK_ */
+
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
@@ -84,8 +84,7 @@ mutationSelect(Client cntxt, Mutant m){
return;
assert( m->src->profiler);
- pushInstruction(m->src, old[0]);
- for (i = 1; i < limit; i++) {
+ for (i = 0; i < limit; i++) {
p= old[i];
if ( i == pc){
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
@@ -78,12 +78,11 @@ RUNmulticore(Client cntxt, MalBlkPtr mb,
mutant->credit = 1;
mutant->debit = 0;
mutant->baseDebit = 0;
- } else {
- if( mutant->next) {
- mutant->serialExecTime = mutant->next->serialExecTime;
- MUTupdateGlobalMin(mutant);
- MUTupdateRateOfFall(cntxt, mutant);
- }
+ } else
+ if( mutant->next) {
+ mutant->serialExecTime = mutant->next->serialExecTime;
+ MUTupdateGlobalMin(mutant);
+ MUTupdateRateOfFall(cntxt, mutant);
}
DEBUG_PRINT_TIME
_______________________________________________
checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list