Changeset: a8614dc8dd2f for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=a8614dc8dd2f
Added Files:
        monetdb5/optimizer/opt_mrunal.mx
Branch: MapR
Log Message:

added Mrunal_optimizer


diffs (truncated from 905 to 300 lines):

diff --git a/monetdb5/optimizer/opt_mrunal.mx b/monetdb5/optimizer/opt_mrunal.mx
new file mode 100644
--- /dev/null
+++ b/monetdb5/optimizer/opt_mrunal.mx
@@ -0,0 +1,900 @@
+@/
+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-2012 MonetDB B.V.
+All Rights Reserved.
+@
+
+@f opt_mrunal
+
+@mal
+module mrunal;
+
+
+pattern optimizer.mrunal():str
+address OPTmrunal;
+pattern optimizer.mrunal(mod:str, fcn:str):str
+address OPTmrunal
+comment "Modify the plan to exploit parallel processing on multiple cores";
+
+@h
+#ifndef _OPT_MITOSIS_
+#define _OPT_MITOSIS_
+#include "opt_prelude.h"
+#include "opt_support.h"
+
+#define MAXSLICES 256          /* to be refined */
+#define MINPARTCNT 100000      /* minimal record count per partition */
+
+Lifespan span = NULL;
+
+typedef struct varNode{
+       int varId;
+       struct varNode *next;
+} *ptrVarNode, varNodeRecord;
+
+ptrVarNode matpckHeadQ = NULL, matpckTailQ = NULL;
+
+int mapCnt=0;
+
+void copyVarRecords(MalBlkPtr, MalBlkPtr);
+void addNodeTmpQ(ptrVarNode, ptrVarNode *, ptrVarNode *);
+ptrVarNode getNodeTmpQ(ptrVarNode *, ptrVarNode *);
+void addNodeMatPckQ(ptrVarNode );
+ptrVarNode getNodeMatPckQ();
+void recurseInMal(int, MalBlkPtr, MalBlkPtr);
+opt_export str addRegWrap (Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr 
pc);
+
+#define MAP_NAME_LENGTH 5
+  
+
+@:exportOptimizer(mrunal)@
+#define OPTDEBUGmrunal  if ( optDebug & ((lng)1 <<DEBUG_OPT_MITOSIS) )
+#endif
+
+@c
+#include "monetdb_config.h"
+#include "opt_mrunal.h"
+#include "opt_octopus.h"
+#include "mal_interpreter.h"
+#include "opt_mrunal.h"
+
+
+void addNodeTmpQ(ptrVarNode ptrNode, ptrVarNode *tmpHeadQ, ptrVarNode 
*tmpTailQ)
+{
+       if(NULL != tmpHeadQ)
+       {
+               if(NULL == *tmpHeadQ)
+               {
+                       *tmpHeadQ=ptrNode;
+                       *tmpTailQ=ptrNode;
+               }
+                else
+               {
+                       (*tmpTailQ)->next=ptrNode;
+                       *tmpTailQ=ptrNode;
+               }
+       }
+       else 
+       {
+               printf("Error in assigning tmpHeadQ\n");
+       }
+}
+
+ptrVarNode getNodeTmpQ(ptrVarNode *tmpHeadQ, ptrVarNode *tmpTailQ)
+{
+       ptrVarNode ptrNodeQ = NULL;
+
+       if(NULL != tmpHeadQ)
+       {
+               if(*tmpHeadQ != NULL)
+               {
+                       ptrNodeQ= *tmpHeadQ;
+                       *tmpHeadQ = (*tmpHeadQ)->next;  
+                       if(*tmpHeadQ == NULL)
+                       {
+                               *tmpTailQ=NULL; 
+                       }
+               }       
+               else
+               {
+                       printf("Empty Queue\n");
+               }
+       }else{
+               printf("Error in allocating tmpHeadQ pointer\n");
+       }
+       return ptrNodeQ;
+}
+
+void addNodeMatPckQ(ptrVarNode ptrNode)
+{
+       if(matpckHeadQ == NULL)
+       {
+               matpckHeadQ=ptrNode;
+               matpckTailQ=ptrNode;
+       }
+       else
+       {
+               matpckTailQ->next=ptrNode;
+               matpckTailQ=ptrNode;
+       }
+}
+
+ptrVarNode getNodeMatPckQ()
+{
+       ptrVarNode ptrNodeQ = NULL;
+       if(matpckHeadQ != NULL)
+       {
+               ptrNodeQ= matpckHeadQ;
+               matpckHeadQ = matpckHeadQ->next;        
+               if(matpckHeadQ == NULL)
+               {
+                       matpckTailQ = NULL;     
+               }
+       }       
+       else
+       {
+               printf("Empty Queue\n");
+       }
+
+       return ptrNodeQ;
+}
+
+void copyVarRecords(MalBlkPtr newMb, MalBlkPtr oldMb)
+{
+       int i;
+
+       assert(oldMb);
+       assert(newMb);  
+
+       newMb->var = (VarPtr *) GDKrealloc(newMb->var, 
(oldMb->vsize*sizeof(VarPtr)));
+       newMb->vsize = oldMb->vsize;
+
+        newMb->vtop=1; 
+        for (i = 1; i < oldMb->vtop; i++) 
+       {
+                copyVariable(newMb, getVar(oldMb, i));
+                newMb->vtop++;
+        }
+       // Assign null values to the rest of the vrecord array of pointers, 
else this will give an error
+       // when a newTmpVariable is tried to assigned 
+       for (i=oldMb->vtop; i<=oldMb->vsize; i++)
+               newMb->var[i] = NULL;   
+}
+
+void copyPrps(MalBlkPtr newMb, MalBlkPtr oldMb)
+{
+       int i;
+       if (oldMb->prps) 
+       {
+               newMb->prps = (MalProp *) GDKmalloc(oldMb->psize * 
sizeof(MalProp));
+               newMb->psize = oldMb->psize;
+               newMb->ptop = oldMb->ptop;
+               for (i = 0; i < oldMb->ptop; i++)
+                       newMb->prps[i] = oldMb->prps[i];
+        }
+}
+
+void recurseInMal(int varId, MalBlkPtr mb, MalBlkPtr newMb)
+{
+       InstrPtr ptrInstr = NULL, newInstr=NULL;        
+       int j;
+       ptrVarNode tmpHeadQ=NULL, tmpTailQ=NULL, tmpArg=NULL;
+       
+       int pc =  span[varId].beginLifespan;
+//     printf("\nVariable= %d pc= %d ", var, pc);
+
+       if(varId!=1)            // This condition takes care of the argument 
variables to the mal blk function, Its hard coded at present 
+       {
+               ptrInstr = getInstrPtr(mb, pc);        
+                       
+               for (j = 1; j < ptrInstr->argc; j++) 
+               {
+                       if(!isVarConstant(mb,getArg(ptrInstr,j)))
+                       {
+       //                printf("X_%d ",getArg(p,j));
+                         tmpArg= (ptrVarNode)malloc(sizeof(varNodeRecord));    
                
+                         if(NULL == tmpArg)
+                         {
+                               printf("Malloc failed\n");
+                         }
+                        
+                         tmpArg->next=NULL;
+                         tmpArg->varId=getArg(ptrInstr,j);     
+                         addNodeTmpQ(tmpArg, &tmpHeadQ, &tmpTailQ);            
                 
+                       }
+               }
+               while(tmpHeadQ)
+               {
+                       ptrVarNode ptrArg = getNodeTmpQ(&tmpHeadQ, &tmpTailQ);
+                       //sleep(1);
+                       recurseInMal(ptrArg->varId,mb,newMb);
+               }
+               // The end condition where an instruction which does not have a 
corresponding argument list is reached, such x_3=sql.mvc();
+               // so we push this instruction
+               if(ptrInstr)
+               {
+                       newInstr = copyInstruction(ptrInstr);
+                       pushInstruction(newMb, newInstr);                       
+               }
+               else
+               {
+                       printf("Instruction pointer p is null");
+               }
+       }
+}
+
+
+void createMainFunction(MalBlkPtr oldMb, Module nspace)
+{
+       MalBlkPtr mb = NULL;
+       Symbol symb = NULL;
+       char mainFuncName[]="main1";
+       char mapFuncName[6];
+       char reduceFuncName[7]="reduce";
+       InstrPtr ptrMapInstr = NULL, ptrReduceInstr = NULL, ptrTmpInstr=NULL;
+       int i, dlt=0, cnst, flowblock, tpe;
+        ValRecord cst;
+
+       // create main function
+       symb = newFunction(userRef, putName(mainFuncName,strlen(mainFuncName)), 
FUNCTIONsymbol);        
+       mb = symb->def;
+       insertSymbol(nspace, symb);
+       setDestType(mb, getInstrPtr(mb, 0), TYPE_void);
+
+       copyVarRecords(symb->def, oldMb);                               
+       copyPrps(symb->def, oldMb);
+
+       ptrTmpInstr = getInstrPtr(mb, 0);
+//     ptrTmpInstr->argv[1] = 1;       // A0
+       getArg(ptrTmpInstr, 1) = 1;     // This is the hack
+       
+       pushArgument(mb, getInstrPtr(mb, 0), getArg(getInstrPtr(mb, 0), 1));    
// This is done to increment argc in a legal way
+
+//     ValRecord cst;
+//     int tpe = newBatType(TYPE_oid,TYPE_lng);
+//
+//     setVarType(mq,getArg(q,0),tpe);
+//     cst.vtype = TYPE_bat;
+//     cst.val.bval = bat_nil;
+//     getArg(q,1) = defConstant(mq, tpe, &cst);
+//     setVarType(mq, getArg(q,1), tpe);
+
+       for(i=0; i<mapCnt; i++)
+       {
+               ptrTmpInstr = newAssignment(mb);
+                setDestType(mb, ptrTmpInstr, newBatType(TYPE_oid, TYPE_lng));
+               setVarUDFtype(mb, getArg(ptrTmpInstr, 0));      
+
+               tpe = newBatType(TYPE_oid,TYPE_lng);
+               pushNil(mb, ptrTmpInstr, tpe);  
+/*             tpe = newBatType(TYPE_oid,TYPE_lng);
+               cst.vtype = TYPE_bat;
+               cst.val.bval = bat_nil;
+               cnst = defConstant(mb, tpe, &cst);
+               setVarUDFtype(mb, cnst);
+               pushArgument(mb, ptrTmpInstr, cnst);                            
       
+*/
+       }
+
+       // Create dataflow barrier instruction
+        ptrTmpInstr= newFcnCall(mb,languageRef,dataflowRef);
+        ptrTmpInstr->barrier= BARRIERsymbol;
+       flowblock = getArg(ptrTmpInstr, 0);
_______________________________________________
Checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list

Reply via email to