Maximize Threading, Load Balancing

BlitzMax Forums/BlitzMax Programming/Maximize Threading, Load Balancing

BLaBZ(Posted 2013) [#1]
Hi!

What are some techniques used to maximize performance via threads? Are there some automatic load balancing methods?

How do you get your game to use threads in the most optimized fashion?

Thanks!
-BLaBZ


xlsior(Posted 2013) [#2]
Keep in mind that not all operations are thread-safe, and certain things (like drawing anything to the screen) can only happen in the main thread.

With that in mind, there are only certain things you can off-load to threads: data processing, network communications, game logic, etc.


ImaginaryHuman(Posted 2013) [#3]
The o/s is mostly responsible for load balancing and distributing threads etc. Look into creating a reusable thread pool. I suggest creating twice as many threads as the number of CPU cores (including hyperthreaded cores), so that at least 2 threads might run on each. I've seen multithreaded apps which have 1 thread per core and the cpu doesn't use the whole cores performance because occasionally the thread has to wait for the o/s or something else and the cpu core idles. Also when you deal with data try to remember the cache - maybe try interleaved memory accesses if the cache is shared. Try to do stuff that doesn't require too much access to the same exact data otherwise you have to use locks etc which stalls things.