Page MenuHomeSoftware Heritage
Paste P548

Masterwork From Distant Lands
ActivePublic

Authored by seirl on Oct 14 2019, 1:52 PM.
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<Runnable>(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]);
}
}
}

Event Timeline

seirl changed the title of this paste from untitled to Masterwork From Distant Lands.
seirl updated the paste's language from autodetect to java.Oct 14 2019, 1:52 PM
seirl changed the visibility from "All Users" to "Public (No Login Required)".Oct 15 2019, 11:23 PM