Search in sources :

Example 1 with PartitionStat

use of com.baidu.hugegraph.computer.core.graph.partition.PartitionStat in project hugegraph-computer by hugegraph.

the class FileGraphPartition method output.

protected PartitionStat output() {
    ComputerOutput output = this.context.config().createObject(ComputerOptions.OUTPUT_CLASS);
    output.init(this.context.config(), this.partition);
    try {
        this.beforeOutput();
    } catch (IOException e) {
        throw new ComputerException("Error occurred when beforeOutput", e);
    }
    Value result = this.context.config().createObject(ComputerOptions.ALGORITHM_RESULT_CLASS);
    while (this.vertexInput.hasNext()) {
        Vertex vertex = this.vertexInput.next();
        this.readVertexStatusAndValue(vertex, result);
        Edges edges = this.edgesInput.edges(this.vertexInput.idPointer());
        vertex.edges(edges);
        output.write(vertex);
    }
    try {
        this.afterOutput();
    } catch (IOException e) {
        throw new ComputerException("Error occurred when afterOutput", e);
    }
    output.close();
    return new PartitionStat(this.partition, this.vertexCount, this.edgeCount, 0L);
}
Also used : Vertex(com.baidu.hugegraph.computer.core.graph.vertex.Vertex) PartitionStat(com.baidu.hugegraph.computer.core.graph.partition.PartitionStat) Value(com.baidu.hugegraph.computer.core.graph.value.Value) IOException(java.io.IOException) Edges(com.baidu.hugegraph.computer.core.graph.edge.Edges) ComputerException(com.baidu.hugegraph.computer.core.common.exception.ComputerException) ComputerOutput(com.baidu.hugegraph.computer.core.output.ComputerOutput)

Example 2 with PartitionStat

use of com.baidu.hugegraph.computer.core.graph.partition.PartitionStat in project hugegraph-computer by hugegraph.

the class ComputeManager method output.

public void output() {
    // TODO: Write results back parallel
    for (FileGraphPartition partition : this.partitions.values()) {
        PartitionStat stat = partition.output();
        LOG.info("Output partition {} complete, stat='{}'", partition.partition(), stat);
    }
}
Also used : PartitionStat(com.baidu.hugegraph.computer.core.graph.partition.PartitionStat)

Example 3 with PartitionStat

use of com.baidu.hugegraph.computer.core.graph.partition.PartitionStat in project hugegraph-computer by hugegraph.

the class WorkerStatTest method testEquals.

@Test
public void testEquals() {
    PartitionStat stat1 = new PartitionStat(0, 1L, 2L, 0L);
    PartitionStat stat2 = new PartitionStat(1, 4L, 3L, 2L);
    WorkerStat workerStat1 = new WorkerStat();
    workerStat1.add(stat1);
    workerStat1.add(stat2);
    WorkerStat workerStat2 = new WorkerStat();
    workerStat2.add(stat1);
    workerStat2.add(stat2);
    WorkerStat workerStat3 = new WorkerStat();
    Assert.assertEquals(workerStat1, workerStat2);
    Assert.assertNotEquals(workerStat1, workerStat3);
    Assert.assertNotEquals(workerStat1, new Object());
}
Also used : PartitionStat(com.baidu.hugegraph.computer.core.graph.partition.PartitionStat) Test(org.junit.Test)

Example 4 with PartitionStat

use of com.baidu.hugegraph.computer.core.graph.partition.PartitionStat in project hugegraph-computer by hugegraph.

the class WorkerStatTest method testConstructor.

@Test
public void testConstructor() {
    WorkerStat workerStat1 = new WorkerStat();
    PartitionStat stat1 = new PartitionStat(0, 1L, 2L, 0L);
    PartitionStat stat2 = new PartitionStat(1, 4L, 3L, 2L);
    workerStat1.add(stat1);
    workerStat1.add(stat2);
    Assert.assertEquals(2, workerStat1.size());
    Assert.assertEquals(stat1, workerStat1.get(0));
    Assert.assertEquals(stat2, workerStat1.get(1));
    WorkerStat workerStat2 = new WorkerStat(1);
    Assert.assertEquals(1, workerStat2.workerId());
    Assert.assertEquals(0, workerStat2.size());
}
Also used : PartitionStat(com.baidu.hugegraph.computer.core.graph.partition.PartitionStat) Test(org.junit.Test)

Example 5 with PartitionStat

use of com.baidu.hugegraph.computer.core.graph.partition.PartitionStat in project hugegraph-computer by hugegraph.

the class WorkerStatTest method testHashCode.

@Test
public void testHashCode() {
    PartitionStat stat1 = new PartitionStat(0, 1L, 2L, 0L);
    PartitionStat stat2 = new PartitionStat(1, 4L, 3L, 2L);
    WorkerStat workerStat1 = new WorkerStat(1);
    workerStat1.add(stat1);
    workerStat1.add(stat2);
    WorkerStat workerStat2 = new WorkerStat(1);
    workerStat2.add(stat1);
    workerStat2.add(stat2);
    WorkerStat workerStat3 = new WorkerStat(2);
    Assert.assertEquals(workerStat1.hashCode(), workerStat2.hashCode());
    Assert.assertNotEquals(workerStat1.hashCode(), workerStat3.hashCode());
}
Also used : PartitionStat(com.baidu.hugegraph.computer.core.graph.partition.PartitionStat) Test(org.junit.Test)

Aggregations

PartitionStat (com.baidu.hugegraph.computer.core.graph.partition.PartitionStat)24 Test (org.junit.Test)15 MessageStat (com.baidu.hugegraph.computer.core.receiver.MessageStat)10 WorkerStat (com.baidu.hugegraph.computer.core.worker.WorkerStat)6 ComputerException (com.baidu.hugegraph.computer.core.common.exception.ComputerException)5 IOException (java.io.IOException)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 KvEntry (com.baidu.hugegraph.computer.core.store.entry.KvEntry)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 SuperstepStat (com.baidu.hugegraph.computer.core.graph.SuperstepStat)1 Edges (com.baidu.hugegraph.computer.core.graph.edge.Edges)1 Value (com.baidu.hugegraph.computer.core.graph.value.Value)1 Vertex (com.baidu.hugegraph.computer.core.graph.vertex.Vertex)1 BufferedFileOutput (com.baidu.hugegraph.computer.core.io.BufferedFileOutput)1 ComputerOutput (com.baidu.hugegraph.computer.core.output.ComputerOutput)1 PeekableIterator (com.baidu.hugegraph.computer.core.sort.flusher.PeekableIterator)1 Pointer (com.baidu.hugegraph.computer.core.store.entry.Pointer)1 Consumers (com.baidu.hugegraph.computer.core.util.Consumers)1