comparison graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/VecmathNBodyTest.java @ 18163:c88ab4f1f04a

re-enabled Checkstyle with the release of 6.0 that supports Java 8; fixed existing Checkstyle warnings
author Doug Simon <doug.simon@oracle.com>
date Fri, 24 Oct 2014 16:18:10 +0200
parents 976c6cb2bf69
children
comparison
equal deleted inserted replaced
18162:ab62800259ff 18163:c88ab4f1f04a
44 /** 44 /**
45 * 45 *
46 */ 46 */
47 private static final long serialVersionUID = 1L; 47 private static final long serialVersionUID = 1L;
48 48
49 public Body(float _x, float _y, float _z, float _m) { 49 public Body(float x, float y, float z, float m) {
50 super(_x, _y, _z); 50 super(x, y, z);
51 m = _m; 51 this.m = m;
52 v = new Vector3f(0, 0, 0); 52 this.v = new Vector3f(0, 0, 0);
53 } 53 }
54 54
55 float m; 55 float m;
56 Vector3f v; 56 Vector3f v;
57 57
58 public float getM() { 58 public float getM() {
59 return m; 59 return m;
60 } 60 }
61 61
62 public Vector3f computeAcc(Body[] in_bodies, float espSqr1, float delT1) { 62 public Vector3f computeAcc(Body[] inBodies, float espSqr1, float delT1) {
63 Vector3f acc = new Vector3f(); 63 Vector3f acc = new Vector3f();
64 64
65 for (Body b : in_bodies) { 65 for (Body b : inBodies) {
66 Vector3f d = new Vector3f(); 66 Vector3f d = new Vector3f();
67 d.sub(b, this); 67 d.sub(b, this);
68 float invDist = 1.0f / (float) Math.sqrt(d.lengthSquared() + espSqr1); 68 float invDist = 1.0f / (float) Math.sqrt(d.lengthSquared() + espSqr1);
69 float s = b.getM() * invDist * invDist * invDist; 69 float s = b.getM() * invDist * invDist * invDist;
70 acc.scaleAdd(s, d, acc); 70 acc.scaleAdd(s, d, acc);
74 acc.scale(delT1); 74 acc.scale(delT1);
75 return acc; 75 return acc;
76 } 76 }
77 } 77 }
78 78
79 @Result Body[] in_bodies = new Body[bodies]; 79 @Result Body[] inBodies = new Body[bodies];
80 @Result Body[] out_bodies = new Body[bodies]; 80 @Result Body[] outBodies = new Body[bodies];
81 81
82 static Body[] seed_bodies = new Body[bodies]; 82 static Body[] seedBodies = new Body[bodies];
83 83
84 static { 84 static {
85 java.util.Random randgen = new Random(0); 85 java.util.Random randgen = new Random(0);
86 final float maxDist = width / 4; 86 final float maxDist = width / 4;
87 for (int body = 0; body < bodies; body++) { 87 for (int body = 0; body < bodies; body++) {
89 final float phi = (float) (randgen.nextFloat() * Math.PI * 2); 89 final float phi = (float) (randgen.nextFloat() * Math.PI * 2);
90 final float radius = randgen.nextFloat() * maxDist; 90 final float radius = randgen.nextFloat() * maxDist;
91 float x = (float) (radius * Math.cos(theta) * Math.sin(phi)) + width / 2; 91 float x = (float) (radius * Math.cos(theta) * Math.sin(phi)) + width / 2;
92 float y = (float) (radius * Math.sin(theta) * Math.sin(phi)) + height / 2; 92 float y = (float) (radius * Math.sin(theta) * Math.sin(phi)) + height / 2;
93 float z = (float) (radius * Math.cos(phi)); 93 float z = (float) (radius * Math.cos(phi));
94 seed_bodies[body] = new Body(x, y, z, mass); 94 seedBodies[body] = new Body(x, y, z, mass);
95 } 95 }
96 } 96 }
97 97
98 @Override 98 @Override
99 public void runTest() { 99 public void runTest() {
100 System.arraycopy(seed_bodies, 0, in_bodies, 0, seed_bodies.length); 100 System.arraycopy(seedBodies, 0, inBodies, 0, seedBodies.length);
101 for (int b = 0; b < bodies; b++) { 101 for (int b = 0; b < bodies; b++) {
102 out_bodies[b] = new Body(0, 0, 0, mass); 102 outBodies[b] = new Body(0, 0, 0, mass);
103 } 103 }
104 // no local copies of arrays so we make it an instance lambda 104 // no local copies of arrays so we make it an instance lambda
105 105
106 dispatchLambdaKernel(bodies, (gid) -> { 106 dispatchLambdaKernel(bodies, (gid) -> {
107 Body inb = in_bodies[gid]; 107 Body inb = inBodies[gid];
108 Body outb = out_bodies[gid]; 108 Body outb = outBodies[gid];
109 Vector3f acc = inb.computeAcc(in_bodies, espSqr, delT); 109 Vector3f acc = inb.computeAcc(inBodies, espSqr, delT);
110 110
111 Vector3f tmpPos = new Vector3f(); 111 Vector3f tmpPos = new Vector3f();
112 tmpPos.scaleAdd(delT, inb.v, inb); 112 tmpPos.scaleAdd(delT, inb.v, inb);
113 tmpPos.scaleAdd(0.5f * delT, acc, tmpPos); 113 tmpPos.scaleAdd(0.5f * delT, acc, tmpPos);
114 outb.set(tmpPos); 114 outb.set(tmpPos);