changes to bigraph....Alokika's are included in this commit
authorbdemsky <bdemsky>
Tue, 15 Apr 2008 16:59:47 +0000 (16:59 +0000)
committerbdemsky <bdemsky>
Tue, 15 Apr 2008 16:59:47 +0000 (16:59 +0000)
Robust/src/Benchmarks/Prefetch/Em3d/dsm/BiGraph.java
Robust/src/Benchmarks/Prefetch/Em3d/dsm/Em3d.java
Robust/src/Benchmarks/Prefetch/Em3d/dsm/Node.java

index f577de74bb7a86b14fe35efbcc01f1d9ed6beeeb..81ff95c0987ff56691e5f4cfe5316d134266ac60 100644 (file)
@@ -36,7 +36,7 @@ public class BiGraph
    * @return the bi graph that we've created.
    **/
 
-  BiGraph create(int numNodes, int numDegree, boolean verbose, Random r)
+  static BiGraph create(int numNodes, int numDegree, boolean verbose, Random r)
   {
 
     // making nodes (we create a table)
index 644a283dd7e33296fc3eb64f2f570ea39ea691e9..2e2f363d253f0c369c8712ffde7069a9b93fd0a1 100644 (file)
@@ -114,11 +114,13 @@ public class Em3d extends Thread
    **/
   public static void main(String args[])
   {
-    Em3d em;
+    Em3d em = new Em3d();
+    Em3d.parseCmdLine(args, em);
+    /*
     atomic {
        em = global new Em3d();
-    }
     Em3d.parseCmdLine(args, em);
+    }
     
     boolean printMsgs, printResult;
     int numIter;
@@ -127,10 +129,11 @@ public class Em3d extends Thread
       numIter = em.numIter;
       printResult = em.printResult;
     }
-    if (printMsgs) 
+    */
+    if (em.printMsgs) 
       System.printString("Initializing em3d random graph...");
     long start0 = System.currentTimeMillis();
-    int numThreads = 2;
+    int numThreads = 1;
     System.printString("DEBUG -> numThreads = " + numThreads);
     Barrier mybarr;
     atomic {
@@ -138,21 +141,21 @@ public class Em3d extends Thread
     }
     BiGraph graph;
     BiGraph graph1;
-    Random rand;
+    Random rand = new Random(783);
+   // atomic {
+      //rand = global new Random(783);
+    //}
     atomic {
-      rand = global new Random(783);
-    }
-    atomic {
-      graph1 = global new BiGraph();
+      //graph1 = global new BiGraph();
       graph = global new BiGraph();
-      graph =  graph1.create(em.numNodes, em.numDegree, em.printResult, rand);
+      graph =  BiGraph.create(em.numNodes, em.numDegree, em.printResult, rand);
     }
 
     long end0 = System.currentTimeMillis();
 
     // compute a single iteration of electro-magnetic propagation
-    if (printMsgs) 
-      System.printString("Propagating field values for " + numIter + 
+    if (em.printMsgs) 
+      System.printString("Propagating field values for " + em.numIter + 
           " iteration(s)...");
     long start1 = System.currentTimeMillis();
     Em3d[] em3d;
@@ -161,8 +164,9 @@ public class Em3d extends Thread
     }
 
     atomic {
-      em3d[0] = global new Em3d(graph, 1, em.numNodes/2, em.numIter, mybarr);
-      em3d[1] = global new Em3d(graph, (em.numNodes/2)+1, em.numNodes, em.numIter, mybarr);
+      em3d[0] = global new Em3d(graph, 1, em.numNodes, em.numIter, mybarr);
+      //em3d[0] = global new Em3d(graph, 1, em.numNodes/2, em.numIter, mybarr);
+      //em3d[1] = global new Em3d(graph, (em.numNodes/2)+1, em.numNodes, em.numIter, mybarr);
     }
 
     int mid = (128<<24)|(195<<16)|(175<<8)|73;
@@ -183,11 +187,37 @@ public class Em3d extends Thread
     long end1 = System.currentTimeMillis();
 
     // print current field values
-    if (printResult) {
-      //System.printString(graph);
+    if (em.printResult) {
+     // System.printString(graph.eNodes);
+      StringBuffer retval = new StringBuffer();
+      double newtmp;
+      atomic {
+        newtmp = graph.eNodes.value;
+      }
+      int xtmp = (int)newtmp;
+      System.printString("Value = " +xtmp);
+      /*
+      while(newtmp!=null) {
+          Node n = newtmp;
+          retval.append("E: " + n + "\n");
+         // newtmp = newtmp.next;
+      }
+      */
+      /*
+      atomic {
+        newtmp = graph.hNodes;
+      }
+      while(newtmp!=null) {
+        Node n = newtmp;
+        retval.append("H: " + n + "\n");
+        newtmp = newtmp.next;
+      }
+
+      System.printString(retval.toString());
+      */
     }
 
-    if (printMsgs) {
+    if (em.printMsgs) {
       System.printString("EM3D build time "+ (long)((end0 - start0)/1000.0));
       System.printString("EM3D compute time " + (long)((end1 - start1)/1000.0));
       System.printString("EM3D total time " + (long)((end1 - start0)/1000.0));
@@ -212,37 +242,38 @@ public class Em3d extends Thread
       // check for options that require arguments
       if (arg.equals("-n")) {
         if (i < args.length) {
-           atomic {
+          // atomic {
                em.numNodes = new Integer(args[i++]).intValue();
-           }
+          // }
         }
       } else if (arg.equals("-d")) {
         if (i < args.length) {
-           atomic {
+           //atomic {
                em.numDegree = new Integer(args[i++]).intValue();
-           }
+           //}
         }
       } else if (arg.equals("-i")) {
         if (i < args.length) {
-          atomic {
-            em.numIter = global new Integer(args[i++]).intValue();
-          }
+          //atomic {
+            //em.numIter = global new Integer(args[i++]).intValue();
+            em.numIter = new Integer(args[i++]).intValue();
+          //}
         }
       } else if (arg.equals("-p")) {
-         atomic {
+         //atomic {
              em.printResult = true;
-         }
+         //}
       } else if (arg.equals("-m")) {
-         atomic {
+         //atomic {
              em.printMsgs = true;
-         }
+         //}
       } else if (arg.equals("-h")) {
-        //em.usage();
+        em.usage();
       }
     }
 
-    //if (em.numNodes == 0 || em.numDegree == 0) 
-      //em.usage();
+    if (em.numNodes == 0 || em.numDegree == 0) 
+      em.usage();
   }
 
   /**
index 02d7941a11d885065cbf7d9f0ed6e96b0d074db1..c3467a3800b497d6e2beebe9f494980b25637d3b 100644 (file)
  * up random neighbors and propagates field values among neighbors.
  */
 public class Node {
-    /**
-     * The value of the node.
-     **/
-    double value;
-    /**
-     * The next node in the list.
-     **/
-    protected Node next;
-    /**
-     * Array of nodes to which we send our value.
-     **/
-    Node[] toNodes;
-    /**
-     * Array of nodes from which we receive values.
-     **/
-    Node[] fromNodes;
-    /**
-     * Coefficients on the fromNodes edges
-     **/
-    double[] coeffs;
-    /**
-     * The number of fromNodes edges
-     **/
-    int fromCount;
-    /**
-     * Used to create the fromEdges - keeps track of the number of edges that have
-     * been added
-     **/
-    int fromLength;
-
-    public Node() {
-
-    }
-
-    /** 
-     * Constructor for a node with given `degree'.   The value of the
-     * node is initialized to a random value.
-     **/
-    public Node(int degree, Random r) 
-    {
-        value = r.nextDouble();
-        // create empty array for holding toNodes
-        toNodes = global new Node[degree];
-
-        next = null;
-        for (int i = 0; i<fromCount; i++) {
-            fromNodes[i] = null;
-            coeffs[i] = 0.0;
-        }
-        fromCount = 0;
-        fromLength = 0;
+  /**
+   * The value of the node.
+   **/
+  double value;
+  /**
+   * The next node in the list.
+   **/
+  protected Node next;
+  /**
+   * Array of nodes to which we send our value.
+   **/
+  Node[] toNodes;
+  /**
+   * Array of nodes from which we receive values.
+   **/
+  Node[] fromNodes;
+  /**
+   * Coefficients on the fromNodes edges
+   **/
+  double[] coeffs;
+  /**
+   * The number of fromNodes edges
+   **/
+  int fromCount;
+  /**
+   * Used to create the fromEdges - keeps track of the number of edges that have
+   * been added
+   **/
+  int fromLength;
+
+  public Node() {
+
+  }
+
+  /** 
+   * Constructor for a node with given `degree'.   The value of the
+   * node is initialized to a random value.
+   **/
+  public Node(int degree, Random r) 
+  {
+    value = r.nextDouble();
+    // create empty array for holding toNodes
+
+    toNodes = global new Node[degree];
+  }
+
+  /**
+   * Create the linked list of E or H nodes.  We create a table which is used
+   * later to create links among the nodes.
+   * @param size the no. of nodes to create
+   * @param degree the out degree of each node
+   * @return a table containing all the nodes.
+   **/
+  public static Node[] fillTable(int size, int degree, Random r)
+  {
+    Node[] table;
+    Node prevNode;
+    table = global new Node[size];
+    prevNode = global new Node(degree, r);
+    table[0] = prevNode;
+    for (int i = 1; i < size; i++) {
+        Node curNode = global new Node(degree, r);
+        table[i] = curNode;
+        prevNode.next = curNode;
+        prevNode = curNode;
     }
-
-    /**
-     * Create the linked list of E or H nodes.  We create a table which is used
-     * later to create links among the nodes.
-     * @param size the no. of nodes to create
-     * @param degree the out degree of each node
-     * @return a table containing all the nodes.
-     **/
-    public static Node[] fillTable(int size, int degree, Random r)
-    {
-        Node[] table = global new Node[size];
-
-        Node prevNode = global new Node(degree, r);
-        table[0] = prevNode;
-        for (int i = 1; i < size; i++) {
-            Node curNode = global new Node(degree, r);
-            table[i] = curNode;
-            prevNode.next = curNode;
-            prevNode = curNode;
+    return table;
+  }
+
+  /** 
+   * Create unique `degree' neighbors from the nodes given in nodeTable.
+   * We do this by selecting a random node from the give nodeTable to
+   * be neighbor. If this neighbor has been previously selected, then
+   * a different random neighbor is chosen.
+   * @param nodeTable the list of nodes to choose from.
+   **/
+  public void makeUniqueNeighbors(Node[] nodeTable, Random rand)
+  {
+    for (int filled = 0; filled < toNodes.length; filled++) {
+      int k;
+      Node otherNode;
+
+      do {
+        boolean isBreak = false;
+        // generate a random number in the correct range
+        int index = rand.nextInt();
+        if (index < 0) index = -index;
+        index = index % nodeTable.length;
+
+        // find a node with the random index in the given table
+        otherNode = nodeTable[index];
+
+        for (k = 0; (k < filled) && (isBreak==false); k++) {
+          if (otherNode == toNodes[filled]) 
+            isBreak = true;
         }
-        return table;
-    }
+      } while (k < filled);
 
-    /** 
-     * Create unique `degree' neighbors from the nodes given in nodeTable.
-     * We do this by selecting a random node from the give nodeTable to
-     * be neighbor. If this neighbor has been previously selected, then
-     * a different random neighbor is chosen.
-     * @param nodeTable the list of nodes to choose from.
-     **/
-    public void makeUniqueNeighbors(Node[] nodeTable, Random rand)
-    {
-        for (int filled = 0; filled < toNodes.length; filled++) {
-            int k;
-            Node otherNode;
-            boolean isBreak;
-
-            do {
-                isBreak = false;
-                // generate a random number in the correct range
-                int index = rand.nextInt();
-                if (index < 0) index = -index;
-                index = index % nodeTable.length;
-
-                // find a node with the random index in the given table
-                otherNode = nodeTable[index];
-
-                for (k = 0; (k < filled) && (isBreak==false); k++) {
-                    if (otherNode == toNodes[filled]) 
-                        isBreak = true;
-                        //break;
-                }
-            } while (k < filled);
-
-            // other node is definitely unique among "filled" toNodes
-            toNodes[filled] = otherNode;
-
-            // update fromCount for the other node
-            otherNode.fromCount++;
-        }
-    }
+      // other node is definitely unique among "filled" toNodes
+      toNodes[filled] = otherNode;
 
-    /** 
-     * Allocate the right number of FromNodes for this node. This
-     * step can only happen once we know the right number of from nodes
-     * to allocate. Can be done after unique neighbors are created and known.
-     *
-     * It also initializes random coefficients on the edges.
-     **/
-    public void makeFromNodes()
-    {
-        fromNodes = global new Node[fromCount]; // nodes fill be filled in later
-        coeffs = global new double[fromCount];
-    }
-
-    /**
-     * Fill in the fromNode field in "other" nodes which are pointed to
-     * by this node.
-     **/
-    public void updateFromNodes(Random rand)
-    {
-        for (int i = 0; i < toNodes.length; i++) {
-            Node otherNode = toNodes[i];
-            int count = otherNode.fromLength++;
-            otherNode.fromNodes[count] = this;
-            otherNode.coeffs[count] = rand.nextDouble();
-        }
-    }
-
-    /** 
-     * Get the new value of the current node based on its neighboring
-     * from_nodes and coefficients.
-     **/
-
-    /*
-    public void computeNewValue()
-    {
-        for (int i = 0; i < fromCount; i++) {
-            value -= coeffs[i] * fromNodes[i].value;
-        }
+      // update fromCount for the other node
+      otherNode.fromCount++;
     }
-    */
-
-    /**
-     * Override the toString method to return the value of the node.
-     * @return the value of the node.
-     **/
-    public String toString()
-    {
-        String returnString;
-        returnString = "value " + (long)value + ", from_count " + fromCount;
-        //return "value " + value + ", from_count " + fromCount;
+  }
+
+  /** 
+   * Allocate the right number of FromNodes for this node. This
+   * step can only happen once we know the right number of from nodes
+   * to allocate. Can be done after unique neighbors are created and known.
+   *
+   * It also initializes random coefficients on the edges.
+   **/
+  public void makeFromNodes()
+  {
+    fromNodes = global new Node[fromCount]; // nodes fill be filled in later
+    coeffs = global new double[fromCount];
+  }
+
+  /**
+   * Fill in the fromNode field in "other" nodes which are pointed to
+   * by this node.
+   **/
+  public void updateFromNodes(Random rand)
+  {
+    for (int i = 0; i < toNodes.length; i++) {
+      Node otherNode = toNodes[i];
+      int count = otherNode.fromLength++;
+      otherNode.fromNodes[count] = this;
+      otherNode.coeffs[count] = rand.nextDouble();
     }
+  }
+
+  /** 
+   * Get the new value of the current node based on its neighboring
+   * from_nodes and coefficients.
+   **/
+
+  /*
+     public void computeNewValue()
+     {
+     for (int i = 0; i < fromCount; i++) {
+     value -= coeffs[i] * fromNodes[i].value;
+     }
+     }
+     */
+
+  /**
+   * Override the toString method to return the value of the node.
+   * @return the value of the node.
+   **/
+  public String toString()
+  {
+    String returnString;
+    returnString = "value " + (long)value + ", from_count " + fromCount;
+    //return "value " + value + ", from_count " + fromCount;
+  }
 
 }