New benchmark
[IRC.git] / Robust / src / Benchmarks / Prefetch / LUFact / java / LinpackRunner.java
1 /**************************************************************************
2 *                                                                         *
3 *         Java Grande Forum Benchmark Suite - Thread Version 1.0          *
4 *                                                                         *
5 *                            produced by                                  *
6 *                                                                         *
7 *                  Java Grande Benchmarking Project                       *
8 *                                                                         *
9 *                                at                                       *
10 *                                                                         *
11 *                Edinburgh Parallel Computing Centre                      *
12 *                                                                         *
13 *                email: epcc-javagrande@epcc.ed.ac.uk                     *
14 *                                                                         *
15 *                                                                         *
16 *      This version copyright (c) The University of Edinburgh, 2001.      *
17 *                         All rights reserved.                            *
18 *                                                                         *
19 **************************************************************************/
20
21 class LinpackRunner extends Thread {
22   int id,lda,n,info,ipvt[];
23   double a[][];
24   TournamentBarrier br;
25   int nthreads;
26
27   public LinpackRunner(int id, double a[][], int lda, int n, int ipvt[],TournamentBarrier br, int nthreads) {
28     this.id = id;
29     this.a=a;
30     this.lda=lda;
31     this.n=n;
32     this.ipvt=ipvt;
33     this.br=br;
34     //this.instr = instr;
35     this.nthreads = nthreads;
36   }
37
38   double abs (double d) {
39     //return (d >= 0) ? d : -d;
40     if (d >= 0) return d;
41     else return -d;
42   }
43
44   public void run() {
45     double[] col_k, col_j;
46     double t;
47     int j,k,kp1,l,nm1;
48     int info;
49     int slice,ilow,iupper;
50     // gaussian elimination with partial pivoting
51     info = 0;
52     nm1 = n - 1;
53     if (nm1 >=  0) {
54       for (k = 0; k < nm1; k++) {
55         col_k = a[k];
56         kp1 = k + 1;
57         // find l = pivot index
58         l = idamax(n-k,col_k,k,1) + k;
59         if(id==0) {
60           ipvt[k] = l;
61         }
62         // synchronise threads
63         br.DoBarrier(id);
64         // zero pivot implies this column already triangularized
65         if (col_k[l] != 0) {
66           br.DoBarrier(id);
67           // interchange if necessary
68           if(id == 0 ) {
69             if (l != k) {
70               t = col_k[l];
71               col_k[l] = col_k[k];
72               col_k[k] = t;
73             }
74           }
75           // synchronise threads
76           br.DoBarrier(id);
77           // compute multipliers
78           t = -1.0/col_k[k];
79           if(id == 0) {
80             dscal(n-(kp1),t,col_k,kp1,1);
81           }
82           // synchronise threads
83           br.DoBarrier(id);
84           // row elimination with column indexing
85           slice = ((n-kp1) + nthreads-1)/nthreads;
86           ilow = (id*slice)+kp1;
87           iupper = ((id+1)*slice)+kp1;
88           if (iupper > n ) iupper=n;
89           if (ilow > n ) ilow=n;
90           for (j = ilow; j < iupper; j++) {
91             col_j = a[j];
92             t = col_j[l];
93             if (l != k) {
94               col_j[l] = col_j[k];
95               col_j[k] = t;
96             }
97             daxpy(n-(kp1),t,col_k,kp1,1,
98                 col_j,kp1,1);
99           }
100           // synchronise threads
101           br.DoBarrier(id);
102         } else {
103           info = k;
104         }
105         br.DoBarrier(id);
106       }
107     }
108
109     if(id==0) {
110       ipvt[n-1] = n-1;
111     }
112     if (a[(n-1)][(n-1)] == 0) info = n-1;
113   }
114
115   /*
116      finds the index of element having max. absolute value.
117      jack dongarra, linpack, 3/11/78.
118      */
119   int idamax( int n, double dx[], int dx_off, int incx)
120   {
121     double dmax, dtemp;
122     int i, ix, itemp=0;
123
124     if (n < 1) {
125       itemp = -1;
126     } else if (n ==1) {
127       itemp = 0;
128     } else if (incx != 1) {
129       // code for increment not equal to 1
130       dmax = abs(dx[0 +dx_off]);
131       ix = 1 + incx;
132       for (i = 1; i < n; i++) {
133         dtemp = abs(dx[ix + dx_off]);
134         if (dtemp > dmax)  {
135           itemp = i;
136           dmax = dtemp;
137         }
138         ix += incx;
139       }
140     } else {
141       // code for increment equal to 1
142       itemp = 0;
143       dmax = abs(dx[0 +dx_off]);
144       for (i = 1; i < n; i++) {
145         dtemp = abs(dx[i + dx_off]);
146         if (dtemp > dmax) {
147           itemp = i;
148           dmax = dtemp;
149         }
150       }
151     }
152     return (itemp);
153   }
154
155   /*
156      scales a vector by a constant.
157      jack dongarra, linpack, 3/11/78.
158      */
159   void dscal( int n, double da, double dx[], int dx_off, int incx)
160   {
161     int i,nincx;
162     if (n > 0) {
163       if (incx != 1) {
164         // code for increment not equal to 1
165         nincx = n*incx;
166         for (i = 0; i < nincx; i += incx)
167           dx[i +dx_off] *= da;
168       } else {
169         // code for increment equal to 1
170         for (i = 0; i < n; i++)
171           dx[i +dx_off] *= da;
172       }
173     }
174   }
175
176   /*
177      constant times a vector plus a vector.
178      jack dongarra, linpack, 3/11/78.
179      */
180   void daxpy( int n, double da, double dx[], int dx_off, int incx,
181       double dy[], int dy_off, int incy)
182   {
183     int i,ix,iy;
184     if ((n > 0) && (da != 0)) {
185       if (incx != 1 || incy != 1) {
186         // code for unequal increments or equal increments not equal to 1
187         ix = 0;
188         iy = 0;
189         if (incx < 0) ix = (-n+1)*incx;
190         if (incy < 0) iy = (-n+1)*incy;
191         for (i = 0;i < n; i++) {
192           dy[iy +dy_off] += da*dx[ix +dx_off];
193           ix += incx;
194           iy += incy;
195         }
196         return;
197       } else {
198         // code for both increments equal to 1
199         for (i=0; i < n; i++)
200           dy[i +dy_off] += da*dx[i +dx_off];
201       }
202     }
203   }
204 }
205