Skip to content

Commit

Permalink
move profiling function from BackendDAEUtil > Util
Browse files Browse the repository at this point in the history
Belonging to [master]:
  - OpenModelica/OMCompiler#2271
  • Loading branch information
Willi Braun authored and OpenModelica-Hudson committed Mar 14, 2018
1 parent 09e106c commit 995c5ef
Show file tree
Hide file tree
Showing 3 changed files with 119 additions and 112 deletions.
81 changes: 0 additions & 81 deletions Compiler/BackEnd/BackendDAEUtil.mo
Expand Up @@ -8051,87 +8051,6 @@ algorithm
end for;
end isInitOptModuleActivated;

/*************************************************
* profiler stuff
************************************************/

public function profilerinit
algorithm
setGlobalRoot(Global.profilerTime1Index, 0.0);
setGlobalRoot(Global.profilerTime2Index, 0.0);
System.realtimeTick(ClockIndexes.RT_PROFILER0);
end profilerinit;

public function profilerresults
protected
Real tg,t1,t2;
algorithm
tg := System.realtimeTock(ClockIndexes.RT_PROFILER0);
t1 := profilertime1();
t2 := profilertime2();
print("Time all: "); print(realString(tg)); print("\n");
print("Time t1: "); print(realString(t1)); print("\n");
print("Time t2: "); print(realString(t2)); print("\n");
print("Time all-t1-t2: "); print(realString(realSub(realSub(tg,t1),t2))); print("\n");
end profilerresults;

public function profilertime1
output Real t1;
algorithm
t1 := getGlobalRoot(Global.profilerTime1Index);
end profilertime1;

public function profilertime2
output Real t2;
algorithm
t2 := getGlobalRoot(Global.profilerTime2Index);
end profilertime2;

public function profilerstart1
algorithm
System.realtimeTick(ClockIndexes.RT_PROFILER1);
end profilerstart1;

public function profilerstart2
algorithm
System.realtimeTick(ClockIndexes.RT_PROFILER2);
end profilerstart2;

public function profilerstop1
protected
Real t;
algorithm
t := System.realtimeTock(ClockIndexes.RT_PROFILER1);
setGlobalRoot(Global.profilerTime1Index,
realAdd(getGlobalRoot(Global.profilerTime1Index),t));
end profilerstop1;

public function profilerstop2
protected
Real t;
algorithm
t := System.realtimeTock(ClockIndexes.RT_PROFILER2);
setGlobalRoot(Global.profilerTime2Index,
realAdd(getGlobalRoot(Global.profilerTime2Index),t));
end profilerstop2;

public function profilerreset1
algorithm
setGlobalRoot(Global.profilerTime1Index, 0.0);
end profilerreset1;

public function profilerreset2
algorithm
setGlobalRoot(Global.profilerTime2Index, 0.0);
end profilerreset2;

public function profilertock1
output Real t;
algorithm
t := System.realtimeTock(ClockIndexes.RT_PROFILER1);
end profilertock1;


/*************************************************
* traverse BackendDAE equation systems
************************************************/
Expand Down
62 changes: 31 additions & 31 deletions Compiler/BackEnd/OnRelaxation.mo
Expand Up @@ -135,9 +135,9 @@ algorithm
(BackendDAE.EQUATIONSYSTEM(eqns=eindex, vars=vindx, jac=BackendDAE.FULL_JACOBIAN(SOME(jac)), jacType=BackendDAE.JAC_LINEAR()))::comps)
equation
print("try to relax\n");
BackendDAEUtil.profilerinit();
BackendDAEUtil.profilerstart2();
BackendDAEUtil.profilerstart1();
Util.profilerinit();
Util.profilerstart2();
Util.profilerstart1();
size = listLength(vindx);
esize = listLength(eindex);
ass1 = arrayCreate(size, -1);
Expand Down Expand Up @@ -223,10 +223,10 @@ algorithm
// DumpGraphML.dumpSystem(subsyst, shared, NONE(), intString(size) + "SystemOneFreeMatching.graphml");

