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 int len=toNodes.length;
54 for (int filled = 0; filled < len; filled++) {
59 boolean isBreak = false;
60 // generate a random number in the correct range
61 index = rand.nextInt();
62 if (index < 0) index = -index;
63 //local vs remote from em3d benchmark
65 index=index%nodeTable.length;
67 index=begin+(index%(end-begin));
69 // find a node with the random index in the given table
70 otherNode = nodeTable[index];
72 for (k = 0; (k < filled) && (isBreak==false); k++) {
73 if (otherNode == toNodes[k])
78 // other node is definitely unique among "filled" toNodes
79 toNodes[filled] = otherNode;
81 // update fromCount for the other node
82 if (reversetable[index]==null)
83 reversetable[index]=global new EVector();
84 reversetable[index].addElement(this);
89 * Allocate the right number of FromNodes for this node. This
90 * step can only happen once we know the right number of from nodes
91 * to allocate. Can be done after unique neighbors are created and known.
93 * It also initializes random coefficients on the edges.
96 public void makeFromNodes() {
97 fromNodes = global new Node[fromCount]; // nodes fill be filled in later
98 coeffs = global new double[fromCount];
102 * Fill in the fromNode field in "other" nodes which are pointed to
105 public void updateFromNodes(Random rand) {
106 for (int i = 0; i < toNodes.length; i++) {
107 Node otherNode = toNodes[i];
108 int count = otherNode.fromLength++;
109 otherNode.fromNodes[count] = this;
110 otherNode.coeffs[count] = rand.nextDouble();
115 * Override the toString method to return the value of the node.
116 * @return the value of the node.
118 public String toString() {
120 returnString = "value " + (long)value + ", from_count " + fromCount;