[Swift-commit] r6326 - in branches/release-0.94: resources src/org/griphyn/vdl/engine src/org/griphyn/vdl/karajan/lib

hategan at ci.uchicago.edu hategan at ci.uchicago.edu
Sun Mar 3 01:06:00 CST 2013


Author: hategan
Date: 2013-03-03 01:06:00 -0600 (Sun, 03 Mar 2013)
New Revision: 6326

Added:
   branches/release-0.94/src/org/griphyn/vdl/karajan/lib/RefCount.java
   branches/release-0.94/src/org/griphyn/vdl/karajan/lib/StaticRefCount.java
Modified:
   branches/release-0.94/resources/Karajan.stg
   branches/release-0.94/src/org/griphyn/vdl/engine/Karajan.java
   branches/release-0.94/src/org/griphyn/vdl/karajan/lib/InfiniteCountingWhile.java
   branches/release-0.94/src/org/griphyn/vdl/karajan/lib/ThrottledParallelFor.java
Log:
fixed array writing in iterate bug reported by Yadu (see http://lists.ci.uchicago.edu/pipermail/swift-devel/2013-March/010100.html)

Modified: branches/release-0.94/resources/Karajan.stg
===================================================================
--- branches/release-0.94/resources/Karajan.stg	2013-03-03 00:21:48 UTC (rev 6325)
+++ branches/release-0.94/resources/Karajan.stg	2013-03-03 07:06:00 UTC (rev 6326)
@@ -219,9 +219,8 @@
 </swiftscript:$name$>
 >>
 
-iterate(declarations,statements,cond,var,cleanups,trace,line) ::= <<
-
-<vdl:infinitecountingwhile var="$var$" $if(trace)$ _traceline="$line$"$endif$>
+iterate(declarations, statements, cond, var, refs, cleanups, trace, line) ::= <<
+<vdl:infinitecountingwhile var="$var$" $if(trace)$ _traceline="$line$"$endif$$if(refs)$ refs="$refs;separator=" "$"$endif$>
   $sub_comp(declarations=declarations, statements=statements, cleanups=cleanups)$
   <sys:if>
     <vdl:getfieldvalue>$cond$</vdl:getfieldvalue>

Modified: branches/release-0.94/src/org/griphyn/vdl/engine/Karajan.java
===================================================================
--- branches/release-0.94/src/org/griphyn/vdl/engine/Karajan.java	2013-03-03 00:21:48 UTC (rev 6325)
+++ branches/release-0.94/src/org/griphyn/vdl/engine/Karajan.java	2013-03-03 07:06:00 UTC (rev 6326)
@@ -908,7 +908,7 @@
     }
 
     public void iterateStat(Iterate iterate, VariableScope scope) throws CompilationException {
-		VariableScope loopScope = new VariableScope(this, scope, EnclosureType.LOOP, iterate);
+		VariableScope loopScope = new VariableScope(this, scope, EnclosureType.ALL, iterate);
 		VariableScope innerScope = new VariableScope(this, loopScope, EnclosureType.LOOP, iterate);
 
 		loopScope.addVariable(iterate.getVar(), "int", "Iteration variable", iterate);
@@ -1531,8 +1531,6 @@
 		        throw new CompilationException("Procedure " + name + " must have exactly one " +
 		        		"return value to be used in an expression.");
 		    }
-		    
-		    Warnings.warn(c, "Procedure " + name + " is deprecated");
 
 		    StringTemplate call = template("callexpr");
 

Modified: branches/release-0.94/src/org/griphyn/vdl/karajan/lib/InfiniteCountingWhile.java
===================================================================
--- branches/release-0.94/src/org/griphyn/vdl/karajan/lib/InfiniteCountingWhile.java	2013-03-03 00:21:48 UTC (rev 6325)
+++ branches/release-0.94/src/org/griphyn/vdl/karajan/lib/InfiniteCountingWhile.java	2013-03-03 07:06:00 UTC (rev 6326)
@@ -34,8 +34,10 @@
     
     public static final String COUNTER_NAME = "$";
     public static final Arg.Positional VAR = new Arg.Positional("var");
+    public static final Arg O_REFS = new Arg.Optional("refs", null);
     
     private Tracer tracer;
