MultiThreadedPageRank { public int run() { LongArrayList noOuts = new LongArrayList(); LongIterator iter = nodes.iterator(); while (iter.hasNext()) { long v = iter.nextLong(); if (graph.getOutDegree(v) == 0) { noOuts.add(v); } } double dampingAmount = (1.0 - dampingFactor) / nodeCount; prVector = new AtomicDoubleArray((int) (maxNodeId + 1)); nodes.forEach(v -> prVector.set((int) (long) v, 1.0 / nodeCount)); LongArrayList[] nodePartitions = new LongArrayList[threads]; int partitionSize = nodes.size() / threads; for (int i=0; i<threads; i++) { int startPos = i * partitionSize; int endPos = i == (threads - 1) ? nodes.size() : (i + 1) * partitionSize; nodePartitions[i] = new LongArrayList(nodes.subList(startPos, endPos)); } int i = 0; while (i < this.maxIterations && normL1 > tolerance) { iterate(dampingAmount, noOuts, nodePartitions); i++; } return i; } MultiThreadedPageRank(OutIndexedDirectedGraph graph, LongArrayList nodes,
                               long maxNodeId, double dampingFactor, int maxIterations,
                               double tolerance, int threads); int run(); double getL1Norm(); AtomicDoubleArray getPageRankVector();  }
@Test public void testRun() { LongArrayList longArrayList = new LongArrayList(); MultiThreadedPageRank multiThreadedPageRank = new MultiThreadedPageRank(null, longArrayList, 3237L, 0.0, 1, 0.0, 1); assertEquals(1, multiThreadedPageRank.run()); assertEquals(0.0, multiThreadedPageRank.getL1Norm(), 0.01); }