2 # Copyright (C) 2006-2009, Parrot Foundation.
4 # The Computer Language Shootout
5 # http://shootout.alioth.debian.org/
8 # Contributed by Joshua Isom
9 # speed up from 1m25 to 6s by Leopold Toetsch
10 # changed default value to 1000 to match shootout default (karl)
20 # save on repetition of code
21 .macro InitBodies (bodies, i, num1, num2, num3, num4, num5, num6, num7)
25 $N3 = .num7 * 39.478417604357428
26 $P0 = new 'FixedFloatArray'
29 .bodies[.i; x] = .num1
30 .bodies[.i; y] = .num2
31 .bodies[.i; z] = .num3
40 .local int argc, n, nbodies
43 unless argc > 1 goto argsok
48 bodies = new 'FixedPMCArray'
51 .InitBodies(bodies, 0, 0, 0, 0, 0, 0, 0, 1)
53 .InitBodies(bodies, 1,
54 4.84143144246472090e+00,
55 -1.16032004402742839e+00,
56 -1.03622044471123109e-01,
57 1.66007664274403694e-03,
58 7.69901118419740425e-03,
59 -6.90460016972063023e-05,
60 9.54791938424326609e-04)
62 .InitBodies(bodies, 2,
63 8.34336671824457987e+00,
64 4.12479856412430479e+00,
65 -4.03523417114321381e-01,
66 -2.76742510726862411e-03,
67 4.99852801234917238e-03,
68 2.30417297573763929e-05,
69 2.85885980666130812e-04)
71 .InitBodies(bodies, 3,
72 1.28943695621391310e+01,
73 -1.51111514016986312e+01,
74 -2.23307578892655734e-01,
75 2.96460137564761618e-03,
76 2.37847173959480950e-03,
77 -2.96589568540237556e-05,
78 4.36624404335156298e-05)
80 .InitBodies(bodies, 4,
81 1.53796971148509165e+01,
82 -2.59193146099879641e+01,
83 1.79258772950371181e-01,
84 2.68067772490389322e-03,
85 1.62824170038242295e-03,
86 -9.51592254519715870e-05,
87 5.15138902046611451e-05)
90 offset_momentum(nbodies, bodies)
91 $N0 = energy(nbodies, bodies)
93 spf = new 'FixedFloatArray'
96 $S0 = sprintf "%.9f\n", spf
101 unless i < n goto endfor
102 advance(nbodies, bodies, 0.01)
107 $N0 = energy(nbodies, bodies)
109 $S0 = sprintf "%.9f\n", spf
117 .local num px, py, pz
124 unless i < nbodies goto endfor
140 # bodies[0].vx = - px / solar_mass;
141 px /= -39.478417604357428
143 py /= -39.478417604357428
145 pz /= -39.478417604357428
157 unless i < nbodies goto endfor_0
159 # e += 0.5 * b->mass * (b->vx * b->vx + b->vy * b->vy + b->vz * b->vz);
160 $N0 = bodies[i; m] # mass
163 $N1 = bodies[i; vx] # vx
166 $N1 = bodies[i; vy] # vy
170 $N1 = bodies[i; vz] # vz
180 unless j < nbodies goto endfor_1
181 .local num dx, dy, dz, distance
198 # distance = sqrt(dx * dx + dy * dy + dz * dz);
206 # e -= (b->mass * b2->mass) / distance;
228 .local num dx, dy, dz, distance, mag
229 .local num bx, by, bz, bm, bvx, bvy, bvz
230 .local num b2x, b2y, b2z, b2m
234 unless i < nbodies goto endfor_0
246 unless j < nbodies goto endfor_1
260 # distance = sqrt(dx * dx + dy * dy + dz * dz);
268 # mag = dt / (distance * distance * distance);
269 $N0 = distance * distance
273 # b->vx -= dx * b2->mass * mag;
278 # b->vy -= dy * b2->mass * mag;
283 # b->vz -= dz * b2->mass * mag;
288 # b2->vx += dx * b->mass * mag;
295 # b2->vy += dy * b->mass * mag;
302 # b2->vz += dz * b->mass * mag;
322 unless i < nbodies goto endfor_2
324 # b->x += dt * b->vx;
331 # b->y += dt * b->vy;
338 # b->z += dt * b->vz;
355 # vim: expandtab shiftwidth=4 ft=pir: