Dear Mr. Luke, dear "Masonists",
I'm working on a model where agents (consumers) are connected by a
social network. On every time step they take a new decision, based on
their individual parameters and the parameters of their direct
neighbors in the network.
In order to implemet multiple runs with multiple parameter
specifications for different runs, I wrote a wrapper class from which
the model ("MainModel") is called. The basic structure of the wrapper
class, holding the main(String args) method, is:
for # runs
MainModel model = new MainModel(seed, parameter specifications...);
steps = model.schedule.getSteps();
while(steps < 240);
... do some file writing etc.
In order to speed up the simulation I decided to let
ParallelSequence's do the job of scheduling the model agents,
contained in the Bag networkAgents, to step and do their lookups in
their neighborhoods and to take new decisions each time step. The
structure is as follows:
Steppable steppable = new Steppable[numberOfCPUs];
for(int j = 0; j<numberOfCPUs;j++)
final int p = j;
steppable[j] = new Steppable ()
public void step(SimState state)
for(int i = p*NUMBER_OF_AGENTS/numberOfCPUs;i<(p+1)
Agent a = (Agent)(networkAgents.get(i));
a does something...
ParallelSequence update = new ParallelSequence(steppable);
The problem I'am facing now is that after some simulation runs, speed
drops sharply until it finally breaks down and java throws its
"Exception in thread "main" java.lang.OutOfMemoryError: Java heap
space". The problem occurs faster if the number of model agents is
higher. I also tried it with more space by java -Xmx200m or 400m,
even 800m, unfortunately the break down is only postponed but still
occurs. The problem occurs both under linux and Mac Osx (10.4), I am
using simple personal computers with two or for CPUs.
The Apple Activity Monitor shows for every new sim run an increasing
number of threads. It also shows that the space the simulation uses
is constantly growing but at break down is still far below the
virtual space reserved by java. The heap space problem only comes up
with ParallelSequences, not with Sequences.
I'm not an experienced programmer, but this seems to tell me that
after a sim run is over and the model instance has been finished the
threads that were created for or by the ParallelSequences are not
finished and therefore not garbage collected. Obviously the creation
of the sequence alone is sufficient to evoke these problems, because
when I commented out "schedule.scheduleRepeating(Schedule.EPOCH,
0,update,1);", and the simulation made only "empty" steps without any
real actions of the agents, the problem did not go away. Also the
idea of putting the Sequences into a OneShotStoppable wrapper (see
L&P=R236&I=-3) did not do the job.
Do you have an idea, what could be done to avoid these problems? Help
is really appreciated...
With Best Regards