Hi,

Daniel Carrera <[email protected]> writes:
> I already have simulation software that works well enough for this. I
> just wanted to experiment with Julia to see if this could be made
> parallel. An irritating problem with all the codes that solve
> planetary systems is that they are all serial -- this problem is
> apparently hard to parallelize.

I was not very lucky with getting Julia in parallel to perform
efficiently, but (and this is a bit off-topic) parallelizing simple
N-body codes is quite easy. I have a demo code for this in Fortran. The
serial part just does basically the same as your Julia code (plus
calculate also the new velocities and positions for all the bodies):

,----
|   DO t = 0.0, t_end, dt
|      v = v + a * dt/2
|      r = r + v * dt
| 
|      a = 0.0
|      DO i = 1,n
|         DO j = i+1,n
|            rji = r(j,:) - r(i,:)
|            r2 = SUM(rji**2)
|            r3 = r2 * SQRT(r2)
|            a(i,:) = a(i,:) + m(j) * rji / r3
|            a(j,:) = a(j,:) - m(i) * rji / r3
|         END DO
|      END DO
|      
|      v = v + a * dt/2
| 
|      t_out = t_out + dt
|      IF (t_out >= dt_out) THEN
|         DO i = 1,n
|            PRINT*, r(i,:)
|         END DO
|         t_out = 0.0
|      END IF
| 
|   END DO
`----

The parallel version (with MPI) of this toy code is quite efficient. For
1000 bodies and 10k iterations, the serial code at my work station
measured with 'time' takes ~138 seconds. The parallel version (running
in 4 processors) takes only ~33 seconds (by the way, showing that
super-linear speedup, though unusual, is possible :-)

[angelv@comer ~/NBODY]$ time ./nbody_serial < stars_sphere.txt >
stars_serial.out
137.414u 0.079s 2:17.83 99.7%0+0k 0+9056io 0pf+0w

[angelv@comer ~/NBODY]$ time mpirun -np 4 ./nbody_parallel <
stars_sphere.txt > stars_parallel.out
110.891u 0.954s 0:32.80 340.9%0+0k 15128+8992io 64pf+0w

Since this doesn't involve Julia at all, if you want further details or
the code itself, perhaps we can talk off-list to avoid non-Julia noise
in the list.

Cheers,
-- 
Ángel de Vicente
http://www.iac.es/galeria/angelv/          

Reply via email to