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