start of new file
[IRC.git] / Robust / src / Benchmarks / Prefetch / Em3d / dsm / BiGraphN.java
1 /** 
2  * A class that represents the irregular bipartite graph used in
3  * EM3D.  The graph contains two linked structures that represent the
4  * E nodes and the N nodes in the application.
5  **/
6 public class BiGraph
7 {
8   public BiGraph() {
9   }
10   /**
11    * Nodes that represent the electrical field.
12    **/
13   Node[] eNodes;
14   /**
15    * Nodes that representhe the magnetic field.
16    **/
17   Node[] hNodes;
18
19   /**
20    * Construct the bipartite graph.
21    * @param e the nodes representing the electric fields
22    * @param h the nodes representing the magnetic fields
23    **/ 
24   BiGraph(Node[] e, Node[] h)
25   {
26       eNodes = e;
27       hNodes = h;
28   }
29
30   /**
31    * Create the bi graph that contains the linked list of
32    * e and h nodes.
33    * @param numNodes the number of nodes to create
34    * @param numDegree the out-degree of each node
35    * @param verbose should we print out runtime messages
36    * @return the bi graph that we've created.
37    **/
38
39   static BiGraph create(int numNodes, int degree, boolean verbose, Random r)
40   {
41     // making nodes (we create a table)
42     //if (verbose) System.printString("making nodes (tables in orig. version)");
43     //Node [] eTable=Node.fillTable(numNodes, numDegree, r);
44     //Node [] hTable=Node.fillTable(numNodes, numDegree, r);
45
46     Node [] eTable = global new Node[numNodes];
47     Node [] hTable = global new Node[numNodes];
48
49     eTable[0] = global new Node(degree, r);
50     hTable[0] = global new Node(degree, r);
51       
52     BiGraph g = global new BiGraph(eTable, hTable);
53
54     return g;
55   }
56
57     
58   /**
59    * 
60    *
61    * @return 
62    **/
63   public void allocate( int indexBegin, int indexEnd, int degree, Random r )
64   { 
65       Node prevNodeE = global new Node(degree, r);
66       Node prevNodeH = global new Node(degree, r);
67
68       eNodes[indexBegin] = prevNodeE;
69       hNodes[indexBegin] = prevNodeH;
70
71       for( int i = indexBegin + 1; i < indexEnd; i++ ) {
72           Node curNodeE = global new Node(degree, r);
73           Node curNodeH = global new Node(degree, r);
74
75           eNodes[i] = curNodeE;
76           hNodes[i] = curNodeH;
77
78           prevNodeE.next = curNodeE;
79           prevNodeH.next = curNodeH;
80
81           prevNodeE = curNodeE;
82           prevNodeH = curNodeH;
83       }
84   }
85
86   
87   public void linkSegments( int index ) {
88       eNodes[index - 1].next = eNodes[index];
89       hNodes[index - 1].next = hNodes[index];
90   }
91
92
93   /**
94    * 
95    *
96    * @return 
97    **/
98   public void makeNeighbors( int indexBegin, int indexEnd, Random r )
99   {
100       //System.printString( "Making unique neighbors for hNodes...\n" );
101
102       // making neighbors
103       //if (verbose) System.printString("updating from and coeffs");
104       for(int i = indexBegin; i < indexEnd; i++) {
105           Node n = hNodes[i];
106           n.makeUniqueNeighbors(eNodes, r);
107       }
108
109       //System.printString( "Making unique neighbors for eNodes...\n" );
110
111       for (int i = indexBegin; i < indexEnd; i++) {
112           Node n = eNodes[i];
113           n.makeUniqueNeighbors(hNodes, r);
114       }
115   }
116
117
118   public void makeFromNodes( int indexBegin, int indexEnd )
119   {
120       //System.printString( "Making h fromNodes...\n" );
121
122       // Create the fromNodes and coeff field
123       //if (verbose) System.printString("filling from fields");
124       for(int i = indexBegin; i < indexEnd; i++) {
125           Node n = hNodes[i];
126           n.makeFromNodes();
127       }
128       
129       //System.printString( "Making e fromNodes...\n" );
130
131       for(int i = indexBegin; i < indexEnd; i++) {
132           Node n = eNodes[i];
133           n.makeFromNodes();
134       }   
135   }
136
137
138   public void makeFromLinks( int indexBegin, int indexEnd, Random r )
139   {
140       //System.printString( "Updating h fromNodes...\n" );
141
142       // Update the fromNodes
143       for(int i = indexBegin; i < indexEnd; i++) {
144           Node n = hNodes[i];
145           n.updateFromNodes(r);
146       }
147
148       //System.printString( "Updating e fromNodes...\n" );
149
150       for(int i = indexBegin; i < indexEnd; i++) {
151           Node n = eNodes[i];
152           n.updateFromNodes(r);
153       }      
154   }
155
156
157   /**
158    * Override the toString method to print out the values of the e and h nodes.
159    * @return a string contain the values of the e and h nodes.
160    **/
161   public String toString()
162   {
163       StringBuffer retval = new StringBuffer();
164       Node tmp = eNodes[0];
165       while(tmp!=null) {
166           Node n = tmp;
167           retval.append("E: " + n + "\n");
168           tmp = tmp.next;
169       }
170       tmp = hNodes[0];
171       while(tmp!=null) {
172           Node n = tmp;
173           retval.append("H: " + n + "\n");
174           tmp = tmp.next;
175       }
176       return retval.toString();
177   }
178
179 }