213a708449b42f638f080ef3386161c677ad84a9
[IRC.git] / Robust / src / Benchmarks / Scheduling / GC / NON_BAMBOO / bh / TestRunner.java
1
2 /*import java.util.Enumeration;
3 import java.lang.Math;*/
4
5 /**
6  * A Java implementation of the <tt>bh</tt> Olden benchmark.
7  * The Olden benchmark implements the Barnes-Hut benchmark
8  * that is decribed in :
9  * <p><cite>
10  * J. Barnes and P. Hut, "A hierarchical o(NlogN) force-calculation algorithm",
11  * Nature, 324:446-449, Dec. 1986
12  * </cite>
13  * <p>
14  * The original code in the Olden benchmark suite is derived from the
15  * <a href="ftp://hubble.ifa.hawaii.edu/pub/barnes/treecode">
16  * source distributed by Barnes</a>.
17  **/
18 public class TestRunner extends Thread
19 {
20   
21   /**
22    * The user specified number of bodies to create.
23    **/
24   public  int nbody; // = 0;
25
26   /**
27    * The maximum number of time steps to take in the simulation
28    **/
29   public  int nsteps; // = 10;
30
31   /**
32    * Should we print information messsages
33    **/
34   //private static boolean printMsgs = false;
35   /**
36    * Should we print detailed results
37    **/
38   //private static boolean printResults = false;
39
40   public  double DTIME; // = 0.0125;
41   public  double TSTOP; // = 2.0;
42   
43   public TestRunner(int nbody) {
44     this.nbody = nbody;
45     this.nsteps = 10;
46     this.DTIME = 0.0125;
47     this.TSTOP = 2.0;
48   }
49
50   public void run()
51   {
52     //parseCmdLine(args);
53
54     /*if (printMsgs)
55       System.out.println("nbody = " + nbody);*/
56
57     //long start0 = System.currentTimeMillis();
58     Tree root = new Tree(this.DTIME);
59     root.createTestData(nbody);
60     /*long end0 = System.currentTimeMillis();
61     if (printMsgs)
62       System.out.println("Bodies created");
63
64     long start1 = System.currentTimeMillis();*/
65     double tnow = 0.0;
66     int i = 0;
67     while ((tnow < (TSTOP + 0.1f*DTIME)) && (i < nsteps)) {
68       root.stepSystem(i++);
69       tnow += DTIME;
70     }
71     /*long end1 = System.currentTimeMillis();
72
73     if (printResults) {
74       int j = 0;
75       for (Enumeration e = root.bodies(); e.hasMoreElements(); ) {
76         Body b = (Body)e.nextElement();
77         System.out.println("body " + j++ + " -- " + b.pos);
78       }
79     }
80
81     if (printMsgs) {
82       System.out.println("Build Time " + (end0 - start0)/1000.0);
83       System.out.println("Compute Time " + (end1 - start1)/1000.0);
84       System.out.println("Total Time " + (end1 - start0)/1000.0);
85     }
86     System.out.println("Done!");*/
87   }
88
89   /**
90    * Random number generator used by the orignal BH benchmark.
91    * @param seed the seed to the generator
92    * @return a random number
93    **/
94   public  double myRand(double seed)
95   {
96     double t = 16807.0*seed + 1;
97     
98     seed = t - 2147483647.0 * Math.floor(t / 2147483647.0f);
99     return seed;
100   }
101
102   /**
103    * Generate a doubleing point random number.  Used by
104    * the original BH benchmark.
105    *
106    * @param xl lower bound
107    * @param xh upper bound
108    * @param r seed
109    * @return a doubleing point randon number
110    **/
111   public  double xRand(double xl, double xh, double r)
112   {
113     double res = xl + (xh-xl)*r/2147483647.0;
114     return res;
115   }
116
117   public static void main(String[] args) {
118     int threadnum = 62;
119     int nbody = 700;
120     for(int i = 0; i < threadnum; ++i) {
121       TestRunner tr = new TestRunner(nbody);
122       tr.run();
123     }
124   }
125 }