From 137767a3d3ddf607ef7edb3ee692977c49176d15 Mon Sep 17 00:00:00 2001 From: vwaurich Date: Mon, 19 Oct 2015 15:19:53 +0200 Subject: [PATCH] - restructured and extended graph dump of bipartite graphs --- Compiler/BackEnd/BackendDAEUtil.mo | 2 +- Compiler/BackEnd/BackendDump.mo | 396 +++++++++++++++++++++++++++ Compiler/BackEnd/HpcOmEqSystems.mo | 413 +---------------------------- Compiler/BackEnd/HpcOmTaskGraph.mo | 25 -- Compiler/BackEnd/IndexReduction.mo | 6 +- Compiler/BackEnd/ResolveLoops.mo | 25 +- Compiler/Util/Util.mo | 7 + 7 files changed, 433 insertions(+), 441 deletions(-) diff --git a/Compiler/BackEnd/BackendDAEUtil.mo b/Compiler/BackEnd/BackendDAEUtil.mo index 5d58d190bcd..79d9636f485 100644 --- a/Compiler/BackEnd/BackendDAEUtil.mo +++ b/Compiler/BackEnd/BackendDAEUtil.mo @@ -6521,7 +6521,7 @@ algorithm SimCodeFunctionUtil.execStat("remove unused functions"); if Flags.isSet(Flags.GRAPHML) then - HpcOmTaskGraph.dumpBipartiteGraph(dae, fileNamePrefix); + BackendDump.dumpBipartiteGraphDAE(dae, fileNamePrefix); end if; if Flags.isSet(Flags.BLT_DUMP) then diff --git a/Compiler/BackEnd/BackendDump.mo b/Compiler/BackEnd/BackendDump.mo index e6ad801a4cf..30112a1a0e1 100644 --- a/Compiler/BackEnd/BackendDump.mo +++ b/Compiler/BackEnd/BackendDump.mo @@ -53,6 +53,7 @@ public import HashSet; public import Tpl; protected import Absyn; +protected import Array; protected import BackendDAEUtil; protected import BackendEquation; protected import BackendVariable; @@ -69,6 +70,8 @@ protected import Expression; protected import ExpressionDump; protected import Flags; protected import GraphvizDump; +protected import GraphML; +protected import HpcOmTaskGraph; protected import Initialization; protected import IOStream; protected import List; @@ -3591,5 +3594,398 @@ algorithm end matchcontinue; end printCompInfo; +// ============================================================================= +// section for all garphML dumping function functions +// +// These are functions, that print directly to the standard-stream. +// - printBackendDAE +// - printEqSystem +// - printEquation +// - printEquationArray +// - printEquationList +// - printEquations +// - printClassAttributes +// - printShared +// - printStateSets +// - printVar +// - printVariables +// - printVarList +// ============================================================================= + +public function dumpBipartiteGraphDAE" Dumps a *.graphml of the complete BackendDAE.BackendDAE as a bipartite graph. Can be opened with yEd. +author: Waurich" + input BackendDAE.BackendDAE dae; + input String fileName; +protected + BackendDAE.Variables vars; + BackendDAE.EquationArray eqs; + BackendDAE.EqSystems eqSysts; + BackendDAE.IncidenceMatrix m; + BackendDAE.Shared shared; + list eqLst; + list varLst; + list> varAtts,eqAtts; +algorithm + BackendDAE.DAE(eqs=eqSysts, shared=shared) := dae; + eqLst := List.flatten(List.map(List.map(eqSysts,BackendEquation.getEqnsFromEqSystem),BackendEquation.equationList)); + varLst := List.flatten(List.map(List.map(eqSysts,BackendVariable.daeVars),BackendVariable.varList)); + vars := BackendVariable.listVar1(varLst); + eqs := BackendEquation.listEquation(eqLst); + // build the incidence matrix for the whole System + (_,m,_,_,_) := BackendDAEUtil.getIncidenceMatrixScalar(BackendDAE.EQSYSTEM(vars,eqs,NONE(),NONE(),BackendDAE.NO_MATCHING(), {},BackendDAE.UNKNOWN_PARTITION(), BackendEquation.emptyEqns()),BackendDAE.SOLVABLE(), SOME(BackendDAEUtil.getFunctions(shared))); + varAtts := List.threadMap(List.fill(false,listLength(varLst)),List.fill("",listLength(varLst)),Util.makeTuple); + eqAtts := List.threadMap(List.fill(false,listLength(eqLst)),List.fill("",listLength(eqLst)),Util.makeTuple); + dumpBipartiteGraphStrongComponent2(vars,eqs,m,varAtts,eqAtts,"BipartiteGraph_"+fileName); +end dumpBipartiteGraphDAE; + + public function dumpBipartiteGraphEqSystem" Dumps a *.graphml of an BackendDAE.EqSystem as a bipartite graph. Can be opened with yEd. +author: Waurich" + input BackendDAE.EqSystem syst; + input BackendDAE.Shared shared; + input String fileName; +protected + BackendDAE.Variables vars; + BackendDAE.EquationArray eqs; + BackendDAE.AdjacencyMatrixEnhanced me,meT; + BackendDAE.IncidenceMatrix m; + Option mO; + list eqLst; + list varLst; + list> varAtts,eqAtts; +algorithm + BackendDAE.EQSYSTEM(orderedVars=vars, orderedEqs=eqs, m=mO) := syst; + varLst := BackendVariable.varList(vars); + eqLst := BackendEquation.equationList(eqs); + varAtts := List.threadMap(List.fill(false,listLength(varLst)),List.fill("",listLength(varLst)),Util.makeTuple); + eqAtts := List.threadMap(List.fill(false,listLength(eqLst)),List.fill("",listLength(eqLst)),Util.makeTuple); + if Util.isSome(mO) then + dumpBipartiteGraphStrongComponent2(vars,eqs,Util.getOption(mO),varAtts,eqAtts,"BipartiteGraph_"+fileName); + else + // build the incidence matrix + (_,m,_,_,_) := BackendDAEUtil.getIncidenceMatrixScalar(syst, BackendDAE.SOLVABLE(), SOME(BackendDAEUtil.getFunctions(shared))); + dumpBipartiteGraphStrongComponent2(vars,eqs,m,varAtts,eqAtts,"BipartiteGraph_"+fileName); + end if; +end dumpBipartiteGraphEqSystem; + +public function dumpBipartiteGraphStrongComponent"dumps a bipartite graph of an equation system or a torn system as graphml.Can be opened with yEd. +waurich: TUD 2014-09" + input BackendDAE.StrongComponent inComp; + input BackendDAE.EqSystem eqSys; + input String name; +protected + BackendDAE.EquationArray eqs; + BackendDAE.Variables vars; + list varLst; + list eqLst; +algorithm + BackendDAE.EQSYSTEM(orderedVars=vars, orderedEqs=eqs) := eqSys; + varLst := BackendVariable.varList(vars); + eqLst := BackendEquation.equationList(eqs); + dumpBipartiteGraphStrongComponent1(inComp,eqLst,varLst,name); +end dumpBipartiteGraphStrongComponent; + +public function dumpBipartiteGraphStrongComponent1"helper function for dumpBipartiteGraphStrongComponent which handles either an equationsystem or a torn system" + input BackendDAE.StrongComponent inComp; + input list eqsIn; + input list varsIn; + input String graphName; +algorithm + () := matchcontinue(inComp,eqsIn,varsIn,graphName) + local + Integer numEqs, numVars, compIdx; + list tornInfo; + list addInfo; + list eqIdcs,varIdcs,tVarIdcs,rEqIdcs, tVarIdcsNew, rEqIdcsNew; + list>> otherEqnVarTplIdcs; + list> varAtts,eqAtts; + BackendDAE.EquationArray compEqs; + BackendDAE.Variables compVars; + BackendDAE.StrongComponent comp; + BackendDAE.IncidenceMatrix m,mT; + list compEqLst; + list compVarLst; + case((BackendDAE.EQUATIONSYSTEM(eqns=eqIdcs,vars=varIdcs)),_,_,_) + equation + compEqLst = List.map1(eqIdcs,List.getIndexFirst,eqsIn); + compVarLst = List.map1(varIdcs,List.getIndexFirst,varsIn); + compVars = BackendVariable.listVar1(compVarLst); + compEqs = BackendEquation.listEquation(compEqLst); + + numEqs = listLength(compEqLst); + numVars = listLength(compVarLst); + (m,_) = BackendDAEUtil.incidenceMatrixDispatch(compVars,compEqs, BackendDAE.NORMAL()); + + varAtts = List.threadMap(List.fill(false,numVars),List.fill("",numVars),Util.makeTuple); + eqAtts = List.threadMap(List.fill(false,numEqs),List.fill("",numEqs),Util.makeTuple); + dumpBipartiteGraphStrongComponent2(compVars,compEqs,m,varAtts,eqAtts,"rL_eqSys_"+graphName); + then (); + case((BackendDAE.TORNSYSTEM(BackendDAE.TEARINGSET(residualequations=rEqIdcs,tearingvars=tVarIdcs,otherEqnVarTpl=otherEqnVarTplIdcs))),_,_,_) + equation + //gather equations ans variables + eqIdcs = List.map(otherEqnVarTplIdcs,Util.tuple21); + eqIdcs = listAppend(eqIdcs, rEqIdcs); + varIdcs = List.flatten(List.map(otherEqnVarTplIdcs,Util.tuple22)); + varIdcs = listAppend(varIdcs, tVarIdcs); + compEqLst = List.map1(eqIdcs,List.getIndexFirst,eqsIn); + compVarLst = List.map1(varIdcs,List.getIndexFirst,varsIn); + compVars = BackendVariable.listVar1(compVarLst); + compEqs = BackendEquation.listEquation(compEqLst); + + // get incidence matrix + numEqs = listLength(compEqLst); + numVars = listLength(compVarLst); + m = BackendDAEUtil.incidenceMatrixDispatch(compVars,compEqs, BackendDAE.NORMAL()); + + // add tearing info to graph object and dump graph + addInfo = List.map(varIdcs,intString);// the DAE idcs for the vars + tornInfo = List.fill(true,numVars); + tVarIdcsNew = List.intRange(numVars-listLength(tVarIdcs)); + tornInfo = List.fold1(tVarIdcsNew,List.replaceAtIndexFirst,false,tornInfo);//is it a tearing var or not + varAtts = List.threadMap(tornInfo,addInfo,Util.makeTuple); + addInfo = List.map(eqIdcs,intString);// the DAE idcs for the eqs + tornInfo = List.fill(true,numEqs); + rEqIdcsNew = List.intRange(numEqs-listLength(rEqIdcs)); + tornInfo = List.fold1(rEqIdcsNew,List.replaceAtIndexFirst,false,tornInfo);//is it a residual eq or not + eqAtts = List.threadMap(tornInfo,addInfo,Util.makeTuple); + dumpBipartiteGraphStrongComponent2(compVars,compEqs,m,varAtts,eqAtts,graphName); + then (); + else + equation + print("dumpTornSystemBipartiteGraphML1 failed\n"); + then (); + end matchcontinue; +end dumpBipartiteGraphStrongComponent1; + +public function dumpBipartiteGraphStrongComponent2"helper function for dumpBipartiteGraphStrongComponent1 which dumps the graphml" + input BackendDAE.Variables varsIn; + input BackendDAE.EquationArray eqsIn; + input BackendDAE.IncidenceMatrix mIn; + input list> varAtts; // + input list> eqAtts; // + input String name; +protected + Integer nameAttIdx,typeAttIdx,idxAttIdx, numVars,numEqs; + list varRange,eqRange; + BackendDAE.IncidenceMatrix m; + GraphML.GraphInfo graphInfo; + Integer graphIdx; +algorithm + numEqs := BackendDAEUtil.equationArraySize(eqsIn); + numVars := BackendVariable.varsSize(varsIn); + varRange := List.intRange(numVars); + eqRange := List.intRange(numEqs); + graphInfo := GraphML.createGraphInfo(); + (graphInfo,(_,graphIdx)) := GraphML.addGraph("EqSystemGraph", true, graphInfo); + (graphInfo,(_,typeAttIdx)) := GraphML.addAttribute("", "type", GraphML.TYPE_STRING(), GraphML.TARGET_NODE(), graphInfo); + (graphInfo,(_,nameAttIdx)) := GraphML.addAttribute("", "name", GraphML.TYPE_STRING(), GraphML.TARGET_NODE(), graphInfo); + (graphInfo,(_,idxAttIdx)) := GraphML.addAttribute("", "systIdx", GraphML.TYPE_STRING(), GraphML.TARGET_NODE(), graphInfo); + ((graphInfo,graphIdx)) := List.fold3(eqRange,addEqNodeToGraph,eqsIn,eqAtts,{nameAttIdx,typeAttIdx,idxAttIdx}, (graphInfo,graphIdx)); + ((graphInfo,graphIdx)) := List.fold3(varRange,addVarNodeToGraph,varsIn,varAtts,{nameAttIdx,typeAttIdx,idxAttIdx}, (graphInfo,graphIdx)); + graphInfo := List.fold1(eqRange,addEdgeToGraph,mIn,graphInfo); + GraphML.dumpGraph(graphInfo,name+".graphml"); +end dumpBipartiteGraphStrongComponent2; + +public function dumpDAGStrongComponent"dumps a directed acyclic graph for the matched strongly connected component" + input HpcOmTaskGraph.TaskGraph graphIn; + input HpcOmTaskGraph.TaskGraphMeta metaIn; + input String fileName; +protected + Integer graphIdx, nameAttIdx; + GraphML.GraphInfo graphInfo; +algorithm + graphInfo := GraphML.createGraphInfo(); + (graphInfo, (_,graphIdx)) := GraphML.addGraph("TornSystemGraph", true, graphInfo); + (graphInfo,(_,nameAttIdx)) := GraphML.addAttribute("", "Name", GraphML.TYPE_STRING(), GraphML.TARGET_NODE(), graphInfo); + graphInfo := buildGraphInfoDAG(graphIn,metaIn,graphInfo,graphIdx,{nameAttIdx}); + GraphML.dumpGraph(graphInfo, fileName+".graphml"); +end dumpDAGStrongComponent; + +protected function buildGraphInfoDAG"helper function for dumpDAGStrongComponent" + input HpcOmTaskGraph.TaskGraph graphIn; + input HpcOmTaskGraph.TaskGraphMeta metaIn; + input GraphML.GraphInfo graphInfoIn; + input Integer graphIdx; + input list attIdcs; + output GraphML.GraphInfo graphInfoOut; +protected + GraphML.GraphInfo graphInfo; + list nodeIdcs; + list nodes; + Integer nameAttIdx; +algorithm + nameAttIdx := listHead(attIdcs); + nodeIdcs := List.intRange(arrayLength(graphIn)); + graphInfoOut := List.fold4(nodeIdcs,addNodeToDAG,graphIn,metaIn,graphIdx,{nameAttIdx},graphInfoIn); + GraphML.GRAPHINFO(nodes=nodes) := graphInfoOut; +end buildGraphInfoDAG; + +protected function addNodeToDAG"add a node to a DAG. +author:Waurich TUD 2014-07" + input Integer nodeIdx; + input HpcOmTaskGraph.TaskGraph graphIn; + input HpcOmTaskGraph.TaskGraphMeta metaIn; + input Integer graphIdx; + input list atts; //{nameAtt} + input GraphML.GraphInfo graphInfoIn; + output GraphML.GraphInfo graphInfoOut; +protected + GraphML.GraphInfo tmpGraph; + Integer nameAttIdx; + list childNodes; + array compDescs; + array> inComps; + GraphML.NodeLabel nodeLabel; + String nodeString, nodeDesc, compName; +algorithm + HpcOmTaskGraph.TASKGRAPHMETA(inComps=inComps,compDescs=compDescs) := metaIn; + nodeDesc := arrayGet(compDescs,nodeIdx); + nodeString := intString(nodeIdx); + compName := stringDelimitList(List.map(arrayGet(inComps,nodeIdx),intString),","); + nameAttIdx := listGet(atts,1); + nodeLabel := GraphML.NODELABEL_INTERNAL(nodeString,NONE(),GraphML.FONTPLAIN()); + (tmpGraph,(_,_)) := GraphML.addNode("Node"+intString(nodeIdx), + GraphML.COLOR_ORANGE, + {nodeLabel}, + GraphML.RECTANGLE(), + SOME(nodeDesc), + {(nameAttIdx,compName)}, + graphIdx, + graphInfoIn); + childNodes := arrayGet(graphIn,nodeIdx); + graphInfoOut := List.fold1(childNodes, addDirectedEdge, nodeIdx, tmpGraph); +end addNodeToDAG; + +protected function addDirectedEdge"add a directed edge from child to parent +author: Waurich TUD 2014-07" + input Integer child; + input Integer parent; + input GraphML.GraphInfo graphInfoIn; + output GraphML.GraphInfo graphInfoOut; +algorithm + (graphInfoOut,(_,_)) := GraphML.addEdge( "Edge" + intString(parent)+intString(child), + "Node" + intString(child), + "Node" + intString(parent), + GraphML.COLOR_BLACK, + GraphML.LINE(), + GraphML.LINEWIDTH_STANDARD, + false,{}, + (GraphML.ARROWNONE(),GraphML.ARROWSTANDART()), + {}, + graphInfoIn); +end addDirectedEdge; + +protected function addVarNodeToGraph "adds a node for a variable to the graph. +author:Waurich TUD 2013-12" + input Integer indx; + input BackendDAE.Variables vars; + input list> attsIn; // + input list attributeIdcs;// + input tuple graphInfoIn; + output tuple graphInfoOut; +protected + BackendDAE.Var var; + Boolean isTearVar; + Integer nameAttrIdx,typeAttIdx,idxAttrIdx, graphIdx; + String varString, varNodeId, idxString, typeStr, daeIdxStr; + list varChars; + GraphML.GraphInfo graphInfo; + GraphML.NodeLabel nodeLabel; +algorithm + (graphInfo,graphIdx) := graphInfoIn; + nameAttrIdx := listGet(attributeIdcs,1); + typeAttIdx := listGet(attributeIdcs,2); // if its a tearingvar or not + idxAttrIdx:= listGet(attributeIdcs,3); + isTearVar := Util.tuple21(listGet(attsIn,indx)); + daeIdxStr := Util.tuple22(listGet(attsIn,indx)); + typeStr := if isTearVar then "tearingVar" else "otherVar"; + var := BackendVariable.getVarAt(vars,indx); + varString := BackendDump.varString(var); + varNodeId := getVarNodeIdx(indx); + idxString := intString(indx); + nodeLabel := GraphML.NODELABEL_INTERNAL(idxString,NONE(),GraphML.FONTPLAIN()); + (graphInfo,_) := GraphML.addNode(varNodeId, GraphML.COLOR_ORANGE2, {nodeLabel},GraphML.ELLIPSE(),SOME(varString),{(nameAttrIdx,varString),(typeAttIdx,typeStr),(idxAttrIdx,daeIdxStr)},graphIdx,graphInfo); + graphInfoOut := (graphInfo,graphIdx); +end addVarNodeToGraph; + +protected function addEqNodeToGraph "adds a node for an equation to the graph. +author:Waurich TUD 2013-12" + input Integer indx; + input BackendDAE.EquationArray eqs; + input list> attsIn; // + input list attributeIdcs;// + input tuple graphInfoIn; + output tuple graphInfoOut; +protected + BackendDAE.Equation eq; + Boolean isResEq; + Integer nameAttrIdx,typeAttrIdx,idxAttrIdx, graphIdx; + String eqString, eqNodeId, idxString, typeStr, daeIdxStr; + list eqChars; + GraphML.GraphInfo graphInfo; + GraphML.NodeLabel nodeLabel; +algorithm + (graphInfo,graphIdx) := graphInfoIn; + nameAttrIdx := listGet(attributeIdcs,1); + typeAttrIdx := listGet(attributeIdcs,2); // if its a residual or not + idxAttrIdx := listGet(attributeIdcs,3); + isResEq := Util.tuple21(listGet(attsIn,indx)); + daeIdxStr := Util.tuple22(listGet(attsIn,indx)); + typeStr := if isResEq then "residualEq" else "otherEq"; + {eq} := BackendEquation.getEqns({indx}, eqs); + eqString := BackendDump.equationString(eq); + eqNodeId := getEqNodeIdx(indx); + idxString := intString(indx); + nodeLabel := GraphML.NODELABEL_INTERNAL(idxString,NONE(),GraphML.FONTPLAIN()); + (graphInfo,_) := GraphML.addNode(eqNodeId,GraphML.COLOR_GREEN2,{nodeLabel},GraphML.RECTANGLE(),SOME(eqString),{(nameAttrIdx,eqString),(typeAttrIdx,typeStr),(idxAttrIdx,daeIdxStr)},graphIdx,graphInfo); + graphInfoOut := (graphInfo,graphIdx); +end addEqNodeToGraph; + +protected function addEdgeToGraph "adds an edge to the graph by traversing the incidence matrix. +author:Waurich TUD 2013-12" + input Integer eqIdx; + input BackendDAE.IncidenceMatrix m; + input GraphML.GraphInfo graphInfoIn; + output GraphML.GraphInfo graphInfoOut; +protected + list varLst; +algorithm + varLst := arrayGet(m,eqIdx); + graphInfoOut := List.fold1(varLst,addEdgeToGraph2,eqIdx,graphInfoIn); +end addEdgeToGraph; + +protected function addEdgeToGraph2 "helper for addEdgeToGraph. +author:Waurich TUD 2013-12" + input Integer varIdxIn; + input Integer eqIdx; + input GraphML.GraphInfo graphInfoIn; + output GraphML.GraphInfo graphInfoOut; +protected + Integer varIdx; + String eqNodeId, varNodeId; + GraphML.LineType lt; +algorithm + if varIdxIn <= 0 then lt := GraphML.DASHED(); else lt := GraphML.LINE(); end if; + varIdx := intAbs(varIdxIn); + eqNodeId := getEqNodeIdx(eqIdx); + varNodeId := getVarNodeIdx(varIdx); + (graphInfoOut,_) := GraphML.addEdge("Edge_"+intString(varIdx)+"_"+intString(eqIdx),varNodeId,eqNodeId,GraphML.COLOR_BLACK,lt,GraphML.LINEWIDTH_STANDARD,false,{},(GraphML.ARROWNONE(),GraphML.ARROWNONE()),{}, graphInfoIn); +end addEdgeToGraph2; + +protected function getVarNodeIdx "outputs the identifier string for the given varIdx. +author:Waurich TUD 2013-12" + input Integer idx; + output String varString; +algorithm + varString := "varNode"+intString(intAbs(idx)); +end getVarNodeIdx; + +protected function getEqNodeIdx "outputs the identifier string for the given eqIdx. +author:Waurich TUD 2013-12" + input Integer idx; + output String eqString; +algorithm + eqString := "eqNode"+intString(intAbs(idx)); +end getEqNodeIdx; + annotation(__OpenModelica_Interface="backend"); end BackendDump; diff --git a/Compiler/BackEnd/HpcOmEqSystems.mo b/Compiler/BackEnd/HpcOmEqSystems.mo index 104701292c9..b11f3406df6 100644 --- a/Compiler/BackEnd/HpcOmEqSystems.mo +++ b/Compiler/BackEnd/HpcOmEqSystems.mo @@ -2172,309 +2172,6 @@ algorithm end dumpEqArrLst1; -//--------------------------------------------------// -// functions to dump the equation system as .graphml -//-------------------------------------------------// - -public function dumpEquationSystemBipartiteGraph"dumps a bipartite graph of the torn systems as graphml. -waurich: TUD 2014-09" - input BackendDAE.StrongComponent inComp; - input BackendDAE.EqSystem eqSys; - input String name; -protected - BackendDAE.EquationArray eqs; - BackendDAE.Variables vars; - list varLst; - list eqLst; -algorithm - BackendDAE.EQSYSTEM(orderedVars=vars, orderedEqs=eqs) := eqSys; - varLst := BackendVariable.varList(vars); - eqLst := BackendEquation.equationList(eqs); - dumpEquationSystemBipartiteGraph1(inComp,eqLst,varLst,name); -end dumpEquationSystemBipartiteGraph; - -public function dumpEquationSystemBipartiteGraph1 - input BackendDAE.StrongComponent inComp; - input list eqsIn; - input list varsIn; - input String graphName; -algorithm - () := matchcontinue(inComp,eqsIn,varsIn,graphName) - local - Integer numEqs, numVars, compIdx; - list tornInfo; - list addInfo; - list eqIdcs,varIdcs,tVarIdcs,rEqIdcs, tVarIdcsNew, rEqIdcsNew; - list>> otherEqnVarTplIdcs; - list> varAtts,eqAtts; - BackendDAE.EquationArray compEqs; - BackendDAE.Variables compVars; - BackendDAE.StrongComponent comp; - BackendDAE.IncidenceMatrix m,mT; - list compEqLst; - list compVarLst; - case((BackendDAE.EQUATIONSYSTEM(eqns=eqIdcs,vars=varIdcs)),_,_,_) - equation - compEqLst = List.map1(eqIdcs,List.getIndexFirst,eqsIn); - compVarLst = List.map1(varIdcs,List.getIndexFirst,varsIn); - compVars = BackendVariable.listVar1(compVarLst); - compEqs = BackendEquation.listEquation(compEqLst); - - numEqs = listLength(compEqLst); - numVars = listLength(compVarLst); - (m,_) = BackendDAEUtil.incidenceMatrixDispatch(compVars,compEqs, BackendDAE.ABSOLUTE()); - - varAtts = List.threadMap(List.fill(false,numVars),List.fill("",numVars),Util.makeTuple); - eqAtts = List.threadMap(List.fill(false,numEqs),List.fill("",numEqs),Util.makeTuple); - dumpEquationSystemBipartiteGraph2(compVars,compEqs,m,varAtts,eqAtts,"rL_eqSys_"+graphName); - then (); - case((BackendDAE.TORNSYSTEM(BackendDAE.TEARINGSET(residualequations=rEqIdcs,tearingvars=tVarIdcs,otherEqnVarTpl=otherEqnVarTplIdcs))),_,_,_) - equation - //gather equations ans variables - eqIdcs = List.map(otherEqnVarTplIdcs,Util.tuple21); - eqIdcs = listAppend(eqIdcs, rEqIdcs); - varIdcs = List.flatten(List.map(otherEqnVarTplIdcs,Util.tuple22)); - varIdcs = listAppend(varIdcs, tVarIdcs); - compEqLst = List.map1(eqIdcs,List.getIndexFirst,eqsIn); - compVarLst = List.map1(varIdcs,List.getIndexFirst,varsIn); - compVars = BackendVariable.listVar1(compVarLst); - compEqs = BackendEquation.listEquation(compEqLst); - - // get incidence matrix - numEqs = listLength(compEqLst); - numVars = listLength(compVarLst); - m = BackendDAEUtil.incidenceMatrixDispatch(compVars,compEqs, BackendDAE.ABSOLUTE()); - - // add tearing info to graph object and dump graph - addInfo = List.map(varIdcs,intString);// the DAE idcs for the vars - tornInfo = List.fill(true,numVars); - tVarIdcsNew = List.intRange(numVars-listLength(tVarIdcs)); - tornInfo = List.fold1(tVarIdcsNew,List.replaceAtIndexFirst,false,tornInfo);//is it a tearing var or not - varAtts = List.threadMap(tornInfo,addInfo,Util.makeTuple); - addInfo = List.map(eqIdcs,intString);// the DAE idcs for the eqs - tornInfo = List.fill(true,numEqs); - rEqIdcsNew = List.intRange(numEqs-listLength(rEqIdcs)); - tornInfo = List.fold1(rEqIdcsNew,List.replaceAtIndexFirst,false,tornInfo);//is it a residual eq or not - eqAtts = List.threadMap(tornInfo,addInfo,Util.makeTuple); - dumpEquationSystemBipartiteGraph2(compVars,compEqs,m,varAtts,eqAtts,graphName); - then (); - else - equation - print("dumpTornSystemBipartiteGraphML1 failed\n"); - then (); - end matchcontinue; -end dumpEquationSystemBipartiteGraph1; - -public function dumpEquationSystemBipartiteGraph2 - input BackendDAE.Variables varsIn; - input BackendDAE.EquationArray eqsIn; - input BackendDAE.IncidenceMatrix mIn; - input list> varAtts; // - input list> eqAtts; // - input String name; -protected - Integer nameAttIdx,typeAttIdx,idxAttIdx, numVars,numEqs; - list varRange,eqRange; - BackendDAE.IncidenceMatrix m; - GraphML.GraphInfo graphInfo; - Integer graphIdx; -algorithm - numEqs := BackendDAEUtil.equationArraySize(eqsIn); - numVars := BackendVariable.varsSize(varsIn); - varRange := List.intRange(numVars); - eqRange := List.intRange(numEqs); - graphInfo := GraphML.createGraphInfo(); - (graphInfo,(_,graphIdx)) := GraphML.addGraph("EqSystemGraph", true, graphInfo); - (graphInfo,(_,typeAttIdx)) := GraphML.addAttribute("", "type", GraphML.TYPE_STRING(), GraphML.TARGET_NODE(), graphInfo); - (graphInfo,(_,nameAttIdx)) := GraphML.addAttribute("", "name", GraphML.TYPE_STRING(), GraphML.TARGET_NODE(), graphInfo); - (graphInfo,(_,idxAttIdx)) := GraphML.addAttribute("", "systIdx", GraphML.TYPE_STRING(), GraphML.TARGET_NODE(), graphInfo); - ((graphInfo,graphIdx)) := List.fold3(eqRange,addEqNodeToGraph,eqsIn,eqAtts,{nameAttIdx,typeAttIdx,idxAttIdx}, (graphInfo,graphIdx)); - ((graphInfo,graphIdx)) := List.fold3(varRange,addVarNodeToGraph,varsIn,varAtts,{nameAttIdx,typeAttIdx,idxAttIdx}, (graphInfo,graphIdx)); - graphInfo := List.fold1(eqRange,addEdgeToGraph,mIn,graphInfo); - GraphML.dumpGraph(graphInfo,name+".graphml"); -end dumpEquationSystemBipartiteGraph2; - -public function dumpEquationSystemBipartiteGraphSolve2 - input BackendDAE.Variables varsIn; - input BackendDAE.EquationArray eqsIn; - input BackendDAE.AdjacencyMatrixEnhanced meIn; - input list> varAtts; // - input list> eqAtts; // - input String name; -protected - Integer nameAttIdx,typeAttIdx,idxAttIdx, numVars,numEqs; - list varRange,eqRange; - GraphML.GraphInfo graphInfo; - Integer graphIdx; -algorithm - numEqs := BackendDAEUtil.equationArraySize(eqsIn); - numVars := BackendVariable.varsSize(varsIn); - varRange := List.intRange(numVars); - eqRange := List.intRange(numEqs); - graphInfo := GraphML.createGraphInfo(); - (graphInfo,(_,graphIdx)) := GraphML.addGraph("EqSystemGraph", true, graphInfo); - (graphInfo,(_,typeAttIdx)) := GraphML.addAttribute("", "type", GraphML.TYPE_STRING(), GraphML.TARGET_NODE(), graphInfo); - (graphInfo,(_,nameAttIdx)) := GraphML.addAttribute("", "name", GraphML.TYPE_STRING(), GraphML.TARGET_NODE(), graphInfo); - (graphInfo,(_,idxAttIdx)) := GraphML.addAttribute("", "systIdx", GraphML.TYPE_STRING(), GraphML.TARGET_NODE(), graphInfo); - ((graphInfo,graphIdx)) := List.fold3(eqRange,addEqNodeToGraph,eqsIn,eqAtts,{nameAttIdx,typeAttIdx,idxAttIdx}, (graphInfo,graphIdx)); - ((graphInfo,graphIdx)) := List.fold3(varRange,addVarNodeToGraph,varsIn,varAtts,{nameAttIdx,typeAttIdx,idxAttIdx}, (graphInfo,graphIdx)); - graphInfo := List.fold1(eqRange,addSolvEdgeToGraph,meIn,graphInfo); - GraphML.dumpGraph(graphInfo,name+".graphml"); -end dumpEquationSystemBipartiteGraphSolve2; - -protected function addVarNodeToGraph "adds a node for a variable to the graph. -author:Waurich TUD 2013-12" - input Integer indx; - input BackendDAE.Variables vars; - input list> attsIn; // - input list attributeIdcs;// - input tuple graphInfoIn; - output tuple graphInfoOut; -protected - BackendDAE.Var var; - Boolean isTearVar; - Integer nameAttrIdx,typeAttIdx,idxAttrIdx, graphIdx; - String varString, varNodeId, idxString, typeStr, daeIdxStr; - list varChars; - GraphML.GraphInfo graphInfo; - GraphML.NodeLabel nodeLabel; -algorithm - (graphInfo,graphIdx) := graphInfoIn; - nameAttrIdx := listGet(attributeIdcs,1); - typeAttIdx := listGet(attributeIdcs,2); // if its a tearingvar or not - idxAttrIdx:= listGet(attributeIdcs,3); - isTearVar := Util.tuple21(listGet(attsIn,indx)); - daeIdxStr := Util.tuple22(listGet(attsIn,indx)); - typeStr := if isTearVar then "tearingVar" else "otherVar"; - var := BackendVariable.getVarAt(vars,indx); - varString := BackendDump.varString(var); - varNodeId := getVarNodeIdx(indx); - idxString := intString(indx); - nodeLabel := GraphML.NODELABEL_INTERNAL(idxString,NONE(),GraphML.FONTPLAIN()); - (graphInfo,_) := GraphML.addNode(varNodeId, GraphML.COLOR_ORANGE2, {nodeLabel},GraphML.ELLIPSE(),SOME(varString),{(nameAttrIdx,varString),(typeAttIdx,typeStr),(idxAttrIdx,daeIdxStr)},graphIdx,graphInfo); - graphInfoOut := (graphInfo,graphIdx); -end addVarNodeToGraph; - -protected function addEqNodeToGraph "adds a node for an equation to the graph. -author:Waurich TUD 2013-12" - input Integer indx; - input BackendDAE.EquationArray eqs; - input list> attsIn; // - input list attributeIdcs;// - input tuple graphInfoIn; - output tuple graphInfoOut; -protected - BackendDAE.Equation eq; - Boolean isResEq; - Integer nameAttrIdx,typeAttrIdx,idxAttrIdx, graphIdx; - String eqString, eqNodeId, idxString, typeStr, daeIdxStr; - list eqChars; - GraphML.GraphInfo graphInfo; - GraphML.NodeLabel nodeLabel; -algorithm - (graphInfo,graphIdx) := graphInfoIn; - nameAttrIdx := listGet(attributeIdcs,1); - typeAttrIdx := listGet(attributeIdcs,2); // if its a residual or not - idxAttrIdx := listGet(attributeIdcs,3); - isResEq := Util.tuple21(listGet(attsIn,indx)); - daeIdxStr := Util.tuple22(listGet(attsIn,indx)); - typeStr := if isResEq then "residualEq" else "otherEq"; - {eq} := BackendEquation.getEqns({indx}, eqs); - eqString := BackendDump.equationString(eq); - eqNodeId := getEqNodeIdx(indx); - idxString := intString(indx); - nodeLabel := GraphML.NODELABEL_INTERNAL(idxString,NONE(),GraphML.FONTPLAIN()); - (graphInfo,_) := GraphML.addNode(eqNodeId,GraphML.COLOR_GREEN2,{nodeLabel},GraphML.RECTANGLE(),SOME(eqString),{(nameAttrIdx,eqString),(typeAttrIdx,typeStr),(idxAttrIdx,daeIdxStr)},graphIdx,graphInfo); - graphInfoOut := (graphInfo,graphIdx); -end addEqNodeToGraph; - -protected function addEdgeToGraph "adds an edge to the graph by traversing the incidence matrix. -author:Waurich TUD 2013-12" - input Integer eqIdx; - input BackendDAE.IncidenceMatrix m; - input GraphML.GraphInfo graphInfoIn; - output GraphML.GraphInfo graphInfoOut; -protected - list varLst; -algorithm - varLst := arrayGet(m,eqIdx); - graphInfoOut := List.fold1(varLst,addEdgeToGraph2,eqIdx,graphInfoIn); -end addEdgeToGraph; - -protected function addEdgeToGraph2 "helper for addEdgeToGraph. -author:Waurich TUD 2013-12" - input Integer varIdx; - input Integer eqIdx; - input GraphML.GraphInfo graphInfoIn; - output GraphML.GraphInfo graphInfoOut; -protected - String eqNodeId, varNodeId; -algorithm - eqNodeId := getEqNodeIdx(eqIdx); - varNodeId := getVarNodeIdx(varIdx); - (graphInfoOut,_) := GraphML.addEdge("Edge_"+intString(varIdx)+"_"+intString(eqIdx),varNodeId,eqNodeId,GraphML.COLOR_BLACK,GraphML.LINE(),GraphML.LINEWIDTH_STANDARD,false,{},(GraphML.ARROWNONE(),GraphML.ARROWNONE()),{}, graphInfoIn); -end addEdgeToGraph2; - -protected function addSolvEdgeToGraph "adds an edge with solvability information to the graph by traversing the enhanced adjacency matrix. -author:Waurich TUD 2013-12" - input Integer eqIdx; - input BackendDAE.AdjacencyMatrixEnhanced me; - input GraphML.GraphInfo graphInfoIn; - output GraphML.GraphInfo graphInfoOut; -protected - BackendDAE.AdjacencyMatrixElementEnhanced row; -algorithm - row := arrayGet(me,eqIdx); - graphInfoOut := List.fold1(row,addSolvEdgeToGraph2,eqIdx,graphInfoIn); -end addSolvEdgeToGraph; - -protected function addSolvEdgeToGraph2 "helper for addSolvEdgeToGraph. -author:Waurich TUD 2013-12" - input BackendDAE.AdjacencyMatrixElementEnhancedEntry var; - input Integer eqIdx; - input GraphML.GraphInfo graphInfoIn; - output GraphML.GraphInfo graphInfoOut; -protected - Boolean solvable; - String eqNodeId, varNodeId; - Real lineWidth; - Integer varIdx; -algorithm - (varIdx,_) := var; - solvable := Tearing.unsolvable({var}); - eqNodeId := getEqNodeIdx(eqIdx); - varNodeId := getVarNodeIdx(varIdx); - lineWidth := if solvable then GraphML.LINEWIDTH_BOLD else GraphML.LINEWIDTH_STANDARD; - (graphInfoOut,_) := GraphML.addEdge("Edge_"+intString(varIdx)+"_"+intString(eqIdx),varNodeId,eqNodeId,GraphML.COLOR_BLACK,GraphML.LINE(),lineWidth,false,{},(GraphML.ARROWNONE(),GraphML.ARROWNONE()),{}, graphInfoIn); -end addSolvEdgeToGraph2; - -protected function genSystemVarIdcs - input list idcsIn; - input Integer idx; - output list idcsOut; - output Integer idx2; -algorithm - idx2 := listLength(idcsIn)+idx; - idcsOut := List.intRange2(idx,idx2-1); -end genSystemVarIdcs; - -protected function getVarNodeIdx "outputs the identifier string for the given varIdx. -author:Waurich TUD 2013-12" - input Integer idx; - output String varString; -algorithm - varString := "varNode"+intString(idx); -end getVarNodeIdx; - -protected function getEqNodeIdx "outputs the identifier string for the given eqIdx. -author:Waurich TUD 2013-12" - input Integer idx; - output String eqString; -algorithm - eqString := "eqNode"+intString(idx); -end getEqNodeIdx; - - //--------------------------------------------------// // solve torn systems in parallel //-------------------------------------------------// @@ -2626,15 +2323,15 @@ algorithm //print("otherSimEqSysIdcs "+stringDelimitList(List.map(otherSimEqSysIdcs,intString),",")+"\n"); // dump graphs - dumpEquationSystemBipartiteGraph1(comp,eqsIn,varsIn,"tornSys_bipartite_"+intString(compIdxIn)); - dumpEquationSystemDAG(graph,meta,"tornSys_matched_"+intString(compIdxIn)); + BackendDump.dumpBipartiteGraphStrongComponent1(comp,eqsIn,varsIn,"tornSys_bipartite_"+intString(compIdxIn)); + BackendDump.dumpDAGStrongComponent(graph,meta,"tornSys_matched_"+intString(compIdxIn)); //GRS //(graphMerged,metaMerged) = HpcOmSimCodeMain.applyGRS(graph,meta); (graphMerged,metaMerged) = (graph,meta); Error.addMessage(Error.INTERNAL_ERROR, {"function pts_traverseCompsAndParallelize failed. GRS is temporarily disabled."}); - dumpEquationSystemDAG(graphMerged,metaMerged,"tornSys_matched2_"+intString(compIdxIn)); + BackendDump.dumpDAGStrongComponent(graphMerged,metaMerged,"tornSys_matched2_"+intString(compIdxIn)); //HpcOmTaskGraph.printTaskGraph(graphMerged); //HpcOmTaskGraph.printTaskGraphMeta(metaMerged); @@ -2714,6 +2411,17 @@ algorithm end matchcontinue; end pts_transformScheduleToTask; +protected function genSystemVarIdcs + input list idcsIn; + input Integer idx; + output list idcsOut; + output Integer idx2; +algorithm + idx2 := listLength(idcsIn)+idx; + idcsOut := List.intRange2(idx,idx2-1); +end genSystemVarIdcs; + + //05-09-2014 marcusw: Changed because of dependency-task restructuring for MPI //protected function appendStringToLockIdcs"appends the suffix to the lockIds of the given tasks //author: Waurich TUD 2014-07" @@ -2859,98 +2567,5 @@ algorithm schedule := HpcOmSimCode.THREADSCHEDULE(threadTasks,{},scheduledTasks,allCalcTasks); end createSingleBlockSchedule; -//--------------------------------------------------// -// dump torn system of equations as a directed acyclic graph (the matched system) -//-------------------------------------------------// - -protected function dumpEquationSystemDAG - input HpcOmTaskGraph.TaskGraph graphIn; - input HpcOmTaskGraph.TaskGraphMeta metaIn; - input String fileName; -protected - Integer graphIdx, nameAttIdx; - GraphML.GraphInfo graphInfo; -algorithm - graphInfo := GraphML.createGraphInfo(); - (graphInfo, (_,graphIdx)) := GraphML.addGraph("TornSystemGraph", true, graphInfo); - (graphInfo,(_,nameAttIdx)) := GraphML.addAttribute("", "Name", GraphML.TYPE_STRING(), GraphML.TARGET_NODE(), graphInfo); - graphInfo := buildGraphInfoDAG(graphIn,metaIn,graphInfo,graphIdx,{nameAttIdx}); - GraphML.dumpGraph(graphInfo, fileName+".graphml"); -end dumpEquationSystemDAG; - -protected function buildGraphInfoDAG - input HpcOmTaskGraph.TaskGraph graphIn; - input HpcOmTaskGraph.TaskGraphMeta metaIn; - input GraphML.GraphInfo graphInfoIn; - input Integer graphIdx; - input list attIdcs; - output GraphML.GraphInfo graphInfoOut; -protected - GraphML.GraphInfo graphInfo; - list nodeIdcs; - list nodes; - Integer nameAttIdx; -algorithm - nameAttIdx := listHead(attIdcs); - nodeIdcs := List.intRange(arrayLength(graphIn)); - graphInfoOut := List.fold4(nodeIdcs,addNodeToDAG,graphIn,metaIn,graphIdx,{nameAttIdx},graphInfoIn); - GraphML.GRAPHINFO(nodes=nodes) := graphInfoOut; -end buildGraphInfoDAG; - -protected function addNodeToDAG"add a node to a DAG. -author:Waurich TUD 2014-07" - input Integer nodeIdx; - input HpcOmTaskGraph.TaskGraph graphIn; - input HpcOmTaskGraph.TaskGraphMeta metaIn; - input Integer graphIdx; - input list atts; //{nameAtt} - input GraphML.GraphInfo graphInfoIn; - output GraphML.GraphInfo graphInfoOut; -protected - GraphML.GraphInfo tmpGraph; - Integer nameAttIdx; - list childNodes; - array compDescs; - array> inComps; - GraphML.NodeLabel nodeLabel; - String nodeString, nodeDesc, compName; -algorithm - HpcOmTaskGraph.TASKGRAPHMETA(inComps=inComps,compDescs=compDescs) := metaIn; - nodeDesc := arrayGet(compDescs,nodeIdx); - nodeString := intString(nodeIdx); - compName := stringDelimitList(List.map(arrayGet(inComps,nodeIdx),intString),","); - nameAttIdx := listGet(atts,1); - nodeLabel := GraphML.NODELABEL_INTERNAL(nodeString,NONE(),GraphML.FONTPLAIN()); - (tmpGraph,(_,_)) := GraphML.addNode("Node"+intString(nodeIdx), - GraphML.COLOR_ORANGE, - {nodeLabel}, - GraphML.RECTANGLE(), - SOME(nodeDesc), - {(nameAttIdx,compName)}, - graphIdx, - graphInfoIn); - childNodes := arrayGet(graphIn,nodeIdx); - graphInfoOut := List.fold1(childNodes, addDirectedEdge, nodeIdx, tmpGraph); -end addNodeToDAG; - -protected function addDirectedEdge"add a directed edge from child to parent -author: Waurich TUD 2014-07" - input Integer child; - input Integer parent; - input GraphML.GraphInfo graphInfoIn; - output GraphML.GraphInfo graphInfoOut; -algorithm - (graphInfoOut,(_,_)) := GraphML.addEdge( "Edge" + intString(parent)+intString(child), - "Node" + intString(child), - "Node" + intString(parent), - GraphML.COLOR_BLACK, - GraphML.LINE(), - GraphML.LINEWIDTH_STANDARD, - false,{}, - (GraphML.ARROWNONE(),GraphML.ARROWSTANDART()), - {}, - graphInfoIn); -end addDirectedEdge; - annotation(__OpenModelica_Interface="backend"); end HpcOmEqSystems; diff --git a/Compiler/BackEnd/HpcOmTaskGraph.mo b/Compiler/BackEnd/HpcOmTaskGraph.mo index b82a3af04f2..f8465571537 100644 --- a/Compiler/BackEnd/HpcOmTaskGraph.mo +++ b/Compiler/BackEnd/HpcOmTaskGraph.mo @@ -2672,31 +2672,6 @@ algorithm HpcOmTaskGraph.dumpAsGraphMLSccLevel(taskGraph, taskGraphData, name, "", {}, {}, sccSimEqMapping, schedulerInfo, HpcOmTaskGraph.GRAPHDUMPOPTIONS(false,false,true,true)); end dumpTaskGraph; -public function dumpBipartiteGraph - input BackendDAE.BackendDAE dae; - input String fileName; -protected - BackendDAE.Variables vars; - BackendDAE.EquationArray eqs; - BackendDAE.EqSystems eqSysts; - BackendDAE.IncidenceMatrix m,mT; - list eqLst; - list varLst; - list> varAtts,eqAtts; -algorithm - BackendDAE.DAE(eqs=eqSysts) := dae; - eqLst := List.flatten(List.map(List.map(eqSysts,BackendEquation.getEqnsFromEqSystem),BackendEquation.equationList)); - varLst := List.flatten(List.map(List.map(eqSysts,BackendVariable.daeVars),BackendVariable.varList)); - vars := BackendVariable.listVar1(varLst); - eqs := BackendEquation.listEquation(eqLst); - // build the incidence matrix for the whole System - (m,mT) := BackendDAEUtil.incidenceMatrixDispatch(vars,eqs, BackendDAE.NORMAL()); - m := Array.map(m,function List.filter1OnTrue(inFilterFunc=intGt,inArg1=0)); - varAtts := List.threadMap(List.fill(false,listLength(varLst)),List.fill("",listLength(varLst)),Util.makeTuple); - eqAtts := List.threadMap(List.fill(false,listLength(eqLst)),List.fill("",listLength(eqLst)),Util.makeTuple); - HpcOmEqSystems.dumpEquationSystemBipartiteGraph2(vars,eqs,m,varAtts,eqAtts,"BipartiteGraph_"+fileName); -end dumpBipartiteGraph; - public function dumpAsGraphMLSccLevel "author: marcusw, waurich Write out the given graph as a graphml file." input TaskGraph iGraph; diff --git a/Compiler/BackEnd/IndexReduction.mo b/Compiler/BackEnd/IndexReduction.mo index b2f0d7ea891..ce8d5ea5473 100644 --- a/Compiler/BackEnd/IndexReduction.mo +++ b/Compiler/BackEnd/IndexReduction.mo @@ -88,7 +88,7 @@ protected import ValuesUtil; public function pantelidesIndexReduction "author: Frenkel TUD 2012-04 Index Reduction algorithm to get a index 1 or 0 system." - input list> inEqns; + input list> inEqns; // the MSSS input Integer inActualEqn; input BackendDAE.EqSystem inSystem; input BackendDAE.Shared inShared; @@ -731,9 +731,9 @@ algorithm case (e::es,_,_,_,_) equation eqn = BackendEquation.equationNth1(eqns, e); - // fcall(Flags.BLT_DUMP, print, "differentiate equation " + intString(e) + " " + BackendDump.equationString(eqn) + "\n"); + //if Flags.isSet(Flags.BLT_DUMP) then print("differentiate equation " + intString(e) + " " + BackendDump.equationString(eqn) + "\n"); end if; (eqn_1, shared) = Differentiate.differentiateEquationTime(eqn, vars, inShared); - // fcall(Flags.BLT_DUMP, print, "differentiated equation " + intString(e) + " " + BackendDump.equationString(eqn_1) + "\n"); + //if Flags.isSet(Flags.BLT_DUMP) then print("differentiated equation " + intString(e) + " " + BackendDump.equationString(eqn_1) + "\n"); end if; eqn = BackendEquation.markDifferentiated(eqn); (eqntpl, shared) = differentiateEqnsLst(es,vars,eqns,shared,(e,SOME(eqn_1),eqn)::inEqnTpl); then diff --git a/Compiler/BackEnd/ResolveLoops.mo b/Compiler/BackEnd/ResolveLoops.mo index 8c3c50a1448..413f6298b9a 100644 --- a/Compiler/BackEnd/ResolveLoops.mo +++ b/Compiler/BackEnd/ResolveLoops.mo @@ -82,7 +82,7 @@ protected function resolveLoops_main "author: Waurich TUD 2014-01 eqSystem can be output. All variables and equations which do not belong to a loop will be removed. the loops will be analysed and resolved" input BackendDAE.EqSystem inEqSys; - input BackendDAE.Shared inShared "unused"; + input BackendDAE.Shared inShared "unused, just for dumping graphml"; input Integer inSysIdx; output BackendDAE.EqSystem outEqSys; output BackendDAE.Shared outShared = inShared "unused"; @@ -111,13 +111,10 @@ algorithm varLst = BackendVariable.varList(vars); // build the incidence matrix for the whole System - numSimpEqs = listLength(eqLst); - numVars = listLength(varLst); - (m,mT) = BackendDAEUtil.incidenceMatrixDispatch(vars,eqs, BackendDAE.ABSOLUTE()); - - varAtts = List.threadMap(List.fill(false,listLength(varLst)),List.fill("",listLength(varLst)),Util.makeTuple); - eqAtts = List.threadMap(List.fill(false,listLength(eqLst)),List.fill("",listLength(eqLst)),Util.makeTuple); - HpcOmEqSystems.dumpEquationSystemBipartiteGraph2(vars,eqs,m,varAtts,eqAtts,"whole System_"+intString(inSysIdx)); + //numSimpEqs = listLength(eqLst); + //numVars = listLength(varLst); + //(m,mT) = BackendDAEUtil.incidenceMatrixDispatch(vars,eqs, BackendDAE.ABSOLUTE()); + BackendDump.dumpBipartiteGraphEqSystem(syst,inShared, "whole System_"+intString(inSysIdx)); //BackendDump.dumpEquationArray(eqs,"the complete DAE"); // get the linear equations and their vars @@ -135,7 +132,7 @@ algorithm varAtts = List.threadMap(List.fill(false,numVars),List.fill("",numVars),Util.makeTuple); eqAtts = List.threadMap(List.fill(false,numSimpEqs),List.fill("",numSimpEqs),Util.makeTuple); - HpcOmEqSystems.dumpEquationSystemBipartiteGraph2(simpVars,simpEqs,m,varAtts,eqAtts,"rL_simpEqs_"+intString(inSysIdx)); + BackendDump.dumpBipartiteGraphStrongComponent2(simpVars,simpEqs,m,varAtts,eqAtts,"rL_simpEqs_"+intString(inSysIdx)); //partition graph partitions = arrayList(partitionBipartiteGraph(m,mT)); @@ -149,7 +146,7 @@ algorithm varAtts = List.threadMap(List.fill(false,numVars),List.fill("",numVars),Util.makeTuple); eqAtts = List.threadMap(List.fill(false,numSimpEqs),List.fill("",numSimpEqs),Util.makeTuple); - HpcOmEqSystems.dumpEquationSystemBipartiteGraph2(simpVars,simpEqs,m_cut,varAtts,eqAtts,"rL_loops_"+intString(inSysIdx)); + BackendDump.dumpBipartiteGraphStrongComponent2(simpVars,simpEqs,m_cut,varAtts,eqAtts,"rL_loops_"+intString(inSysIdx)); // handle the partitions separately, resolve the loops in the partitions, insert the resolved equation eqLst = resolveLoops_resolvePartitions(partitions,m_cut,mT_cut,m,mT,eqMapping,varMapping,eqLst,varLst,nonLoopEqIdcs); @@ -165,7 +162,7 @@ algorithm varAtts = List.threadMap(List.fill(false,numVars),List.fill("",numVars),Util.makeTuple); eqAtts = List.threadMap(List.fill(false,numSimpEqs),List.fill("",numSimpEqs),Util.makeTuple); - HpcOmEqSystems.dumpEquationSystemBipartiteGraph2(simpVars,simpEqs,m_after,varAtts,eqAtts,"rL_after_"+intString(inSysIdx)); + BackendDump.dumpBipartiteGraphStrongComponent2(simpVars,simpEqs,m_after,varAtts,eqAtts,"rL_after_"+intString(inSysIdx)); eqSys = BackendDAEUtil.clearEqSyst(syst); then (eqSys, inSysIdx+1); @@ -1788,6 +1785,7 @@ protected BackendDAE.Variables vars, daeVars; BackendDAE.EqSystem subSys; BackendDAE.AdjacencyMatrixEnhanced me, me2, meT; + BackendDAE.IncidenceMatrix m; DAE.FunctionTree funcs; list eqLst,eqsInLst; list varLst; @@ -1802,13 +1800,14 @@ algorithm vars := BackendVariable.listVar1(varLst); subSys := BackendDAEUtil.createEqSystem(vars, eqs); (me,meT,_,_) := BackendDAEUtil.getAdjacencyMatrixEnhancedScalar(subSys,shared,false); + (_,m,_,_,_) := BackendDAEUtil.getIncidenceMatrixScalar(subSys,BackendDAE.SOLVABLE(),SOME(BackendDAEUtil.getFunctions(shared))); ass1 := arrayCreate(size,-1); ass2 := arrayCreate(size,-1); // dump system as graphML varAtts := List.threadMap(List.fill(false,listLength(varLst)),List.map(eqIdcs,intString),Util.makeTuple); eqAtts := List.threadMap(List.fill(false,listLength(eqLst)),List.map(varIdcs,intString),Util.makeTuple); - HpcOmEqSystems.dumpEquationSystemBipartiteGraphSolve2(vars,eqs,me,varAtts,eqAtts,"shuffle_pre"); + BackendDump.dumpBipartiteGraphStrongComponent2(vars,eqs,m,varAtts,eqAtts,"shuffle_pre"); //start reshuffling resEqs := reshuffling_post3_selectShuffleEqs(me,meT); @@ -1819,7 +1818,7 @@ algorithm // dump system as graphML //subSys := BackendDAEUtil.createEqSystem(vars, replEqs); //(me2,_,_,_) := BackendDAEUtil.getAdjacencyMatrixEnhancedScalar(subSys,shared,false); - //HpcOmEqSystems.dumpEquationSystemBipartiteGraphSolve2(vars,replEqs,me2,varAtts,eqAtts,"shuffle_post"); + //BackendDump.dumpBipartiteGraphStrongComponentSolvable(vars,replEqs,me2,varAtts,eqAtts,"shuffle_post"); // the new eqSystem daeEqs := List.threadFold(eqIdcs,eqsInLst,BackendEquation.setAtIndexFirst,daeEqs); diff --git a/Compiler/Util/Util.mo b/Compiler/Util/Util.mo index bad9d1ea102..daf3da0eb50 100644 --- a/Compiler/Util/Util.mo +++ b/Compiler/Util/Util.mo @@ -1716,5 +1716,12 @@ algorithm else stringAppendList({pwd,pd,inFileName}); end absoluteOrRelative; +public function intLstString + input list lst; + output String s; +algorithm + s := stringDelimitList(List.map(lst,intString),", "); +end intLstString; + annotation(__OpenModelica_Interface="util"); end Util;