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.
63 float omega = (float) 3.1415926535897932; // Fundamental frequency.
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
69 pair[0] = TrapezoidIntegrate((float)0.0,
73 1); // 1 = cosine term.
74 //System.printI(0xa2);
75 // Calculate the B[i] terms.
76 pair[1] = TrapezoidIntegrate((float)0.0,
82 //System.printI(0xa3);
83 //System.printString("coefficient NO.");
85 //System.printI((int)(pair[0]*10000));
86 //System.printI((int)(pair[1]*10000));
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));
114 //System.printI(0xa8);
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.
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.
134 float x; // Independent variable.
135 float dx; // Step size.
136 float rvalue; // Return value.
138 //System.printI(0xb0);
139 // Initialize independent variable.
143 // Calculate stepsize.
145 dx = (x1 - x0) / (float)nsteps;
146 //System.printI((int)(dx * 1000000));
147 //System.printI(0xb1);
149 // Initialize the return value.
151 rvalue = thefunction(x0, omegan, select) / (float)2.0;
152 //System.printI((int)(rvalue * 1000000));
153 //System.printI(0xb2);
155 // Compute the other terms of the integral.
159 //System.printI(0xb3);
160 --nsteps; // Already done 1 step.
163 //System.printI(0xb4);
164 //System.printI(nsteps);
166 rvalue += thefunction(x, omegan, select);
167 //System.printI((int)(rvalue * 1000000));
168 //System.printI(0xb5);
172 // Finish computation.
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);
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.
191 private float thefunction(float x, // Independent variable.
192 float omegan, // Omega * term.
193 int select) // Choose type.
196 // Use select to pick which function we call.
197 //System.printI(0xc0);
198 float result = (float)0.0;
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));
211 //System.printI(0xc4);
212 // We should never reach this point, but the following
213 // keeps compilers from issuing a warning message.