From e79d44ab41bd3e0775097c87ca4d57550457468b Mon Sep 17 00:00:00 2001 From: megacz Date: Sat, 14 Mar 2009 18:25:10 -0700 Subject: [PATCH] more cleanup --- src/edu/berkeley/fleet/dataflow/DataFlowGraph.java | 8 ++--- src/edu/berkeley/fleet/dataflow/ForeverNode.java | 2 +- src/edu/berkeley/fleet/dataflow/MemoryNode.java | 10 +++--- src/edu/berkeley/fleet/dataflow/MergeSort.java | 4 +-- src/edu/berkeley/fleet/dataflow/Node.java | 32 +++++++++++--------- src/edu/berkeley/fleet/dataflow/OnceNode.java | 2 +- 6 files changed, 30 insertions(+), 28 deletions(-) diff --git a/src/edu/berkeley/fleet/dataflow/DataFlowGraph.java b/src/edu/berkeley/fleet/dataflow/DataFlowGraph.java index 1510a7b..7131e87 100644 --- a/src/edu/berkeley/fleet/dataflow/DataFlowGraph.java +++ b/src/edu/berkeley/fleet/dataflow/DataFlowGraph.java @@ -27,7 +27,6 @@ public class DataFlowGraph { public final ShipPool pool; private HashSet nodes = new HashSet(); - public static int reset_count = 0; public static HashSet torpedoes = new HashSet(); public DataFlowGraph(Fleet fleet) { @@ -44,11 +43,12 @@ public class DataFlowGraph { for(Node mod : nodes) mod.build(ctx); } - public void reset(Context ctx, int phase, Destination ackDestination) { - reset_count = 0; + public int reset(Context ctx, int phase, Destination ackDestination) { + int ret = 0; torpedoes.clear(); for(Node mod : nodes) - mod.reset(ctx, phase, ackDestination); + ret += mod.reset(ctx, phase, ackDestination); + return ret; } } diff --git a/src/edu/berkeley/fleet/dataflow/ForeverNode.java b/src/edu/berkeley/fleet/dataflow/ForeverNode.java index 3119f39..6f66ad0 100644 --- a/src/edu/berkeley/fleet/dataflow/ForeverNode.java +++ b/src/edu/berkeley/fleet/dataflow/ForeverNode.java @@ -14,7 +14,7 @@ public class ForeverNode extends Node { public void sendToken(LoopFactory lf) { } public void recvWord(LoopFactory lf) { } public void build(Context ctx) { } - public void reset(Context ctx, int phase, Destination ackDestination) { } + public int reset(Context ctx, int phase, Destination ackDestination) { return 0; } public void setPeer(InPort peer) { this.peer = peer; DockInPort pip = ((DockInPort)peer); diff --git a/src/edu/berkeley/fleet/dataflow/MemoryNode.java b/src/edu/berkeley/fleet/dataflow/MemoryNode.java index e606803..cac6391 100644 --- a/src/edu/berkeley/fleet/dataflow/MemoryNode.java +++ b/src/edu/berkeley/fleet/dataflow/MemoryNode.java @@ -28,8 +28,8 @@ public class MemoryNode extends Node { public void sendWord(LoopFactory lf) { lf.sendWord(ship.getDock("inAddrRead").getDataDestination(), new BitVector(1).set(0)); } public void build(Context ctx) { } public int getTokensToAbsorb() { return outRead1.peer.getTokensToAbsorb(); } - public void reset(Context ctx, int phase, Destination ackDestination) { - doReset(ctx, phase, ship.getDock("inAddrRead"), null, ackDestination, false); + public int reset(Context ctx, int phase, Destination ackDestination) { + return doReset(ctx, phase, ship.getDock("inAddrRead"), null, ackDestination, false); } }; this.inAddrRead2 = new InPort("inAddrRead2") { @@ -37,19 +37,19 @@ public class MemoryNode extends Node { public void sendWord(LoopFactory lf) { lf.sendWord(ship.getDock("inAddrRead").getDataDestination(), new BitVector(1).set(1)); } public void build(Context ctx) { } public int getTokensToAbsorb() { return outRead2.peer.getTokensToAbsorb(); } - public void reset(Context ctx, int phase, Destination ackDestination) { } + public int reset(Context ctx, int phase, Destination ackDestination) { return 0; } }; this.outRead1 = new OutPort("outRead1") { public void sendToken(LoopFactory lf) { inAddrRead1.peer.sendToken(lf); } public void recvWord(LoopFactory lf) { lf.recvWord(); } public void build(Context ctx) { } - public void reset(Context ctx, int phase, Destination ackDestination) { } + public int reset(Context ctx, int phase, Destination ackDestination) { return 0; } }; this.outRead2 = new OutPort("outRead2") { public void sendToken(LoopFactory lf) { inAddrRead2.peer.sendToken(lf); } public void recvWord(LoopFactory lf) { lf.recvWord(); } public void build(Context ctx) { } - public void reset(Context ctx, int phase, Destination ackDestination) { } + public int reset(Context ctx, int phase, Destination ackDestination) { return 0; } }; this.outWrite = new DockOutPort("out", ship.getDock("out")) { protected void build(Context ctx, LoopFactory lf) { diff --git a/src/edu/berkeley/fleet/dataflow/MergeSort.java b/src/edu/berkeley/fleet/dataflow/MergeSort.java index 36cd08f..e39e1b7 100644 --- a/src/edu/berkeley/fleet/dataflow/MergeSort.java +++ b/src/edu/berkeley/fleet/dataflow/MergeSort.java @@ -114,7 +114,7 @@ public class MergeSort { ctx2 = new Context(fp.getFleet()); Destination ackDestination = counter.getDock("in2").getDataDestination(); - proc.reset(ctx2, phase, ackDestination); + int expected_tokens = proc.reset(ctx2, phase, ackDestination); Context ctx3 = new Context(fp.getFleet()); lf = new LoopFactory(ctx3, counter.getDock("inOp"), 1); @@ -123,7 +123,7 @@ public class MergeSort { lf.literal(5); lf.deliver(); lf = new LoopFactory(ctx3, counter.getDock("in1"), 1); - lf.literal(DataFlowGraph.reset_count-1); + lf.literal(expected_tokens-1); lf.deliver(); lf.literal(1); lf.deliver(); diff --git a/src/edu/berkeley/fleet/dataflow/Node.java b/src/edu/berkeley/fleet/dataflow/Node.java index 5684e84..383121e 100644 --- a/src/edu/berkeley/fleet/dataflow/Node.java +++ b/src/edu/berkeley/fleet/dataflow/Node.java @@ -14,8 +14,9 @@ import static edu.berkeley.fleet.util.BitManipulations.*; public class Node { - void doReset(Context ctx, int phase, Dock dock, Port peer, Destination ackDestination, boolean peerUsed) { - if (dock.getShip().getType().equals("Debug")) return; + int doReset(Context ctx, int phase, Dock dock, Port peer, Destination ackDestination, boolean peerUsed) { + int ret = 0; + if (dock.getShip().getType().equals("Debug")) return ret; switch(phase) { @@ -34,7 +35,7 @@ public class Node { lf = lf.makeNext(0); lf.abortLoopIfTorpedoPresent(); lf.collectWord(); - DataFlowGraph.reset_count++; + ret++; } break; } @@ -56,7 +57,7 @@ public class Node { ((OutPort)peer).recvWord(lf); ((OutPort)peer).sendToken(lf); } - DataFlowGraph.reset_count++; + ret++; } break; } @@ -70,7 +71,7 @@ public class Node { for(int i=0; i<((InPort)peer).getTokensToAbsorb(); i++) lf.recvToken(); lf.sendToken(ackDestination); - DataFlowGraph.reset_count++; + ret++; } break; } @@ -83,13 +84,12 @@ public class Node { } LoopFactory lf = new LoopFactory(ctx, dock, 1); lf.sendToken(ackDestination); - DataFlowGraph.reset_count++; + ret++; } break; } - - } + return ret; } public final DataFlowGraph dfg; @@ -104,8 +104,10 @@ public class Node { public OutPort getOutPort(String name) { return (OutPort)ports.get(name); } public void build(Context ctx) { for(Port p : ports.values()) p.build(ctx); } - public void reset(Context ctx, int phase, Destination ackDestination) { - for(Port p : ports.values()) p.reset(ctx, phase, ackDestination); + public int reset(Context ctx, int phase, Destination ackDestination) { + int ret = 0; + for(Port p : ports.values()) ret += p.reset(ctx, phase, ackDestination); + return ret; } public abstract class Port { @@ -116,7 +118,7 @@ public class Node { Node.this.ports.put(name,this); } public abstract void build(Context ctx); - public abstract void reset(Context ctx, int phase, Destination ackDestination); + public abstract int reset(Context ctx, int phase, Destination ackDestination); } public abstract class InPort extends Port { @@ -181,8 +183,8 @@ public class Node { for(int i=0; i