6

we have a single threaded application that simulates the interaction of a hundred of thousands of objects over time with the shared memory model.
obviously, it suffers from its inability to scale over multi CPU hardware.

after reading a little about agent based modeling and functional programming/actor model I was considering a rewrite with the message-passing paradigm.

the idea is very simple - each object will be an actor and their interactions will be messages so that the simulation could happen in parallel. given a configuration of objects at a certain time - its future consequences can be easily computed.

the question is how to model the time:
for example let's assume the the behavior of object X depends on A and B, as the actors and the messages calculations order is not guaranteed it could be that when X is to be computed A has already sent its message to X but B didn't. how to make sure the computation happens correctly?

I hope the question is clear
thanks in advance.

akiva
  • 2,677
  • 3
  • 31
  • 40

1 Answers1

10

Your approach of using message passing to parallelize a (discrete-event?) simulation is well-known and does not require a functional style per se (although, of course, this does not prevent you to implement it like that).

The basic problem you describe w.r.t. to the timing of events is also known as the local causality constraint (see, for example, this textbook). Basically, you need to use a synchronization protocol to ensure that each object (or agent) processes its messages in the right order. In the domain of parallel discrete-event simulation, such objects are called logical processes, and they communicate via events (i.e. time-stamped messages).

Correctly implementing a synchronization protocol for these events is challenging and the right choice of protocol is highly application-specific. For example, one important factor is the average amount of computation required per event: if there is little computation required, the communication costs dominate the overall execution time and it will be hard to scale the simulation.

I would therefore recommend to look for existing solutions/libraries on top of the actors framework you intend to use before starting from scratch.

Roland Ewald
  • 4,630
  • 3
  • 35
  • 49
  • 2
    Hi and thanks for your kind reply! 1. indeed this is a discrete-event simulation 2. the reason I preferred the functional style is that I wanted to have copies and immutable data structures in order to avoid the complexity of data protection, and this is done more naturally with functional programming paradigm. 3. thanks for referring me to the textbook, I'll definitively look at it. your usage of the exact terms is a great assistance as it helps me to refine y search queries when looking for more information. 4. sure, I'm into examination if existing libraries, currently I'm evaluating akka – akiva Nov 26 '12 at 06:56
  • 2
    You're welcome. As you planning to use Akka with Scala? In that case, you may want to have a look at Scalation (https://code.google.com/p/scalation), which AFAIK does not support parallel execution but has representations for the different 'world views' of discrete-event simulation, as well as some other components that may be useful to you. The Java framework JAMES II (http://jamesii.org) also offers many of the components you will need (e.g. event queues) and has a Scala interface for experiment specification (http://sessl.org) [DISCLAIMER: I'm one of the devs]. – Roland Ewald Nov 26 '12 at 10:00