1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38 package ffx.numerics.fft;
39
40 import static org.junit.Assert.assertEquals;
41
42 import edu.rit.pj.ParallelTeam;
43 import java.util.Arrays;
44 import java.util.Collection;
45 import java.util.Random;
46
47 import ffx.utilities.FFXTest;
48 import org.junit.After;
49 import org.junit.Before;
50 import org.junit.Test;
51 import org.junit.runner.RunWith;
52 import org.junit.runners.Parameterized;
53 import org.junit.runners.Parameterized.Parameters;
54
55
56 @RunWith(Parameterized.class)
57 public class Complex3DParallelTest extends FFXTest {
58
59 private final String info;
60 private final int nx;
61 private final int ny;
62 private final int nz;
63 private final int tot;
64 private final double[] data;
65 private final double[] expected;
66 private final double[] recip;
67 private final ParallelTeam parallelTeam;
68 private final double tolerance = 1.0e-14;
69
70 public Complex3DParallelTest(String info, int nx, int ny, int nz, int nCPUs) {
71 this.info = info;
72 this.nx = nx;
73 this.ny = ny;
74 this.nz = nz;
75 tot = nx * ny * nz;
76 data = new double[tot * 2];
77 expected = new double[tot];
78 recip = new double[tot];
79 parallelTeam = new ParallelTeam(nCPUs);
80 }
81
82 @Parameters
83 public static Collection<Object[]> data() {
84 return Arrays.asList(
85 new Object[][] {
86 {"Test nx=32, ny=32, nz=32, nCPUs=1}", 32, 32, 32, 1},
87 {"Test nx=32, ny=32, nz=32, nCPUs=2}", 32, 32, 32, 2},
88 {"Test nx=32, ny=45, nz=21, nCPUs=1}", 32, 45, 21, 1},
89 {"Test nx=32, ny=45, nz=21, nCPUs=2}", 32, 45, 21, 2}
90 });
91 }
92
93 @Before
94 public void setUp() {
95 Random random = new Random();
96 for (int i = 0; i < tot; i++) {
97 int index = i * 2;
98 double r = random.nextDouble();
99 data[index] = r;
100 expected[i] = r;
101 recip[i] = 1.0e0;
102 }
103 }
104
105 @After
106 public void after() throws Exception {
107 parallelTeam.shutdown();
108 }
109
110
111 @Test
112 public void testConvolution() {
113 Complex3DParallel complex3D = new Complex3DParallel(nx, ny, nz, parallelTeam);
114 complex3D.setRecip(recip);
115 complex3D.convolution(data);
116 for (int i = 0; i < tot; i++) {
117 int index = i * 2;
118 double actual = data[index] / tot;
119 double orig = expected[i];
120 assertEquals(info, orig, actual, tolerance);
121 }
122 }
123
124
125 @Test
126 public void testFft() {
127 Complex3DParallel complex3D = new Complex3DParallel(nx, ny, nz, parallelTeam);
128 complex3D.fft(data);
129 complex3D.ifft(data);
130 for (int i = 0; i < tot; i++) {
131 int index = i * 2;
132 double actual = data[index] / tot;
133 double orig = expected[i];
134 assertEquals(info, orig, actual, tolerance);
135 }
136 }
137 }