}
private final double broadcastError(
BSPPeer<VertexWritable, VertexArrayWritable, Text, DoubleWritable> peer,
double error) throws IOException, SyncException, InterruptedException {
peer.send(MASTER_TASK_NAME, new DoubleMessage("", error));
peer.sync();
if (peer.getPeerName().equals(MASTER_TASK_NAME)) {
double errorSum = 0.0;
int count = 0;
DoubleMessage message;
while ((message = (DoubleMessage) peer.getCurrentMessage()) != null) {
errorSum += message.getData();
count++;
}
double avgError = errorSum / (double) count;
// LOG.info("Average error: " + avgError);
for (String name : peer.getAllPeerNames()) {
peer.send(name, new DoubleMessage("", avgError));
}
}
peer.sync();
DoubleMessage message = (DoubleMessage) peer.getCurrentMessage();
return message.getData();
}