1 /** Single thread C 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 *
18 * This version copyright (c) The University of Edinburgh, 2001. *
19 * All rights reserved. *
21 **************************************************************************/
35 float TrapezoidIntegrate(float x0, float x1, int nsteps, float omegan, int select);
36 float thefunction(float x, float omegan, int select);
39 int main(int argc, char **argv) {
49 for(i = 0; i < datasize; ++i) {
53 raw_test_pass(raw_get_cycle());
60 // Calculate the fourier series. Begin by calculating A[0].
62 pair[0] = TrapezoidIntegrate((float)0.0, //Lower bound.
63 (float)2.0, // Upper bound.
65 (float)0.0, // No omega*n needed.
66 0) / (float)2.0; // 0 = term A[0].
69 // Calculate the fundamental frequency.
70 // ( 2 * pi ) / period...and since the period
71 // is 2, omega is simply pi.
72 float omega = (float) 3.1415926535897932; // Fundamental frequency.
74 // Calculate A[i] terms. Note, once again, that we
75 // can ignore the 2/period term outside the integral
76 // since the period is 2 and the term cancels itself
78 pair[0] = TrapezoidIntegrate((float)0.0,
82 1); // 1 = cosine term.
83 //System.printI(0xa2);
84 // Calculate the B[i] terms.
85 pair[1] = TrapezoidIntegrate((float)0.0,
93 //raw_test_pass_reg(id);
94 //raw_test_pass((int)(pair[0]*10000));
95 //raw_test_pass((int)(pair[1]*10000));
97 printf("coefficient NO. %d: %f; %f \n", id, pair[0], pair[1]);
104 ref[0][0] = 2.8729524964837996;
106 ref[1][0] = 1.1161046676147888;
107 ref[1][1] = -1.8819691893398025;
108 ref[2][0] = 0.34429060398168704;
109 ref[2][1] = -1.1645642623320958;
110 ref[3][0] = 0.15238898702519288;
111 ref[3][1] = -0.8143461113044298;
112 for (j = 0; j < 2; j++){
113 float error = abs(pair[j] - ref[id][j]);
114 if (error > 1.0e-12 ){
116 //raw_test_pass(0xeeee);
118 printf("Validation failed for coefficient %d:%d \n", j, id);
119 printf("Computed value = %f \n", pair[j]);
120 printf("Reference value = %f \n", ref[id][j]);
130 * Perform a simple trapezoid integration on the function (x+1)**x.
131 * x0,x1 set the lower and upper bounds of the integration.
132 * nsteps indicates # of trapezoidal sections.
133 * omegan is the fundamental frequency times the series member #.
134 * select = 0 for the A[0] term, 1 for cosine terms, and 2 for
135 * sine terms. Returns the value.
138 float TrapezoidIntegrate (float x0, // Lower bound.
139 float x1, // Upper bound.
140 int nsteps, // # of steps.
141 float omegan, // omega * n.
142 int select) { // Term type.
143 float x; // Independent variable.
144 float dx; // Step size.
145 float rvalue; // Return value.
147 // Initialize independent variable.
150 // Calculate stepsize.
151 dx = (x1 - x0) / (float)nsteps;
153 // Initialize the return value.
154 rvalue = thefunction(x0, omegan, select) / (float)2.0;
156 // Compute the other terms of the integral.
158 --nsteps; // Already done 1 step.
159 while (--nsteps > 0) {
161 rvalue += thefunction(x, omegan, select);
165 // Finish computation.
166 rvalue=(rvalue + thefunction(x1,omegan,select) / (float)2.0) * dx;
173 * This routine selects the function to be used in the Trapezoid
174 * integration. x is the independent variable, omegan is omega * n,
175 * and select chooses which of the sine/cosine functions
176 * are used. Note the special case for select=0.
179 float thefunction(float x, // Independent variable.
180 float omegan, // Omega * term.
181 int select) { // Choose type.
183 // Use select to pick which function we call.
186 result = powf(x+(float)1.0,x);
187 } else if (1 == select) {
188 return(powf(x+(float)1.0,x) * cosf(omegan*x));
189 } else if (2 == select) {
190 return(powf(x+(float)1.0,x) * sinf(omegan*x));
193 // We should never reach this point, but the following
194 // keeps compilers from issuing a warning message.