Skip to content

Commit

Permalink
- optimized parallel write output
Browse files Browse the repository at this point in the history
- added profiling points for the write output functionality
- added profiling based on papi counters to the cpp-runtime

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@22439 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Marcus Walther committed Sep 26, 2014
1 parent 487c23d commit 4f656e7
Show file tree
Hide file tree
Showing 14 changed files with 1,388 additions and 1,000 deletions.
146 changes: 109 additions & 37 deletions Compiler/Template/CodegenCpp.tpl
Expand Up @@ -392,6 +392,11 @@ case SIMCODE(modelInfo=MODELINFO(__),simulationSettingsOpt = SOME(settings as SI
void writeBoolParameterDescription(vector<string>& names);
HistoryImplType* _historyImpl;
<% if boolNot(stringEq(getConfigString(PROFILING_LEVEL),"none")) then
<<
MeasureTimeValues *measuredStartValues, *measuredStartValues1, *measuredEndValues, *measuredEndValues1;
std::vector<MeasureTimeData> measureTimeWriteOutput;
>>%>
};
>>
end simulationWriteOutputHeaderFile;
Expand Down Expand Up @@ -603,6 +608,18 @@ case SIMCODE(modelInfo = MODELINFO(__)) then
: <%lastIdentOfPath(modelInfo.name)%>(globalSettings,nonlinsolverfactory,simData)
{
_historyImpl = new HistoryImplType(*globalSettings);
<% if boolNot(stringEq(getConfigString(PROFILING_LEVEL),"none")) then
<<
measureTimeWriteOutput = std::vector<MeasureTimeData>(2);
measureTimeWriteOutput[0] = MeasureTimeData("writeOutputComplete");
measureTimeWriteOutput[1] = MeasureTimeData("writeOutputAssignVars");
MeasureTime::addResultContentBlock("<%dotPath(modelInfo.name)%>","writeOutputMeasurements", &measureTimeWriteOutput);
measuredStartValues = MeasureTime::getZeroValues();
measuredEndValues = MeasureTime::getZeroValues();
measuredStartValues1 = MeasureTime::getZeroValues();
measuredEndValues1 = MeasureTime::getZeroValues();
>>%>
}


Expand Down Expand Up @@ -1271,15 +1288,27 @@ case SIMCODE(modelInfo=MODELINFO(__), makefileParams=MAKEFILE_PARAMS(__)) then
#include <Core/ModelicaDefine.h>
#include <SimCoreFactory/Policies/FactoryConfig.h>
#include <SimController/ISimController.h>
<% if boolNot(stringEq(getConfigString(PROFILING_LEVEL),"none")) then '#include "Core/Utils/extension/measure_time_rdtsc.hpp"' %>
<%
match(getConfigString(PROFILING_LEVEL))
case("none") then ''
case("all_perf") then '#include "Core/Utils/extension/measure_time_papi.hpp"'
else '#include "Core/Utils/extension/measure_time_rdtsc.hpp"'
end match
%>
#if defined(_MSC_VER) || defined(__MINGW32__)
#include <tchar.h>
int _tmain(int argc, const _TCHAR* argv[])
#else
int main(int argc, const char* argv[])
#endif
{
<% if boolNot(stringEq(getConfigString(PROFILING_LEVEL),"none")) then 'MeasureTimeRDTSC::initialize();' %>
<%
match(getConfigString(PROFILING_LEVEL))
case("none") then ''
case("all_perf") then 'MeasureTimePAPI::initialize();'
else 'MeasureTimeRDTSC::initialize();'
end match
%>
try
{
boost::shared_ptr<OMCFactory> _factory = boost::shared_ptr<OMCFactory>(new OMCFactory());
Expand Down Expand Up @@ -1589,7 +1618,13 @@ let libsPos1 = if not dirExtra then libsStr //else ""
let libsPos2 = if dirExtra then libsStr // else ""
let _extraCflags = match sopt case SOME(s as SIMULATION_SETTINGS(__)) then ""
let extraCflags = '<%_extraCflags%><% if Flags.isSet(Flags.GEN_DEBUG_SYMBOLS) then " -g"%>'
let &timeMeasureLink += if boolNot(stringEq(getConfigString(PROFILING_LEVEL),"none")) then ' -Wl,-rpath,"<%makefileParams.omhome%>/lib/omc/cpp" -lOMCppExtensionUtilities'
let omHome = makefileParams.omhome
let &timeMeasureLink +=
match(getConfigString(PROFILING_LEVEL))
case("none") then ''
case("all_perf") then ' -Wl,-rpath,"<%omHome%>/lib/omc/cpp" -lOMCppExtensionUtilities -lOMCppExtensionUtilities_papi -lpapi'
else ' -Wl,-rpath,"<%omHome%>/lib/omc/cpp" -lOMCppExtensionUtilities'
end match
<<
# Makefile generated by OpenModelica
include <%makefileParams.omhome%>/include/omc/cpp/ModelicaConfig.inc
Expand Down Expand Up @@ -1667,16 +1702,20 @@ case SIMCODE(modelInfo = MODELINFO(__)) then
>>
%>
<%if boolNot(stringEq(getConfigString(PROFILING_LEVEL),"none")) then
let numOfEqs = SimCodeUtil.getMaxSimEqSystemIndex(simCode)
<<
measureTimeArray = std::vector<MeasureTimeData>(<%numOfEqs%>);
MeasureTime::addJsonContentBlock("<%dotPath(modelInfo.name)%>","profileBlocks",&measureTimeArray);
measuredStartValues = MeasureTime::getZeroValues();
measuredEndValues = MeasureTime::getZeroValues();
for(int i = 0; i < <%numOfEqs%>; i++)
measureTimeArray[i] = MeasureTimeData();
>>
let numOfEqs = SimCodeUtil.getMaxSimEqSystemIndex(simCode)
<<
measureTimeArray = std::vector<MeasureTimeData>(<%numOfEqs%>);
MeasureTime::addResultContentBlock("<%dotPath(modelInfo.name)%>","profileBlocks",&measureTimeArray);
measuredStartValues = MeasureTime::getZeroValues();
measuredEndValues = MeasureTime::getZeroValues();
for(int i = 0; i < <%numOfEqs%>; i++)
{
ostringstream ss;
ss << i;
measureTimeArray[i] = MeasureTimeData(ss.str());
}
>>
%>
//DAE's are not supported yet, Index reduction is enabled
_dimAE = 0; // algebraic equations
Expand Down Expand Up @@ -4097,7 +4136,10 @@ case SIMCODE(modelInfo = MODELINFO(__),simulationSettingsOpt = SOME(settings as
<<
void <%lastIdentOfPath(modelInfo.name)%>WriteOutput::writeOutput(const IWriteOutput::OUTPUT command)
{
<% if boolNot(stringEq(getConfigString(PROFILING_LEVEL),"none")) then
<<
MeasureTime::getTimeValuesStart(measuredStartValues);
>>%>
//Write head line
if (command & IWriteOutput::HEAD_LINE)
{
Expand Down Expand Up @@ -4154,31 +4196,61 @@ case SIMCODE(modelInfo = MODELINFO(__),simulationSettingsOpt = SOME(settings as
//Write the current values
else
{
HistoryImplType::value_type_v v;
HistoryImplType::value_type_dv v2;
/* HistoryImplType::value_type_v *vP = new HistoryImplType::value_type_v(<%numAlgvars(modelInfo)%>+<%numInOutvars(modelInfo)%>+<%numAliasvars(modelInfo)%>+<%numStatevars(modelInfo)%>);
HistoryImplType::value_type_dv *v2P = new HistoryImplType::value_type_dv(<%numDerivativevars(modelInfo)%>);
HistoryImplType::value_type_v &v = *vP;
HistoryImplType::value_type_dv &v2 = *v2P;*/
<% if boolNot(stringEq(getConfigString(PROFILING_LEVEL),"none")) then
<<
MeasureTime::getTimeValuesStart(measuredStartValues1);
>>%>
/* HistoryImplType::value_type_v v;
HistoryImplType::value_type_dv v2; */
boost::tuple<HistoryImplType::value_type_v*, HistoryImplType::value_type_dv*, double> *container = _historyImpl->getFreeContainer();
HistoryImplType::value_type_v *v = container->get<0>();
HistoryImplType::value_type_dv *v2 = container->get<1>();
container->get<2>() = _simTime;
<%writeoutput2(modelInfo,simCode,useFlatArrayNotation)%>
<%if Flags.isSet(Flags.WRITE_TO_BUFFER) then
<<
HistoryImplType::value_type_r v3;
<%(allEquations |> eqs => (eqs |> eq => writeoutputAlgloopsolvers(eq,simCode));separator="\n")%>
double residues [] = {<%(allEquations |> eqn => writeoutput3(eqn, simCode, useFlatArrayNotation));separator=","%>};
for(int i=0;i<<%numResidues(allEquations)%>;i++) v3(i) = residues[i];

<% if boolNot(stringEq(getConfigString(PROFILING_LEVEL),"none")) then
<<
MeasureTime::getTimeValuesEnd(measuredEndValues1);
measuredEndValues1->sub(measuredStartValues1);
measuredEndValues1->sub(MeasureTime::getOverhead());
measureTimeWriteOutput[1].sumMeasuredValues->add(measuredEndValues1);
++(measureTimeWriteOutput[1].numCalcs);
>>%>

_historyImpl->write(v,v2,v3,_simTime);
/* delete vP;
delete v2P; */
>>
else
<<
_historyImpl->write(v,v2,_simTime);
//_historyImpl->write(vP,v2P,_simTime);
<% if boolNot(stringEq(getConfigString(PROFILING_LEVEL),"none")) then
<<
MeasureTime::getTimeValuesEnd(measuredEndValues1);
measuredEndValues1->sub(measuredStartValues1);
measuredEndValues1->sub(MeasureTime::getOverhead());
measureTimeWriteOutput[1].sumMeasuredValues->add(measuredEndValues1);
++(measureTimeWriteOutput[1].numCalcs);
>>%>

//_historyImpl->write(v,v2,_simTime);
_historyImpl->addContainerToWriteQueue(container);
>>
%>
}

<% if boolNot(stringEq(getConfigString(PROFILING_LEVEL),"none")) then
<<
MeasureTime::getTimeValuesEnd(measuredEndValues);
measuredEndValues->sub(measuredStartValues);
measuredEndValues->sub(MeasureTime::getOverhead());
measureTimeWriteOutput[0].sumMeasuredValues->add(measuredEndValues);
++(measureTimeWriteOutput[0].numCalcs);
>>%>
}
<%writeoutput1(modelInfo)%>
>>
Expand Down Expand Up @@ -4355,7 +4427,7 @@ match modelInfo
<% if boolNot(stringEq(getConfigString(PROFILING_LEVEL),"none")) then
<<
std::vector<MeasureTimeData> measureTimeArray;
MeasureTimeValues *measuredStartValues, *measuredEndValues, *measuredOverheadValues;
MeasureTimeValues *measuredStartValues, *measuredEndValues;
>>%>
<%memberfuncs%>
Expand Down Expand Up @@ -6403,17 +6475,17 @@ case MODELINFO(vars=SIMVARS(__)) then
const int boolAliasVarsStart = <%boolAliasVarsStart%>;
const int stateVarsStart = <%stateVarsStart%>; */

<%vars.algVars |> SIMVAR(isProtected=false) hasindex i0 =>'v(<%intAdd(stringInt(algVarsStart),stringInt(i0))%>)=<%cref(name, useFlatArrayNotation)%>;';align=8 %>
<%vars.discreteAlgVars |> SIMVAR(isProtected=false) hasindex i0 =>'v(<%intAdd(stringInt(discrAlgVarsStart), stringInt(i0))%>)=<%cref(name, useFlatArrayNotation)%>;';align=8 %>
<%vars.intAlgVars |> SIMVAR(isProtected=false) hasindex i1 =>'v(<%intAdd(stringInt(intAlgVarsStart), stringInt(i1))%>)=<%cref(name, useFlatArrayNotation)%>;';align=8%>
<%vars.boolAlgVars |> SIMVAR(isProtected=false) hasindex i2 =>'v(<%intAdd(stringInt(boolAlgVarsStart), stringInt(i2))%>)=<%cref(name, useFlatArrayNotation)%>;';align=8 %>
<%vars.algVars |> SIMVAR(isProtected=false) hasindex i0 =>'(*v)(<%intAdd(stringInt(algVarsStart),stringInt(i0))%>)=<%cref(name, useFlatArrayNotation)%>;';align=8 %>
<%vars.discreteAlgVars |> SIMVAR(isProtected=false) hasindex i0 =>'(*v)(<%intAdd(stringInt(discrAlgVarsStart), stringInt(i0))%>)=<%cref(name, useFlatArrayNotation)%>;';align=8 %>
<%vars.intAlgVars |> SIMVAR(isProtected=false) hasindex i1 =>'(*v)(<%intAdd(stringInt(intAlgVarsStart), stringInt(i1))%>)=<%cref(name, useFlatArrayNotation)%>;';align=8%>
<%vars.boolAlgVars |> SIMVAR(isProtected=false) hasindex i2 =>'(*v)(<%intAdd(stringInt(boolAlgVarsStart), stringInt(i2))%>)=<%cref(name, useFlatArrayNotation)%>;';align=8 %>

<%vars.aliasVars |> SIMVAR(isProtected=false) hasindex i5 =>'v(<%intAdd(stringInt(aliasVarsStart), stringInt(i5))%>)=<%getAliasVar(aliasvar, simCode,contextOther, useFlatArrayNotation)%>;';align=8 %>
<%vars.intAliasVars |> SIMVAR(isProtected=false) hasindex i6 =>'v(<%intAdd(stringInt(intAliasVarsStart), stringInt(i6))%>)=<%getAliasVar(aliasvar, simCode,contextOther, useFlatArrayNotation)%>;';align=8 %>
<%vars.boolAliasVars |> SIMVAR(isProtected=false) hasindex i7 =>'v(<%intAdd(stringInt(boolAliasVarsStart), stringInt(i7))%>)=<%getAliasVar(aliasvar, simCode,contextOther, useFlatArrayNotation)%>;';align=8 %>
<%vars.aliasVars |> SIMVAR(isProtected=false) hasindex i5 =>'(*v)(<%intAdd(stringInt(aliasVarsStart), stringInt(i5))%>)=<%getAliasVar(aliasvar, simCode,contextOther, useFlatArrayNotation)%>;';align=8 %>
<%vars.intAliasVars |> SIMVAR(isProtected=false) hasindex i6 =>'(*v)(<%intAdd(stringInt(intAliasVarsStart), stringInt(i6))%>)=<%getAliasVar(aliasvar, simCode,contextOther, useFlatArrayNotation)%>;';align=8 %>
<%vars.boolAliasVars |> SIMVAR(isProtected=false) hasindex i7 =>'(*v)(<%intAdd(stringInt(boolAliasVarsStart), stringInt(i7))%>)=<%getAliasVar(aliasvar, simCode,contextOther, useFlatArrayNotation)%>;';align=8 %>

<%(vars.stateVars |> SIMVAR() hasindex i8 =>'v(<%intAdd(stringInt(stateVarsStart), stringInt(i8))%>)=__z[<%index%>]; ';align=8 )%>
<%(vars.derivativeVars |> SIMVAR() hasindex i9 fromindex 1 =>'v2(<%i9%>)=__zDot[<%index%>]; ';align=8 )%>
<%(vars.stateVars |> SIMVAR() hasindex i8 =>'(*v)(<%intAdd(stringInt(stateVarsStart), stringInt(i8))%>)=__z[<%index%>]; ';align=8 )%>
<%(vars.derivativeVars |> SIMVAR() hasindex i9 fromindex 1 =>'(*v2)(<%i9%>)=__zDot[<%index%>]; ';align=8 )%>
>>
end writeoutput2;

Expand Down Expand Up @@ -7376,8 +7448,8 @@ template measureTimeStop(String eq_number)
//}
MeasureTime::getTimeValuesEnd(measuredEndValues);
measuredEndValues->sub(measuredStartValues);
measuredEndValues->div(10);
//measuredEndValues->sub(MeasureTime::getOverhead());
//measuredEndValues->div(10);
measuredEndValues->sub(MeasureTime::getOverhead());
//if(measure_t > measureTimeArray[<%eqNumber%>].max_time) measureTimeArray[<%eqNumber%>].max_time = measuredEndValues;
(measureTimeArray[<%eqNumber%>].sumMeasuredValues)->add(measuredEndValues);
++(measureTimeArray[<%eqNumber%>].numCalcs);
Expand Down
3 changes: 2 additions & 1 deletion Compiler/Util/Flags.mo
Expand Up @@ -891,7 +891,8 @@ constant ConfigFlag PROFILING_LEVEL = CONFIG_FLAG(57, "profiling",
("none",Util.gettext("Generate code without profiling")),
("blocks",Util.gettext("Generate code for profiling function calls as well as linear and non-linear systems of equations")),
("blocks+html",Util.gettext("Like blocks, but also run xsltproc and gnuplot to generate an html report")),
("all",Util.gettext("Generate code for profiling of all functions and equations"))
("all",Util.gettext("Generate code for profiling of all functions and equations")),
("all_papi",Util.gettext("Generate code for profiling of all functions and equations with additional performance data using the papi-interface (cpp-runtime)"))
})),
Util.gettext("Sets the profiling level to use. Profiled equations and functions record execution time and count for each time step taken by the integrator."));

Expand Down

0 comments on commit 4f656e7

Please sign in to comment.