+    private List<StaticRefCount> srefs;
 
 	public InfiniteCountingWhile() {
 		setOptimize(false);
@@ -45,18 +47,21 @@
     protected void initializeStatic() {
         super.initializeStatic();
         tracer = Tracer.getTracer(this);
+        srefs = StaticRefCount.build((String) O_REFS.getStatic(this));
     }
 
     public void pre(VariableStack stack) throws ExecutionException {
 		ThreadingContext tc = (ThreadingContext)stack.getVar("#thread");
 		stack.setVar("#iteratethread", tc);
 		stack.setVar("#thread", tc.split(0));
+		stack.setVar("#refs", RefCount.build(srefs, stack));
 		stack.setVar(COUNTER_NAME, Collections.singletonList(0));
 		String var = (String) VAR.getStatic(this);
 		if (tracer.isEnabled()) {
 		    tracer.trace(tc.toString(), var + " = 0");
 		}
 		stack.setVar(var, new RootDataNode(Types.INT, 0));
+		incRefs(stack);
 		super.pre(stack);
 	}
 
@@ -89,6 +94,7 @@
                 tracer.trace(ntc.toString(), var + " = " + i);
             }
             stack.setVar(var, new RootDataNode(Types.INT, i));
+            incRefs(stack);
 		}
 		if (index >= elementCount()) {
 			// starting new iteration
@@ -102,6 +108,16 @@
 		startElement(fn, stack);
 	}
 	
