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 {
43 public SeriesRunner(int id, int range){
49 float pair[][] = new float[2][range];
50 // Calculate the fourier series. Begin by calculating A[0].
52 pair[0][0] = TrapezoidIntegrate((float)0.0, //Lower bound.
53 (float)2.0, // Upper bound.
55 (float)0.0, // No omega*n needed.
56 0) / (float)2.0; // 0 = term A[0].
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.
66 int iupper = (id+1)*range;
67 for(int i = ilow; i < iupper; i++) {
69 // Calculate A[i] terms. Note, once again, that we
70 // can ignore the 2/period term outside the integral
71 // since the period is 2 and the term cancels itself
73 pair[0][j] = TrapezoidIntegrate((float)0.0,
77 1); // 1 = cosine term.
78 // Calculate the B[i] terms.
79 pair[1][j] = TrapezoidIntegrate((float)0.0,
88 float ref[][] = new float[4][2];
89 ref[0][0] = (float)2.87290112;
90 ref[0][1] = (float)0.0;
91 ref[1][0] = (float)1.11594856;
92 ref[1][1] = (float)-1.88199680;
93 ref[2][0] = (float)0.34412988;
94 ref[2][1] = (float)-1.16458096;
95 ref[3][0] = (float)0.15222694;
96 ref[3][1] = (float)-0.81435320;
97 for(int i = 0; i < 4; i++) {
98 for (int j = 0; j < 2; j++){
99 float error = Math.abs(pair[j][i] - ref[i][j]);
100 if (error > 1.0e-7 ){
101 //System.printI(0xa7);
102 //System.printString("Validation failed for coefficient " + j + "," + id + "\n");
103 //System.printString("Computed value = " + (int)(pair[j]*100000000) + "\n");
104 //System.printString("Reference value = " + (int)(ref[id][j]*100000000) + "\n");
105 //System.printI((int)(pair[j]*10000));
106 //System.printI((int)(ref[id][j]*10000));
116 * Perform a simple trapezoid integration on the function (x+1)**x.
117 * x0,x1 set the lower and upper bounds of the integration.
118 * nsteps indicates # of trapezoidal sections.
119 * omegan is the fundamental frequency times the series member #.
120 * select = 0 for the A[0] term, 1 for cosine terms, and 2 for
121 * sine terms. Returns the value.
124 private float TrapezoidIntegrate (float x0, // Lower bound.
125 float x1, // Upper bound.
126 int nsteps, // # of steps.
127 float omegan, // omega * n.
128 int select) // Term type.
130 float x; // Independent variable.
131 float dx; // Step size.
132 float rvalue; // Return value.
133 float tmpvalue = (float)0.0;
135 // Initialize independent variable.
138 // Calculate stepsize.
139 dx = (x1 - x0) / (float)nsteps;
141 // Initialize the return value.
142 rvalue = thefunction(x0, omegan, select) / (float)2.0;
144 // Compute the other terms of the integral.
147 --nsteps; // Already done 1 step.
151 tmpvalue = thefunction(x, omegan, select);
157 // Finish computation.
158 tmpvalue = thefunction(x1,omegan,select) / (float)2.0;
159 rvalue=(float)(rvalue + tmpvalue) * dx;
166 * This routine selects the function to be used in the Trapezoid
167 * integration. x is the independent variable, omegan is omega * n,
168 * and select chooses which of the sine/cosine functions
169 * are used. Note the special case for select=0.
172 private float thefunction(float x, // Independent variable.
173 float omegan, // Omega * term.
174 int select) // Choose type.
177 // Use select to pick which function we call.
178 float tmp = x+(float)1.0;
179 float result = (float)0.0;
180 float v1 = (float)0.0;
181 float v2 = (float)1.0;
182 v1 = Math.powf(tmp,x);
185 } else if (1 == select) {
186 v2 = Math.cosf(omegan*x);
187 } else if (2 == select) {
188 v2 = Math.sinf(omegan*x);
192 // We should never reach this point, but the following
193 // keeps compilers from issuing a warning message.