Skip to content

Commit

Permalink
- made c++ runtime more c++11 friendly, which means that explicit nam…
Browse files Browse the repository at this point in the history
…espaces are removed for boost (example: boost::shared_ptr -> shared_ptr)

- cmake now detects if the compiler is able to work with c++11 and it will switch the following types from boost to std:
  bind, function, thread, atomic, mutex, memory_order_release, memory_order_relaxed, condition_variable, unique_lock, array, tuple, shared_ptr, weak_ptr, dynamic_pointer_cast
  • Loading branch information
Marcus Walther committed Sep 29, 2015
1 parent 116b7c7 commit 8c75262
Show file tree
Hide file tree
Showing 86 changed files with 666 additions and 549 deletions.
160 changes: 80 additions & 80 deletions Compiler/Template/CodegenCpp.tpl

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions Compiler/Template/CodegenCppHpcom.tpl
Expand Up @@ -213,8 +213,8 @@ template generateAdditionalStructHeaders(Schedule odeSchedule)
<<
//Required for Intel TBB
struct VoidFunctionBody {
boost::function<void(void)> void_function;
VoidFunctionBody(boost::function<void(void)> void_function) : void_function(void_function) { }
function<void(void)> void_function;
VoidFunctionBody(function<void(void)> void_function) : void_function(void_function) { }
FORCE_INLINE void operator()( tbb::flow::continue_msg ) const
{
void_function();
Expand Down Expand Up @@ -397,7 +397,7 @@ template generateThreadHeaderDecl(Integer threadIdx, String iType)
>>
else
<<
boost::thread* evaluateThread<%threadIdx%>;
thread* evaluateThread<%threadIdx%>;
>>
end match
end generateThreadHeaderDecl;
Expand Down Expand Up @@ -1377,7 +1377,7 @@ template generateTbbConstructorExtensionNodesAndEdges(tuple<Task,list<Integer>>
let parentEdges = parents |> p => 'tbb::flow::make_edge(*(_tbbNodeList_<%funcSuffix%>.at(<%intSub(p,1)%>)),*(_tbbNodeList_<%funcSuffix%>.at(<%taskIndex%>)));'; separator = "\n"
let startNodeEdge = if intEq(0, listLength(parents)) then 'tbb::flow::make_edge(_tbbStartNode,*(_tbbNodeList_<%funcSuffix%>.at(<%taskIndex%>)));' else ""
<<
tbb_task = new tbb::flow::continue_node<tbb::flow::continue_msg>(_tbbGraph,VoidFunctionBody(boost::bind<void>(&<%modelNamePrefixStr%>::task_func_<%funcSuffix%>_<%task.index%>,this)));
tbb_task = new tbb::flow::continue_node<tbb::flow::continue_msg>(_tbbGraph,VoidFunctionBody(bind<void>(&<%modelNamePrefixStr%>::task_func_<%funcSuffix%>_<%task.index%>,this)));
_tbbNodeList_<%funcSuffix%>.at(<%taskIndex%>) = tbb_task;
<%parentEdges%>
<%startNodeEdge%>
Expand Down Expand Up @@ -1719,7 +1719,7 @@ template generateThread(Integer threadIdx, String iType, String modelNamePrefixS
>>
else
<<
evaluateThread<%threadIdx%> = new boost::thread(boost::bind(&<%modelNamePrefixStr%>::<%funcName%><%threadIdx%>, this));
evaluateThread<%threadIdx%> = new thread(bind(&<%modelNamePrefixStr%>::<%funcName%><%threadIdx%>, this));
>>
end match
end generateThread;
Expand Down
14 changes: 7 additions & 7 deletions Compiler/Template/CodegenFMUCpp.tpl
Expand Up @@ -149,7 +149,7 @@ case SIMCODE(modelInfo=MODELINFO(__),simulationSettingsOpt = SOME(settings as SI
// Dummy code for FMU that writes no output file
class <%lastIdentOfPath(modelInfo.name)%>WriteOutput {
public:
<%lastIdentOfPath(modelInfo.name)%>WriteOutput(IGlobalSettings* globalSettings, boost::shared_ptr<IAlgLoopSolverFactory> nonLinSolverFactory, boost::shared_ptr<ISimData> simData, boost::shared_ptr<ISimVars> simVars) {}
<%lastIdentOfPath(modelInfo.name)%>WriteOutput(IGlobalSettings* globalSettings, shared_ptr<IAlgLoopSolverFactory> nonLinSolverFactory, shared_ptr<ISimData> simData, shared_ptr<ISimVars> simVars) {}
virtual ~<%lastIdentOfPath(modelInfo.name)%>WriteOutput() {}

virtual void writeOutput(const IWriteOutput::OUTPUT command = IWriteOutput::UNDEF_OUTPUT) {}
Expand Down Expand Up @@ -209,9 +209,9 @@ case SIMCODE(modelInfo=MODELINFO(__)) then
// constructor
<%modelShortName%>FMU(IGlobalSettings* globalSettings,
boost::shared_ptr<IAlgLoopSolverFactory> nonLinSolverFactory,
boost::shared_ptr<ISimData> simData,
boost::shared_ptr<ISimVars> simVars);
shared_ptr<IAlgLoopSolverFactory> nonLinSolverFactory,
shared_ptr<ISimData> simData,
shared_ptr<ISimVars> simVars);
// initialization
virtual void initialize();
Expand Down Expand Up @@ -269,9 +269,9 @@ case SIMCODE(modelInfo=MODELINFO(__)) then

// constructor
<%modelShortName%>FMU::<%modelShortName%>FMU(IGlobalSettings* globalSettings,
boost::shared_ptr<IAlgLoopSolverFactory> nonLinSolverFactory,
boost::shared_ptr<ISimData> simData,
boost::shared_ptr<ISimVars> simVars):
shared_ptr<IAlgLoopSolverFactory> nonLinSolverFactory,
shared_ptr<ISimData> simData,
shared_ptr<ISimVars> simVars):
<%modelShortName%>(globalSettings, nonLinSolverFactory, simData, simVars),
<%modelShortName%>Extension(globalSettings, nonLinSolverFactory, simData, simVars) {
}
Expand Down
64 changes: 51 additions & 13 deletions SimulationRuntime/cpp/CMakeLists.txt
Expand Up @@ -2,7 +2,7 @@
#
# The following conditional defines are passed to the c++ compiler:
# if the Boost_log and Boost_setup_log libraries were found -DUSE_BOOST_LOG
# if the Boost_thread library was found -DUSE_BOOST_THREAD
# if the Boost_thread library was found or C++ 11 is available -DUSE_THREAD
# if the UMFPack library of SuiteSparse was found -DUSE_UMFPACK
# if the PAPI library was found -DUSE_PAPI
# if the Sundials libraries were found -DPMC_USE_SUNDIALS
Expand All @@ -16,10 +16,12 @@
# 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
# if ScoreP should be used for performance analysis -DUSE_SCOREP=ON
# if the boost libraries should be linked statically -DBOOST_STATIC_LINKING=ON
# if boost libraries should be linked against absolute path libraries -DUSE_BOOST_REALPATHS=ON
# if write output should be handled in parallel -DUSE_PARALLEL_OUTPUT=ON [default: OFF]
# if ScoreP should be used for performance analysis -DUSE_SCOREP=ON [default: OFF]
# if the boost libraries should be linked statically -DBOOST_STATIC_LINKING=ON [default: OFF]
# if boost libraries should be linked against absolute path libraries -DUSE_BOOST_REALPATHS=ON [default: OFF]
# disable c++11, even if the compiler is able to use it -DUSE_CPP_ELEVEN=OFF [default: ON]
# if the equation systems of a FMU should be solved with sundials solvers -DFMU_SUNDIALS=ON [default: OFF]
#
# Example: "cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo" to create statically linked libraries
#
Expand All @@ -36,9 +38,11 @@ MESSAGE(STATUS "CMake version ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CM
OPTION(USE_PARALLEL_OUTPUT "USE_PARALLEL_OUTPUT" OFF)
OPTION(USE_SCOREP "USE_SCOREP" OFF)
OPTION(BOOST_STATIC_LINKING "BOOST_STATIC_LINKING" OFF)
OPTION(USE_BOOST_REALPATHS "USE_BOOST_REALPATHS" OFF)
OPTION(RUNTIME_PROFILING "RUNTIME_PROFILING" OFF)
OPTION(FMU_SUNDIALS "FMU_SUNDIALS" OFF)
OPTION(SUNDIALS_ROOT "SUNDIALS ROOT" "")
OPTION(USE_CPP_ELEVEN "USE_CPP_ELEVEN" ON)

#Set Variables
SET(MODELICAEXTERNALCDIR "${CMAKE_SOURCE_DIR}/../../3rdParty/ModelicaExternalC/C-Sources")
Expand Down Expand Up @@ -94,6 +98,36 @@ ENDIF(USE_BOOST_REALPATHS)

INCLUDE(${CMAKE_SOURCE_DIR}/PrecompiledHeader.cmake)

# Check C++11
IF(USE_CPP_ELEVEN)
IF(MSVC)
IF(MSVC_VERSION GREATER 1500)
SET(COMPILER_SUPPORTS_CXX11 True)
ELSE(MSVC_VERSION GREATER 1500)
SET(COMPILER_SUPPORTS_CXX11 False)
ENDIF(MSVC_VERSION GREATER 1500)
ELSE(MSVC)
INCLUDE(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
IF(COMPILER_SUPPORTS_CXX11)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
SET(CMAKE_CXX_FLAGS_${CMAKE_BUILD_TYPE} "${CMAKE_CXX_FLAGS_${CMAKE_BUILD_TYPE}} -std=c++11")
SET(CXX11_FLAGS " -std=c++11")
ELSE()
SET(COMPILER_SUPPORTS_CXX11 False)
ENDIF(COMPILER_SUPPORTS_CXX11)
ENDIF(MSVC)
ELSE(USE_CPP_ELEVEN)
SET(COMPILER_SUPPORTS_CXX11 False)
ENDIF(USE_CPP_ELEVEN)

IF(COMPILER_SUPPORTS_CXX11)
MESSAGE(STATUS "C++11 support enabled")
ADD_DEFINITIONS(-DUSE_CPP_ELEVEN)
ELSE(COMPILER_SUPPORTS_CXX11)
MESSAGE(STATUS "C++11 support disabled")
ENDIF(COMPILER_SUPPORTS_CXX11)

#Handle static boost linking
IF(NOT BOOST_STATIC_LINKING)
SET(Boost_USE_STATIC_LIBS OFF)
Expand Down Expand Up @@ -285,14 +319,18 @@ FIND_PACKAGE(Boost COMPONENTS log log_setup)

FIND_PACKAGE(Boost COMPONENTS thread atomic)

SET(Boost_LIBRARIES_TMP ${Boost_LIBRARIES_TMP} ${Boost_LIBRARIES})
FIND_PACKAGE(Threads)
IF(Boost_THREAD_FOUND AND Boost_ATOMIC_FOUND)
ADD_DEFINITIONS(-DUSE_BOOST_THREAD)
MESSAGE(STATUS "Using boost thread")
ELSE(Boost_THREAD_FOUND AND Boost_ATOMIC_FOUND)
MESSAGE(STATUS "Boost thread disabled")
ENDIF(Boost_THREAD_FOUND AND Boost_ATOMIC_FOUND)
IF(NOT(COMPILER_SUPPORTS_CXX11))
SET(Boost_LIBRARIES_TMP ${Boost_LIBRARIES_TMP} ${Boost_LIBRARIES})
FIND_PACKAGE(Threads)
IF(Boost_THREAD_FOUND AND Boost_ATOMIC_FOUND)
ADD_DEFINITIONS(-DUSE_THREAD)
MESSAGE(STATUS "Using boost thread")
ELSE(Boost_THREAD_FOUND AND Boost_ATOMIC_FOUND)
MESSAGE(STATUS "Boost thread disabled")
ENDIF(Boost_THREAD_FOUND AND Boost_ATOMIC_FOUND)
ELSE()
MESSAGE(STATUS "Boost thread disabled because of available C++11 support")
ENDIF(NOT(COMPILER_SUPPORTS_CXX11))

FIND_PACKAGE(Boost REQUIRED COMPONENTS filesystem system serialization program_options)
SET(Boost_LIBRARIES_TMP ${Boost_LIBRARIES_TMP} ${Boost_LIBRARIES})
Expand Down
6 changes: 3 additions & 3 deletions SimulationRuntime/cpp/Core/DataExchange/SimData.cpp
Expand Up @@ -24,9 +24,9 @@ ISimData* SimData::clone()
return new SimData(*this);
}

void SimData::Add(string key, boost::shared_ptr<ISimVar> var)
void SimData::Add(string key, shared_ptr<ISimVar> var)
{
std::pair<string,boost::shared_ptr<ISimVar> > elem(key,var);
std::pair<string,shared_ptr<ISimVar> > elem(key,var);
std::pair<Objects_type::iterator,bool> p = _sim_vars.insert(elem);
}

Expand All @@ -37,7 +37,7 @@ ISimVar* SimData::Get(string key)
//Prüfen ob das Simobjekt in Liste ist.
if(iter!=_sim_vars.end())
{
boost::shared_ptr<ISimVar> obj = iter->second;
shared_ptr<ISimVar> obj = iter->second;
return obj.get();
}
else
Expand Down
Expand Up @@ -17,7 +17,7 @@ XmlPropertyReader::~XmlPropertyReader()

}

void XmlPropertyReader::readInitialValues(IContinuous& system, boost::shared_ptr<ISimVars> sim_vars)
void XmlPropertyReader::readInitialValues(IContinuous& system, shared_ptr<ISimVars> sim_vars)
{
using boost::property_tree::ptree;
std::ifstream file;
Expand Down
2 changes: 1 addition & 1 deletion SimulationRuntime/cpp/Core/Modelica/ModelicaSystem.cpp
Expand Up @@ -8,7 +8,7 @@
#include <Core/DataExchange/Policies/TextfileWriter.h>
#include <Core/Modelica/ModelicaSystem.h>

Modelica::Modelica(IGlobalSettings* globalSettings, boost::shared_ptr<IAlgLoopSolverFactory> nonlinsolverfactory, boost::shared_ptr<ISimData> sim_data, boost::shared_ptr<ISimVars> sim_vars)
Modelica::Modelica(IGlobalSettings* globalSettings, shared_ptr<IAlgLoopSolverFactory> nonlinsolverfactory, shared_ptr<ISimData> sim_data, shared_ptr<ISimVars> sim_vars)
: SystemDefaultImplementation(globalSettings,sim_data,sim_vars)
{
_dimBoolean = 0;
Expand Down
4 changes: 2 additions & 2 deletions SimulationRuntime/cpp/Core/SimController/Configuration.cpp
Expand Up @@ -36,11 +36,11 @@ ISolverSettings* Configuration::getSolverSettings()
return _solver_settings.get();
}

boost::shared_ptr<ISolver> Configuration::createSelectedSolver(IMixedSystem* system)
shared_ptr<ISolver> Configuration::createSelectedSolver(IMixedSystem* system)
{
string solver_name = _global_settings->getSelectedSolver();
_solver_settings =_settings_factory->createSelectedSolverSettings();
_simcontroller_settings = boost::shared_ptr<ISimControllerSettings>(new ISimControllerSettings(_global_settings.get()) );
_simcontroller_settings = shared_ptr<ISimControllerSettings>(new ISimControllerSettings(_global_settings.get()) );
_solver = createSolver(system, solver_name, _solver_settings);
return _solver;
}
Expand Down
4 changes: 2 additions & 2 deletions SimulationRuntime/cpp/Core/SimController/FactoryExport.cpp
Expand Up @@ -45,9 +45,9 @@ BOOST_EXTENSION_TYPE_MAP_FUNCTION {
}

#ifdef RUNTIME_STATIC_LINKING
boost::shared_ptr<ISimController> createSimController(PATH library_path, PATH modelicasystem_path)
shared_ptr<ISimController> createSimController(PATH library_path, PATH modelicasystem_path)
{
return boost::shared_ptr<ISimController>(new SimController(library_path, modelicasystem_path));
return shared_ptr<ISimController>(new SimController(library_path, modelicasystem_path));
}
#endif

Expand Down
8 changes: 4 additions & 4 deletions SimulationRuntime/cpp/Core/SimController/Initialization.cpp
Expand Up @@ -7,7 +7,7 @@
#include <Core/Modelica.h>
#include <Core/SimController/Initialization.h>

Initialization::Initialization(boost::shared_ptr<ISystemInitialization> system_initialization, boost::shared_ptr<ISolver> solver)
Initialization::Initialization(shared_ptr<ISystemInitialization> system_initialization, shared_ptr<ISolver> solver)
: _system(system_initialization)
, _solver(solver)
{
Expand All @@ -19,9 +19,9 @@ Initialization::~Initialization(void)

void Initialization::initializeSystem()
{
boost::shared_ptr<IContinuous> continous_system = boost::dynamic_pointer_cast<IContinuous>(_system);
boost::shared_ptr<IEvent> event_system = boost::dynamic_pointer_cast<IEvent>(_system);
boost::shared_ptr<IMixedSystem> mixed_system = boost::dynamic_pointer_cast<IMixedSystem>(_system);
shared_ptr<IContinuous> continous_system = dynamic_pointer_cast<IContinuous>(_system);
shared_ptr<IEvent> event_system = dynamic_pointer_cast<IEvent>(_system);
shared_ptr<IMixedSystem> mixed_system = dynamic_pointer_cast<IMixedSystem>(_system);
int dim = event_system->getDimZeroFunc();
bool* conditions0 = new bool[dim];
bool* conditions1 = new bool[dim];
Expand Down
4 changes: 2 additions & 2 deletions SimulationRuntime/cpp/Core/SimController/Main.cpp
Expand Up @@ -114,9 +114,9 @@ int main(int argc, const char* argv[])

//SimController to start simulation
SimSettings settings = {solver,"newton",starttime,stoptime,stepsize,1e-20,0.01,tollerance,results_file_path.string()};
boost::shared_ptr<ISimController> sim_controller = boost::shared_ptr<ISimController>(new SimController(runtime_lib_path,modelica_path));
shared_ptr<ISimController> sim_controller = shared_ptr<ISimController>(new SimController(runtime_lib_path,modelica_path));
//create Modelica system
std::pair<boost::weak_ptr<IMixedSystem>,boost::weak_ptr<ISimData> > system = sim_controller->LoadSystem("ModelicaSystem");
std::pair<weak_ptr<IMixedSystem>,weak_ptr<ISimData> > system = sim_controller->LoadSystem("ModelicaSystem");

sim_controller->Start(system.first,settings);
}
Expand Down

0 comments on commit 8c75262

Please sign in to comment.