Skip to content

Commit

Permalink
Free synchronus data again (#7141)
Browse files Browse the repository at this point in the history
  • Loading branch information
AnHeuermann committed Feb 16, 2021
1 parent 318558d commit c5c5e43
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
2 changes: 2 additions & 0 deletions OMCompiler/SimulationRuntime/c/simulation/solver/model_help.c
Expand Up @@ -950,6 +950,7 @@ void initializeDataStruc(DATA *data, threadData_t *threadData)
data->modelData->clocksInfo = (CLOCK_INFO*) omc_alloc_interface.malloc_uncollectable(data->modelData->nClocks * sizeof(CLOCK_INFO));
data->modelData->subClocksInfo = (SUBCLOCK_INFO*) omc_alloc_interface.malloc_uncollectable(data->modelData->nSubClocks * sizeof(SUBCLOCK_INFO));
data->simulationInfo->clocksData = (CLOCK_DATA*) calloc(data->modelData->nClocks, sizeof(CLOCK_DATA));
data->simulationInfo->intvlTimers = NULL;

/* set default solvers for algebraic loops */
#if !defined(OMC_MINIMAL_RUNTIME)
Expand Down Expand Up @@ -1179,6 +1180,7 @@ void deInitializeDataStruc(DATA *data)

omc_alloc_interface.free_uncollectable(data->modelData->clocksInfo);
omc_alloc_interface.free_uncollectable(data->modelData->subClocksInfo);
free(data->simulationInfo->clocksData);

/* free simulationInfo arrays */
free(data->simulationInfo->zeroCrossings);
Expand Down
Expand Up @@ -51,6 +51,7 @@
#include "meta/meta_modelica.h"
#include "simulation/solver/epsilon.h"
#include "simulation/solver/external_input.h"
#include "synchronous.h"
#include "linearSystem.h"
#include "sym_solver_ssc.h"
#include "irksco.h"
Expand Down Expand Up @@ -379,6 +380,7 @@ int freeSolverData(DATA* data, SOLVER_INFO* solverInfo)
int i;

freeList(solverInfo->eventLst);
freeSynchronous(data);
/* free solver statistics */
free(solverInfo->solverStats);
free(solverInfo->solverStatsTmp);
Expand Down
29 changes: 27 additions & 2 deletions OMCompiler/SimulationRuntime/c/simulation/solver/synchronous.c
Expand Up @@ -37,13 +37,25 @@ extern "C" {
#endif


/**
* @brief Initialize memory for synchronus functionalities.
*
* Use freeSynchronous to free data again.
*
* @param data
* @param threadData
* @param startTime
*/
void initSynchronous(DATA* data, threadData_t *threadData, modelica_real startTime)
{
TRACE_PUSH
long i;

/* Free in case initSynchronous is called multiple times */
freeSynchronous(data);

data->callback->function_initSynchronous(data, threadData);
data->simulationInfo->intvlTimers = allocList(sizeof(SYNC_TIMER));
long i;

for(i=0; i<data->modelData->nClocks; i++)
{
Expand All @@ -57,12 +69,25 @@ void initSynchronous(DATA* data, threadData_t *threadData, modelica_real startTi
}

for(i=0; i<data->modelData->nSubClocks; i++) {
assertStreamPrint(NULL, NULL != data->modelData->subClocksInfo[i].solverMethod, "Continuous clocked systems aren't supported yet");
assertStreamPrint(threadData, NULL != data->modelData->subClocksInfo[i].solverMethod, "Continuous clocked systems aren't supported yet");
}

TRACE_POP
}


/**
* @brief Frees memories allocated with initSynchronous.
*
* @param data
*/
void freeSynchronous(DATA* data)
{
freeList(data->simulationInfo->intvlTimers);
data->simulationInfo->intvlTimers = NULL;
}


#if !defined(OMC_MINIMAL_RUNTIME)
static void insertTimer(LIST* list, SYNC_TIMER* timer)
{
Expand Down
Expand Up @@ -54,6 +54,7 @@ typedef struct SYNC_TIMER {


void initSynchronous(DATA* data, threadData_t *threadData, modelica_real startTime);
void freeSynchronous(DATA* data);
void checkForSynchronous(DATA *data, SOLVER_INFO* solverInfo);
void fireClock(DATA* data, threadData_t *threadData, long idx, double curTime);
int handleTimers(DATA *data, threadData_t *threadData, SOLVER_INFO* solverInfo);
Expand Down

0 comments on commit c5c5e43

Please sign in to comment.