// hier sollte zur vorsicht noch mal ein matching durchgefuehrt werden
BackendDAEUtil.profilerstop1();
print("Matching time: " + realString(BackendDAEUtil.profilertime1()) + "\n");
BackendDAEUtil.profilerreset1();
BackendDAEUtil.profilerstart1();
Util.profilerstop1();
print("Matching time: " + realString(Util.profilertime1()) + "\n");
Util.profilerreset1();
Util.profilerstart1();
// collect tearing variables and residual equations
vorphans = getOrphans(1, size, ass1, {});
eorphans = getOrphans(1, size, ass2, {});
Expand Down Expand Up @@ -265,10 +265,10 @@ algorithm
// BackendDump.debuglst((roots, intString, ", ", "\n"));
// print("constraints:\n");
// BackendDump.debuglst((constraints, intString, ", ", "\n"));
BackendDAEUtil.profilerstop1();
print("Identifikation time: " + realString(BackendDAEUtil.profilertime1()) + "\n");
BackendDAEUtil.profilerreset1();
BackendDAEUtil.profilerstart1();
Util.profilerstop1();
print("Identifikation time: " + realString(Util.profilertime1()) + "\n");
Util.profilerreset1();
Util.profilerstart1();
// Order of orphans
vorphansarray1 = arrayCreate(size, {});
List.map2_0(roots, doMark, rowmarks, mark);
Expand All @@ -283,10 +283,10 @@ algorithm
// BackendDump.dumpIncidenceMatrix(vorphansarray1);

(vorphans, mark) = getOrphansOrderEdvanced3(roots, otherorphans, constraints, vorphans, vorphansarray1, mark, rowmarks);
BackendDAEUtil.profilerstop1();
print("Reihenfolge time: " + realString(BackendDAEUtil.profilertime1()) + "\n");
BackendDAEUtil.profilerreset1();
BackendDAEUtil.profilerstart1();
Util.profilerstop1();
print("Reihenfolge time: " + realString(Util.profilertime1()) + "\n");
Util.profilerreset1();
Util.profilerstart1();
List.map2_0(constraints, doMark, rowmarks, mark);
otherorphans = List.select2(vorphans, unmarked, rowmarks, mark);

Expand All @@ -303,10 +303,10 @@ algorithm
// print("Matching with Orphans:\n");
// BackendDump.dumpMatching(ass1);
// BackendDump.dumpIncidenceMatrix(ass22);
BackendDAEUtil.profilerstop1();
print("Paarung time: " + realString(BackendDAEUtil.profilertime1()) + "\n");
BackendDAEUtil.profilerreset1();
BackendDAEUtil.profilerstart1();
Util.profilerstop1();
print("Paarung time: " + realString(Util.profilertime1()) + "\n");
Util.profilerreset1();
Util.profilerstart1();
vec1 = arrayCreate(esize, {});
vec2 = arrayCreate(esize, -1);

Expand All @@ -321,10 +321,10 @@ algorithm
// DumpGraphML.dumpSystem(subsyst, shared, SOME(vec3), "System.graphml");

((_, _, _, eqns, vars)) = Array.fold(vec2, getEqnsinOrder, (eqns, vars, ass22, BackendEquation.listEquation({}), BackendVariable.emptyVars()));
BackendDAEUtil.profilerstop1();
print("Indizierung time: " + realString(BackendDAEUtil.profilertime1()) + "\n");
BackendDAEUtil.profilerreset1();
BackendDAEUtil.profilerstart1();
Util.profilerstop1();
print("Indizierung time: " + realString(Util.profilertime1()) + "\n");
Util.profilerreset1();
Util.profilerstart1();
// replace evaluated parametes
//_ = BackendDAEUtil.traverseBackendDAEExpsEqnsWithUpdate(eqns, replaceFinalParameter, BackendVariable.daeGlobalKnownVars(shared));

