Verified Commit 7ed802a9 authored by Amin Bandali's avatar Amin Bandali
Browse files

Add --parallel option for making parallel streams optional

parent 12512076
......@@ -14,6 +14,7 @@ import java.util.Map.Entry;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.Stream;
import edu.mit.csail.sdg.alloy4.A4Reporter;
import edu.mit.csail.sdg.alloy4.ConstList;
......@@ -117,9 +118,10 @@ public final class MainCLI {
.collect(Collectors.toList());
cr.file_count = files.size();
mainPr.ln("number of " + corpus + " models: " + cr.file_count);
r.total_file_count += cr.file_count;
AtomicInteger i = new AtomicInteger(1);
files.parallelStream()
.filter(p -> p.getFileName().toString().endsWith(".als"))
Stream<Path> fs = o.parallel ? files.parallelStream() : files.stream();
fs.filter(p -> p.getFileName().toString().endsWith(".als"))
.filter(p -> !Arrays.asList(o.ignoredFiles).contains(p.getFileName().toString()))
.forEach(p -> cr.file_results.add(analyzeFile(mainPr, p, corpus, i.getAndIncrement(), cr.file_count)));
} catch (Exception e) {
......@@ -310,21 +312,23 @@ public final class MainCLI {
ConstList<Sig> allReachableSigs = module.getAllReachableSigs();
A4Options options = new A4Options();
options.solver = solver.solver;
module.getAllCommands()
.parallelStream()
.forEach(c -> {
RunReporter rep = new RunReporter();
Run run = new Run();
run.solver_id = solver.solver.id();
run.solver_name = solver.solver.toString();
run.command = c.toString();
run.takes = Collections.synchronizedList(new ArrayList<RunResult>());
rep.run = run;
IntStream.range(0, 3).parallel().forEach(i -> {
TranslateAlloyToKodkod.execute_command(rep, allReachableSigs, c, options);
});
mr.runs.add(run);
});
Stream<edu.mit.csail.sdg.ast.Command> cs = o.parallel ?
module.getAllCommands().parallelStream() : module.getAllCommands().stream();
cs.forEach(c -> {
RunReporter rep = new RunReporter();
Run run = new Run();
run.solver_id = solver.solver.id();
run.solver_name = solver.solver.toString();
run.command = c.toString();
run.takes = Collections.synchronizedList(new ArrayList<RunResult>());
rep.run = run;
IntStream is = o.parallel ?
IntStream.range(0, 3).parallel() : IntStream.range(0, 3);
is.forEach(i -> {
TranslateAlloyToKodkod.execute_command(rep, allReachableSigs, c, options);
});
mr.runs.add(run);
});
Instant stop = Instant.now();
......
......@@ -69,6 +69,9 @@ public class Options implements Runnable {
@Option(names = "--ssr", description = "Structure Signature Removal (SSR) mode")
protected boolean ssr;
@Option(names = "--parallel", description = "Parallel mode (use parallel streams)")
protected boolean parallel;
public Options(MainCLI cli) {
app = cli;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment