Jump to content

Design discussion: Threading to use more than one CPU core


Recommended Posts

Does someone have a high level design how this would be accomplished?

Brainstorming I'm thinking how to split up threads:

1. Different AI can be on separate threads

2. Graphics

3. Physics and path finding, simulation of the world

Would be nice to have high level profiling information to more intelligently discuss how to divide up the CPU cores.

What is most of the CPU time spent on?

The design should encompass 16+ cores, since in the not too distance future, ARM chips will have this. Already exist 8 cores.

Edited by DanCar
Link to comment
Share on other sites

We're working on making 0 A.D. more parallel, and your outline roughly mirrors our plans. However, multithreading is a lot harder than it sounds - especially with our limited resources.
I think the current consensus is that most CPU time consuming part is the simulation (pathfinder in particular) and AI. I few months ago I did a few runs in a profiler and the results are here (see cpuprofile1.svg - cpuprofile11.svg and note that this doesn't show javascript time nicely).

  • Like 2
Link to comment
Share on other sites

We want to wait with multithreading until the interfaces are designed well. Both things scheduled for multiple threads: the AI interface and the pathfinder interface, are scheduled for rewrite.

Though so far, they've both been designed with multithreading in mind. So the AI API is designed to never touch the simulation data, and only get a copy of the simulation data every turn. And the pathfinder is designed to be able to only return a path the next turn, so it can also run in a separate thread (or multiple threads). And turns can only advance when every component (simulation, AI, pathfinder, ...) is done.

As developing something that doesn't run in the main thread is hard work, we certainly want to wait with running the pathfinder and the AI in a separate thread. And if threading gets implemented, there should be settings or compiler flags to disable it for sure.

Link to comment
Share on other sites

We're working on making 0 A.D. more parallel, and your outline roughly mirrors our plans. However, multithreading is a lot harder than it sounds - especially with our limited resources.

I think the current consensus is that most CPU time consuming part is the simulation (pathfinder in particular) and AI. I few months ago I did a few runs in a profiler and the results are here (see cpuprofile1.svg - cpuprofile11.svg and note that this doesn't show javascript time nicely).

Thanks Josh for the info. If you document your plans, for example use a shared google doc, then you might find people willing to help out with the tasks.

Link to comment
Share on other sites

  • 1 month later...

Exactly 1 core is being used.

That's not quite true. The game does stuff in multiple threads for random map generation, sound, some network related tasks and the user feedback functionality on the main menu. SpiderMonkey, our Javascript engine, runs JIT compiling of Javascript code in separate threads and some parts of the garbage collection happen off-thread. Saying the game is completely "single threaded" is technically wrong and just means that some very performance intensive tasks that could benefit from multithreading don't do it yet.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...