start of new file
[IRC.git] / Robust / src / Benchmarks / Prefetch / Em3d / java / BiGraph.java
1 import java.util.Random;
2 /** 
3  * A class that represents the irregular bipartite graph used in
4  * EM3D.  The graph contains two linked structures that represent the
5  * E nodes and the N nodes in the application.
6  **/
7 public class BiGraph
8 {
9   public BiGraph() {
10   }
11   /**
12    * Nodes that represent the electrical field.
13    **/
14   Node eNodes;
15   /**
16    * Nodes that representhe the magnetic field.
17    **/
18   Node hNodes;
19
20   /**
21    * Construct the bipartite graph.
22    * @param e the nodes representing the electric fields
23    * @param h the nodes representing the magnetic fields
24    **/ 
25   BiGraph(Node e, Node h)
26   {
27       eNodes = e;
28       hNodes = h;
29   }
30
31   /**
32    * Create the bi graph that contains the linked list of
33    * e and h nodes.
34    * @param numNodes the number of nodes to create
35    * @param numDegree the out-degree of each node
36    * @param verbose should we print out runtime messages
37    * @return the bi graph that we've created.
38    **/
39
40   BiGraph create(int numNodes, int numDegree, boolean verbose, Random r)
41   {
42     // making nodes (we create a table)
43     if (verbose) System.out.println("making nodes (tables in orig. version)");
44     Node[] hTable = Node.fillTable(numNodes, numDegree, r);
45     Node[] eTable = Node.fillTable(numNodes, numDegree, r);
46
47     // making neighbors
48     if (verbose) System.out.println("updating from and coeffs");
49     for(int i = 0; i< numNodes; i++) {
50       Node n = hTable[i];
51       n.makeUniqueNeighbors(eTable, r);
52     }
53
54     for (int i = 0; i < numNodes; i++) {
55       Node n = eTable[i];
56       n.makeUniqueNeighbors(hTable, r);
57     }
58
59     // Create the fromNodes and coeff field
60     if (verbose) System.out.println("filling from fields");
61     for(int i = 0; i< numNodes; i++) {
62       Node n = hTable[i];
63       n.makeFromNodes();
64     }
65
66     for (int i = 0; i < numNodes; i++) {
67       Node n = eTable[i];
68       n.makeFromNodes();
69     }
70
71     // Update the fromNodes
72     for (int i = 0; i < numNodes; i++) {
73       Node n = hTable[i];
74       n.updateFromNodes(r);
75     }
76     for (int i = 0; i < numNodes; i++) {
77       Node n = eTable[i];
78       n.updateFromNodes(r);
79     }
80
81     BiGraph g = new BiGraph(eTable[0], hTable[0]);
82     return g;
83   }
84
85   /** 
86    * Update the field values of e-nodes based on the values of
87    * neighboring h-nodes and vice-versa.
88    **/
89   /*
90   void compute()
91   {
92       Node tmp = eNodes;
93       while(tmp!= null) {
94           Node n = tmp;
95           n.computeNewValue();
96           tmp = tmp.next;
97       }
98       tmp = hNodes;
99       while(tmp!=null) {
100           Node n = tmp;
101           n.computeNewValue();
102           tmp = tmp.next;
103       }
104   }
105   */
106
107   /**
108    * Override the toString method to print out the values of the e and h nodes.
109    * @return a string contain the values of the e and h nodes.
110    **/
111   public String toString()
112   {
113       StringBuffer retval = new StringBuffer();
114       Node tmp = eNodes;
115       while(tmp!=null) {
116           Node n = tmp;
117           retval.append("E: " + n + "\n");
118           tmp = tmp.next;
119       }
120       tmp = hNodes;
121       while(tmp!=null) {
122           Node n = tmp;
123           retval.append("H: " + n + "\n");
124           tmp = tmp.next;
125       }
126       return retval.toString();
127   }
128
129 }
130