On Jan 2, 2016, at 9:37 AM, Axel Kowald <[log in to unmask]> wrote:
> As I understand it, the schedule class effectively steps all steppables
> in a sequential fashion until the queue is empty. I.e. it uses a single
> thread and that is also the reason why a mason simulation uses only 25%
> CPU time on my quadcore PC. I therefore wonder if it would not be
> possible to parallelize schedule so that it uses all the available
> cores. Of course there could be inconsistencies if two neighboring
> agents are stepped in parallel but if the behavior of an agent only
> depends on a certain fixed neighborhood size, a parallelization scheme
> could be used that avoids such conflicts.
I think you need to consider more carefully what it would mean to "parallelize" a schedule. A schedule's job is to evaluate individuals in a specific sorted order. It is by its very nature serial.
MASON's schedule basically does this:
1. Identify the minimum-scheduled item
2. Pull out all items scheduled at the same time as the minimum item.
3. Sort them by their ordering.
4. For each group of items with the same ordering, lower orderings first,
5. step each item in the group in some random order
6. Go to 1.
The only place I can immediately think of which could be parallelized is #4 and 5. But MASON already has a procedure for doing exactly that: a ParallelSequence. Instead of scheduling agents on the schedule, schedule one or more ParallelSequences on the schedule, loaded with agents to run in parallel.
> P.S. Of course I can run several simulations in parallel to use all my
> cores, but often I need the results of one simulation before I can start
> the next, which puts limits on this kind of parallelization :-(
Too bad. Be warned that use of ParallelSequence won't have very impressive speedup -- probably beyond 4x you won't get almost any improvement at all. This is mostly because ABM simulations are generally very highly memory-bound, which is a worst case scenario for parallel threads. On the other hand, running multiple simulations in parallel has very good speedup properties!