Skip to content

Commit

Permalink
improve sparsePattern dump
Browse files Browse the repository at this point in the history
  • Loading branch information
Willi Braun authored and OpenModelica-Hudson committed Nov 17, 2016
1 parent 797a4ef commit fdec2bc
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 7 deletions.
25 changes: 21 additions & 4 deletions Compiler/BackEnd/BackendDump.mo
Expand Up @@ -481,7 +481,7 @@ algorithm

case (curr::rest) equation
(cr, crList) = curr;
crStr = ComponentReference.crefStr(cr);
crStr = ComponentReference.printComponentRefStr(cr);
print(crStr + " affects the following (" + intString(listLength(crList)) + ") outputs\n ");
ComponentReference.printComponentRefList(crList);

Expand Down Expand Up @@ -738,23 +738,40 @@ public function dumpSparsityPattern "author lochel"
input BackendDAE.SparsePattern inPattern;
input String heading;
protected
list<tuple< .DAE.ComponentRef, list< .DAE.ComponentRef>>> pattern;
list<tuple< .DAE.ComponentRef, list< .DAE.ComponentRef>>> pattern,patternT;
list< .DAE.ComponentRef> diffVars, diffedVars;
Integer nnz;
algorithm
(pattern, _, (diffVars, diffedVars), nnz) := inPattern;
(pattern, patternT, (diffVars, diffedVars), nnz) := inPattern;

print("\n" + heading + "\n" + UNDERLINE + "\n");
print("Number of non zero elements: " + intString(nnz) + ")\n");
print("Number of non zero elements: " + intString(nnz) + "\n");
print("independents [or inputs] (" + intString(listLength(diffVars)) + ")\n");
ComponentReference.printComponentRefList(diffVars);

print("dependents [or outputs] (" + intString(listLength(diffedVars)) + ")\n");
ComponentReference.printComponentRefList(diffedVars);

printSparsityPattern(pattern);
print("\n" + "transposed pattern" + "\n");
printSparsityPattern(patternT);
end dumpSparsityPattern;

public function dumpSparseColoring
input BackendDAE.SparseColoring inColoring;
input String heading;
protected
Integer i=0;
algorithm
print("\n" + heading + "\n" + UNDERLINE + "\n");
print("Number of colors: " + intString(listLength(inColoring)) + "\n");
for crList in inColoring loop
print("The following (" + intString(listLength(crList)) + ") independents belong to one color\n"+intString(i)+": ");
ComponentReference.printComponentRefList(crList);
i := i+1;
end for;
end dumpSparseColoring;

public function dumpTearing "
author: Frenkel TUD
Dump tearing vars and residual equations."
Expand Down
13 changes: 10 additions & 3 deletions Compiler/BackEnd/SymbolicJacobian.mo
Expand Up @@ -1192,14 +1192,15 @@ algorithm
if debug then execStat("generateSparsePattern -> postProcess2 "); end if;

nonZeroElements = List.lengthListElements(sparsepattern);
if Flags.isSet(Flags.DUMP_SPARSE) then
if Flags.isSet(Flags.DUMP_SPARSE_VERBOSE) then
// dump statistics
dumpSparsePatternStatistics(nonZeroElements,sparsepatternT);
BackendDump.dumpSparsePattern(sparsepattern);
BackendDump.dumpSparsePattern(sparsepatternT);
//execStat("generateSparsePattern -> nonZeroElements: " + intString(nonZeroElements) + " " ,ClockIndexes.RT_CLOCK_EXECSTAT_BACKEND_MODULES);
end if;


// translated to DAE.ComRefs
translated = list(list(arrayGet(inDepCompRefs, i) for i in lst) for lst in sparsepattern);
sparsetuple = list((cr,t) threaded for cr in depCompRefs, t in translated);
Expand All @@ -1216,8 +1217,14 @@ algorithm
if Flags.isSet(Flags.DUMP_SPARSE_VERBOSE) then
print("analytical Jacobians[SPARSE] -> ready! " + realString(clock()) + "\n");
end if;

outSparsePattern = (sparsetupleT, sparsetuple, (inDepCompRefsLst, depCompRefsLst), nonZeroElements);
if Flags.isSet(Flags.DUMP_SPARSE) then
BackendDump.dumpSparsityPattern(outSparsePattern, " --- SparsityPattern ---");
BackendDump.dumpSparseColoring(coloring, " --- Sparsity Coloring ---");
end if;
if debug then execStat("generateSparsePattern -> final end "); end if;
then ((sparsetupleT, sparsetuple, (inDepCompRefsLst, depCompRefsLst), nonZeroElements), coloring);
then (outSparsePattern, coloring);
else
algorithm
Error.addInternalError("function generateSparsePattern failed", sourceInfo());
Expand Down Expand Up @@ -1274,7 +1281,7 @@ algorithm
coloredArray := arrayCreate(maxColor, {});
mapIndexColors(colored, sizeVars, coloredArray);

if Flags.isSet(Flags.DUMP_SPARSE) then
if Flags.isSet(Flags.DUMP_SPARSE_VERBOSE) then
print("Print Coloring Cols: \n");
BackendDump.dumpSparsePattern(arrayList(coloredArray));
end if;
Expand Down

0 comments on commit fdec2bc

Please sign in to comment.