fix cpu usage when openMP is enabled

This commit is contained in:
Jérémy Rosen 2011-04-16 18:12:31 +00:00
parent f0fb305ad6
commit 867600e99f
3 changed files with 26 additions and 3 deletions

View file

@ -15,6 +15,10 @@ CHANGES
=======
[section="section title"]text[/section]
Wesnoth now has experimental support for OpenMP tu better use multiple cores. This needs to be enabled at compile time.
OpenMP has been tested under linux and windows but needs some testing under MacO, which is why it is currently optional.
In particular we are interested in abnormal CPU usage when openMP is enabled. Please report to Boucman for debug instructions
[section="section title 2"]text 2[/section]
@ -24,4 +28,4 @@ KNOWN BUGS
[list][*] known issue
[*] known issue 2
[/list]
[/list]

View file

@ -80,7 +80,8 @@
#include "version.hpp"
//#ifdef _WIN32
//#include "locale.h"
//#include <process.h>
//#include <env.h>
//#endif
#include "editor/editor_main.hpp"
@ -2390,6 +2391,24 @@ void init_custom_malloc();
int main(int argc, char** argv)
{
#if defined(_OPENMP) && !defined(_WIN32)
// Wesnoth is a special case for OMP
// OMP wait strategy is to have threads busy-loop for 100ms
// if there is nothing to do, they then go to sleep.
// this avoids the scheduler putting the thread to sleep when work
// is about to be available
//
// However Wesnoth has a lot of very small jobs that need to be done
// at each redraw => 50fps every 2ms.
// All the threads are thus busy-waiting all the time, hogging the CPU
// To avoid that problem, we need to set the OMP_WAIT_POLICY env var
// but that var is read by OMP at library loading time (before main)
// thus the relaunching of ourselves after setting the ariable
if (!getenv("OMP_WAIT_POLICY")) {
setenv("OMP_WAIT_POLICY", "PASSIVE", 1);
execv(argv[0], argv);
}
#endif
#ifndef DISABLE_POOL_ALLOC
init_custom_malloc();
#endif

View file

@ -918,7 +918,7 @@ void game_display::invalidate_animations()
#ifdef _OPENMP
#pragma omp parallel for reduction(|:new_inval) shared(unit_list) schedule(guided)
#endif //_OPENMP
for(unsigned int i=0; i < unit_list.size(); i++) {
for(int i=0; i < (int)unit_list.size(); i++) {
new_inval |= unit_list[i]->invalidate(unit_list[i]->get_location());
}
}while(new_inval);