Parallelisation and Java


Having chosen to divide up the Agents, we need to re-write the Model.java code so less agents are made on each machine (an alternative is to make all the agents on one machine, and portion them out at the start, but the agents here are homogeneous and independent, so this is unnecessary).

// Setup
 
int nodeNumberOfAgents = 0;
 
if (node != 0) {
 
   nodeNumberOfAgents = numberOfAgents/(numberOfNodes - 1);
 
   if (node == (numberOfNodes - 1)) {
      nodeNumberOfAgents =
      nodeNumberOfAgents + (numberOfAgents % (numberOfNodes - 1));
   }
 
   agents = new Agent[nodeNumberOfAgents];
 
   for (int i = 0; i < nodeNumberOfAgents; i++) {
 
      agents[i] = new Agent();
      agents[i].setDensityLimit(densityLimit);
 
      // etc...
 
   }
   landscape.setAgents(agents);
 
}

Thus we should end up with no Agents on node zero, with the other nodes getting an even spread, except for the last node, which gets the remainder of the Agents that can't be divided evenly.

We'll also need to adjust our agents[i].step(); loops in Model.java to loop through less agents:

for (int i = 0; i < nodeNumberOfAgents; i++) {
 
   agents[i].step();
 
}

Next we need to get all the worker nodes to send their densities back to node zero, so it can collate them.