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

Revamping of the multicore infrastructure


diffs (truncated from 366 to 300 lines):

diff --git a/monetdb5/optimizer/opt_multicore.c 
b/monetdb5/optimizer/opt_multicore.c
--- a/monetdb5/optimizer/opt_multicore.c
+++ b/monetdb5/optimizer/opt_multicore.c
@@ -22,17 +22,13 @@
 
 /* (c) M Kersten
  * Make sure the symbol table has enough slack to accomodate
- * variables used during the call
+ * variables used during the call.
+ * Add the multicore scheduler call at the beginning of the plan.
  */
 
 int 
 OPTmulticoreImplementation(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr 
pci)
 {
-       int i,limit, slimit;
-       InstrPtr *old= mb->stmt;
-        VarPtr *new;
-
-
        (void) cntxt;
        (void) pci;
        (void) stk;             /* to fool compilers */
@@ -40,41 +36,7 @@ OPTmulticoreImplementation(Client cntxt,
        if (varGetProp(mb, getArg(mb->stmt[0], 0), inlineProp) != NULL)
                return 0;
 
-       limit= mb->stop;
-       slimit = mb->ssize;
-
-       if(mb->vsize < 700)
-       {
-               mb->vsize = 700;
-               new = (VarPtr *) GDKzalloc(mb->vsize * sizeof(VarPtr));
-               if (new == NULL) 
-               {
-                        // throw(MAL,"varPtrAlloc","Internal error");
-                       GDKerror("varPtrAlloc:" MAL_MALLOC_FAIL);
-                       return -1;
-               }
-               memcpy((char *) new, (char *) mb->var, sizeof(VarPtr) * 
mb->vtop);
-               GDKfree(mb->var);               
-               mb->var = new;
-       }
-
-       if ( newMalBlkStmt(mb, mb->ssize) < 0)
-               return 0;
-
-       pushInstruction(mb, old[0]);
-
-       for (i = 1; i < limit; i++) {
-               if ( getModuleId(old[i]) == languageRef && 
getFunctionId(old[i]) == dataflowRef){
-                       setModuleId(old[i], schedulerRef);
-                       setFunctionId(old[i], multicoreRef);
-               }
-               pushInstruction(mb,old[i]);
-       }
-       for(; i<slimit; i++)
-               if( old[i])
-                       freeInstruction(old[i]);
-       GDKfree(old);
-       /* resize the symbol table */
-       resizeMalBlk(mb, mb->ssize * 2, mb->vsize * 2);
+       newStmt(mb,schedulerRef,multicoreRef);
+       moveInstruction(mb, mb->stop-1,1);
        return 1;
 }
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
@@ -18,8 +18,8 @@
  */
 
 /*
- * @a M. Kersten, M. Gawade
- * Run mutated query plans
+ * (c) M. Kersten, M. Gawade
+ * Run query plans under a mutation policy
  * The infrastructure to adapatively create multi-processor parallel plans.
  */
 #include "monetdb_config.h"
@@ -33,118 +33,127 @@
  * For the time being we focus on a limited set op MAL instructions.
  */
 static int
-mutationCandidate(MalBlkPtr mb, InstrPtr p){
-       (void) mb;
-       if ( getModuleId(p) == algebraRef) {
-               if (getFunctionId(p) == subselectRef)
-                       return 1;
+mutationCandidate(InstrPtr p){
+       if ( getModuleId(p) == matRef && getFunctionId(p) == packRef)
+               return 1;
+       return ( getModuleId(p) == algebraRef && 
+                       (getFunctionId(p) == subselectRef ||
+                               getFunctionId(p) == joinRef ||
+                               getFunctionId(p) == leftfetchjoinRef));
+}
+
+
+/* find the most expensive operator with threshold<cost<upperbound)
+ * in a parallel MAL block
+*/
+static int
+MUTfindtarget(Mutant m, int threshold, int upperbound)
+{
+       MalBlkPtr src = m->src;
+       int i,target = -1;
+       InstrPtr p;
+       int parblock= FALSE;
+
+       // The mutation call is known to be the second instruction.
+       for ( i = 2; i < src->stop ; i++) {
+               p = getInstrPtr(src,i);
+               if ( p->barrier == EXITsymbol && parblock){
+                       parblock = FALSE;
+                       continue;
+               }
+               if ( getFunctionId(p) == dataflowRef)
+                       parblock = TRUE;
+               // ignore block entry/exit points
+               if ( p->barrier || !parblock || !mutationCandidate(p))
+                       continue;
+
+               if ( src->profiler[i].ticks/src->calls <= threshold ||
+                       (upperbound && src->profiler[i].ticks/src->calls >= 
upperbound))
+                       continue;
+               target = i;
        }
-       if ( getModuleId(p) == algebraRef) {
-               if (getFunctionId(p) == joinRef)
-                       return 1;
-       }
-        if ( getModuleId(p) == algebraRef) {
-                if (getFunctionId(p) == leftfetchjoinRef)
-                        return 1;
-        }
-        if ( getModuleId(p) == matRef) {
-                if (getFunctionId(p) == packRef)
-                        return 1;
-        }
-
-
+       return target;
+}
 
 /*
-       if ( getModuleId(p) == aggrRef){
-               return 1;
+ * Base line policy is to replace a single, most expensive instruction if you 
can
+ */
+static int
+MUTpolicyIntern(Client cntxt, Mutant m) 
+{
+       MalBlkPtr src = m->src;
+       int i, ssize, target;
+       InstrPtr p;
+
+       (void) cntxt;
+
+       // Find the most expensive instruction to replace
+       target = MUTfindtarget(m,MUT_THRESHOLD,0);
+       if ( target < 0)
+               return 0;
+       m->target = target;
+       DEBUG_MULTICORE{
+               mnstr_printf(cntxt->fdout,"#mutation candidate %d cost 
"LLFMT"\n", m->target, src->profiler[m->target].ticks/src->calls);
+               if ( src->profiler && m->target) {
+                       mnstr_printf(cntxt->fdout,"#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);
+                       
printInstruction(cntxt->fdout,src,0,getInstrPtr(src,m->target),LIST_MAL_ALL);
+               }
        }
-*/
-       return 0;
+
+       /* At this point we have a target instruction to be replaced */
+       /* safe the previous version in the history list */
+       p = getInstrPtr(src, m->target);
+       ssize = src->ssize;
+
+       /* apply heuristics */
+       if ( getModuleId(p) && strncmp(getModuleId(p), "algebra",7)== 0)
+       {
+               if(getFunctionId(p) == joinRef)
+//                             mutationJoinDouble(cntxt,m);
+                       mutationJoin(cntxt,m);
+               else if(getFunctionId(p) == subselectRef)
+                       mutationSelect(cntxt,m);
+                                       else if(getFunctionId(p) == 
leftfetchjoinRef)
+                                                       
mutationLeftFetchJoin(cntxt,m);
+               else    // proxy function
+                       mutationJoinDouble(cntxt,m);
+       }
+       if ( getModuleId(p) && strncmp(getModuleId(p), "aggr",4)== 0)
+               mutationSum(cntxt,m);
+               if ( getModuleId(p) && strncmp(getModuleId(p), "mat",3)== 0)
+                       if(getFunctionId(p) == packRef)
+                               mutationMatPack(cntxt,m);
+
+       /* reset/expand the profiler */
+       if (ssize < src->ssize){
+               DEBUG_MULTICORE
+                       mnstr_printf(cntxt->fdout, "# \n Changed the size of 
stack");
+               GDKfree(src->profiler);
+               src->profiler = 0;
+               initProfiler(src);
+               for( i = 0; i < src->stop; i++)
+                       src->profiler[i].ticks = 0;
+       }
+
+       src->calls = 0;
+       chkProgram(cntxt->fdout,cntxt->nspace,src);
+       chkFlow(cntxt->fdout,src);
+       DEBUG_MULTICORE
+               printFunction(cntxt->fdout, src,0,LIST_MAL_ALL);
+       if ( src->errors)
+               return -1;
+       return 1;
 }
 
-
 str
 MUTpolicy(Client cntxt, Mutant m) 
 {
-       MalBlkPtr src = m->src;
-       int i, ssize;
-       InstrPtr p;
-
-       (void) cntxt;
-
+       int r;
+       /* we take a single mutation attempt, later to be adjusted */
        m->target = 0;
-       // Find an expensive instruction to replace
-       if ( src->profiler && src->calls)
-       for ( i = 2; i < src->stop ; i++) {
-               p = getInstrPtr(src,i);
-               if ( p->barrier)
-                       continue;       // ignore block structures
-               if ( !mutationCandidate(src, p))
-                       continue;
-               if ( src->profiler[i].ticks/src->calls <= MUT_THRESHOLD)
-                       continue;
-       
-
-               DEBUG_MULTICORE
-                       mnstr_printf(cntxt->fdout,"#mutation candidate %d cost 
"LLFMT"\n", i, src->profiler[i].ticks/src->calls);
-
-               if ( m->target == 0)
-                       m->target = i;
-               else
-               if ( src->profiler[i].ticks/src->calls > 
src->profiler[m->target].ticks/src->calls)
-                       m->target = i;
-       }
-               
-       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(cntxt->fdout,"#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);
-       }
-       /* At this point we have a target instruction to be replaced */
-       /* safe the previous version in the history list */
-       if ( mutationCandidate(src,  p = getInstrPtr(src, m->target)) ){
-               ssize = src->ssize;
-
-               /* apply heuristics */
-               if ( getModuleId(p) && strncmp(getModuleId(p), "algebra",7)== 0)
-               {
-                       if(getFunctionId(p) == joinRef)
-//                             mutationJoinDouble(cntxt,m);
-                               mutationJoin(cntxt,m);
-                       else if(getFunctionId(p) == subselectRef)
-                               mutationSelect(cntxt,m);
-                        else if(getFunctionId(p) == leftfetchjoinRef)
-                                mutationLeftFetchJoin(cntxt,m);
-                       else    // proxy function
-                               mutationJoinDouble(cntxt,m);
-               }
-               if ( getModuleId(p) && strncmp(getModuleId(p), "aggr",4)== 0)
-                       mutationSum(cntxt,m);
-               if ( getModuleId(p) && strncmp(getModuleId(p), "mat",3)== 0)
-                       if(getFunctionId(p) == packRef)
-                               mutationMatPack(cntxt,m);
-
-               /* reset/expand the profiler */
-               if (ssize < src->ssize){
-                       
-                       DEBUG_MULTICORE
-                               mnstr_printf(cntxt->fdout, "# \n Changed the 
size of stack");
-                       GDKfree(src->profiler);
-                       src->profiler = 0;
-                       initProfiler(src);
-                       for( i = 0; i < src->stop; i++)
-                               src->profiler[i].ticks = 0;
-               }
-
-               src->calls = 0;
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
http://mail.monetdb.org/mailman/listinfo/checkin-list

Reply via email to