1 |
+ |
/* |
2 |
+ |
* Written by Doug Lea with assistance from members of JCP JSR-166 |
3 |
+ |
* Expert Group and released to the public domain, as explained at |
4 |
+ |
* http://creativecommons.org/publicdomain/zero/1.0/ |
5 |
+ |
*/ |
6 |
+ |
|
7 |
|
// Barrier version of Jacobi iteration |
8 |
|
|
9 |
|
import java.util.*; |
17 |
|
/** |
18 |
|
* The maximum submatrix length (both row-wise and column-wise) |
19 |
|
* for any Segment |
20 |
< |
**/ |
15 |
< |
|
20 |
> |
*/ |
21 |
|
static final double EPSILON = 0.0001; // convergence criterion |
22 |
|
|
23 |
|
static int dimGran; |
38 |
|
} |
39 |
|
|
40 |
|
int granularity = n * n / nprocs; |
41 |
< |
dimGran = (int)(Math.sqrt(granularity)); |
41 |
> |
dimGran = (int) Math.sqrt(granularity); |
42 |
|
|
43 |
|
// allocate enough space for edges |
44 |
|
int dim = n+2; |
66 |
|
driver.compute(); |
67 |
|
|
68 |
|
long time = System.currentTimeMillis() - startTime; |
69 |
< |
double secs = ((double)time) / 1000.0; |
69 |
> |
double secs = (double) time / 1000.0; |
70 |
|
|
71 |
|
System.out.println("Compute Time: " + secs); |
72 |
|
} |
99 |
|
barrier.register(); |
100 |
|
} |
101 |
|
|
97 |
– |
|
102 |
|
public void run() { |
103 |
|
try { |
104 |
|
double[][] a = A; |
111 |
|
double[][] tmp = a; a = b; b = tmp; |
112 |
|
} |
113 |
|
} |
114 |
< |
catch(Exception ex) { |
114 |
> |
catch (Exception ex) { |
115 |
|
ex.printStackTrace(); |
116 |
|
return; |
117 |
|
} |
137 |
|
|
138 |
|
} |
139 |
|
|
136 |
– |
|
140 |
|
static class Driver { |
141 |
|
double[][] A; // matrix to get old values from |
142 |
|
double[][] B; // matrix to put new values into |
160 |
|
|
161 |
|
int rows = hiRow - loRow + 1; |
162 |
|
int cols = hiCol - loCol + 1; |
163 |
< |
int rblocks = (int)(Math.round((float)rows / dimGran)); |
164 |
< |
int cblocks = (int)(Math.round((float)cols / dimGran)); |
163 |
> |
int rblocks = Math.round((float) rows / dimGran); |
164 |
> |
int cblocks = Math.round((float) cols / dimGran); |
165 |
|
|
166 |
|
int n = rblocks * cblocks; |
167 |
|
|
204 |
|
System.out.println("Max diff after " + steps + " steps = " + maxd); |
205 |
|
} |
206 |
|
} |
204 |
– |
|
205 |
– |
|
207 |
|
} |