package org.softwareheritage.graph; import org.softwareheritage.graph.algo.Traversal; import java.io.OutputStream; import java.io.IOException; import java.util.Scanner; import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.RejectedExecutionHandler; import java.util.concurrent.ExecutorService; public class TestDistribution { Graph graph; public void load_graph(String graphBasename) throws IOException { System.err.println("Loading graph " + graphBasename + " ..."); this.graph = new Graph(graphBasename); System.err.println("Graph loaded."); } public static void main(String[] args) { if (args.length != 1) { System.out.println("Usage: TestParallel GRAPH_BASENAME"); System.exit(1); } TestDistribution tp = new TestDistribution(); try { tp.load_graph(args[0]); } catch (IOException e) { System.out.println("Could not load graph: " + e); System.exit(2); } RejectedExecutionHandler handler = new ThreadPoolExecutor.CallerRunsPolicy(); ExecutorService service = new ThreadPoolExecutor( 128, 128, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue(1024), handler); Scanner input = new Scanner(System.in); while (input.hasNextLong()) { service.submit(new CalculationJob(tp.graph, input.nextLong())); } } public static class CalculationJob implements Runnable { Graph graph; long node; public CalculationJob(Graph graph, long node) { this.graph = graph.copy(); this.node = node; } public void run() { Traversal t = new Traversal(this.graph, "backward", "cnt:dir,dir:rev"); int[] count = { 0 }; t.leavesVisitor(this.node, (node) -> { count[0]++; }); System.out.println("" + count[0]); } } }