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
This commit is contained in:
@@ -265,6 +265,6 @@ SET(game_STAT_SRCS
|
||||
GroupReference.h
|
||||
GroupRefManager.h
|
||||
)
|
||||
|
||||
add_definitions(-fopenmp)
|
||||
add_library(game STATIC ${game_STAT_SRCS})
|
||||
ADD_DEPENDENCIES(game revision.h)
|
||||
|
||||
+29
-6
@@ -18,6 +18,7 @@
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include <omp.h>
|
||||
#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<Map*> 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<Map*> 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;i<i_maps.size();i++)
|
||||
update_queue[i]->DoDelayedMovesAndRemoves();
|
||||
}
|
||||
|
||||
bool MapManager::ExistMapAndVMap(uint32 mapid, float x,float y)
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include <omp.h>
|
||||
#include "Common.h"
|
||||
#include "Log.h"
|
||||
#include "Opcodes.h"
|
||||
|
||||
@@ -1029,6 +1029,7 @@ void World::LoadConfigSettings(bool reload)
|
||||
m_configs[CONFIG_SHOW_KICK_IN_WORLD] = sConfig.GetBoolDefault("ShowKickInWorld", false);
|
||||
m_configs[CONFIG_INTERVAL_LOG_UPDATE] = sConfig.GetIntDefault("RecordUpdateTimeDiffInterval", 60000);
|
||||
m_configs[CONFIG_MIN_LOG_UPDATE] = sConfig.GetIntDefault("MinRecordUpdateTimeDiff", 10);
|
||||
m_configs[CONFIG_NUMTHREADS] = sConfig.GetIntDefault("MapUpdate.Threads",1);
|
||||
|
||||
std::string forbiddenmaps = sConfig.GetStringDefault("ForbiddenMaps", "");
|
||||
char * forbiddenMaps = new char[forbiddenmaps.length() + 1];
|
||||
@@ -1596,8 +1597,10 @@ void World::Update(time_t diff)
|
||||
sBattleGroundMgr.Update(diff);
|
||||
RecordTimeDiff("UpdateBattleGroundMgr");
|
||||
|
||||
|
||||
sOutdoorPvPMgr.Update(diff);
|
||||
RecordTimeDiff("UpdateOutdoorPvPMgr");
|
||||
|
||||
}
|
||||
|
||||
RecordTimeDiff(NULL);
|
||||
|
||||
@@ -208,6 +208,8 @@ enum WorldConfigs
|
||||
CONFIG_ENABLE_SINFO_LOGIN,
|
||||
CONFIG_PREMATURE_BG_REWARD,
|
||||
CONFIG_PET_LOS,
|
||||
CONFIG_NUMTHREADS,
|
||||
|
||||
CONFIG_VALUE_COUNT
|
||||
};
|
||||
|
||||
|
||||
@@ -24,5 +24,5 @@ SET(shared_STAT_SRCS
|
||||
WorldPacket.h
|
||||
SystemConfig.h
|
||||
)
|
||||
|
||||
add_definitions(-fopenmp)
|
||||
add_library(shared STATIC ${shared_STAT_SRCS})
|
||||
|
||||
+30
-5
@@ -36,27 +36,52 @@ static MTRandTSS mtRand;
|
||||
|
||||
int32 irand (int32 min, int32 max)
|
||||
{
|
||||
return int32 (mtRand.get ().randInt (max - min)) + min;
|
||||
int32 result;
|
||||
#pragma omp critical (mtrand)
|
||||
{
|
||||
result = mtRand.get ().randInt (max-min) + min;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
uint32 urand (uint32 min, uint32 max)
|
||||
{
|
||||
return mtRand.get ().randInt (max - min) + min;
|
||||
uint32 result;
|
||||
#pragma omp critical (mtrand)
|
||||
{
|
||||
result = mtRand.get ().randInt (max - min) + min;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
int32 rand32 ()
|
||||
{
|
||||
return mtRand.get ().randInt ();
|
||||
int32 result;
|
||||
#pragma omp critical (mtrand)
|
||||
{
|
||||
result = mtRand.get ().randInt ();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
double rand_norm(void)
|
||||
{
|
||||
return mtRand.get ().randExc ();
|
||||
double result;
|
||||
#pragma omp critical (mtrand)
|
||||
{
|
||||
result = mtRand.get ().randExc ();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
double rand_chance (void)
|
||||
{
|
||||
return mtRand.get ().randExc (100.0);
|
||||
double result;
|
||||
#pragma omp critical (mtrand)
|
||||
{
|
||||
result = mtRand.get ().randExc (100.0);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
Tokens StrSplit(const std::string &src, const std::string &sep)
|
||||
|
||||
@@ -45,6 +45,7 @@ vmaps
|
||||
ZThread
|
||||
g3dlite
|
||||
readline
|
||||
gomp
|
||||
${SCRIPT_LIB}
|
||||
${MYSQL_LIBRARIES}
|
||||
${POSTGRE_LIBS}
|
||||
|
||||
@@ -179,6 +179,10 @@ EAIErrorLevel = 2
|
||||
# Default: 1 (permit addon channel)
|
||||
# 0 (do not permit addon channel)
|
||||
#
|
||||
# MapUpdate.Threads
|
||||
# Number of threads to update maps.
|
||||
# Default: 1
|
||||
#
|
||||
###################################################################################################################
|
||||
|
||||
UseProcessors = 0
|
||||
@@ -204,6 +208,7 @@ TargetPosRecalculateRange = 1.5
|
||||
UpdateUptimeInterval = 10
|
||||
MaxCoreStuckTime = 0
|
||||
AddonChannel = 1
|
||||
MapUpdate.Threads = 1
|
||||
|
||||
###################################################################################################################
|
||||
# SERVER LOGGING
|
||||
|
||||
@@ -38,6 +38,7 @@ trinityauth
|
||||
trinityconfig
|
||||
ZThread
|
||||
zlib
|
||||
gomp
|
||||
${SSLLIB}
|
||||
${MYSQL_LIBRARIES}
|
||||
${OSX_LIBS}
|
||||
|
||||
@@ -44,7 +44,7 @@
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
AdditionalOptions="/MP"
|
||||
AdditionalOptions="/MP /openmp"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories="..\..\dep\include;..\..\src\framework;..\..\src\shared;..\..\src\shared\vmap;..\..\dep\ACE_wrappers"
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;TRINITY_DEBUG;_LIB;"
|
||||
@@ -126,7 +126,7 @@
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
AdditionalOptions="/MP"
|
||||
AdditionalOptions="/MP /openmp"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories="..\..\dep\include;..\..\src\framework;..\..\src\shared;..\..\src\shared\vmap;..\..\dep\ACE_wrappers"
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;TRINITY_DEBUG;_LIB;"
|
||||
@@ -207,7 +207,7 @@
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
AdditionalOptions="/MP"
|
||||
AdditionalOptions="/MP /openmp"
|
||||
InlineFunctionExpansion="1"
|
||||
AdditionalIncludeDirectories="..\..\dep\include;..\..\src\framework;..\..\src\shared;..\..\src\shared\vmap;..\..\dep\ACE_wrappers"
|
||||
PreprocessorDefinitions="WIN32;NDEBUG;_LIB;"
|
||||
@@ -289,7 +289,7 @@
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
AdditionalOptions="/MP"
|
||||
AdditionalOptions="/MP /openmp"
|
||||
InlineFunctionExpansion="1"
|
||||
AdditionalIncludeDirectories="..\..\dep\include;..\..\src\framework;..\..\src\shared;..\..\src\shared\vmap;..\..\dep\ACE_wrappers"
|
||||
PreprocessorDefinitions="WIN32;NDEBUG;_LIB;"
|
||||
|
||||
@@ -44,7 +44,7 @@
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
AdditionalOptions="/MP"
|
||||
AdditionalOptions="/MP /openmp"
|
||||
InlineFunctionExpansion="1"
|
||||
AdditionalIncludeDirectories="..\..\dep\include;..\..\dep\include\g3dlite;..\..\src\framework;..\..\src\shared;..\..\dep\ACE_wrappers"
|
||||
PreprocessorDefinitions="WIN32;NDEBUG;_LIB;_CRT_SECURE_NO_DEPRECATE"
|
||||
@@ -127,7 +127,7 @@
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
AdditionalOptions="/MP"
|
||||
AdditionalOptions="/MP /openmp"
|
||||
InlineFunctionExpansion="1"
|
||||
AdditionalIncludeDirectories="..\..\dep\include;..\..\dep\include\g3dlite;..\..\src\framework;..\..\src\shared;..\..\dep\ACE_wrappers"
|
||||
PreprocessorDefinitions="WIN32;NDEBUG;_LIB;_CRT_SECURE_NO_DEPRECATE"
|
||||
@@ -208,7 +208,7 @@
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
AdditionalOptions="/MP"
|
||||
AdditionalOptions="/MP /openmp"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories="..\..\dep\include;..\..\dep\include\g3dlite;..\..\src\framework;..\..\src\shared;..\..\dep\ACE_wrappers"
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;TRINITY_DEBUG;_LIB;_CRT_SECURE_NO_DEPRECATE"
|
||||
@@ -289,7 +289,7 @@
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
AdditionalOptions="/MP"
|
||||
AdditionalOptions="/MP /openmp"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories="..\..\dep\include;..\..\dep\include\g3dlite;..\..\src\framework;..\..\src\shared;..\..\dep\ACE_wrappers"
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;TRINITY_DEBUG;_LIB;_CRT_SECURE_NO_DEPRECATE"
|
||||
|
||||
@@ -45,7 +45,7 @@
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
AdditionalOptions="/MP"
|
||||
AdditionalOptions="/MP /openmp"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories="..\..\dep\include;..\..\src\framework;..\..\src\shared;..\..\src\shared\vmap;..\..\dep\ACE_wrappers"
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;TRINITY_DEBUG;_LIB;"
|
||||
@@ -128,7 +128,7 @@
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
AdditionalOptions="/MP"
|
||||
AdditionalOptions="/MP /openmp"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories="..\..\dep\include;..\..\src\framework;..\..\src\shared;..\..\src\shared\vmap;..\..\dep\ACE_wrappers"
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;TRINITY_DEBUG;_LIB;"
|
||||
@@ -210,7 +210,7 @@
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
AdditionalOptions="/MP"
|
||||
AdditionalOptions="/MP /openmp"
|
||||
InlineFunctionExpansion="1"
|
||||
AdditionalIncludeDirectories="..\..\dep\include;..\..\src\framework;..\..\src\shared;..\..\src\shared\vmap;..\..\dep\ACE_wrappers"
|
||||
PreprocessorDefinitions="WIN32;NDEBUG;_LIB;"
|
||||
@@ -293,7 +293,7 @@
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
AdditionalOptions="/MP"
|
||||
AdditionalOptions="/MP /openmp"
|
||||
InlineFunctionExpansion="1"
|
||||
AdditionalIncludeDirectories="..\..\dep\include;..\..\src\framework;..\..\src\shared;..\..\src\shared\vmap;..\..\dep\ACE_wrappers"
|
||||
PreprocessorDefinitions="WIN32;NDEBUG;_LIB;"
|
||||
|
||||
@@ -46,7 +46,7 @@
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
AdditionalOptions="/MP"
|
||||
AdditionalOptions="/MP /openmp"
|
||||
InlineFunctionExpansion="1"
|
||||
AdditionalIncludeDirectories="..\..\dep\include;..\..\dep\include\g3dlite;..\..\src\framework;..\..\src\shared;..\..\dep\ACE_wrappers"
|
||||
PreprocessorDefinitions="WIN32;NDEBUG;_LIB;_CRT_SECURE_NO_DEPRECATE"
|
||||
@@ -130,7 +130,7 @@
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
AdditionalOptions="/MP"
|
||||
AdditionalOptions="/MP /openmp"
|
||||
InlineFunctionExpansion="1"
|
||||
AdditionalIncludeDirectories="..\..\dep\include;..\..\dep\include\g3dlite;..\..\src\framework;..\..\src\shared;..\..\dep\ACE_wrappers"
|
||||
PreprocessorDefinitions="WIN32;NDEBUG;_LIB;_CRT_SECURE_NO_DEPRECATE"
|
||||
@@ -213,7 +213,7 @@
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
AdditionalOptions="/MP"
|
||||
AdditionalOptions="/MP /openmp"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories="..\..\dep\include;..\..\dep\include\g3dlite;..\..\src\framework;..\..\src\shared;..\..\dep\ACE_wrappers"
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;TRINITY_DEBUG;_LIB;_CRT_SECURE_NO_DEPRECATE"
|
||||
@@ -295,7 +295,7 @@
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
AdditionalOptions="/MP"
|
||||
AdditionalOptions="/MP /openmp"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories="..\..\dep\include;..\..\dep\include\g3dlite;..\..\src\framework;..\..\src\shared;..\..\dep\ACE_wrappers"
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;TRINITY_DEBUG;_LIB;_CRT_SECURE_NO_DEPRECATE"
|
||||
|
||||
Reference in New Issue
Block a user