Advertisement

My multicore performance test

Started by April 05, 2008 08:13 AM
2 comments, last by captain_crunch 16 years, 7 months ago
I wanted to see how well (or badly) a modern multicore processor is utilized when there are lengthy AI calculations in the main loop. I used XNA for the test, and I simulated a lengthy AI job by a for-loop with 2 mio. iterations. The job is run on each Update of the main loop. Using the Windows performance monitor I could keep an eye on how well the 4 CPU cores were used. This is with the entire job running in the main thread: Free Image Hosting at www.ImageShack.us This is with the load split between the main thread and one added thread (they each have to do 1 mio. iterations): Free Image Hosting at www.ImageShack.us This is with the load split between the main thread and two added threads (they each have to do 667.000 iterations): Free Image Hosting at www.ImageShack.us Conclusion: Running everything in the main thread will only utilize about 25% of the processing power of an 4-core processor. 1 core will do about 100 % of the work and the others will stand unused. With just the main thread and an extra thread, the load could be evenly split between 3 cores out of 4. The 4th was still mostly idle. With 3 threads in all, the job was finally divided equally on all 4 cores. With this in mind, I am now very eager to find articles or books on multithreaded AI. Do you have any good suggestions?
You have two significant problems to consider...

(1) If you're programming AI for a single agent, how will you ensure the integrity of state information between the threads? You'll end up spending most of your time just managing information between threads rather than doing useful computations on that data.

(2) If you're programming AI for multiple agents then do you assign them each a thread? You still have the same problem of managing information between threads.

The typical multi-threaded approach is to run your computationally intensive AI in a separate thread (such as pathfinding, terrain analysis, etc) and to run the rest of the game in the main thread (along with lower intensity AI like steering, target selection, etc). You can queue tasks for the AI thread and allow that thread to churn through them and spit out results as they are available. You can add time constraints on tasks as well.

This doesn't mean this is the best way to go though. You can handle many AI computational tasks in a single main thread (along with game code) with the smart application of scheduling techniques and some task management overhead.

Regards,

Timkin
Advertisement
You might be able to get some good ideas from sources on Distributed AI. In certain ways, multithreaded AI is like running a localled distributed AI algorithm. You'll run into some of the same limitations, bottle necks, and general issues.
I feel like describing my project a bit more.

My project is a real time strategy game with many (100 - 200) agents. In the game, they are supposed to autonomously cooperate while completing various building and transporting tasks that the player has laid down. I am representing these tasks as "jobs", that the agents can choose from.

I have also decided to use a goal-based architecture for the AI. So when an agent is idle, it will pick a job from the list, and this job will be represented in the AI's mind as a series of goals to complete in sequence (like "Go to A and fetch item X", "Go to B", "Start building").

Regarding multithreading, my idea was first to assign each agent its own thread. This seems logical, after all, they are all independent agents, right?

But the more I think about it, the more inclined I am to use a single thread for doing the AI work. Otherwise I will get in trouble when several agents go for the same objectives (items, tasks, resources etc.)
Putting this kind of resource allocation in one thread will be easier and safer, as well as more efficient, if it wasn't for the multicore performance penalty.

So I feel you are right about only multithreading subsystems.
I am going to do this with the pathfinder by spawning a thread for each pathfinding request that comes in.

This topic is closed to new replies.

Advertisement