quote:
Originally posted by The-Moon:
<STRONG>Multi threading is not hard at all to program. In fact its quite easy.I used pthread's before in a server client app i was working on. It was really a piece of cake to get it working once i knew how to use it correctly.</STRONG>
Parallelism is all about making sure that two tasks are independent (and if not, using some kind of synchronization). Once you have a parallel algorithm to implement, it's not *too* bad to code up, though there remain some pretty substantial pitfalls. What's really hard is figuring out what things are truly independent. On top of that, synchronization overheads can very easily eat up all the gains.
Path planning is a good example. Every planned path looks like it's totally independent of every other, so that's a good candidate. But, first thing, to make it fast Toady is likely storing some data in each tile. So now you have to remember to have each tile store data for each thread, and have a mapping from threads to that index. And now each tile has size that differs depending on the number of threads. OK, we fix all that, so that the path planner is independent across threads. But we still haven't achieved anything: there's still only one path planner being spawned at a time. So before we see any benefits, we also need to parallelize the per-frame loop over all animals (dwarves and gobbos included) that updates their state and does path planning. State updates are going to react to each other, so there's definitely some non-independence that needs to be coaxed out via mutexes or greater re-engineering; this will be hard. OK, *now* we can parallelize path planning (and state updates). How much faster is dwarf state update now? Twice as fast on our beloved dual-core chips, minus synchronization overhead and memory hierarchy overhead that probably triples (actual number from many things I've seen) the total work, which yields a speedup of... OK, on our beloved quad-core machines, it's faster. But we only sped up part of the program, so it's not much faster.
This constitutes a lot of development time, especially if Toady isn't already an expert at this kind of stuff. Compare that with just running the sequential program in a profiler and looking for bottlenecks and fixing them using traditional techniques that Toady presumably knows well (using fewer instructions, using less memory, etc). Or with fixing bugs and adding content.