helpful progress reporting
[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
64             // Calculate A[i] terms. Note, once again, that we
65             // can ignore the 2/period term outside the integral
66             // since the period is 2 and the term cancels itself
67             // out.
68             pair[0] = TrapezoidIntegrate((float)0.0,
69                                          (float)2.0,
70                                          1000,
71                                          omega * (float)id, 
72                                          1);                       // 1 = cosine term.
73             //System.printI(0xa2);
74             // Calculate the B[i] terms.
75             pair[1] = TrapezoidIntegrate((float)0.0,
76                                          (float)2.0,
77                                          1000,
78                                          omega * (float)id,
79                                          2);                       // 2 = sine term.
80         }
81         //System.printI(0xa3);
82         //System.printString("coefficient NO.");
83         //System.printI(id);
84         //System.printI((int)(pair[0]*10000));
85         //System.printI((int)(pair[1]*10000));
86
87         // validate
88         if(id < 4) {
89             //System.printI(0xa4);
90             float ref[][] = new float[4][2];
91             ref[0][0] = (float)2.87290112;
92             ref[0][1] = (float)0.0;
93             ref[1][0] = (float)1.11594856;
94             ref[1][1] = (float)-1.88199680;
95             ref[2][0] = (float)0.34412988;
96             ref[2][1] = (float)-1.16458096;
97             ref[3][0] = (float)0.15222694;
98             ref[3][1] = (float)-0.81435320;
99             //System.printI(0xa5);
100             for (int j = 0; j < 2; j++){
101                 //System.printI(0xa6);
102                 float error = Math.abs(pair[j] - ref[id][j]);
103                 if (error > 1.0e-7 ){
104                         //System.printI(0xa7);
105                     //System.printString("Validation failed for coefficient " + j + "," + id + "\n");
106                     //System.printString("Computed value = " + (int)(pair[j]*100000000) + "\n");
107                     //System.printString("Reference value = " + (int)(ref[id][j]*100000000) + "\n");
108                         //System.printI((int)(pair[j]*10000));
109                         //System.printI((int)(ref[id][j]*10000));
110                 }
111             }
112         }
113         //System.printI(0xa8);
114     }
115
116     /*
117      * TrapezoidIntegrate
118      *
119      * Perform a simple trapezoid integration on the function (x+1)**x.
120      * x0,x1 set the lower and upper bounds of the integration.
121      * nsteps indicates # of trapezoidal sections.
122      * omegan is the fundamental frequency times the series member #.
123      * select = 0 for the A[0] term, 1 for cosine terms, and 2 for
124      * sine terms. Returns the value.
125      */
126
127     private float TrapezoidIntegrate (float x0,     // Lower bound.
128                                       float x1,     // Upper bound.
129                                       int nsteps,    // # of steps.
130                                       float omegan, // omega * n.
131                                       int select)    // Term type.
132     {
133         float x;               // Independent variable.
134         float dx;              // Step size.
135         float rvalue;          // Return value.
136
137         //System.printI(0xb0);
138         // Initialize independent variable.
139
140         x = x0;
141
142         // Calculate stepsize.
143
144         dx = (x1 - x0) / (float)nsteps;
145         //System.printI((int)(dx * 1000000));
146         //System.printI(0xb1);
147
148         // Initialize the return value.
149
150         rvalue = thefunction(x0, omegan, select) / (float)2.0;
151         //System.printI((int)(rvalue * 1000000));
152         //System.printI(0xb2);
153
154         // Compute the other terms of the integral.
155
156         if (nsteps != 1)
157         {
158             //System.printI(0xb3);
159             --nsteps;               // Already done 1 step.
160             while (--nsteps > 0)
161             {
162                 //System.printI(0xb4);
163                 //System.printI(nsteps);
164                 x += dx;
165                 rvalue += thefunction(x, omegan, select);
166                 //System.printI((int)(rvalue * 1000000));
167                 //System.printI(0xb5);
168             }
169         }
170
171         // Finish computation.
172
173         //System.printI(0xb6);
174         rvalue=(float)(rvalue + thefunction(x1,omegan,select) / (float)2.0) * dx;
175         //System.printI((int)(rvalue * 1000000));
176         //System.printString("rvalue: " + (int)(rvalue * 10000) + "\n");
177         //System.printI(0xb7);
178         return(rvalue);
179     }
180
181     /*
182      * thefunction
183      *
184      * This routine selects the function to be used in the Trapezoid
185      * integration. x is the independent variable, omegan is omega * n,
186      * and select chooses which of the sine/cosine functions
187      * are used. Note the special case for select=0.
188      */
189
190     private float thefunction(float x,      // Independent variable.
191                               float omegan, // Omega * term.
192                               int select)    // Choose type.
193     {
194
195         // Use select to pick which function we call.
196         //System.printI(0xc0);
197         float result = (float)0.0;
198         if(0 == select) {
199             //System.printI(0xc1);
200             result = Math.powf(x+(float)1.0,x);
201             //System.printI((int)(result * 1000000));
202         } else if (1 == select) {
203             //System.printI(0xc2);
204             return(Math.powf(x+(float)1.0,x) * Math.cosf(omegan*x));
205         } else if (2 == select) {
206             //System.printI(0xc3);
207             return(Math.powf(x+(float)1.0,x) * Math.sinf(omegan*x));
208         }
209
210         //System.printI(0xc4);
211         // We should never reach this point, but the following
212         // keeps compilers from issuing a warning message.
213         return result;
214     }    
215 }
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234