Skip to content
This repository was archived by the owner on May 18, 2019. It is now read-only.

Commit 72fdfb4

Browse files
sjoelundOpenModelica-Hudson
authored andcommitted
Do not run both event and output timers at the same time
When doing event iteration, we sometimes emit to the result-file. When doing so, we should not include this time in the time it takes to perform event iteration. Fixes https://trac.openmodelica.org/OpenModelica/ticket/5381 Belonging to [master]: - #2993
1 parent d85a258 commit 72fdfb4

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

SimulationRuntime/c/simulation/solver/perform_simulation.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,11 @@ static int simulationUpdate(DATA* data, threadData_t *threadData, SOLVER_INFO* s
110110
threadData->currentErrorStage = ERROR_EVENTHANDLING;
111111
infoStreamPrint(LOG_EVENTS, 1, "%s event at time=%.12g", eventType == 1 ? "time" : "state", solverInfo->currentTime);
112112
/* prevent emit if noEventEmit flag is used */
113-
if (!(omc_flag[FLAG_NOEVENTEMIT])) /* output left limit */
113+
if (!(omc_flag[FLAG_NOEVENTEMIT])) /* output left limit */ {
114+
rt_accumulate(SIM_TIMER_EVENT);
114115
sim_result.emit(&sim_result, data, threadData);
116+
rt_tick(SIM_TIMER_EVENT);
117+
}
115118
handleEvents(data, threadData, solverInfo->eventLst, &(solverInfo->currentTime), solverInfo);
116119
cleanUpOldValueListAfterEvent(data, solverInfo->currentTime);
117120
messageClose(LOG_EVENTS);
@@ -125,7 +128,7 @@ static int simulationUpdate(DATA* data, threadData_t *threadData, SOLVER_INFO* s
125128
solverInfo->didEventStep = 0;
126129
}
127130

128-
if (measure_time_flag) rt_accumulate(SIM_TIMER_EVENT);
131+
if (measure_time_flag) { rt_accumulate(SIM_TIMER_EVENT); rt_tick(SIM_TIMER_EVENT); }
129132
/***** End event handling *****/
130133

131134

@@ -208,8 +211,8 @@ static void fmtEmitStep(DATA* data, threadData_t *threadData, MEASURE_TIME* mt,
208211
double tmpdbl;
209212
unsigned int tmpint;
210213
int total = data->modelData->modelDataXml.nFunctions + data->modelData->modelDataXml.nProfileBlocks;
211-
rt_tick(SIM_TIMER_OVERHEAD);
212214
rt_accumulate(SIM_TIMER_STEP);
215+
rt_tick(SIM_TIMER_OVERHEAD);
213216

214217
/* Disable time measurements if we have trouble writing to the file... */
215218
flag = flag && 1 == fwrite(&mt->stepNo, sizeof(unsigned int), 1, mt->fmtInt);

SimulationRuntime/c/simulation/solver/solver_main.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,7 @@ int finishSimulation(DATA* data, threadData_t *threadData, SOLVER_INFO* solverIn
512512

513513
int retValue = 0;
514514
int ui;
515+
double t;
515516

516517
SIMULATION_INFO *simInfo = data->simulationInfo;
517518

@@ -555,10 +556,8 @@ int finishSimulation(DATA* data, threadData_t *threadData, SOLVER_INFO* solverIn
555556
infoStreamPrint(LOG_STATS, 0, "%12gs [%5.1f%%] event-handling", rt_accumulated(SIM_TIMER_EVENT), rt_accumulated(SIM_TIMER_EVENT)/rt_accumulated(SIM_TIMER_TOTAL)*100.0);
556557
infoStreamPrint(LOG_STATS, 0, "%12gs [%5.1f%%] overhead", rt_accumulated(SIM_TIMER_OVERHEAD), rt_accumulated(SIM_TIMER_OVERHEAD)/rt_accumulated(SIM_TIMER_TOTAL)*100.0);
557558

558-
if(S_OPTIMIZATION != solverInfo->solverMethod)
559-
infoStreamPrint(LOG_STATS, 0, "%12gs [%5.1f%%] simulation", rt_accumulated(SIM_TIMER_TOTAL)-rt_accumulated(SIM_TIMER_OVERHEAD)-rt_accumulated(SIM_TIMER_EVENT)-rt_accumulated(SIM_TIMER_OUTPUT)-rt_accumulated(SIM_TIMER_STEP)-rt_accumulated(SIM_TIMER_INIT)-rt_accumulated(SIM_TIMER_PREINIT), (rt_accumulated(SIM_TIMER_TOTAL)-rt_accumulated(SIM_TIMER_OVERHEAD)-rt_accumulated(SIM_TIMER_EVENT)-rt_accumulated(SIM_TIMER_OUTPUT)-rt_accumulated(SIM_TIMER_STEP)-rt_accumulated(SIM_TIMER_INIT)-rt_accumulated(SIM_TIMER_PREINIT))/rt_accumulated(SIM_TIMER_TOTAL)*100.0);
560-
else
561-
infoStreamPrint(LOG_STATS, 0, "%12gs [%5.1f%%] optimization", rt_accumulated(SIM_TIMER_TOTAL)-rt_accumulated(SIM_TIMER_OVERHEAD)-rt_accumulated(SIM_TIMER_EVENT)-rt_accumulated(SIM_TIMER_OUTPUT)-rt_accumulated(SIM_TIMER_STEP)-rt_accumulated(SIM_TIMER_INIT)-rt_accumulated(SIM_TIMER_PREINIT), (rt_accumulated(SIM_TIMER_TOTAL)-rt_accumulated(SIM_TIMER_OVERHEAD)-rt_accumulated(SIM_TIMER_EVENT)-rt_accumulated(SIM_TIMER_OUTPUT)-rt_accumulated(SIM_TIMER_STEP)-rt_accumulated(SIM_TIMER_INIT)-rt_accumulated(SIM_TIMER_PREINIT))/rt_accumulated(SIM_TIMER_TOTAL)*100.0);
559+
t = rt_accumulated(SIM_TIMER_TOTAL)-rt_accumulated(SIM_TIMER_OVERHEAD)-rt_accumulated(SIM_TIMER_EVENT)-rt_accumulated(SIM_TIMER_OUTPUT)-rt_accumulated(SIM_TIMER_STEP)-rt_accumulated(SIM_TIMER_INIT)-rt_accumulated(SIM_TIMER_PREINIT);
560+
infoStreamPrint(LOG_STATS, 0, "%12gs [%5.1f%%] %s", t, t/rt_accumulated(SIM_TIMER_TOTAL)*100.0, S_OPTIMIZATION == solverInfo->solverMethod ? "optimization" : "simulation");
562561

563562
infoStreamPrint(LOG_STATS, 0, "%12gs [%5.1f%%] total", rt_accumulated(SIM_TIMER_TOTAL), rt_accumulated(SIM_TIMER_TOTAL)/rt_accumulated(SIM_TIMER_TOTAL)*100.0);
564563
messageClose(LOG_STATS);

0 commit comments

Comments
 (0)