Skip to content

Commit 259fa72

Browse files
Marcus WaltherOpenModelica-Hudson
authored andcommitted
- Peer solver (openMP flavor) is now working
- copy constructor of model extension class makes a deep copy of all important variables now - openmp is now added to all simulation runs, if cmake has find it
1 parent ef76cd6 commit 259fa72

File tree

18 files changed

+792
-863
lines changed

18 files changed

+792
-863
lines changed

Compiler/Template/CodegenCpp.tpl

Lines changed: 49 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ let initeqs = generateEquationMemberFuncDecls(initialEquations,"initEquation")
122122
{
123123
public:
124124
<%lastIdentOfPath(modelInfo.name)%>Initialize(IGlobalSettings* globalSettings, boost::shared_ptr<IAlgLoopSolverFactory> nonlinsolverfactory, boost::shared_ptr<ISimData> sim_data, boost::shared_ptr<ISimVars> sim_vars);
125+
<%lastIdentOfPath(modelInfo.name)%>Initialize(<%lastIdentOfPath(modelInfo.name)%>Initialize& instance);
125126
virtual ~<%lastIdentOfPath(modelInfo.name)%>Initialize();
126127
virtual bool initial();
127128
virtual void setInitial(bool);
@@ -200,6 +201,7 @@ case SIMCODE(modelInfo=MODELINFO(__)) then
200201
%>
201202
public:
202203
<%lastIdentOfPath(modelInfo.name)%>Jacobian(IGlobalSettings* globalSettings, boost::shared_ptr<IAlgLoopSolverFactory> nonlinsolverfactory, boost::shared_ptr<ISimData> sim_data, boost::shared_ptr<ISimVars> sim_vars);
204+
<%lastIdentOfPath(modelInfo.name)%>Jacobian(<%lastIdentOfPath(modelInfo.name)%>Jacobian& instance);
203205
virtual ~<%lastIdentOfPath(modelInfo.name)%>Jacobian();
204206

205207
protected:
@@ -310,6 +312,7 @@ case SIMCODE(modelInfo=MODELINFO(__),simulationSettingsOpt = SOME(settings as SI
310312
{
311313
public:
312314
<%lastIdentOfPath(modelInfo.name)%>WriteOutput(IGlobalSettings* globalSettings, boost::shared_ptr<IAlgLoopSolverFactory> nonlinsolverfactory, boost::shared_ptr<ISimData> sim_data, boost::shared_ptr<ISimVars> sim_vars);
315+
<%lastIdentOfPath(modelInfo.name)%>WriteOutput(<%lastIdentOfPath(modelInfo.name)%>WriteOutput& instance);
313316
virtual ~<%lastIdentOfPath(modelInfo.name)%>WriteOutput();
314317

315318

@@ -413,8 +416,11 @@ case SIMCODE(modelInfo=MODELINFO(vars = vars as SIMVARS(__))) then
413416
{
414417
public:
415418
<%lastIdentOfPath(modelInfo.name)%>Extension(IGlobalSettings* globalSettings, boost::shared_ptr<IAlgLoopSolverFactory> nonlinsolverfactory, boost::shared_ptr<ISimData> sim_data, boost::shared_ptr<ISimVars> sim_vars);
419+
<%lastIdentOfPath(modelInfo.name)%>Extension(<%lastIdentOfPath(modelInfo.name)%>Extension &instance);
416420
virtual ~<%lastIdentOfPath(modelInfo.name)%>Extension();
417421

422+
virtual IMixedSystem* clone();
423+
418424
///Intialization methods from ISystemInitialization
419425
virtual bool initial();
420426
virtual void setInitial(bool);
@@ -534,6 +540,11 @@ case SIMCODE(modelInfo = MODELINFO(__)) then
534540
{
535541
}
536542

543+
<%lastIdentOfPath(modelInfo.name)%>Initialize::<%lastIdentOfPath(modelInfo.name)%>Initialize(<%lastIdentOfPath(modelInfo.name)%>Initialize& instance)
544+
: <%lastIdentOfPath(modelInfo.name)%>(instance)
545+
{
546+
}
547+
537548
<%lastIdentOfPath(modelInfo.name)%>Initialize::~<%lastIdentOfPath(modelInfo.name)%>Initialize()
538549
{
539550
}
@@ -680,6 +691,14 @@ case SIMCODE(modelInfo = MODELINFO(__)) then
680691
{
681692
}
682693

694+
<%lastIdentOfPath(modelInfo.name)%>Jacobian::<%lastIdentOfPath(modelInfo.name)%>Jacobian(<%lastIdentOfPath(modelInfo.name)%>Jacobian& instance)
695+
: <%lastIdentOfPath(modelInfo.name)%>(instance)
696+
, _AColorOfColumn(NULL)
697+
<%initialjacMats%>
698+
<%jacobiansVariableInit(jacobianMatrixes,simCode , &extraFuncs , &extraFuncsDecl, extraFuncsNamespace)%>
699+
{
700+
}
701+
683702
<%lastIdentOfPath(modelInfo.name)%>Jacobian::~<%lastIdentOfPath(modelInfo.name)%>Jacobian()
684703
{
685704
if(_AColorOfColumn)
@@ -736,9 +755,17 @@ case SIMCODE(modelInfo = MODELINFO(__)) then
736755
_historyImpl = new HistoryImplType(*globalSettings);
737756
}
738757

758+
<%lastIdentOfPath(modelInfo.name)%>WriteOutput::<%lastIdentOfPath(modelInfo.name)%>WriteOutput(<%lastIdentOfPath(modelInfo.name)%>WriteOutput& instance)
759+
: <%lastIdentOfPath(modelInfo.name)%>(instance.getGlobalSettings(), instance.getAlgLoopSolverFactory(), instance.getSimData(), instance.getSimVars())
760+
{
761+
_historyImpl = new HistoryImplType(*instance.getGlobalSettings());
762+
}
763+
739764
<%lastIdentOfPath(modelInfo.name)%>WriteOutput::~<%lastIdentOfPath(modelInfo.name)%>WriteOutput()
740765
{
741-
delete _historyImpl;
766+
if(_historyImpl)
767+
delete _historyImpl;
768+
_historyImpl = NULL;
742769
}
743770

744771
IHistory* <%lastIdentOfPath(modelInfo.name)%>WriteOutput::getHistory()
@@ -1035,10 +1062,25 @@ case SIMCODE(modelInfo = MODELINFO(__)) then
10351062
{
10361063
}
10371064

1065+
<%classname%>Extension::<%classname%>Extension(<%classname%>Extension& instance)
1066+
: <%classname%>(instance)
1067+
, <%classname%>WriteOutput(instance)
1068+
, <%classname%>Initialize(instance)
1069+
, <%classname%>Jacobian(instance)
1070+
, <%classname%>StateSelection(instance)
1071+
1072+
{
1073+
}
1074+
10381075
<%classname%>Extension::~<%classname%>Extension()
10391076
{
10401077
}
10411078

1079+
IMixedSystem* <%classname%>Extension::clone()
1080+
{
1081+
return new <%classname%>Extension(*this);
1082+
}
1083+
10421084
bool <%classname%>Extension::initial()
10431085
{
10441086
return <%classname%>Initialize::initial();
@@ -3070,7 +3112,7 @@ case "gcc" then
30703112
# Simulations use -O0 by default
30713113
SIM_OR_DYNLOAD_OPT_LEVEL=-O0
30723114
CC=<%CC%>
3073-
CXX=<%CXX%>
3115+
CXX=<%CXX%> $(OPENMP_FLAGS)
30743116
RUNTIME_STATIC_LINKING=<%if(Flags.isSet(Flags.RUNTIME_STATIC_LINKING)) then 'ON' else 'OFF'%>
30753117
<%MPIEnvVars%>
30763118

@@ -3454,33 +3496,15 @@ case SIMCODE(modelInfo = MODELINFO(__)) then
34543496
<%additionalConstructorBodyStatements%>
34553497
}
34563498

3457-
<%className%>::<%className%>(<%className%> &instance) : SystemDefaultImplementation(instance.getGlobalSettings(),instance._sim_data,instance._sim_vars)
3499+
<%className%>::<%className%>(<%className%> &instance) : SystemDefaultImplementation(instance)
34583500
, _algLoopSolverFactory(instance.getAlgLoopSolverFactory())
3501+
, _pointerToRealVars(instance.getSimVars()->getRealVarsVector())
3502+
, _pointerToIntVars(instance.getSimVars()->getIntVarsVector())
3503+
, _pointerToBoolVars(instance.getSimVars()->getBoolVarsVector())
34593504
<%additionalConstructorVarDefsBuffer%>
34603505
{
34613506
<%generateSimulationCppConstructorContent(simCode, context, extraFuncs, extraFuncsDecl, extraFuncsNamespace, stateDerVectorName, useFlatArrayNotation)%>
3462-
<%match modelInfo
3463-
case MODELINFO(vars=SIMVARS(__)) then
3464-
<<
3465-
double* realVars = new double[<%listLength(listAppend(vars.algVars, listAppend(vars.discreteAlgVars, listAppend(vars.aliasVars, vars.paramVars))))%> + _dimContinuousStates + _dimContinuousStates];
3466-
int* integerVars = new int[<%listLength(listAppend(listAppend(vars.intAlgVars, vars.intParamVars), vars.intAliasVars))%>];
3467-
bool* booleanVars = new bool[<%listLength(listAppend(listAppend(vars.boolAlgVars, vars.boolParamVars), vars.boolAliasVars))%>];
3468-
string* stringVars = new string[<%listLength(listAppend(listAppend(vars.stringAlgVars, vars.stringParamVars), vars.stringAliasVars))%>];
3469-
instance.getReal(realVars);
3470-
instance.getInteger(integerVars);
3471-
instance.getBoolean(booleanVars);
3472-
instance.getString(stringVars);
3473-
setReal(realVars);
3474-
setInteger(integerVars);
3475-
setBoolean(booleanVars);
3476-
setString(stringVars);
3477-
delete[] realVars;
3478-
delete[] integerVars;
3479-
delete[] booleanVars;
3480-
delete[] stringVars;
3481-
>>
3482-
%>
3483-
<%additionalConstructorBodyStatements%>
3507+
<%additionalConstructorBodyStatements%>
34843508
}
34853509

34863510
/* Destructor */

SimulationRuntime/cpp/CMakeLists.txt

Lines changed: 48 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,23 @@ IF(WIN32)
191191
SET(INSTALL_OMDEV_LIBS ON)
192192
ENDIF(WIN32)
193193

194+
# Find OpenMP
195+
FIND_PACKAGE(OpenMP)
196+
IF(OPENMP_FOUND)
197+
MESSAGE(STATUS "OPENMP enabled")
198+
ELSE(OPENMP_FOUND)
199+
MESSAGE(STATUS "OPENMP disabled")
200+
ENDIF(OPENMP_FOUND)
201+
SET(USE_OPENMP_ ${OPENMP_FOUND})
202+
203+
# Find MPI
204+
FIND_PACKAGE(MPI)
205+
IF(MPI_FOUND)
206+
MESSAGE(STATUS "MPI enabled")
207+
ELSE(MPI_FOUND)
208+
MESSAGE(STATUS "MPI disabled")
209+
ENDIF(MPI_FOUND)
210+
SET(USE_MPI_ ${MPI_FOUND})
194211

195212
# Find CMinpack
196213
# Note: Visual Studio libs are located in install/msvc, libs for gcc are directly in install
@@ -474,37 +491,37 @@ endif()
474491

475492

476493

477-
if(USE_SUNDIALS)
478-
#add Cvode solver project
479-
add_subdirectory (Solver/CVode)
480-
#add_subdirectory (Solver/ARKode)
481-
add_subdirectory(Solver/IDA)
482-
add_subdirectory (Solver/Kinsol)
483-
#add Idas solver project
484-
##add_subdirectory (Solver/Idas/Implementation)
485-
##add_subdirectory (Solver/Ida/Implementation)
486-
GET_TARGET_PROPERTY(libCVode ${CVodeName} LOCATION)
487-
GET_TARGET_PROPERTY(libARKode ${ARKodeName} LOCATION)
488-
GET_FILENAME_COMPONENT(libCVodeName ${libCVode} NAME)
489-
GET_FILENAME_COMPONENT(libARKodeName ${libARKode} NAME)
490-
491-
GET_TARGET_PROPERTY(libIDA ${IDAName} LOCATION)
492-
GET_FILENAME_COMPONENT(libIDAName ${libIDA} NAME)
493-
494-
GET_TARGET_PROPERTY(libKinsol ${KinsolName} LOCATION)
495-
GET_FILENAME_COMPONENT(libKinsolName ${libKinsol} NAME)
496-
#GET_TARGET_PROPERTY(libIdas ${IdasName} LOCATION)
497-
#GET_FILENAME_COMPONENT(libIdasName ${libIdas} NAME)
498-
#GET_TARGET_PROPERTY(libIda ${IdaName} LOCATION)
499-
#GET_FILENAME_COMPONENT(libIdaName ${libIda} NAME)
500-
501-
#set (IDAS_LIB ${libIdasName})
502-
set (CVODE_LIB ${libCVodeName})
503-
set (ARKODE_LIB ${libARKodeName})
504-
set(IDA_LIB ${libIDAName})
505-
set (KINSOL_LIB ${libKinsolName})
506-
#set (IDA_LIB ${libIdaName})
507-
endIf()
494+
IF(USE_SUNDIALS)
495+
#add Cvode solver project
496+
ADD_SUBDIRECTORY (Solver/CVode)
497+
#add_subdirectory (Solver/ARKode)
498+
ADD_SUBDIRECTORY(Solver/IDA)
499+
ADD_SUBDIRECTORY(Solver/Kinsol)
500+
#add Idas solver project
501+
##add_subdirectory (Solver/Idas/Implementation)
502+
##add_subdirectory (Solver/Ida/Implementation)
503+
GET_TARGET_PROPERTY(libCVode ${CVodeName} LOCATION)
504+
GET_TARGET_PROPERTY(libARKode ${ARKodeName} LOCATION)
505+
GET_FILENAME_COMPONENT(libCVodeName ${libCVode} NAME)
506+
GET_FILENAME_COMPONENT(libARKodeName ${libARKode} NAME)
507+
508+
GET_TARGET_PROPERTY(libIDA ${IDAName} LOCATION)
509+
GET_FILENAME_COMPONENT(libIDAName ${libIDA} NAME)
510+
511+
GET_TARGET_PROPERTY(libKinsol ${KinsolName} LOCATION)
512+
GET_FILENAME_COMPONENT(libKinsolName ${libKinsol} NAME)
513+
#GET_TARGET_PROPERTY(libIdas ${IdasName} LOCATION)
514+
#GET_FILENAME_COMPONENT(libIdasName ${libIdas} NAME)
515+
#GET_TARGET_PROPERTY(libIda ${IdaName} LOCATION)
516+
#GET_FILENAME_COMPONENT(libIdaName ${libIda} NAME)
517+
518+
#set (IDAS_LIB ${libIdasName})
519+
SET(CVODE_LIB ${libCVodeName})
520+
SET(ARKODE_LIB ${libARKodeName})
521+
SET(IDA_LIB ${libIDAName})
522+
SET(KINSOL_LIB ${libKinsolName})
523+
#set(IDA_LIB ${libIdaName})
524+
ENDIF(USE_SUNDIALS)
508525

509526
GET_TARGET_PROPERTY(libPeer ${PeerName} LOCATION)
510527
GET_FILENAME_COMPONENT(libPeerName ${libPeer} NAME)

SimulationRuntime/cpp/Core/DataExchange/SimData.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,19 @@ SimData::SimData(void)
1111
{
1212
}
1313

14+
SimData::SimData(SimData &instance)
15+
{
16+
}
17+
1418
SimData::~SimData(void)
1519
{
1620
}
1721

22+
ISimData* SimData::clone()
23+
{
24+
return new SimData(*this);
25+
}
26+
1827
void SimData::Add(string key, boost::shared_ptr<ISimVar> var)
1928
{
2029
std::pair<string,boost::shared_ptr<ISimVar> > elem(key,var);

SimulationRuntime/cpp/Core/Modelica/ModelicaConfig_gcc.inc.in

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,7 @@ SCOREP_INCLUDE=@SCOREP_INCLUDE_@
3737
USE_SCOREP=@USE_SCOREP_@
3838
USE_FMU_KINSOL=@USE_FMU_KINSOL_@
3939
USE_PAPI=@USE_PAPI_@
40+
41+
USE_MPI=@USE_MPI_@
42+
USE_OPENMP=@USE_OPENMP_@
43+
OPENMP_FLAGS=@OpenMP_CXX_FLAGS@

SimulationRuntime/cpp/Core/SimController/SimManager.cpp

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -602,32 +602,33 @@ void SimManager::runSingleProcess()
602602
_solverTask = ISolver::SOLVERCALL(_solverTask | ISolver::RECALL);
603603
}
604604
startTime = endTime;
605-
if (_dimtimeevent)
606-
{
607-
// Find all time events at the current time
608-
while((iter !=_tStops[0].end()) && (abs(iter->first - endTime) <1e4*UROUND))
609-
{
610-
_timeeventcounter[iter->second]++;
611-
iter++;
612-
}
613-
// set the iterator back to the current end time
614-
iter--;
615-
616-
// Then handle time events
617-
_timeevent_system->handleTimeEvent(_timeeventcounter);
605+
if (_dimtimeevent)
606+
{
607+
// Find all time events at the current time
608+
while((iter !=_tStops[0].end()) && (abs(iter->first - endTime) <1e4*UROUND))
609+
{
610+
_timeeventcounter[iter->second]++;
611+
iter++;
612+
}
613+
// set the iterator back to the current end time
614+
iter--;
615+
616+
// Then handle time events
617+
_timeevent_system->handleTimeEvent(_timeeventcounter);
618618

619-
_event_system->getZeroFunc(zeroVal_new);
620-
for (int i = 0; i < _dimZeroFunc; i++)
621-
_events[i] = bool(zeroVal_new[i]);
622-
_mixed_system->handleSystemEvents(_events);
623-
//reset time-events
624-
_timeevent_system->handleTimeEvent(_timeeventcounter);
625-
}
619+
_event_system->getZeroFunc(zeroVal_new);
620+
for (int i = 0; i < _dimZeroFunc; i++)
621+
_events[i] = bool(zeroVal_new[i]);
622+
_mixed_system->handleSystemEvents(_events);
623+
//reset time-events
624+
_timeevent_system->handleTimeEvent(_timeeventcounter);
625+
}
626626

627-
user_stop = (_solver->getSolverStatus() & ISolver::USER_STOP);
628-
if (user_stop)
629-
break;
627+
user_stop = (_solver->getSolverStatus() & ISolver::USER_STOP);
628+
if (user_stop)
629+
break;
630630
} // end for time events
631+
631632
if (abs(_tEnd - endTime) > _config->getSimControllerSettings()->dTendTol && !user_stop)
632633
{
633634
startTime = endTime;

SimulationRuntime/cpp/Core/System/EventHandling.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,16 @@ Constructor
1616
*/
1717
EventHandling::EventHandling()
1818
{
19-
_continuousEvents = boost::shared_ptr<ContinuousEvents>(new ContinuousEvents());
19+
_continuousEvents = boost::shared_ptr<ContinuousEvents>(new ContinuousEvents());
2020
}
2121

22-
EventHandling::~EventHandling(void)
22+
EventHandling::EventHandling(EventHandling& instance)
2323
{
24+
_continuousEvents = boost::shared_ptr<ContinuousEvents>(new ContinuousEvents());
25+
}
2426

25-
27+
EventHandling::~EventHandling(void)
28+
{
2629
}
2730

2831
/**

0 commit comments

Comments
 (0)