views:

541

answers:

2

Hello folks, this is a follow up to this. (You don't have to read all the answers, just the question)

People explained to me the difference between processes and threads. On the one hand, I wanted processes so I could fully exploit all core of the CPU, on the other hand, passing information between processes was less than ideal, and I didn't want to have two copies of the huge object I was dealing with.

So I've been thinking about a way to do this, combining processes and threads; tell me if this makes sense. The main process in my program is the GUI process. I will have it spawn a "rendering-manager" thread. The rendering-manager thread will be responsible for rendering the simulation, however, it will not render them by itself, but spawn other processes to do the work for it.

These are the goals:

  1. Rendering should take advantage of all the cores available.
  2. The GUI should never become sluggish.

The reason I want the rendering-manager to be a thread is because it has to share a lot of information with the GUI: Namely, the simulation-timeline.

So do you think this is a good design? Do you have any suggestions for improvement?

Update:

Sorry for my confusing use of the word "render". By render I mean calculate the simulation, not render it on screen.

A: 

The main process in my program is the GUI process. I will have it spawn a "rendering-manager" thread. The rendering-manager thread will be responsible for rendering the simulation, however, it will not render them by itself, but spawn other processes to do the work for it.

I'm no expert on graphics technologies, but this sounds a lot like what GPUs are intended for. Perhaps pygame is more what you're looking for?

Jason Baker
I don't understand... GPU for what? I will use a GPU for drawing the simulation state on the screen, but by "render" I mean calculate the simulations, according to whatever world-laws are defined for that specific simulation. I think it will be on the CPU.
cool-RR
I think you may be confusing people by your use of the word "render". Render is pretty closely associated with turning data into images for the screen. It might be better to just describe this as "runn the simulation" or something similar in the question.
Chris Upchurch
You're right Chris.
cool-RR
+2  A: 

Before using processes, make sure that:

  • Your algorithm can be parallelized between all the processors.
  • You need this parallelism.

In my opinion a good rule of thumb is:

  1. Make it work.
  2. Make it right.
  3. Make it fast.

So I'd suggest to “simply” use threads first. Maybe you will realize that even with one thread computing the simulation it's fast enough.

Bastien Léonard
+1 for the 1-2-3 approach ..although you could probably add 4. Realise the bottlenecks are elsewhere and make it work again ;-)
Jon Cage