+    private void incRefs(VariableStack stack) {
+        @SuppressWarnings("unchecked")
+        List<RefCount> rcs = (List<RefCount>) stack.currentFrame().getVar("#refs");
+        if (rcs != null) {
+            for (RefCount rc : rcs) {
+                rc.var.updateWriteRefCount(rc.count);
+            }
+        }
+    }
+
     public void failed(VariableStack stack, ExecutionException e)
             throws ExecutionException {
         if (e instanceof While.Break) {

Added: branches/release-0.94/src/org/griphyn/vdl/karajan/lib/RefCount.java
===================================================================
--- branches/release-0.94/src/org/griphyn/vdl/karajan/lib/RefCount.java	                        (rev 0)
+++ branches/release-0.94/src/org/griphyn/vdl/karajan/lib/RefCount.java	2013-03-03 07:06:00 UTC (rev 6326)
@@ -0,0 +1,38 @@
+//----------------------------------------------------------------------
+//This code is developed as part of the Java CoG Kit project
+//The terms of the license can be found at http://www.cogkit.org/license
+//This message may not be removed or altered.
+//----------------------------------------------------------------------
+
+/*
+ * Created on Mar 2, 2013
+ */
+package org.griphyn.vdl.karajan.lib;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.globus.cog.karajan.stack.VariableNotFoundException;
+import org.globus.cog.karajan.stack.VariableStack;
+import org.griphyn.vdl.mapping.DSHandle;
+
+public class RefCount {
+    public final DSHandle var;
+    public final int count;
+    
+    public RefCount(DSHandle var, int count) {
+        this.var = var;
+        this.count = count;
+    }
+    
+    public static List<RefCount> build(List<StaticRefCount> srefs, VariableStack stack) throws VariableNotFoundException {
+        if (srefs == null) {
+            return null;
+        }
+        List<RefCount> l = new ArrayList<RefCount>(srefs.size());
+        for (StaticRefCount s : srefs) {
+            l.add(new RefCount((DSHandle) stack.getVar(s.name), s.count));
+        }
+        return l;
+    }
+}
\ No newline at end of file

Added: branches/release-0.94/src/org/griphyn/vdl/karajan/lib/StaticRefCount.java
===================================================================
--- branches/release-0.94/src/org/griphyn/vdl/karajan/lib/StaticRefCount.java	                        (rev 0)
+++ branches/release-0.94/src/org/griphyn/vdl/karajan/lib/StaticRefCount.java	2013-03-03 07:06:00 UTC (rev 6326)
@@ -0,0 +1,45 @@
+//----------------------------------------------------------------------
+//This code is developed as part of the Java CoG Kit project
+//The terms of the license can be found at http://www.cogkit.org/license
+//This message may not be removed or altered.
+//----------------------------------------------------------------------
+
+/*
+ * Created on Mar 2, 2013
+ */
+package org.griphyn.vdl.karajan.lib;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.StringTokenizer;
+
+public class StaticRefCount {
+    public final String name;
+    public final int count;
+    
+    public StaticRefCount(String name, int count) {
+        this.name = name;
+        this.count = count;
+    }
+    
+    public static List<StaticRefCount> build(String refs) {
+        if (refs == null) {
+            return null;
+        }
+        List<StaticRefCount> l = new ArrayList<StaticRefCount>();
+        String name = null;
+        boolean flip = true;
+        StringTokenizer st = new StringTokenizer(refs);
+        while (st.hasMoreTokens()) {
+            if (flip) {
+                name = st.nextToken();
+            }
+            else {
+                int count = Integer.parseInt(st.nextToken());
+                l.add(new StaticRefCount(name.toLowerCase(), count));
+            }
+            flip = !flip;
+        }
+        return l;
+    }
+}
\ No newline at end of file

Modified: branches/release-0.94/src/org/griphyn/vdl/karajan/lib/ThrottledParallelFor.java
===================================================================
--- branches/release-0.94/src/org/griphyn/vdl/karajan/lib/ThrottledParallelFor.java	2013-03-03 00:21:48 UTC (rev 6325)
+++ branches/release-0.94/src/org/griphyn/vdl/karajan/lib/ThrottledParallelFor.java	2013-03-03 07:06:00 UTC (rev 6326)
@@ -21,7 +21,6 @@
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
-import java.util.StringTokenizer;
 
 import org.apache.log4j.Logger;
 import org.globus.cog.karajan.arguments.Arg;
@@ -40,7 +39,6 @@
 import org.globus.cog.karajan.workflow.futures.ListenerStackPair;
 import org.globus.cog.karajan.workflow.nodes.AbstractParallelIterator;
 import org.griphyn.vdl.karajan.Pair;
-import org.griphyn.vdl.mapping.DSHandle;
 import org.griphyn.vdl.util.VDL2Config;
 
 public class ThrottledParallelFor extends AbstractParallelIterator {
@@ -64,77 +62,16 @@
 	private String kvar, vvar;
 	private List<StaticRefCount> srefs;
 	
-	private static class StaticRefCount {
-	    public final String name;
-        public final int count;
-        
-        public StaticRefCount(String name, int count) {
-            this.name = name;
-            this.count = count;
-        }
-	}
-	
-	private static class RefCount {
-	    public final DSHandle var;
-	    public final int count;
-	    
-	    public RefCount(DSHandle var, int count) {
-	        this.var = var;
-	        this.count = count;
-	    }
-	    
-	    public void inc() {
-	        
-	    }
-	    
-	    public void dec() {
-	        
-	    }
-	}
-	
-    @Override
+	@Override
     protected void initializeStatic() {
         super.initializeStatic();
         forTracer = Tracer.getTracer(this, "FOREACH");
         iterationTracer = Tracer.getTracer(this, "ITERATION");
         kvar = (String) getProperty("_kvar");
         vvar = (String) getProperty("_vvar");
-        srefs = buildStaticRefs();
+        srefs = StaticRefCount.build((String) O_REFS.getStatic(this));
     }
 
-    private List<StaticRefCount> buildStaticRefs() {
-        String refs = (String) O_REFS.getStatic(this);
-        if (refs == null) {
-            return null;
-        }
-        List<StaticRefCount> l = new ArrayList<StaticRefCount>();
-        String name = null;
-        boolean flip = true;
-        StringTokenizer st = new StringTokenizer(refs);
-        while (st.hasMoreTokens()) {
-            if (flip) {
-                name = st.nextToken();
-            }
-            else {
-                int count = Integer.parseInt(st.nextToken());
-                l.add(new StaticRefCount(name.toLowerCase(), count));
-            }
-            flip = !flip;
-        }
-        return l;
-    }
-
-    private List<RefCount> buildRefs(VariableStack stack) throws VariableNotFoundException {
-        if (srefs == null) {
-            return null;
-        }
-        List<RefCount> l = new ArrayList<RefCount>(srefs.size());
-        for (StaticRefCount s : srefs) {
-            l.add(new RefCount((DSHandle) stack.getVar(s.name), s.count));
-        }
-        return l;
-    }
-
     protected void partialArgumentsEvaluated(VariableStack stack)
             throws ExecutionException {
         if (forTracer.isEnabled()) {
@@ -313,7 +250,7 @@
 				maxThreadCount = DEFAULT_MAX_THREADS;
 			}
 		}
-		stack.setVar(THREAD_COUNT, new ThreadCount(maxThreadCount, selfClose, i, buildRefs(stack)));
+		stack.setVar(THREAD_COUNT, new ThreadCount(maxThreadCount, selfClose, i, RefCount.build(srefs, stack)));
 	}
 
 	private ThreadCount getThreadCount(VariableStack stack)




More information about the Swift-commit mailing list