Well, calculating the results one by one is obviously something which you would have to give up.arjan de lumens said:This does get complicated a bit by the fact that you may well have multiple outstanding physics calculations (?), and you wish to be able to process the results one by one as they appear rather than just waiting for all of them - although that can be solved by replacing the true/false flag with a queue, which is still not unreasonably complex.
Improper use of any code library can result in bad bugs. But it can be managed somewhat by having the code convention of only reading other AI objects' information by reading from a virtual parent class.For such an AI system, you would still need to impose some restrictions on the classes used. For example: would there exist data fields or structures that the AI agent can access, but which are not private to the individual AI agent itself? If such fields/structures exist, one would need to take care to ensure that they are never modified during the parallel-AI evaluation, neither by the AI agent nor by any code outside the AI agents. While this is not a very difficult constraint to obey, the programmer does need to be aware of the fact that such a constraint is present and that violating it WILL result in a big fat heisenbug (in particular since e.g. the C++/Java family languages do not provide the necessary constructs to enforce such a constraint at the language level).
demonic said:I think by 2010, clock speeds will be totally irrelevant then!
Why? A queue such as I indicated should be plenty enough to maintain parallellism for this situation - of course, for such a queue to work maximally efficiently, you need to take into account (in the queue or the main thread itself) that the calculations will finish in a different order than they were issued in.Chalnoth said:Well, calculating the results one by one is obviously something which you would have to give up.
Such a convention addresses some type safety problems, but does not, AFAICS, address any concurrency safety problems. You still need to make sure through other means that when an AI object (during AI evaluation) reads a piece of information from another AI object, that the other object does not have any opportunity to modify that piece of information in-place during the AI evaluation phase. Otherwise you get an annoying race condition.Improper use of any code library can result in bad bugs. But it can be managed somewhat by having the code convention of only reading other AI objects' information by reading from a virtual parent class.
But doing the reading through parent class function calls can solve that issue just fine. It's all about double buffering of the data that can be read. Simply defining the actual variables used here as private would prevent direct reading/writing by derived classes. This adds a somewhat clumsy layer for the programmer to make use of for custom properties that need to be communicated, but it would prevent errors.arjan de lumens said:Such a convention addresses some type safety problems, but does not, AFAICS, address any concurrency safety problems. You still need to make sure through other means that when an AI object (during AI evaluation) reads a piece of information from another AI object, that the other object does not have any opportunity to modify that piece of information in-place during the AI evaluation phase. Otherwise you get an annoying race condition.
Well, OK. Not elegant, but it can prevent at least some misuse of the library.Chalnoth said:But doing the reading through parent class function calls can solve that issue just fine. It's all about double buffering of the data that can be read. Simply defining the actual variables used here as private would prevent direct reading/writing by derived classes. This adds a somewhat clumsy layer for the programmer to make use of for custom properties that need to be communicated, but it would prevent errors.
Severe demands on programmer discipline is usually an indication that the language you are using does not provide the appropriate abstractions for the problem at hand - in this sense, multithreading in C++/Java resembles structured programming in Assembly or object-orientation in straight C - it is entirely possible for a programmer that has enough time, skill, determination and discipline to do it and do it really well indeed (there are undoubtedly people who can put 32 cores to good use from C++), but a code monkey with appropriate tools will get the same task done much more quickly and cheaply.Obviously static class members would need to be avoided or used only very carefully. But no matter which way you slice it, discipline in multithreaded code is something that programmers are going to have to deal with, no matter what. Many-core processors are coming, and to make use of them, we need software that is both writable and capable of making use of more cores. And there are certainly ways of getting it done.
pcchen said:Of course it is relevant. Do you want to use a 100 core CPU running at 1Hz?
arjan de lumens said:I do not know for certain what an appropriate language for multithreaded programming will look like, but something like Haskell or Fortress looks like a much more promising place to start from than any of the C derivatives (even though Fortress still lacks a usable implementation and Haskell in its current form leaves something to be desired performance-wise) - in particular if you want to obtain automated functional parallellism (as opposed to just pure data parallellism, which is more or less a "solved" problem these days).