start of new file
[IRC.git] / Robust / src / Benchmarks / Prefetch / Em3d / dsm / BiGraph2.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     public BiGraph() {
8     }
9     /**
10      * Nodes that represent the electrical field.
11      **/
12     Node[] eNodes;
13     /**
14      * Nodes that representhe the magnetic field.
15      **/
16     Node[] hNodes;
17     
18     EVector [][] reversetable;
19     int numNodes;
20
21     /**
22      * Construct the bipartite graph.
23      * @param e the nodes representing the electric fields
24      * @param h the nodes representing the magnetic fields
25      **/ 
26     BiGraph(Node[] e, Node[] h) {
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     static BiGraph create(int numNodes, int degree, int numThreads) {
41         // making nodes (we create a table)
42         Node [] eTable = global new Node[numNodes];
43         Node [] hTable = global new Node[numNodes];
44         BiGraph g = global new BiGraph(eTable, hTable);
45         g.numNodes=numNodes;
46         g.reversetable=global new EVector[numThreads][];
47         return g;
48     }
49     
50     
51     /**
52      * 
53      *
54      * @return 
55      **/
56     public void allocateNodes( int indexBegin, int indexEnd, int threadIndex) { 
57         for(int i = indexBegin; i < indexEnd; i++ ) {
58             eNodes[i]=global new Node();
59             hNodes[i]=global new Node();
60         }
61         reversetable[threadIndex]=global new EVector[numNodes];
62     }
63     
64     public void initializeNodes(Node[] fromnodes, Node[] tonodes, int begin, int end, int degree, Random r, int threadIndex) {
65         for(int i = begin; i < end; i++ ) {
66             Node n=fromnodes[i];
67             n.init(degree, r.nextDouble());
68             n.makeUniqueNeighbors(reversetable[threadIndex], tonodes, r, begin, end);
69         }
70     }
71     
72     /**
73      * 
74      *
75      * @return 
76      **/
77     
78     public void makeFromNodes(Node[] nodes, int indexBegin, int indexEnd, Random r) {
79         // Create the fromNodes and coeff field
80         int numthreads=reversetable.length;
81         for(int i = indexBegin; i < indexEnd; i++) {
82             Node n = nodes[i];
83             int count=0;
84             for(int j=0;j<numthreads;j++) {
85                 EVector v=reversetable[j][i];
86                 if(v!=null)
87                     count+=v.size();
88             }
89             n.fromCount=count;
90             n.fromNodes=global new Node[count];
91             n.coeffs=global new double[count];
92             count=0;
93             for(int j=0;j<numthreads;j++) {
94                 EVector v=reversetable[j][i];
95                 if(v!=null) {
96                     for(int k=0;k<v.size();k++) {
97                         n.fromNodes[count]=(Node)v.elementAt(k);
98                         n.coeffs[count++]=r.nextDouble();
99                     }
100                 }
101             }
102         }
103     }
104 }