* @param partition Partition to compute
* @return Partition stats for this computed partition
*/
private PartitionStats computePartition(Partition<I, V, E, M> partition)
throws IOException, InterruptedException {
PartitionStats partitionStats =
new PartitionStats(partition.getId(), 0, 0, 0, 0);
// Make sure this is thread-safe across runs
synchronized (partition) {
// Prepare Partition context
WorkerContext workerContext =
graphState.getGraphTaskManager().getWorkerContext();
PartitionContext partitionContext = partition.getPartitionContext();
synchronized (workerContext) {
partitionContext.preSuperstep(workerContext);
}
graphState.setPartitionContext(partition.getPartitionContext());
for (Vertex<I, V, E, M> vertex : partition) {
// Make sure every vertex has this thread's
// graphState before computing
vertex.setGraphState(graphState);
Iterable<M> messages = messageStore.getVertexMessages(vertex.getId());
if (vertex.isHalted() && !Iterables.isEmpty(messages)) {
vertex.wakeUp();
}
if (!vertex.isHalted()) {
context.progress();
TimerContext computeOneTimerContext = computeOneTimer.time();
try {
vertex.compute(messages);
} finally {
computeOneTimerContext.stop();
}
// Need to unwrap the mutated edges (possibly)
vertex.unwrapMutableEdges();
// Write vertex to superstep output (no-op if it is not used)
vertexWriter.writeVertex(vertex);
// Need to save the vertex changes (possibly)
partition.saveVertex(vertex);
}
if (vertex.isHalted()) {
partitionStats.incrFinishedVertexCount();
}
// Remove the messages now that the vertex has finished computation
messageStore.clearVertexMessages(vertex.getId());
// Add statistics for this vertex
partitionStats.incrVertexCount();
partitionStats.addEdgeCount(vertex.getNumEdges());
}
messageStore.clearPartition(partition.getId());
synchronized (workerContext) {