Commit 6a4561df authored by uahhx's avatar uahhx

sync, eeep, admins doing stuff

TODO: pseudographics
look into buffer behaviour
parent 2e94ea6a
package FunnelNetSim;
import java.util.ArrayList;
import java.util.HashSet;
import FunnelNetSim.Nodes.*;
......@@ -30,6 +31,7 @@ public class FunnelNet {
public HashSet<NetNode> netNodes = new HashSet<NetNode>();
public HashSet<SlaveNode> slavesNodes = new HashSet<SlaveNode>();
public HashSet<Node> allNodes = new HashSet<Node>();
public ArrayList<ArrayList<Node>> layerNodes= new ArrayList<ArrayList<Node>>();
public static int packetCounter = 0;
......@@ -49,7 +51,6 @@ public class FunnelNet {
createNet();
System.out.println("Number of Layers: " + numLayers);
System.out.println("Number of Slaves: " + numSlaves);
master.listTree();
}
private void createNet() {
......@@ -57,37 +58,50 @@ public class FunnelNet {
master = new MasterNode(layerNumber, 0, this);
master.setSuperNeighbor(null);
HashSet<Node> curLayerNodes = new HashSet<Node>();
ArrayList<Node> curLayerNodes = new ArrayList<Node>();
curLayerNodes.add(master);
layerNodes.add(curLayerNodes);
while(curLayerNodes.size()*numDownConnections < numSlaves || layerNumber < minNetLayers) {
layerNumber++;
curLayerNodes = createNetLayer(numDownConnections, layerNumber, curLayerNodes);
layerNodes.add(curLayerNodes);
}
layerNumber++;
createSlaveLayer(numDownConnections, layerNumber, curLayerNodes);
layerNodes.add(createSlaveLayer(numDownConnections, layerNumber, curLayerNodes));
allNodes = new HashSet<Node>();
allNodes.add(master);
allNodes.addAll(netNodes);
allNodes.addAll(slavesNodes);
}
private ArrayList<Node> initLayerList(int layerNumber) {
int elementCount = (int)Math.pow(numDownConnections, layerNumber);
ArrayList<Node> list = new ArrayList<Node>(elementCount);
for (int i = 0; i < elementCount; i++) {
list.add(null);
}
return list;
}
private HashSet<Node> createNetLayer(int numNewNodes, int layerNumber, HashSet<Node> prevLayerNodes) {
HashSet<Node> nextLayerNodes = new HashSet<Node>();
for(Node curNode : prevLayerNodes) {
private ArrayList<Node> createNetLayer(int numNewNodes, int layerNumber, ArrayList<Node> prevLayerNodes) {
ArrayList<Node> nextLayerNodes = initLayerList(layerNumber);//new ArrayList<Node>(numDownConnections);
for(int i = 0; i < prevLayerNodes.size(); i++) {
Node curNode = prevLayerNodes.get(i);
NetNode[] newNetNodes = new NetNode[numNewNodes];
for (int i = 0; i < newNetNodes.length; i++) {
NetNode curNewNode = new NetNode(layerNumber, curNode.getNodeNumber()*numNewNodes+i, this);
for (int j = 0; j < newNetNodes.length; j++) {
NetNode curNewNode = new NetNode(layerNumber, curNode.getNodeNumber()*numNewNodes+j, this);
curNewNode.setSuperNeighbor(curNode);
newNetNodes[i] = curNewNode;
newNetNodes[j] = curNewNode;
netNodes.add(curNewNode);
nextLayerNodes.add(curNewNode);
//nextLayerNodes.add(curNewNode);
nextLayerNodes.set(curNewNode.getNodeNumber(), curNewNode);
}
curNode.setSubNeighbors(newNetNodes);
}
return nextLayerNodes;// = new HashSet<Node>(); TODO: remove comment when stuff's working
}
private void createSlaveLayer(int numNewNodes, int layerNumber, HashSet<Node> prevLayerNodes) {
private ArrayList<Node> createSlaveLayer(int numNewNodes, int layerNumber, ArrayList<Node> prevLayerNodes) {
numLayers = layerNumber+1;
int numClusters = prevLayerNodes.size();
//int funnelWidth = numClusters*numDownConnections;
......@@ -97,24 +111,27 @@ public class FunnelNet {
int homogeneousReduction = slack/numClusters;
int inhomogeneousReduction = slack%numClusters;
HashSet<Node> nextLayerNodes = new HashSet<Node>();
for(Node curNode : prevLayerNodes) {
ArrayList<Node> nextLayerNodes = initLayerList(layerNumber);//new ArrayList<Node>();
for(int i = 0; i < prevLayerNodes.size(); i++) {
Node curNode = prevLayerNodes.get(i);
//SlaveNode[] newSlaveNodes = new SlaveNode[numNewNodes];
//for (int i = 0; i < newSlaveNodes.length - homogeneousReduction - (inhomogeneousReduction > 0 ? 1 : 0); i++) {
SlaveNode[] newSlaveNodes = new SlaveNode[numNewNodes - homogeneousReduction - (inhomogeneousReduction > 0 ? 1 : 0)];
for (int i = 0; i < newSlaveNodes.length; i++) {
SlaveNode curNewNode = new SlaveNode(layerNumber, curNode.getNodeNumber()*numNewNodes+i, this);
for (int j = 0; j < newSlaveNodes.length; j++) {
SlaveNode curNewNode = new SlaveNode(layerNumber, curNode.getNodeNumber()*numNewNodes+j, this);
curNewNode.setSuperNeighbor(curNode);
curNewNode.setSubNeighbors(new Node[0]);
newSlaveNodes[i] = curNewNode;
newSlaveNodes[j] = curNewNode;
slavesNodes.add(curNewNode);
nextLayerNodes.add(curNewNode);
//nextLayerNodes.add(curNewNode);
nextLayerNodes.set(curNewNode.getNodeNumber(), curNewNode);
}
curNode.setSubNeighbors(newSlaveNodes);
if (inhomogeneousReduction > 0)
inhomogeneousReduction--; //irrelevant after reaching 0, but making counting it down conditional doesn't help performance wise
}
return nextLayerNodes;
}
public int getNumLayers() {
......
......@@ -74,14 +74,14 @@ public abstract class Node {
return subNeighbors;
}
public void listTree() {
Node curNode;
System.out.println("Layer: " + layerNumber + ", Number: " + nodeNumber + ", Node: " + this.toString());
if(subNeighbors != null)
for (int i = 0; i < subNeighbors.length; i++)
subNeighbors[i].listTree();
}
// public void listTree() {
// Node curNode;
// System.out.println("Layer: " + layerNumber + ", Number: " + nodeNumber + ", Node: " + this.toString());
//
// if(subNeighbors != null)
// for (int i = 0; i < subNeighbors.length; i++)
// subNeighbors[i].listTree();
// }
//handle incoming data. call all nodes pretick before tick to keep things "parallel"
public abstract void preTickUpdateLines();
......
......@@ -4,12 +4,23 @@ import FunnelNetSim.Nodes.Node;
import FunnelNetSim.Nodes.SlaveNode;
import FunnelNetSim.Strategies.GlobalTimeStamp;
import FunnelNetSim.Strategies.TestStrategy;
import FunnelNetSim.Visualizers.PseudoGraphics;
import java.io.IOException;
public class SimHost {
public static final boolean verbose = false;//true;
public static final boolean verbose = true;//true;
public static void main(String[] args) {
// for (int i = 0; i < 10; i++) {
// try {
// System.in.read();
// } catch (IOException e) {
// e.printStackTrace();
// }
// System.out.println(i);
// }
run();
}
......@@ -17,6 +28,8 @@ public class SimHost {
//FunnelNet net = new FunnelNet(new TestStrategy());
//FunnelNet net = new FunnelNet(new TestStrategy(), 8, 2, 1);
FunnelNet net = new FunnelNet(new GlobalTimeStamp(), 4, 2, 1);
PseudoGraphics graph = new PseudoGraphics();
graph.draw(net.layerNodes);
int a = 2;
int b = a+1;
int c = b+20;
......
package FunnelNetSim.Visualizers;
import FunnelNetSim.Nodes.Node;
import FunnelNetSim.SimHost;
import java.util.ArrayList;
public class PseudoGraphics {
public void draw(ArrayList<ArrayList<Node>> layerList) {
for (int i = 0; i < layerList.size(); i++) {
ArrayList<Node> currentLayer = layerList.get(i);
for (int j = 0; j < currentLayer.size(); j++) {
Node currentNode = currentLayer.get(i);
if (currentNode != null) {
}
else if (SimHost.verbose)
System.out.println("Layer " + i + ", Node " + j + " is null.");
}
}
}
}
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