2 * This class implements nodes (both E- and H-nodes) of the EM graph. Sets
3 * up random neighbors and propagates field values among neighbors.
7 * The value of the node.
11 * Array of nodes to which we send our value.
15 * Array of nodes from which we receive values.
19 * Coefficients on the fromNodes edges
23 * The number of fromNodes edges
27 * Used to create the fromEdges - keeps track of the number of edges that have
33 * Constructor for a node with given `degree'. The value of the
34 * node is initialized to a random value.
39 public void init(int degree, double val) {
41 // create empty array for holding toNodes
42 toNodes = global new Node[degree];
46 * Create unique `degree' neighbors from the nodes given in nodeTable.
47 * We do this by selecting a random node from the give nodeTable to
48 * be neighbor. If this neighbor has been previously selected, then
49 * a different random neighbor is chosen.
50 * @param nodeTable the list of nodes to choose from.
52 public void makeUniqueNeighbors(EVector[] reversetable,Node[] nodeTable, Random rand, int begin, int end) {
53 for (int filled = 0; filled < toNodes.length; filled++) {
58 boolean isBreak = false;
59 // generate a random number in the correct range
60 index = rand.nextInt();
61 if (index < 0) index = -index;
62 //local vs remote from em3d benchmark
63 if ((rand.nextInt()%4)==0)
64 index=index%nodeTable.length;
66 index=begin+(index%(end-begin));
68 // find a node with the random index in the given table
69 otherNode = nodeTable[index];
71 for (k = 0; (k < filled) && (isBreak==false); k++) {
72 if (otherNode == toNodes[k])
77 // other node is definitely unique among "filled" toNodes
78 toNodes[filled] = otherNode;
80 // update fromCount for the other node
81 if (reversetable[index]==null)
82 reversetable[index]=global new EVector();
83 reversetable[index].addElement(this);
88 * Allocate the right number of FromNodes for this node. This
89 * step can only happen once we know the right number of from nodes
90 * to allocate. Can be done after unique neighbors are created and known.
92 * It also initializes random coefficients on the edges.
95 public void makeFromNodes() {
96 fromNodes = global new Node[fromCount]; // nodes fill be filled in later
97 coeffs = global new double[fromCount];
101 * Fill in the fromNode field in "other" nodes which are pointed to
104 public void updateFromNodes(Random rand) {
105 for (int i = 0; i < toNodes.length; i++) {
106 Node otherNode = toNodes[i];
107 int count = otherNode.fromLength++;
108 otherNode.fromNodes[count] = this;
109 otherNode.coeffs[count] = rand.nextDouble();
114 * Override the toString method to return the value of the node.
115 * @return the value of the node.
117 public String toString() {
119 returnString = "value " + (long)value + ", from_count " + fromCount;