Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian krause2014-10-01 08:14:27 +0000
committerChristian krause2014-10-01 08:16:47 +0000
commit409416f7fbc83c1695d99a126e0e78eb0517fdde (patch)
tree31c2cf853fabc3f59c67fe2d3b92f191d9afa3a4 /plugins/org.eclipse.emf.henshin.examples/src/org/eclipse/emf/henshin/examples
parent8af9df8ce46bcda63209b2ecceee0a8032dbe662 (diff)
downloadorg.eclipse.emft.henshin-409416f7fbc83c1695d99a126e0e78eb0517fdde.tar.gz
org.eclipse.emft.henshin-409416f7fbc83c1695d99a126e0e78eb0517fdde.tar.xz
org.eclipse.emft.henshin-409416f7fbc83c1695d99a126e0e78eb0517fdde.zip
New engine flag: "destroy-matches"
This flag tells the engine whether it is ok to destroy matches during the construction of changes. This is useful when dealing with very large amounts of multi-matches. For example, in the Sierpinski benchmark the matches and the changes take up lots of memory. When setting this flag, the engine can get rid of the matches during the construction of the changes. Basically the freed memory of the matches can be used for the change descriptions. I verified this positive effect in the Sierpinski benchmark. By default, the flag is disabled though. Change-Id: Ie916a54e6fcc598d9f72f941e0269f91bba8dd21 Signed-off-by: Christian krause <henshin.ck@gmail.com>
Diffstat (limited to 'plugins/org.eclipse.emf.henshin.examples/src/org/eclipse/emf/henshin/examples')
-rw-r--r--plugins/org.eclipse.emf.henshin.examples/src/org/eclipse/emf/henshin/examples/sierpinski/SierpinskiBenchmark.java120
1 files changed, 64 insertions, 56 deletions
diff --git a/plugins/org.eclipse.emf.henshin.examples/src/org/eclipse/emf/henshin/examples/sierpinski/SierpinskiBenchmark.java b/plugins/org.eclipse.emf.henshin.examples/src/org/eclipse/emf/henshin/examples/sierpinski/SierpinskiBenchmark.java
index 5de21f367..e09d2b39f 100644
--- a/plugins/org.eclipse.emf.henshin.examples/src/org/eclipse/emf/henshin/examples/sierpinski/SierpinskiBenchmark.java
+++ b/plugins/org.eclipse.emf.henshin.examples/src/org/eclipse/emf/henshin/examples/sierpinski/SierpinskiBenchmark.java
@@ -43,7 +43,7 @@ public class SierpinskiBenchmark {
public static void run(String path, int iterations) {
// Determine number of threads to be used:
- int threads = Runtime.getRuntime().availableProcessors();
+ int threads = Runtime.getRuntime().availableProcessors() / 2;
// Create a resource set with a base directory:
HenshinResourceSet resourceSet = new HenshinResourceSet(path);
@@ -60,69 +60,77 @@ public class SierpinskiBenchmark {
EObject container = resource.getContents().get(0);
graph.remove(container);
- // Create an engine and a rule application:
+ // Create an engine:
Engine engine = new EngineImpl();
engine.getOptions().put(Engine.OPTION_WORKER_THREADS, threads);
- RuleApplication application = new RuleApplicationImpl(engine);
- application.setRule(rule);
- application.setEGraph(graph);
+ engine.getOptions().put(Engine.OPTION_DESTROY_MATCHES, true);
+
+ try {
+
+ RuleApplication application = new RuleApplicationImpl(engine);
+ application.setRule(rule);
+ application.setEGraph(graph);
+
+ // Check how much memory is available:
+ System.out.println("Starting Sierpinski benchmark...");
+ System.out.println(Runtime.getRuntime().maxMemory() / (1024 * 1024) + "MB available memory");
+ System.out.println("Using " + threads + " worker threads\n");
+ System.out.println("Level\tMatches\tNodes\tMatTime\tAppTime\tTotTime");
+
+ // For computing the expected number of nodes:
+ int expectedNodes = 3;
+ int expectedMatches = 1;
+
+ // Iteratively compute the Sierpinski triangle:
+ for (int i = 0; i < iterations; i++) {
+
+ // Collect garbage:
+ System.gc();
+ try {
+ Thread.sleep(1000);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+
+ // Find match:
+ long startTime = System.currentTimeMillis();
+ Match match = engine.findMatches(rule, graph, null).iterator().next();
+ long matchingTime = (System.currentTimeMillis() - startTime);
+
+ // Count number of multi-matches:
+ int matchCount = match.getMultiMatches(rule.getMultiRules().get(0)).size();
+
+ // Apply rule:
+ startTime = System.currentTimeMillis();
+ application.setCompleteMatch(match);
+ if (!application.execute(null)) {
+ throw new RuntimeException("Error transforming Sierpinski model");
+ }
+
+ long runtime = (System.currentTimeMillis() - startTime);
+
+ // Print info:
+ System.out.println((i + 1) + "\t" + matchCount + "\t" + graph.size() + "\t" + matchingTime + "\t"
+ + runtime + "\t" + (matchingTime + runtime));
+
+ // Check whether the number of matches and nodes is correct:
+ if (matchCount != expectedMatches) {
+ throw new RuntimeException("Expected " + expectedMatches + " matches instead of " + matchCount);
+ }
+ expectedMatches *= 3;
+ expectedNodes += expectedMatches;
+ if (graph.size() != expectedNodes) {
+ throw new RuntimeException("Expected " + expectedNodes + " nodes instead of " + graph.size());
+ }
- // Check how much memory is available:
- System.out.println("Starting Sierpinski benchmark...");
- System.out.println(Runtime.getRuntime().maxMemory() / (1024 * 1024) + "MB available memory\n");
-
- System.out.println("Level\tMatches\tNodes\tMatTime\tAppTime\tTotTime");
-
- // For computing the expected number of nodes:
- int expectedNodes = 3;
- int expectedMatches = 1;
-
- // Iteratively compute the Sierpinski triangle:
- for (int i = 0; i < iterations; i++) {
-
- // Collect garbage:
- System.gc();
- try {
- Thread.sleep(1000);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
-
- // Find match:
- long startTime = System.currentTimeMillis();
- Match match = engine.findMatches(rule, graph, null).iterator().next();
- long matchingTime = (System.currentTimeMillis() - startTime);
-
- // Apply rule:
- startTime = System.currentTimeMillis();
- application.setCompleteMatch(match);
- if (!application.execute(null)) {
- throw new RuntimeException("Error transforming Sierpinski model");
}
-
- long runtime = (System.currentTimeMillis() - startTime);
-
- // Print info:
- int matches = match.getMultiMatches(rule.getMultiRules().get(0)).size();
- System.out.println((i + 1) + "\t" + matches + "\t" + graph.size() + "\t" + matchingTime + "\t" + runtime
- + "\t" + (matchingTime + runtime));
-
- // Check whether the number of matches and nodes is correct:
- if (matches != expectedMatches) {
- throw new RuntimeException("Expected " + expectedMatches + " matches instead of " + matches);
- }
- expectedMatches *= 3;
- expectedNodes += expectedMatches;
- if (graph.size() != expectedNodes) {
- throw new RuntimeException("Expected " + expectedNodes + " nodes instead of " + graph.size());
- }
-
+ } finally {
+ engine.shutdown();
}
-
}
public static void main(String[] args) {
- int iterations = args.length > 0 ? Integer.parseInt(args[0]) : 10;
+ int iterations = args.length > 0 ? Integer.parseInt(args[0]) : 12;
run(PATH, iterations); // we assume the working directory is the root of the examples plug-in
}

Back to the top