Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
niklwors committed Aug 13, 2015
2 parents 03cb48d + 44f0b91 commit ed2fbf8
Show file tree
Hide file tree
Showing 16 changed files with 143 additions and 112 deletions.
5 changes: 3 additions & 2 deletions Compiler/BackEnd/HpcOmScheduler.mo
Expand Up @@ -2475,10 +2475,11 @@ algorithm
extInfo = HpcOmSchedulerExt.scheduleMetis(xadj, adjncy, vwgt, adjwgt, iNumberOfThreads);
extInfoArr = listArray(extInfo);
else
extInfoArr = arrayCreate(arrayLength(iTaskGraph), -1);
extInfoArr = arrayCreate(arrayLength(iTaskGraph), 1);
extInfo = arrayList(extInfoArr);
end if;

//print("External scheduling info: " + stringDelimitList(List.map(extInfo, intString), ",") + "\n");
//print("Metis scheduling info: " + stringDelimitList(List.map(extInfo, intString), ",") + "\n");
true = intEq(arrayLength(iTaskGraph),arrayLength(extInfoArr));
taskGraphT = BackendDAEUtil.transposeMatrix(iTaskGraph,arrayLength(iTaskGraph));
rootNodes = HpcOmTaskGraph.getRootNodes(iTaskGraph);
Expand Down
23 changes: 11 additions & 12 deletions Compiler/Template/CodegenC.tpl
Expand Up @@ -312,23 +312,24 @@ match baseClock
case DAE.BOOLEAN_CLOCK(__) then
let cond = cref(expCref(condition))
<<
if (data->simulationInfo.clocksData[i].cnt > 0)
data->simulationInfo.clocksData[i].interval = time - data->simulationInfo.clocksData[i].timepoint;
else
if (data->simulationInfo.clocksData[i].cnt > 0) {
data->simulationInfo.clocksData[i].interval = data->localData[0]->timeValue - data->simulationInfo.clocksData[i].timepoint;
} else {
data->simulationInfo.clocksData[i].interval = <%startInterval%>;
data->simulationInfo.clocksData[i].timepoint = time;
}
data->simulationInfo.clocksData[i].timepoint = data->localData[0]->timeValue;
'return <%cond%> && !$P$PRE<%cond%>;'
>>
else
let &preExp = buffer ""
let intvl = daeExp(getClockIntvl(baseClock), contextOther, &preExp, &varDecls, &auxFunction)
<<
<%preExp%>
if (time < data->simulationInfo.clocksData[i].timepoint)
if (data->localData[0]->timeValue < data->simulationInfo.clocksData[i].timepoint)
ret = <%boolStrC(false)%>;
else {
data->simulationInfo.clocksData[i].interval = <%intvl%>;
data->simulationInfo.clocksData[i].timepoint = time + data->simulationInfo.clocksData[i].interval;
data->simulationInfo.clocksData[i].timepoint = data->localData[0]->timeValue + data->simulationInfo.clocksData[i].interval;
ret = <%boolStrC(true)%>;
}
>>
Expand Down Expand Up @@ -1102,8 +1103,6 @@ template variableDefinitions(ModelInfo modelInfo, list<BackendDAE.TimeEvent> tim
match modelInfo
case MODELINFO(varInfo=VARINFO(numStateVars=numStateVars, numAlgVars= numAlgVars, numDiscreteReal=numDiscreteReal, numOptimizeConstraints=numOptimizeConstraints, numOptimizeFinalConstraints=numOptimizeFinalConstraints), vars=SIMVARS(__)) then
<<
#define time data->localData[0]->timeValue

/* States */
<%vars.stateVars |> var =>
globalDataVarDefine(var, "realVars", 0)
Expand Down Expand Up @@ -2731,7 +2730,7 @@ template functionStoreDelayed(DelayedExpression delayed, String modelNamePrefix)
let delayExpMax = daeExp(delayMax, contextSimulationNonDiscrete, &preExp, &varDecls, &auxFunction)
<<
<%preExp%>
storeDelayedExpression(data, threadData, <%id%>, <%eRes%>, time, <%delayExp%>, <%delayExpMax%>);<%\n%>
storeDelayedExpression(data, threadData, <%id%>, <%eRes%>, data->localData[0]->timeValue, <%delayExp%>, <%delayExpMax%>);<%\n%>
>>
))
<<
Expand Down Expand Up @@ -4623,7 +4622,7 @@ template equationNonlinear(SimEqSystem eq, Context context, Text &varDecls, Stri
let returnval2 = match at case at as SOME(__) then 'return 0;' case at as NONE() then ''
<<
int retValue;
debugDouble(LOG_DT, "Solving nonlinear system <%nls.index%> (STRICT TEARING SET if tearing enabled) at time =", time);
debugDouble(LOG_DT, "Solving nonlinear system <%nls.index%> (STRICT TEARING SET if tearing enabled) at time =", data->localData[0]->timeValue);
<% if profileSome() then
<<
SIM_PROF_TICK_EQ(modelInfoGetEquation(&data->modelData.modelDataXml,<%nls.index%>).profileBlockIndex);
Expand All @@ -4643,7 +4642,7 @@ template equationNonlinear(SimEqSystem eq, Context context, Text &varDecls, Stri
/* check if solution process was successful */
if (retValue > 0){
const int indexes[2] = {1,<%nls.index%>};
throwStreamPrintWithEquationIndexes(threadData, indexes, "Solving non-linear system <%nls.index%> failed at time=%.15g.\nFor more information please use -lv LOG_NLS.", time);
throwStreamPrintWithEquationIndexes(threadData, indexes, "Solving non-linear system <%nls.index%> failed at time=%.15g.\nFor more information please use -lv LOG_NLS.", data->localData[0]->timeValue);
<%returnval2%>
}
/* write solution */
Expand All @@ -4666,7 +4665,7 @@ template equationNonlinearAlternativeTearing(SimEqSystem eq, Context context, Te
let nonlinindx = at.indexNonLinearSystem
<<
int retValue;
debugDouble(LOG_DT, "Solving nonlinear system <%at.index%> (CASUAL TEARING SET) at time =", time);
debugDouble(LOG_DT, "Solving nonlinear system <%at.index%> (CASUAL TEARING SET) at time =", data->localData[0]->timeValue);
<% if profileSome() then
<<
SIM_PROF_TICK_EQ(modelInfoGetEquation(&data->modelData.modelDataXml,<%at.index%>).profileBlockIndex);
Expand Down
30 changes: 15 additions & 15 deletions Compiler/Template/CodegenCFunctions.tpl
Expand Up @@ -2010,22 +2010,22 @@ match v
case TYPES_VAR(__) then
let vn = '<%varName%>._<%name%>'
let defaultArrayValue =
match ty
match ty
case ty as T_ARRAY(__) then
let arrayType = expType(ty, true)
let dims = (ty.dims |> dim => dimension(dim) ;separator=", ")
'alloc_<%arrayType%>(&<%vn%>, <%listLength(ty.dims)%>, <%dims%>);'
else
''
end match
'alloc_<%arrayType%>(&<%vn%>, <%listLength(ty.dims)%>, <%dims%>);'
else
''
end match
let defaultValue =
match binding
case VALBOUND(valBound = val) then
'<%vn%> = <%daeExp(valueExp(val), contextFunction, &varInits, &varDecls, &auxFunction)%>;'
case EQBOUND(evaluatedExp = SOME(val)) then
'<%vn%> = <%daeExp(valueExp(val), contextFunction, &varInits, &varDecls, &auxFunction)%>;'
case EQBOUND(exp = exp) then
'<%vn%> = <%daeExp(exp, contextFunction, &varInits, &varDecls, &auxFunction)%>;'
case VALBOUND(valBound = val) then
'<%vn%> = <%daeExp(valueExp(val), contextFunction, &varInits, &varDecls, &auxFunction)%>;'
case EQBOUND(evaluatedExp = SOME(val)) then
'<%vn%> = <%daeExp(valueExp(val), contextFunction, &varInits, &varDecls, &auxFunction)%>;'
case EQBOUND(exp = exp) then
'<%vn%> = <%daeExp(exp, contextFunction, &varInits, &varDecls, &auxFunction)%>;'
else
'<%defaultArrayValue%>'
end match
Expand Down Expand Up @@ -3872,7 +3872,7 @@ template assertCommon(Exp condition, list<Exp> messages, Exp level, Context cont
let msgVar = messages |> message => expToFormatString(message,context,&preExpMsg,&varDecls,&auxFunction) ; separator = ", "
let eqnsindx = match context case FUNCTION_CONTEXT(__) then '' else 'equationIndexes, '
let AddionalFuncName = match context case FUNCTION_CONTEXT(__) then '' else '_withEquationIndexes'
let addInfoTextContext = match context case FUNCTION_CONTEXT(__) then '' else '<%\n%>omc_assert_warning(info, "The following assertion has been violated at time %f\n<%Util.escapeModelicaStringToCString(printExpStr(condition))%>", time);'
let addInfoTextContext = match context case FUNCTION_CONTEXT(__) then '' else '<%\n%>omc_assert_warning(info, "The following assertion has been violated at time %f\n<%Util.escapeModelicaStringToCString(printExpStr(condition))%>", data->localData[0]->timeValue);'
let omcAssertFunc = match level case ENUM_LITERAL(index=2) then 'omc_assert_warning<%AddionalFuncName%>(' else 'omc_assert<%AddionalFuncName%>(threadData, '
let warningTriggered = tempDeclZero("static int", &varDecls)
let TriggerIf = match level case ENUM_LITERAL(index=2) then 'if(!<%warningTriggered%>)<%\n%>' else ''
Expand Down Expand Up @@ -3918,7 +3918,7 @@ template assertCommonVar(Text condVar, Text msgVar, Context context, Text &preEx
<%preExpMsg%>
{
FILE_INFO info = {<%infoArgs(info)%>};
omc_assert_warning(info, "The following assertion has been violated at time %f", time);
omc_assert_warning(info, "The following assertion has been violated at time %f", data->localData[0]->timeValue);
throwStreamPrintWithEquationIndexes(threadData, equationIndexes, <%msgVar%>);
}
}<%\n%>
Expand Down Expand Up @@ -3962,7 +3962,7 @@ end contextIteratorName;
::=
match cr
case CREF_IDENT(ident = "xloc") then crefStr(cr)
case CREF_IDENT(ident = "time") then "time"
case CREF_IDENT(ident = "time") then "data->localData[0]->timeValue"
case WILD(__) then ''
else "$P" + crefToCStr(cr)
end cref;
Expand Down Expand Up @@ -5594,7 +5594,7 @@ template daeExpCall(Exp call, Context context, Text &preExp, Text &varDecls, Tex
let var1 = daeExp(e, context, &preExp, &varDecls, &auxFunction)
let var2 = daeExp(d, context, &preExp, &varDecls, &auxFunction)
let var3 = daeExp(delayMax, context, &preExp, &varDecls, &auxFunction)
let &preExp += '<%tvar%> = delayImpl(data, threadData, <%index%>, <%var1%>, time, <%var2%>, <%var3%>);<%\n%>'
let &preExp += '<%tvar%> = delayImpl(data, threadData, <%index%>, <%var1%>, data->localData[0]->timeValue, <%var2%>, <%var3%>);<%\n%>'
'<%tvar%>'

case CALL(path=IDENT(name="Integer"), expLst={toBeCasted}) then
Expand Down
4 changes: 4 additions & 0 deletions Compiler/Template/CodegenCpp.tpl
Expand Up @@ -3140,6 +3140,10 @@ case "gcc" then
$(eval CFLAGS_COMMON=$(CFLAGS_COMMON) -DMEASURETIME_PROFILEBLOCKS)
endif

ifeq ($(USE_LOGGER),ON)
$(eval CFLAGS_COMMON=$(CFLAGS_COMMON) -DUSE_LOGGER)
endif

CFLAGS_DYNAMIC=$(CFLAGS_COMMON)
CFLAGS_STATIC=$(CFLAGS_COMMON) <%staticIncludes%> -DRUNTIME_STATIC_LINKING

Expand Down
5 changes: 5 additions & 0 deletions Compiler/Template/CodegenFMUCpp.tpl
Expand Up @@ -735,6 +735,11 @@ case SIMCODE(modelInfo=MODELINFO(__), makefileParams=MAKEFILE_PARAMS(__), simula

FMU_CFLAGS=$(SYSTEM_CFLAGS:-O0=$(SIM_OR_DYNLOAD_OPT_LEVEL))
CFLAGS=$(CFLAGS_BASED_ON_INIT_FILE) -Winvalid-pch $(FMU_CFLAGS) -DRUNTIME_STATIC_LINKING -I"$(OMHOME)/include/omc/cpp" -I"$(UMFPACK_INCLUDE)" -I"$(BOOST_INCLUDE)" <%makefileParams.includes ; separator=" "%> <%additionalCFlags_GCC%>

ifeq ($(USE_LOGGER),ON)
$(eval CFLAGS=$(CFLAGS) -DUSE_LOGGER)
endif

CPPFLAGS = $(CFLAGS)
LDFLAGS=-L"$(OMHOME)/lib/<%getTriple()%>/omc/cpp" -L"$(BOOST_LIBS)" <%additionalLinkerFlags_GCC%>
PLATFORM="<%platformstr%>"
Expand Down
4 changes: 2 additions & 2 deletions SimulationRuntime/c/util/division.h
Expand Up @@ -38,10 +38,10 @@
#ifdef CHECK_NAN
#define DIVISION(a,b,c) (((b) != 0) ? (isnan_error(((a) / (b)), c, __FILE__, __LINE__)) : ((a) / division_error(threadData, b, c, __FILE__, __LINE__)))
#else
#define DIVISION(a,b,c) (((b) != 0) ? ((a) / (b)) : ((a) / division_error_time(threadData, b, c, time, __FILE__, __LINE__,data->simulationInfo.noThrowDivZero?1:0)))
#define DIVISION(a,b,c) (((b) != 0) ? ((a) / (b)) : ((a) / division_error_time(threadData, b, c, data->localData[0]->timeValue, __FILE__, __LINE__,data->simulationInfo.noThrowDivZero?1:0)))
#endif

#define DIVISION_SIM(a,b,msg,equation) (initial() && (a) == 0 && (b) == 0 ? 0 : ((b) != 0) ? ((a) / (b)) : ((a) / division_error_equation_time(threadData, a, b, msg, equation, time, data->simulationInfo.noThrowDivZero?1:0)))
#define DIVISION_SIM(a,b,msg,equation) (initial() && (a) == 0 && (b) == 0 ? 0 : ((b) != 0) ? ((a) / (b)) : ((a) / division_error_equation_time(threadData, a, b, msg, equation, data->localData[0]->timeValue, data->simulationInfo.noThrowDivZero?1:0)))

#define DIVISIONNOTIME(a,b,c) (((b) != 0) ? ((a) / (b)) : ((a) / division_error(threadData, b, c, __FILE__, __LINE__)))

Expand Down
17 changes: 15 additions & 2 deletions SimulationRuntime/cpp/CMakeLists.txt
Expand Up @@ -13,6 +13,7 @@
# if the Pugi XML library was found -DUSE_PUGI_XML
# if profiling for the simulation runtime should be enabled -DRUNTIME_PROFILING
# if the equation systems of a FMU should be solved with kinsol -DFMU_KINSOL
# if the logger should be used -DUSE_LOGGER
#
# Some of these options can be controlled by passing arguments to CMAKE
# if write output should be handled in parallel -DUSE_PARALLEL_OUTPUT=ON
Expand Down Expand Up @@ -142,6 +143,16 @@ ELSE(FMU_KINSOL)
MESSAGE(STATUS "FMU kinsol disabled")
ENDIF(FMU_KINSOL)

# Handle Logger usage
IF(USE_LOGGER)
ADD_DEFINITIONS(-DUSE_LOGGER)
SET(USE_LOGGER_ "ON")
MESSAGE(STATUS "Logger enabled")
ELSE(USE_LOGGER)
MESSAGE(STATUS "Logger disabled")
SET(USE_LOGGER_ "OFF")
ENDIF(USE_LOGGER)

# Handle build type
IF(OMC_BUILD)
ADD_DEFINITIONS(-DOMC_BUILD)
Expand Down Expand Up @@ -185,19 +196,21 @@ ENDIF(WIN32)
FIND_PACKAGE(OpenMP)
IF(OPENMP_FOUND)
MESSAGE(STATUS "OPENMP enabled")
SET(USE_OPENMP_ "ON")
ELSE(OPENMP_FOUND)
MESSAGE(STATUS "OPENMP disabled")
SET(USE_OPENMP_ "OFF")
ENDIF(OPENMP_FOUND)
SET(USE_OPENMP_ ${OPENMP_FOUND})

# Find MPI
FIND_PACKAGE(MPI)
IF(MPI_FOUND)
MESSAGE(STATUS "MPI enabled")
SET(USE_MPI_ "ON")
ELSE(MPI_FOUND)
MESSAGE(STATUS "MPI disabled")
SET(USE_MPI_ "OFF")
ENDIF(MPI_FOUND)
SET(USE_MPI_ ${MPI_FOUND})

# Find CMinpack
# Note: Visual Studio libs are located in install/msvc, libs for gcc are directly in install
Expand Down
Expand Up @@ -37,7 +37,8 @@ SCOREP_INCLUDE=@SCOREP_INCLUDE_@
USE_SCOREP=@USE_SCOREP_@
USE_FMU_KINSOL=@USE_FMU_KINSOL_@
USE_PAPI=@USE_PAPI_@
USE_LOGGER=@USE_LOGGER_@

USE_MPI=@USE_MPI_@
USE_OPENMP=@USE_OPENMP_@
OPENMP_FLAGS=@OpenMP_CXX_FLAGS@
OPENMP_FLAGS=@OpenMP_CXX_FLAGS@
Expand Up @@ -32,3 +32,5 @@ H_FILE = @H_FILE@
BUILD_TYPE = @BUILD_TYPE@
SYSTEM_CFLAGS = @SYSTEM_CFLAGS@
ADDITIONAL_DEFINES = @ADDITIONAL_DEFINES@

USE_LOGGER=@USE_LOGGER_@
12 changes: 10 additions & 2 deletions SimulationRuntime/cpp/Include/Core/Utils/extension/logger.hpp
Expand Up @@ -34,16 +34,24 @@ class BOOST_EXTENSION_LOGGER_DECL Logger
initialize(LogSettings());
}

static void write(std::string msg, LogCategory cat, LogLevel lvl)
static inline void write(std::string msg, LogCategory cat, LogLevel lvl)
{
#ifndef USE_LOGGER
return;
#else
Logger* instance = getInstance();
if(instance && instance->isEnabled())
instance->writeInternal(msg, cat, lvl);
#endif
}

static void write(std::string msg, std::pair<LogCategory,LogLevel> mode)
static inline void write(std::string msg, std::pair<LogCategory,LogLevel> mode)
{
#ifndef USE_LOGGER
return;
#else
write(msg, mode.first, mode.second);
#endif
}

static void setEnabled(bool enabled)
Expand Down

0 comments on commit ed2fbf8

Please sign in to comment.