Skip to content

Commit

Permalink
- added a flag "solverThreads" to the c++ runtime. With this flag the…
Browse files Browse the repository at this point in the history
… number of threads that is used by the solver can be controlled (e.g. for parallel jacobian evaluation)
  • Loading branch information
Marcus Walther committed Sep 23, 2015
1 parent 5e4b2b1 commit b384418
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 4 deletions.
2 changes: 2 additions & 0 deletions Compiler/Template/CodegenCpp.tpl
Expand Up @@ -2492,6 +2492,7 @@ case SIMCODE(modelInfo=MODELINFO(__), makefileParams=MAKEFILE_PARAMS(__), simula
opts["-R"] = "<%simulationLibDir(simulationCodeTarget(),simCode , &extraFuncs , &extraFuncsDecl, extraFuncsNamespace)%>";
opts["-M"] = "<%moLib%>";
opts["-F"] = "<%simulationResults(getRunningTestsuite(),simCode , &extraFuncs , &extraFuncsDecl, extraFuncsNamespace)%>";
opts["--solverThreads"] = "<%if(intGt(getConfigInt(NUM_PROC), 0)) then getConfigInt(NUM_PROC) else 1%>";
<%if (stringEq(settings.outputFormat, "empty")) then 'opts["-O"] = "none";' else ""%>
<%
match(getConfigString(PROFILING_LEVEL))
Expand Down Expand Up @@ -12673,6 +12674,7 @@ template createEvaluateAll( list<SimEqSystem> allEquationsPlusWhen, SimCode simC
<%equation_all_func_calls%>

<%if createMeasureTime then generateMeasureTimeEndCode("measuredFunctionStartValues", "measuredFunctionEndValues", "(*measureTimeFunctionsArray)[1]", "evaluateAll", "MEASURETIME_MODELFUNCTIONS") else ""%>

return _state_var_reinitialized;
}
>>
Expand Down
2 changes: 1 addition & 1 deletion SimulationRuntime/cpp/Core/SimController/SimController.cpp
Expand Up @@ -244,7 +244,7 @@ void SimController::Start(SimSettings simsettings, string modelKey)
global_settings->setAlarmTime(simsettings.timeOut);
global_settings->setOutputPointType(simsettings.outputPointType);
global_settings->setNonLinearSolverContinueOnError(simsettings.nonLinearSolverContinueOnError);

global_settings->setSolverThreads(simsettings.solverThreads);
/*boost::shared_ptr<SimManager>*/ _simMgr = boost::shared_ptr<SimManager>(new SimManager(mixedsystem, _config.get()));

ISolverSettings* solver_settings = _config->getSolverSettings();
Expand Down
10 changes: 10 additions & 0 deletions SimulationRuntime/cpp/Core/SimulationSettings/GlobalSettings.cpp
Expand Up @@ -200,4 +200,14 @@ bool GlobalSettings::getNonLinearSolverContinueOnError()
{
return _nonLinSolverContinueOnError;
}

void GlobalSettings::setSolverThreads(int val)
{
_solverThreads = val;
}

int GlobalSettings::getSolverThreads()
{
return _solverThreads;
}
/** @} */ // end of coreSimulationSettings
Expand Up @@ -20,6 +20,7 @@ struct SimSettings
OutputPointType outputPointType;
LogSettings logSettings;
bool nonLinearSolverContinueOnError;
int solverThreads;
};

/**
Expand Down
Expand Up @@ -56,6 +56,9 @@ class GlobalSettings : public IGlobalSettings
virtual void setNonLinearSolverContinueOnError(bool);
virtual bool getNonLinearSolverContinueOnError();

virtual void setSolverThreads(int);
virtual int getSolverThreads();

private:
double
_startTime, ///< Start time of integration (default: 0.0)
Expand All @@ -76,5 +79,6 @@ class GlobalSettings : public IGlobalSettings
OutputPointType _outputPointType;
LogSettings _log_settings;
unsigned int _alarm_time;
int _solverThreads;
};
/** @} */ // end of coreSimulationSettings
Expand Up @@ -89,5 +89,8 @@ class IGlobalSettings

virtual void setNonLinearSolverContinueOnError(bool) = 0;
virtual bool getNonLinearSolverContinueOnError() = 0;

virtual void setSolverThreads(int) = 0;
virtual int getSolverThreads() = 0;
};
/** @} */ // end of coreSimulationSettings
3 changes: 3 additions & 0 deletions SimulationRuntime/cpp/Include/FMU/FMUGlobalSettings.h
Expand Up @@ -53,5 +53,8 @@ class FMUGlobalSettings : public IGlobalSettings
virtual unsigned int getAlarmTime() {return 0;}
virtual void setNonLinearSolverContinueOnError(bool){};
virtual bool getNonLinearSolverContinueOnError(){ return false; };

virtual void setSolverThreads(int){};
virtual int getSolverThreads() { return 1; };
private:
};
2 changes: 2 additions & 0 deletions SimulationRuntime/cpp/Include/FMU2/FMU2GlobalSettings.h
Expand Up @@ -85,5 +85,7 @@ class FMU2GlobalSettings : public IGlobalSettings
virtual unsigned int getAlarmTime() { return 0; }
virtual void setNonLinearSolverContinueOnError(bool){};
virtual bool getNonLinearSolverContinueOnError(){ return false; };
virtual void setSolverThreads(int){};
virtual int getSolverThreads() { return 1; };
};
/** @} */ // end of fmu2
Expand Up @@ -96,8 +96,9 @@ SimSettings OMCFactory::readSimulationParameter(int argc, const char* argv[])
// a group for all options that should not be visible if '--help' is set
po::options_description descHidden("Hidden options");
descHidden.add_options()
("ignored", po::value<vector<string> >(), "Ignored options")
("unrecognized", po::value<vector<string> >(), "Unsupported options")
("ignored", po::value<vector<string> >(), "ignored options")
("unrecognized", po::value<vector<string> >(), "unsupported options")
("solverThreads", po::value<int>()->default_value(1), "number of threads that can be used by the solver")
;

po::options_description descAll("All options");
Expand Down Expand Up @@ -138,6 +139,7 @@ SimSettings OMCFactory::readSimulationParameter(int argc, const char* argv[])
double stoptime = vm["stop-time"].as<double>();
double stepsize =vm["step-size"].as<double>();
bool nlsContinueOnError = vm["nls-continue"].as<bool>();
int solverThreads = vm["solverThreads"].as<int>();

if (!(stepsize > 0.0))
stepsize = (stoptime - starttime) / vm["number-of-intervals"].as<int>();
Expand Down Expand Up @@ -214,7 +216,7 @@ SimSettings OMCFactory::readSimulationParameter(int argc, const char* argv[])
libraries_path.make_preferred();
modelica_path.make_preferred();

SimSettings settings = {solver,linSolver,nonLinSolver,starttime,stoptime,stepsize,1e-24,0.01,tolerance,resultsfilename,timeOut,outputPointType,logSet,nlsContinueOnError};
SimSettings settings = {solver,linSolver,nonLinSolver,starttime,stoptime,stepsize,1e-24,0.01,tolerance,resultsfilename,timeOut,outputPointType,logSet,nlsContinueOnError,solverThreads};

_library_path = libraries_path;
_modelicasystem_path = modelica_path;
Expand Down

0 comments on commit b384418

Please sign in to comment.