[Swift-commit] r5964 - in trunk: resources src/org/griphyn/vdl/engine

hategan at ci.uchicago.edu hategan at ci.uchicago.edu
Sun Oct 14 22:35:17 CDT 2012


Author: hategan
Date: 2012-10-14 22:35:17 -0500 (Sun, 14 Oct 2012)
New Revision: 5964

Modified:
   trunk/resources/Karajan.stg
   trunk/src/org/griphyn/vdl/engine/Karajan.java
Log:
use unbuffered parallel for statements and also drop parallel for call arguments if parameters are passed as variables only

Modified: trunk/resources/Karajan.stg
===================================================================
--- trunk/resources/Karajan.stg	2012-10-10 14:47:34 UTC (rev 5963)
+++ trunk/resources/Karajan.stg	2012-10-15 03:35:17 UTC (rev 5964)
@@ -189,11 +189,13 @@
       </entry>
 >>
 
+// use unbuffered parallel here
+// since calls don't use this macro
 parallel(statements) ::= <<
 $if(rest(statements))$
-<parallel>
+<uparallel>
   $statements;separator="\n"$
-</parallel>
+</uparallel>
 $else$
 <sequentialWithID>
   $statements$
@@ -201,6 +203,7 @@
 $endif$
 >>
 
+
 // the 'function' template outputs a karajan code fragment
 // that calls a function in the 'swiftscript' namespace.
 
@@ -252,15 +255,15 @@
 // they are not
 // $outputs:vdl_log_output();separator="\n"$
 
-callInternal(func, outputs, inputs, line) ::= <<
+callInternal(func, outputs, inputs, line, serialize) ::= <<
 <sequential>
 <unitStart name="$func$" type="INTERNALPROC" outputs="$outputs:list();separator=","$"/>
 $cs()$
 <$func$ _traceline="$line$">
-  <parallel>
+  $if(!serialize)$<parallel>$endif$
     $outputs:callInternal_log_output();separator="\n"$
     $inputs:callInternal_log_input();separator="\n"$
-  </parallel>
+  $if(!serialize)$</parallel>$endif$
 </$func$>
 <unitEnd name="$func$" type="INTERNALPROC"/>
 </sequential>
@@ -292,12 +295,12 @@
 </sequential>
 >>
 
-callUserDefined(func, outputs, inputs, line) ::= <<
+callUserDefined(func, outputs, inputs, line, serialize) ::= <<
 <$func$ _traceline="$line$">
-  <parallel>
+  $if(!serialize)$<parallel>$endif$
     $outputs;separator="\n"$
     $inputs;separator="\n"$
-  </parallel>
+  $if(!serialize)$</parallel>$endif$
 </$func$>
 >>
 

Modified: trunk/src/org/griphyn/vdl/engine/Karajan.java
===================================================================
--- trunk/src/org/griphyn/vdl/engine/Karajan.java	2012-10-10 14:47:34 UTC (rev 5963)
+++ trunk/src/org/griphyn/vdl/engine/Karajan.java	2012-10-15 03:35:17 UTC (rev 5964)
@@ -721,7 +721,7 @@
 				if (proc.getInputArray(i).isOptional())
 					noOfOptInArgs++;
 				inArgs.put(proc.getInputArray(i).getName(), proc.getInputArray(i));
-			}				
+			}
 			if (!proc.getAnyNumOfInputArgs() && (call.sizeOfInputArray() < proc.sizeOfInputArray() - noOfOptInArgs ||
 
 				                                 call.sizeOfInputArray() > proc.sizeOfInputArray()))
@@ -861,12 +861,40 @@
 			if (!inhibitOutput) {
 			    scope.appendStatement(callST);
 			}
+			if (allVariables(callST.getAttribute("outputs")) && allVariables(callST.getAttribute("inputs"))) {
+			    callST.setAttribute("serialize", Boolean.TRUE);
+			}
 			return callST;
 		} catch(CompilationException ce) {
 			throw new CompilationException("Compile error in procedure invocation at "+call.getSrc()+": "+ce.getMessage(),ce);
 		}
 	}
 
+	private static final Set<String> VAR_TYPES;
+	
+	static {
+	    VAR_TYPES = new HashSet<String>();
+	    VAR_TYPES.add("id");
+	    VAR_TYPES.add("extractarrayelement");
+	    VAR_TYPES.add("slicearray");
+	    VAR_TYPES.add("extractstructureelement");
+	}
+	
+    private boolean allVariables(Object list) {
+        @SuppressWarnings("unchecked")
+        List<StringTemplate> l = (List<StringTemplate>) list;
+        for (StringTemplate pst : l) {
+            if (!pst.getName().equals("call_arg")) {
+                return false;
+            }
+            StringTemplate expr = (StringTemplate) pst.getAttribute("expr");
+            if (!VAR_TYPES.contains(expr.getName())) {
+                return false;
+            }
+        }
+        return true;
+    }
+
     private void addWriterToScope(VariableScope scope, XmlObject var) throws CompilationException {
         String rootvar = abstractExpressionToRootVariable(var);
         boolean partial = rootVariableIsPartial(var);




More information about the Swift-commit mailing list