1 /** Bristlecone Version **/
3 /**************************************************************************
5 * Java Grande Forum Benchmark Suite - Thread Version 1.0 *
9 * Java Grande Benchmarking Project *
13 * Edinburgh Parallel Computing Centre *
15 * email: epcc-javagrande@epcc.ed.ac.uk *
17 * Original version of this code by *
18 * Gabriel Zachmann (zach@igd.fhg.de) *
20 * This version copyright (c) The University of Edinburgh, 2001. *
21 * All rights reserved. *
23 **************************************************************************/
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).
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).
37 public class SeriesRunner {
42 public SeriesRunner(int id){
47 //System.printI(0xa0);
48 float pair[] = new float[2];
49 // Calculate the fourier series. Begin by calculating A[0].
51 pair[0] = TrapezoidIntegrate((float)0.0, //Lower bound.
52 (float)2.0, // Upper bound.
54 (float)0.0, // No omega*n needed.
55 0) / (float)2.0; // 0 = term A[0].
56 //System.printI(0xa1);
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.
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
68 pair[0] = TrapezoidIntegrate((float)0.0,
72 1); // 1 = cosine term.
73 //System.printI(0xa2);
74 // Calculate the B[i] terms.
75 pair[1] = TrapezoidIntegrate((float)0.0,
81 //System.printI(0xa3);
82 //System.printString("coefficient NO.");
84 //System.printI((int)(pair[0]*10000));
85 //System.printI((int)(pair[1]*10000));
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));
113 //System.printI(0xa8);
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.
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.
133 float x; // Independent variable.
134 float dx; // Step size.
135 float rvalue; // Return value.
137 //System.printI(0xb0);
138 // Initialize independent variable.
142 // Calculate stepsize.
144 dx = (x1 - x0) / (float)nsteps;
145 //System.printI((int)(dx * 1000000));
146 //System.printI(0xb1);
148 // Initialize the return value.
150 rvalue = thefunction(x0, omegan, select) / (float)2.0;
151 //System.printI((int)(rvalue * 1000000));
152 //System.printI(0xb2);
154 // Compute the other terms of the integral.
158 //System.printI(0xb3);
159 --nsteps; // Already done 1 step.
162 //System.printI(0xb4);
163 //System.printI(nsteps);
165 rvalue += thefunction(x, omegan, select);
166 //System.printI((int)(rvalue * 1000000));
167 //System.printI(0xb5);
171 // Finish computation.
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);
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.
190 private float thefunction(float x, // Independent variable.
191 float omegan, // Omega * term.
192 int select) // Choose type.
195 // Use select to pick which function we call.
196 //System.printI(0xc0);
197 float result = (float)0.0;
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));
210 //System.printI(0xc4);
211 // We should never reach this point, but the following
212 // keeps compilers from issuing a warning message.