/*------------------------------------------*/ /* An Example of N-Body Simulation. */ /* Modified by Saleh Elmohamed 10/20/98 */ /* NPAC, CPS-615 , Fall 98. */ /*------------------------------------------*/ /* Function: */ /* A simple version of an n-body code. */ /* It uses the simple but highly */ /* suboptimal n^2 algorithm, and does not */ /* take advantage of symmetry. */ /* The time integrator is a simple leapfrog */ /* scheme. */ /*------------------------------------------*/ #include "mpi.h" #include #include extern void srand48(); extern double drand48(); /* Pipeline version of the algorithm... but the MPE is not supported in SunMPI ....... */ /* we really need the velocities as well... */ typedef struct { double x, y, z; double mass; } Particle; /* Save the forces and old velocities */ typedef struct { double xold, yold, zold; double fx, fy, fz; } ParticleV; #define MAX_PARTICLES 4000 /* This is 2-D only */ void ComputeForces(Particle *particles, ParticleV *pv, int npart, Particle *recvbuf, int rlen, double *max_f ) { int i, j; double xi, yi, mi, rx, ry, mj, r, fx, fy; double xnew, ynew, rmin; /* Compute forces (2D only) */ for (i=0; i *max_f) *max_f = fx; } } void PrintParticles(Particle *particles, int npart, double t ) { int i; for (i=0; i 1) npart = atoi(argv[1]) / size; if (npart > MAX_PARTICLES) MPI_Abort( MPI_COMM_WORLD, 1 ); MPI_Allreduce( &npart, &totpart, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD ); cnt = 100; MPI_Type_contiguous( 4, MPI_DOUBLE, &particletype ); MPI_Type_commit( &particletype ); /* Generate the initial values */ srand48( rank * 117 ); for (i=0; i= dt. We leave a little room */ dt_est = 1.0/sqrt(max_f); /* Set a minimum: */ if (dt_est < 1.0e-6) dt_est = 1.0e-6; MPI_Allreduce( &dt_est, &dt_new, 1, MPI_DOUBLE, MPI_MIN, MPI_COMM_WORLD ); /* Modify time step */ if (dt_new < dt) { dt_old = dt; dt = dt_new; if (debug_flag && rank == 0) printf( "#New time step is %lf\n", dt ); } else if (dt_new > 4.0 * dt) { dt_old = dt; dt *= 2.0; if (debug_flag && rank == 0) printf( "#New time step is %lf\n", dt ); } /* We could do graphics here (move particles on the display) */ } time = MPI_Wtime() - time; if (rank == 0) { printf( "#Computed %d particles in %lf seconds\n", totpart, time ); } #if 0 MPE_Pipe_free( &pipe ); MPI_Type_free( &particletype ); #endif MPI_Finalize(); }