Une MAJ de sécurité est nécessaire sur notre version actuelle. Elle sera effectuée lundi 02/08 entre 12h30 et 13h. L'interruption de service devrait durer quelques minutes (probablement moins de 5 minutes).

Commit cc5b2aa8 authored by VAN TOLL Wouter's avatar VAN TOLL Wouter
Browse files

Simulation loop now allows multithreading.

parent 5829476c
......@@ -27,6 +27,8 @@ set (CMAKE_CXX_STANDARD 14)
#set(EXECUTABLE_OUTPUT_PATH bin/${CMAKE_BUILD_TYPE})
# === include 3rd-party code
#set(Boost_USE_STATIC_LIBS ON)
#find_package(Boost COMPONENTS system filesystem regex REQUIRED)
include_directories( ./include )
......@@ -40,14 +42,27 @@ link_directories( ./lib/${CMAKE_BUILD_TYPE} )
file( GLOB_RECURSE source_files src/* include/*)
file( GLOB_RECURSE 3rd_party 3rd-party/tinyxml/* 3rd-party/nanoflann/*)
# === use multithreading?
option(OCSR_USE_MULTITHREADING "Allow the program to use multiple parallel threads" ON)
if (OCSR_USE_MULTITHREADING)
if (MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP /openmp")
endif (MSVC)
endif(OCSR_USE_MULTITHREADING)
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
else()
#linux compatibility compiler option
add_definitions(-fPIC)
endif()
# === Engine project: a static library that performs the simulation
add_library(Engine STATIC ${source_files} ${3rd_party})
# === Console application
IF (WIN32)
add_executable(OCSR_ConsoleApplication_windows main.cpp)
target_link_libraries(OCSR_ConsoleApplication_windows Engine)
......@@ -56,21 +71,12 @@ add_executable(OCSR_ConsoleApplication_linux main.cpp)
target_link_libraries(OCSR_ConsoleApplication_linux Engine)
ENDIF()
#add_executable(test_xmlparser ./test/test_xmlparser.cpp ${source_files} ${3rd_party})
#add_executable(test_socialforces ./test/SocialForcesExample.cpp ${source_files} ${tinyxml_src})
#add_executable(test_ttcaDca ./test/DcaTtcaExample.cpp ${source_files} ${3rd_party})
#add_executable(test_localSearch ./test/TestLocalSearch.cpp ${source_files} ${3rd_party})
# === Dynamic library (e.g. a DLL on Windows) to include into other programs
add_library(OCSR_Library SHARED "APIFunctions.h" "APIFunctions.cpp")
target_link_libraries(OCSR_Library Engine)
#target_link_libraries(my_app)
#target_link_libraries(test_xmlparser)
#target_link_libraries(test_socialforces)
#target_link_libraries(test_ttcaDca)
#target_link_libraries(test_localSearch)
#message(${Boost_LIBRARIES})
#message(${Boost_LIBRARY_DIRS})
# === Clean up the project's directory structure
foreach(_source IN ITEMS ${source_files})
get_filename_component(_source_path "${_source}" PATH)
......
......@@ -104,39 +104,25 @@ Agent * WorldBase::findNearestNeighborWithinRadius(size_t agent_id, const Vector
void WorldBase::doStep()
{
kdtree.buildIndex();
time_ += delta_time_;
for (size_t i = 0; i < agents_.size(); ++i)
{
agents_[i]->runPolicy(this);
}
kdtree.buildIndex();
time_ += delta_time_;
/*Vector2D agentPosition;
Vector2D agentVelocity;*/
/*for (size_t i = 0; i < agents_.size(); ++i)
{
// Check for collision with nearest neighbor
//The behavior of finding the nearest neighbor is probably incorrect
Vector2D agentNextPosition = agents_[i]->getPosition() + agents_[i]->getNextVelocity() * delta_time_;
if(findNearestNeighborWithinRadius(i, agentNextPosition, agents_[i]->getRadius()) != nullptr)
{
// TODO : decide of a strategy in case of collision
// For now, we do nothing
}
}*/
#pragma omp parallel for
for (int i = 0; i < (int)agents_.size(); ++i)
agents_[i]->runPolicy(this);
updateAllAgents();
updateAllAgents();
}
void WorldBase::updateAllAgents()
{
for (unsigned int i = 0; i < agents_.size(); i++)
{
Agent* agent = agents_[i].get();
agent->setVelocity(agent->getNextVelocity());
agent->setPosition(agent->getPosition() + agent->getVelocity() * delta_time_);
}
#pragma omp parallel for
for (int i = 0; i < (int)agents_.size(); i++)
{
Agent* agent = agents_[i].get();
agent->setVelocity(agent->getNextVelocity());
agent->setPosition(agent->getPosition() + agent->getVelocity() * delta_time_);
}
}
std::vector<Agent *> WorldBase::getAgents() const
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment