5
d = int(sys.argv[1]) #Distributed
6
n = int(sys.argv[2]) #Number of bodies
7
k = int(sys.argv[3]) #Number of iterations
16
G = 1 #Gravitational constant
17
dT = 0.01 #Time increment
21
M = np.random.random_sample((n,1))
23
#np.ufunc_random(MT,MT)
24
MT = np.random.random_sample((1,n))
26
#np.ufunc_random(Px,Px)
27
Px = np.random.random_sample((n,1))
29
#np.ufunc_random(Py,Py)
30
Py = np.random.random_sample((n,1))
32
#np.ufunc_random(Pz,Pz)
33
Pz = np.random.random_sample((n,1))
35
#np.ufunc_random(PxT,PxT)
36
PxT = np.random.random_sample((1,n))
38
#np.ufunc_random(PyT,PyT)
39
PyT = np.random.random_sample((1,n))
41
#np.ufunc_random(PzT,PzT)
42
PzT = np.random.random_sample((1,n))
44
#np.ufunc_random(Vx,Vx)
45
Vx = np.random.random_sample((n,1))
47
#np.ufunc_random(Vy,Vy)
48
Vy = np.random.random_sample((n,1))
50
#np.ufunc_random(Vz,Vz)
51
Vz = np.random.random_sample((n,1))
53
OnesCol = np.zeros((n,1), dtype=float)+1.0
54
OnesRow = np.zeros((1,n), dtype=float)+1.0
55
#Identity= array(diag([1]*n), dtype=double)
61
#distance between all pairs of objects
62
Fx = np.dot(OnesCol, PxT) - np.dot(Px, OnesRow)
63
Fy = np.dot(OnesCol, PyT) - np.dot(Py, OnesRow)
64
Fz = np.dot(OnesCol, PzT) - np.dot(Pz, OnesRow)
72
#mutual forces between all pairs of objects
77
#F = F - diag(diag(F))#set 'self attraction' to 0
87
#net force on each body
88
Fnet_x = np.add.reduce(Fx,1)
89
Fnet_y = np.add.reduce(Fy,1)
90
Fnet_z = np.add.reduce(Fz,1)
92
Fnet_x = Fnet_x[:,np.newaxis]
93
Fnet_y = Fnet_y[:,np.newaxis]
94
Fnet_z = Fnet_z[:,np.newaxis]
114
print 'nbody with #bodies: ', n,', iter: ', i+1, 'in sec: ', time.time() - stime,
116
print " (Dist) notes: %s"%sys.argv[4]
118
print " (Non-Dist) notes: %s"%sys.argv[4]
124
#distance between all pairs of objects
125
Fx = dot(OnesCol, PxT) - dot(Px, OnesRow)
126
Fy = dot(OnesCol, PyT) - dot(Py, OnesRow)
127
Fz = dot(OnesCol, PzT) - dot(Pz, OnesRow)
129
Dsq = Fx * Fx + Fy * Fy + Fx * Fz #+ Identity
132
#mutual forces between all pairs of objects
133
F = G * dot(M, MT) / Dsq
135
#F = F - diag(diag(F))#set 'self attraction' to 0
140
#net force on each body
141
Fnet_x = add.reduce(Fx,1)
142
Fnet_x = add.reduce(Fy,1)
143
Fnet_x = add.reduce(Fz,1)
146
Vx += Fnet_x[:,newaxis] * dT / M
147
Vy += Fnet_y[:,newaxis] * dT / M
148
Vz += Fnet_z[:,newaxis] * dT / M