some benchmarks for scheduling
[IRC.git] / Robust / src / Benchmarks / Scheduling / JGFSeries / SeriesRunner.java
1 /** Bristlecone Version  **/
2
3 /**************************************************************************
4  *                                                                         *
5  *         Java Grande Forum Benchmark Suite - Thread Version 1.0          *
6  *                                                                         *
7  *                            produced by                                  *
8  *                                                                         *
9  *                  Java Grande Benchmarking Project                       *
10  *                                                                         *
11  *                                at                                       *
12  *                                                                         *
13  *                Edinburgh Parallel Computing Centre                      *
14  *                                                                         * 
15  *                email: epcc-javagrande@epcc.ed.ac.uk                     *
16  *                                                                         *
17  *                  Original version of this code by                       *
18  *                 Gabriel Zachmann (zach@igd.fhg.de)                      *
19  *                                                                         *
20  *      This version copyright (c) The University of Edinburgh, 2001.      *
21  *                         All rights reserved.                            *
22  *                                                                         *
23  **************************************************************************/
24
25 /**
26  * Class SeriesRunner
27  *
28  * Performs the transcendental/trigonometric portion of the
29  * benchmark. This test calculates the nth fourier
30  * coefficients of the function (x+1)^x defined on the interval
31  * 0,2 (where n is an arbitrary number set in the constructor).
32  *
33  * The first four pairs of coefficients calculated shoud be:
34  * (2.83777, 0), (1.04578, -1.8791), (0.2741, -1.15884), and
35  * (0.0824148, -0.805759).
36  */
37 public class SeriesRunner {
38     flag finish;
39
40     int id;
41
42     public SeriesRunner(int id){
43         this.id=id;
44     }
45
46     public void run() {
47         //System.printI(0xa0);
48         float pair[] = new float[2];
49         // Calculate the fourier series. Begin by calculating A[0].
50         if (id==0) {
51             pair[0] = TrapezoidIntegrate((float)0.0, //Lower bound.
52                                          (float)2.0, // Upper bound.
53                                          1000,        // # of steps.
54                                          (float)0.0, // No omega*n needed.
55                                          0) / (float)2.0; // 0 = term A[0].
56             //System.printI(0xa1);
57             pair[1] = 0;
58         } else {
59             // Calculate the fundamental frequency.
60             // ( 2 * pi ) / period...and since the period
61             // is 2, omega is simply pi.
62             //float omega = (float) 3.1415926535897932; // Fundamental frequency.
63             float omega = (float) 3.1415926535897932; // Fundamental frequency.
64
65             // Calculate A[i] terms. Note, once again, that we
66             // can ignore the 2/period term outside the integral
67             // since the period is 2 and the term cancels itself
68             // out.
69             pair[0] = TrapezoidIntegrate((float)0.0,
70                                          (float)2.0,
71                                          1000,
72                                          omega * (float)id, 
73                                          1);                       // 1 = cosine term.
74             //System.printI(0xa2);
75             // Calculate the B[i] terms.
76             pair[1] = TrapezoidIntegrate((float)0.0,
77                                          (float)2.0,
78                                          1000,
79                                          omega * (float)id,
80                                          2);                       // 2 = sine term.
81         }
82         //System.printI(0xa3);
83         //System.printString("coefficient NO.");
84         //System.printI(id);
85         //System.printI((int)(pair[0]*10000));
86         //System.printI((int)(pair[1]*10000));
87
88         // validate
89         if(id < 4) {
90             //System.printI(0xa4);
91             float ref[][] = new float[4][2];
92             ref[0][0] = (float)2.87290112;
93             ref[0][1] = (float)0.0;
94             ref[1][0] = (float)1.11594856;
95             ref[1][1] = (float)-1.88199680;
96             ref[2][0] = (float)0.34412988;
97             ref[2][1] = (float)-1.16458096;
98             ref[3][0] = (float)0.15222694;
99             ref[3][1] = (float)-0.81435320;
100             //System.printI(0xa5);
101             for (int j = 0; j < 2; j++){
102                 //System.printI(0xa6);
103                 float error = Math.abs(pair[j] - ref[id][j]);
104                 if (error > 1.0e-7 ){
105                         //System.printI(0xa7);
106                     //System.printString("Validation failed for coefficient " + j + "," + id + "\n");
107                     //System.printString("Computed value = " + (int)(pair[j]*100000000) + "\n");
108                     //System.printString("Reference value = " + (int)(ref[id][j]*100000000) + "\n");
109                         //System.printI((int)(pair[j]*10000));
110                         //System.printI((int)(ref[id][j]*10000));
111                 }
112             }
113         }
114         //System.printI(0xa8);
115     }
116
117     /*
118      * TrapezoidIntegrate
119      *
120      * Perform a simple trapezoid integration on the function (x+1)**x.
121      * x0,x1 set the lower and upper bounds of the integration.
122      * nsteps indicates # of trapezoidal sections.
123      * omegan is the fundamental frequency times the series member #.
124      * select = 0 for the A[0] term, 1 for cosine terms, and 2 for
125      * sine terms. Returns the value.
126      */
127
128     private float TrapezoidIntegrate (float x0,     // Lower bound.
129                                       float x1,     // Upper bound.
130                                       int nsteps,    // # of steps.
131                                       float omegan, // omega * n.
132                                       int select)    // Term type.
133     {
134         float x;               // Independent variable.
135         float dx;              // Step size.
136         float rvalue;          // Return value.
137
138         //System.printI(0xb0);
139         // Initialize independent variable.
140
141         x = x0;
142
143         // Calculate stepsize.
144
145         dx = (x1 - x0) / (float)nsteps;
146         //System.printI((int)(dx * 1000000));
147         //System.printI(0xb1);
148
149         // Initialize the return value.
150
151         rvalue = thefunction(x0, omegan, select) / (float)2.0;
152         //System.printI((int)(rvalue * 1000000));
153         //System.printI(0xb2);
154
155         // Compute the other terms of the integral.
156
157         if (nsteps != 1)
158         {
159             //System.printI(0xb3);
160             --nsteps;               // Already done 1 step.
161             while (--nsteps > 0)
162             {
163                 //System.printI(0xb4);
164                 //System.printI(nsteps);
165                 x += dx;
166                 rvalue += thefunction(x, omegan, select);
167                 //System.printI((int)(rvalue * 1000000));
168                 //System.printI(0xb5);
169             }
170         }
171
172         // Finish computation.
173
174         //System.printI(0xb6);
175         rvalue=(float)(rvalue + thefunction(x1,omegan,select) / (float)2.0) * dx;
176         //System.printI((int)(rvalue * 1000000));
177         //System.printString("rvalue: " + (int)(rvalue * 10000) + "\n");
178         //System.printI(0xb7);
179         return(rvalue);
180     }
181
182     /*
183      * thefunction
184      *
185      * This routine selects the function to be used in the Trapezoid
186      * integration. x is the independent variable, omegan is omega * n,
187      * and select chooses which of the sine/cosine functions
188      * are used. Note the special case for select=0.
189      */
190
191     private float thefunction(float x,      // Independent variable.
192                               float omegan, // Omega * term.
193                               int select)    // Choose type.
194     {
195
196         // Use select to pick which function we call.
197         //System.printI(0xc0);
198         float result = (float)0.0;
199         if(0 == select) {
200             //System.printI(0xc1);
201             result = Math.powf(x+(float)1.0,x);
202             //System.printI((int)(result * 1000000));
203         } else if (1 == select) {
204             //System.printI(0xc2);
205             return(Math.powf(x+(float)1.0,x) * Math.cosf(omegan*x));
206         } else if (2 == select) {
207             //System.printI(0xc3);
208             return(Math.powf(x+(float)1.0,x) * Math.sinf(omegan*x));
209         }
210
211         //System.printI(0xc4);
212         // We should never reach this point, but the following
213         // keeps compilers from issuing a warning message.
214         return result;
215     }    
216 }
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235