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();
}
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();
}
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;
}
Aggregations