From 19225e8880b12bf3b72743ea253a94b52635a212 Mon Sep 17 00:00:00 2001 From: raczman Date: Mon, 15 Jun 2009 09:07:51 +0200 Subject: Added basic support for multithreaded map updates using openmp standard. Windows users need to install Platform SDK to use this feature, linux users have everything they need in gcc. Number of threads used to update world is set by confiuration file, and can be changed dynamically without restarting core. Thanks to megamage and Jeniczek for testing and helping out with this. --HG-- branch : trunk --- src/game/MapManager.cpp | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) (limited to 'src/game/MapManager.cpp') diff --git a/src/game/MapManager.cpp b/src/game/MapManager.cpp index 6a8cd130691..5a66ab6cea8 100644 --- a/src/game/MapManager.cpp +++ b/src/game/MapManager.cpp @@ -18,6 +18,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#include #include "MapManager.h" #include "InstanceSaveMgr.h" #include "Policies/SingletonImp.h" @@ -248,12 +249,25 @@ MapManager::Update(time_t diff) ObjectAccessor::Instance().UpdatePlayers(i_timer.GetCurrent()); sWorld.RecordTimeDiff("UpdatePlayers"); - - for(MapMapType::iterator iter=i_maps.begin(); iter != i_maps.end(); ++iter) + uint32 i=0; + MapMapType::iterator iter; + std::vector update_queue(i_maps.size()); + omp_set_num_threads(sWorld.getConfig(CONFIG_NUMTHREADS)); + for(iter = i_maps.begin(), i=0;iter != i_maps.end(); ++iter, i++) + update_queue[i]=iter->second; +/* + gomp in gcc <4.4 version cannot parallelise loops using random access iterators + so until gcc 4.4 isnt standard, we need the update_queue workaround +*/ + +#pragma omp parallel for schedule(dynamic) private(i) shared(update_queue) + for(int32 i = 0; i < i_maps.size(); ++i) { checkAndCorrectGridStatesArray(); // debugging code, should be deleted some day - iter->second->Update(i_timer.GetCurrent()); - sWorld.RecordTimeDiff("UpdateMap %u", iter->second->GetId()); + update_queue[i]->Update(i_timer.GetCurrent()); + sWorld.RecordTimeDiff("UpdateMap %u", update_queue[i]->GetId()); + // sLog.outError("This is thread %d out of %d threads,updating map %u",omp_get_thread_num(),omp_get_num_threads(),iter->second->GetId()); + } ObjectAccessor::Instance().Update(i_timer.GetCurrent()); @@ -267,8 +281,17 @@ MapManager::Update(time_t diff) void MapManager::DoDelayedMovesAndRemoves() { - for(MapMapType::iterator iter=i_maps.begin(); iter != i_maps.end(); ++iter) - iter->second->DoDelayedMovesAndRemoves(); + int i =0; + std::vector update_queue(i_maps.size()); + MapMapType::iterator iter; + for(iter = i_maps.begin();iter != i_maps.end(); ++iter, i++) + update_queue[i] = iter->second; + + omp_set_num_threads(sWorld.getConfig(CONFIG_NUMTHREADS)); + +#pragma omp parallel for schedule(dynamic) private(i) shared(update_queue) + for(i=0;iDoDelayedMovesAndRemoves(); } bool MapManager::ExistMapAndVMap(uint32 mapid, float x,float y) -- cgit v1.2.3