Search in sources :

Example 66 with PrimitiveLongIterator

use of org.neo4j.collection.primitive.PrimitiveLongIterator in project neo4j-apoc-procedures by neo4j-contrib.

the class PregelTest method runPageRank3.

@Test
public void runPageRank3() throws Exception {
    GraphDatabaseAPI db = (GraphDatabaseAPI) new TestGraphDatabaseFactory().newImpermanentDatabaseBuilder().setConfig(GraphDatabaseSettings.pagecache_memory, "100M").newGraphDatabase();
    int nodeCount = 100_001;
    int[] degrees = new int[nodeCount];
    createRankTestData(db, nodeCount, degrees);
    long start = System.currentTimeMillis();
    Pregel pregel = new Pregel(db, guard).withBatchSize(10000);
    PrimitiveLongIterator nodes;
    try (Transaction tx = db.beginTx()) {
        nodes = pregel.statement().readOperations().nodesGetAll();
        tx.success();
    }
    float[] ranks = pregel.runProgram3(nodes, new Pregel.AllExpander(), new PageRankProgram(nodeCount, degrees, new float[nodeCount], null));
    long time = System.currentTimeMillis() - start;
    Arrays.sort(ranks);
    // System.err.println("PageRank Program ran for "+nodeCount+" nodes in "+time+" ms. 10 hightest Ranks "+Arrays.toString(Arrays.copyOfRange(ranks,ranks.length-10,ranks.length)));
    db.shutdown();
}
Also used : PrimitiveLongIterator(org.neo4j.collection.primitive.PrimitiveLongIterator) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) Transaction(org.neo4j.graphdb.Transaction) TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory) Test(org.junit.Test)

Example 67 with PrimitiveLongIterator

use of org.neo4j.collection.primitive.PrimitiveLongIterator in project neo4j-apoc-procedures by neo4j-contrib.

the class PregelTest method runDegreeProgram.

@Test
public void runDegreeProgram() throws Exception {
    GraphDatabaseAPI db = (GraphDatabaseAPI) new TestGraphDatabaseFactory().newImpermanentDatabaseBuilder().setConfig(GraphDatabaseSettings.pagecache_memory, "100M").newGraphDatabase();
    try (Transaction tx = db.beginTx()) {
        for (int i = 0; i < 100_001; i++) {
            Node n = db.createNode();
            int degree = i % 100 == 0 ? i / 100 : 0;
            for (int rel = 0; rel < degree; rel++) {
                n.createRelationshipTo(n, TYPE);
            }
        }
        tx.success();
    }
    Pregel pregel = new Pregel(db, guard).withBatchSize(1000);
    PrimitiveLongIterator nodes;
    long nodeCount;
    try (Transaction tx = db.beginTx()) {
        ReadOperations reads = pregel.statement().readOperations();
        nodes = reads.nodesGetAll();
        nodeCount = reads.nodesGetCount();
        tx.success();
    }
    long start = System.currentTimeMillis();
    int[] degrees = pregel.runProgram(nodes, new Pregel.AllExpander(), new OutDegrees(nodeCount));
    long time = System.currentTimeMillis() - start;
    // System.err.println("Program ran for "+nodeCount+" nodes in "+time+" ms.");
    assertEquals(0, degrees[0]);
    assertEquals(1, degrees[100]);
    assertEquals(10, degrees[1000]);
    assertEquals(100, degrees[10000]);
    db.shutdown();
}
Also used : PrimitiveLongIterator(org.neo4j.collection.primitive.PrimitiveLongIterator) ReadOperations(org.neo4j.kernel.api.ReadOperations) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node) TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory) Test(org.junit.Test)

Example 68 with PrimitiveLongIterator

use of org.neo4j.collection.primitive.PrimitiveLongIterator in project neo4j-apoc-procedures by neo4j-contrib.

the class PageRankArrayStorageParallelSPI method computeDegrees.

private int[] computeDegrees(final ThreadToStatementContextBridge ctx) {
    final int[] degree = new int[nodeCount];
    Arrays.fill(degree, -1);
    PrimitiveLongIterator it = ctx.get().readOperations().nodesGetAll();
    int totalCount = nodeCount;
    runOperations(pool, it, totalCount, db, (ops, id) -> degree[id] = ops.nodeGetDegree(id, Direction.OUTGOING), guard);
    return degree;
}
Also used : PrimitiveLongIterator(org.neo4j.collection.primitive.PrimitiveLongIterator)

Aggregations

PrimitiveLongIterator (org.neo4j.collection.primitive.PrimitiveLongIterator)68 Test (org.junit.Test)47 IndexReader (org.neo4j.storageengine.api.schema.IndexReader)15 Transaction (org.neo4j.graphdb.Transaction)10 IndexQuery (org.neo4j.kernel.api.schema_new.IndexQuery)10 ReadOperations (org.neo4j.kernel.api.ReadOperations)8 TransactionState (org.neo4j.kernel.api.txstate.TransactionState)8 KernelStatement (org.neo4j.kernel.impl.api.KernelStatement)8 StateHandlingStatementOperations (org.neo4j.kernel.impl.api.StateHandlingStatementOperations)8 StoreReadLayer (org.neo4j.storageengine.api.StoreReadLayer)8 IOException (java.io.IOException)4 PrimitiveLongSet (org.neo4j.collection.primitive.PrimitiveLongSet)4 Node (org.neo4j.graphdb.Node)4 Statement (org.neo4j.kernel.api.Statement)4 DiffSets (org.neo4j.kernel.impl.util.diffsets.DiffSets)4 GraphDatabaseAPI (org.neo4j.kernel.internal.GraphDatabaseAPI)4 ArrayList (java.util.ArrayList)3 DocValuesCollector (org.neo4j.kernel.api.impl.index.collector.DocValuesCollector)3 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2