On May 12, 2010, at 3:34 PM, Steven Saul wrote:
> After looking at HeatBugs and the ThreadedDiffuser class, I was
> wondering
> if there was a way to use ParallelSequence to split the processing of
> agents (in this case the actual heat bugs) in each time step. For
> example, if you have 800 heatbugs in any given time step, a computer
> with
> 8 cores would process 100 bugs on each core simultaneously in that
> time
> step.
Sort of. You just schedule a ParallelSequence on the schedule. In
the ParallelSequence you put, say, eight RandomSequences. Each of the
RandomSequences
holds 1/8 of all your bugs.
However you have to be careful there. Each HeatBug reads information,
moves, and writes information. This presents opportunities for race
conditions. First, if one HeatBug is reading a location while another
is writing the same location, you'll get messed up results. Second,
if two HeatBugs access the SparseGrid2D at the same time to move,
they'll break the hash table. This means that realistically you can
only do the read portion of these operations in parallel. So you'd
have the parallel sequence call step() methods which do the reads and
internal computation for each bug in parallel; but after that you'd
have to schedule the bugs serially (as before, maybe in a later
priority) to move themselves and then write to the heat array.
This is advanced threading stuff for people who are really familiar
with the perils of threaded coding. If the above paragraph causes you
to say "huh?", then the answer is NO, you SHOULD NOT parallelize your
agents. :-)
Sean
|