1 |
< |
// Barrier version of Jacobi iteration |
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 |
|
import java.util.concurrent.*; |
8 |
|
|
9 |
+ |
/** Barrier version of Jacobi iteration */ |
10 |
|
public class FJPhaserJacobi { |
11 |
|
|
12 |
|
static int dimGran; |
13 |
|
|
14 |
|
static final double EPSILON = 0.0001; // convergence criterion |
15 |
|
|
16 |
< |
public static void main(String[] args) { |
16 |
> |
public static void main(String[] args) throws Exception { |
17 |
|
int n = 2048; |
18 |
|
int steps = 1000; |
19 |
|
try { |
28 |
|
return; |
29 |
|
} |
30 |
|
|
31 |
< |
ForkJoinPool fjp = new ForkJoinPool(); |
31 |
> |
// ForkJoinPool fjp = new ForkJoinPool(); |
32 |
> |
ForkJoinPool fjp = ForkJoinPool.commonPool(); |
33 |
> |
|
34 |
|
// int granularity = (n * n / fjp.getParallelism()) / 2; |
35 |
|
int granularity = n * n / fjp.getParallelism(); |
36 |
|
dimGran = (int)(Math.sqrt(granularity)); |
46 |
|
for (int j = 1; j < dim-1; ++j) |
47 |
|
a[i][j] = smallVal; |
48 |
|
} |
49 |
< |
int nreps = 3; |
49 |
> |
int nreps = 10; |
50 |
|
for (int rep = 0; rep < nreps; ++rep) { |
51 |
|
// Fill all edges with 1's. |
52 |
|
for (int k = 0; k < dim; ++k) { |
64 |
|
|
65 |
|
System.out.println("Compute Time: " + secs); |
66 |
|
System.out.println(fjp); |
67 |
< |
|
67 |
> |
Thread.sleep(1000); |
68 |
|
} |
62 |
– |
|
69 |
|
} |
70 |
|
|
71 |
|
static class Segment extends CyclicAction { |
143 |
|
public void compute() { |
144 |
|
int rows = hiRow - loRow + 1; |
145 |
|
int cols = hiCol - loCol + 1; |
146 |
< |
int rblocks = (int)(Math.round((float)rows / dimGran)); |
147 |
< |
int cblocks = (int)(Math.round((float)cols / dimGran)); |
146 |
> |
int rblocks = Math.round((float)rows / dimGran); |
147 |
> |
int cblocks = Math.round((float)cols / dimGran); |
148 |
|
|
149 |
|
int n = rblocks * cblocks; |
150 |
|
|
177 |
|
} |
178 |
|
} |
179 |
|
} |
174 |
– |
|