1 /**************************************************************************
3 * Java Grande Forum Benchmark Suite - Thread Version 1.0 *
7 * Java Grande Benchmarking Project *
11 * Edinburgh Parallel Computing Centre *
13 * email: epcc-javagrande@epcc.ed.ac.uk *
16 * This version copyright (c) The University of Edinburgh, 2001. *
17 * All rights reserved. *
19 **************************************************************************/
20 public class JGFLUFactBench {
23 private int[] datasizes;
24 public int cachelinesize;
25 public JGFInstrumentor instr;
29 double ops,total,norma,normx;
32 int n,i,ntimes,info,lda,ldaa,kflops;
35 public JGFLUFactBench(int nthreads, JGFInstrumentor instr) {
36 this.nthreads=nthreads;
38 datasizes = new int[3];
45 public void JGFsetsize(int size) {
49 public void JGFinitialise() {
54 a = new double[ldaa][lda];
55 b = new double [ldaa];
56 x = new double [ldaa];
57 ipvt = new int [ldaa];
59 long nl = (long) n; //avoid integer overflow
60 ops = (2.0*(nl*nl*nl))/3.0 + 2.0*(nl*nl);
61 norma = matgen(a,lda,n,b);
64 public static void JGFkernel(JGFLUFactBench lub, JGFInstrumentor instr) {
66 numthreads = lub.nthreads;
69 LinpackRunner[] thobjects;
71 thobjects = new LinpackRunner[numthreads];
72 br = new TournamentBarrier(numthreads);
74 instr.startTimer("Section2:LUFact:Kernel", instr.timers);
77 int mid = (128<<24)|(195<<16)|(175<<8)|73;
78 for(int i=1;i<numthreads;i++) {
79 thobjects[i] = new LinpackRunner(i,lub.a,lub.lda,lub.n,lub.ipvt,br,lub.nthreads);
84 thobjects[0] = new LinpackRunner(0,lub.a,lub.lda,lub.n,lub.ipvt,br,lub.nthreads);
89 } catch (InterruptedException e) {}
91 for(int i=1;i<numthreads;i++) {
95 } catch (InterruptedException e) {}
98 lub.dgesl(lub.a,lub.lda,lub.n,lub.ipvt,lub.b,0);
99 instr.stopTimer("Section2:LUFact:Kernel", instr.timers);
102 public void JGFvalidate() {
112 for (i = 0; i < n; i++) {
115 norma = matgen(a,lda,n,b);
116 for (i = 0; i < n; i++) {
120 dmxpy(n,b,n,lda,x,a);
123 for (i = 0; i < n; i++) {
124 //resid = (resid > abs(b[i])) ? resid : abs(b[i]);
125 //normx = (normx > abs(x[i])) ? normx : abs(x[i]);
126 if (resid <= abs(b[i])) resid = abs(b[i]);
127 if (normx <= abs(x[i])) normx = abs(x[i]);
129 eps = epslon((double)1.0);
130 residn = resid/( n*norma*normx*eps );
132 if (residn > ref[size]) {
133 System.out.println("Validation failed");
134 System.out.println("Computed Norm Res = " + (long) residn * 1000000);
135 System.out.println("Reference Norm Res = " + (long) ref[size] * 1000000);
139 double abs (double d) {
140 if (d >= 0) return d;
142 //return (d >= 0) ? d : -d;
145 double matgen (double a[][], int lda, int n, double b[])
152 /* Next two for() statements switched. Solver wants
153 matrix in column order. --dmd 3/3/97
155 for (i = 0; i < n; i++) {
156 for (j = 0; j < n; j++) {
157 init = 3125*init % 65536;
158 a[j][i] = (init - 32768.0)/16384.0;
159 //norma = (a[j][i] > norma) ? a[j][i] : norma;
160 if (a[j][i] > norma) {
165 for (i = 0; i < n; i++) {
168 for (j = 0; j < n; j++) {
169 for (i = 0; i < n; i++) {
176 void dgesl( double a[][], int lda, int n, int ipvt[], double b[], int job)
183 // job = 0 , solve a * x = b. first solve l*y = b
185 for (k = 0; k < nm1; k++) {
193 daxpy(n-(kp1),t,a[k],kp1,1,b,kp1,1);
197 for (kb = 0; kb < n; kb++) {
201 daxpy(k,t,a[k],0,1,b,0,1);
204 // job = nonzero, solve trans(a) * x = b. first solve trans(u)*y = b
205 for (k = 0; k < n; k++) {
206 t = ddot(k,a[k],0,1,b,0,1);
207 b[k] = (b[k] - t)/a[k][k];
209 // now solve trans(l)*x = y
211 for (kb = 1; kb < nm1; kb++) {
214 b[k] += ddot(n-(kp1),a[k],kp1,1,b,kp1,1);
227 constant times a vector plus a vector.
228 jack dongarra, linpack, 3/11/78.
230 void daxpy( int n, double da, double dx[], int dx_off, int incx,
231 double dy[], int dy_off, int incy)
235 if ((n > 0) && (da != 0)) {
236 if (incx != 1 || incy != 1) {
237 // code for unequal increments or equal increments not equal to 1
240 if (incx < 0) ix = (-n+1)*incx;
241 if (incy < 0) iy = (-n+1)*incy;
242 for (i = 0;i < n; i++) {
243 dy[iy +dy_off] += da*dx[ix +dx_off];
249 // code for both increments equal to 1
250 for (i=0; i < n; i++)
251 dy[i +dy_off] += da*dx[i +dx_off];
257 forms the dot product of two vectors.
258 jack dongarra, linpack, 3/11/78.
260 double ddot( int n, double dx[], int dx_off, int incx, double dy[],
261 int dy_off, int incy)
267 if (incx != 1 || incy != 1) {
268 // code for unequal increments or equal increments not equal to 1
271 if (incx < 0) ix = (-n+1)*incx;
272 if (incy < 0) iy = (-n+1)*incy;
273 for (i = 0;i < n; i++) {
274 dtemp += dx[ix +dx_off]*dy[iy +dy_off];
279 // code for both increments equal to 1
281 dtemp += dx[i +dx_off]*dy[i +dy_off];
288 scales a vector by a constant.
289 jack dongarra, linpack, 3/11/78.
291 void dscal( int n, double da, double dx[], int dx_off, int incx)
296 // code for increment not equal to 1
298 for (i = 0; i < nincx; i += incx)
301 // code for increment equal to 1
302 for (i = 0; i < n; i++)
309 finds the index of element having max. absolute value.
310 jack dongarra, linpack, 3/11/78.
312 int idamax( int n, double dx[], int dx_off, int incx)
321 } else if (incx != 1) {
322 // code for increment not equal to 1
323 dmax = abs(dx[0 +dx_off]);
325 for (i = 1; i < n; i++) {
326 dtemp = abs(dx[ix + dx_off]);
334 // code for increment equal to 1
336 dmax = abs(dx[0 +dx_off]);
337 for (i = 1; i < n; i++) {
338 dtemp = abs(dx[i + dx_off]);
349 estimate unit roundoff in quantities of size x.
350 this program should function properly on all systems
351 satisfying the following two assumptions,
352 1. the base used in representing dfloating point
353 numbers is not a power of three.
354 2. the quantity a in statement 10 is represented to
355 the accuracy used in dfloating point variables
356 that are stored in memory.
357 the statement number 10 and the go to 10 are intended to
358 force optimizing compilers to generate code satisfying
360 under these assumptions, it should be true that,
361 a is not exactly equal to four-thirds,
362 b has a zero for its last bit or digit,
363 c is not exactly equal to one,
364 eps measures the separation of 1.0 from
365 the next larger dfloating point number.
366 the developers of eispack would appreciate being informed
367 about any systems where these assumptions do not hold.
369 *****************************************************************
370 this routine is one of the auxiliary routines used by eispack iii
371 to avoid machine dependencies.
372 *****************************************************************
374 this version dated 4/6/83.
376 double epslon (double x)
390 void dmxpy ( int n1, double y[], int n2, int ldm, double x[], double m[][])
393 // cleanup odd vector
394 for (j = 0; j < n2; j++) {
395 for (i = 0; i < n1; i++) {
396 y[i] += x[j]*m[j][i];
401 public static void JGFvalidate(JGFLUFactBench lub) {
412 for (i = 0; i < lub.n; i++) {
415 lub.norma = lub.matgen(lub.a,lub.lda,lub.n,lub.b);
416 for (i = 0; i < lub.n; i++) {
417 lub.b[i] = -(lub.b[i]);
420 lub.dmxpy(lub.n,lub.b,lub.n,lub.lda,lub.x,lub.a);
423 for (i = 0; i < lub.n; i++) {
424 //resid = (resid > abs(b[i])) ? resid : abs(b[i]);
425 //normx = (normx > abs(x[i])) ? normx : abs(x[i]);
426 if (lub.resid <= abs(lub.b[i])) lub.resid = lub.abs(lub.b[i]);
427 if (lub.normx <= abs(lub.x[i])) lub.normx = lub.abs(lub.x[i]);
429 eps = lub.epslon((double)1.0);
430 residn = lub.resid/( lub.n*lub.norma*lub.normx*eps );
433 if (residn > ref[size]) {
434 System.out.println("Validation failed");
435 System.out.println("Computed Norm Res = " + (long) residn);
436 System.out.println("Reference Norm Res = " + (long) ref[size]);