Expand Down Expand Up @@ -355,15 +355,15 @@ algorithm
crefexplst = List.map(BackendVariable.varList(vars), makeCrefExps);
crefexps = listArray(crefexplst);
neweqns = makeGausElimination(1, size, matrix, crefexps, {});
BackendDAEUtil.profilerstop1();
print("Gaus Elimination time: " + realString(BackendDAEUtil.profilertime1()) + "\n");
BackendDAEUtil.profilerreset1();
BackendDAEUtil.profilerstart1();
Util.profilerstop1();
print("Gaus Elimination time: " + realString(Util.profilertime1()) + "\n");
Util.profilerreset1();
Util.profilerstart1();
syst = replaceEquationsAddNew(eindex, neweqns, syst);
BackendDAEUtil.profilerstop2();
print("Gesamt time: " + realString(BackendDAEUtil.profilertime2()) + "\n");
BackendDAEUtil.profilerreset1();
BackendDAEUtil.profilerstart1();
Util.profilerstop2();
print("Gesamt time: " + realString(Util.profilertime2()) + "\n");
Util.profilerreset1();
Util.profilerstart1();
/*
vars = BackendVariable.addVars(var_lst, vars);
eqns = BackendEquation.addList(neweqns, teqns);
Expand Down
88 changes: 88 additions & 0 deletions Compiler/Util/Util.mo
Expand Up @@ -84,6 +84,7 @@ public uniontype DateTime
end DATETIME;
end DateTime;

protected import ClockIndexes;
protected import Config;
protected import Error;
protected import Flags;
Expand Down Expand Up @@ -1805,5 +1806,92 @@ algorithm
end match;
end sourceInfoIsEqual;

/*************************************************
* profiler stuff
************************************************/
public

function profilerinit
algorithm
setGlobalRoot(Global.profilerTime1Index, 0.0);
setGlobalRoot(Global.profilerTime2Index, 0.0);
System.realtimeTick(ClockIndexes.RT_PROFILER0);
end profilerinit;

function profilerresults
protected
Real tg,t1,t2;
algorithm
tg := System.realtimeTock(ClockIndexes.RT_PROFILER0);
t1 := profilertime1();
t2 := profilertime2();
print("Time all: "); print(realString(tg)); print("\n");
print("Time t1: "); print(realString(t1)); print("\n");
print("Time t2: "); print(realString(t2)); print("\n");
print("Time all-t1-t2: "); print(realString(realSub(realSub(tg,t1),t2))); print("\n");
end profilerresults;

function profilertime1
output Real t1;
algorithm
t1 := getGlobalRoot(Global.profilerTime1Index);
end profilertime1;

function profilertime2
output Real t2;
algorithm
t2 := getGlobalRoot(Global.profilerTime2Index);
end profilertime2;

function profilerstart1
algorithm
System.realtimeTick(ClockIndexes.RT_PROFILER1);
end profilerstart1;

function profilerstart2
algorithm
System.realtimeTick(ClockIndexes.RT_PROFILER2);
end profilerstart2;

function profilerstop1
protected
Real t;
algorithm
t := System.realtimeTock(ClockIndexes.RT_PROFILER1);
setGlobalRoot(Global.profilerTime1Index,
realAdd(getGlobalRoot(Global.profilerTime1Index),t));
end profilerstop1;

function profilerstop2
protected
Real t;
algorithm
t := System.realtimeTock(ClockIndexes.RT_PROFILER2);
setGlobalRoot(Global.profilerTime2Index,
realAdd(getGlobalRoot(Global.profilerTime2Index),t));
end profilerstop2;

function profilerreset1
algorithm
setGlobalRoot(Global.profilerTime1Index, 0.0);
end profilerreset1;

function profilerreset2
algorithm
setGlobalRoot(Global.profilerTime2Index, 0.0);
end profilerreset2;

function profilertock1
output Real t;
algorithm
t := System.realtimeTock(ClockIndexes.RT_PROFILER1);
end profilertock1;

function profilertock2
output Real t;
algorithm
t := System.realtimeTock(ClockIndexes.RT_PROFILER2);
end profilertock2;

annotation(__OpenModelica_Interface="util");
end Util;

0 comments on commit 995c5ef

Please sign in to comment.