#include #include #include #include #include "nbgenerator.hh" #include "nbio.hh" #include "nbtypes.hh" #include "nbstopwatch.hh" /* * Global constants */ /* physical parameters */ const double mass_sun = 1.988435e30; const double pc_in_m = 3.08567758129e16; const double gamma_si = 6.67428e-11; /* set gravity constant */ const double G = gamma_si/(pc_in_m*pc_in_m*pc_in_m)*mass_sun*(365.25*86400)*(365.25*86400); /* The epsilon^2 for the softening */ const double epsilon2 = 1E-3; /* Block size for tiling */ const int B = 50; /** * Compute acceleration (with tiling) * * \param[in] n Number of bodies * \param[in] r Positions of the bodies * \param[in] m Masses of the bodies * \param[out] a The computed accelerations of the bodies * * The inner loop executes 26 floating point operations and is executed * ((n*n)-n)/2 times, resulting in 13*n*(n-1) floating point operations total * per call to acceleration(). */ void acceleration (int n, vector3* r, double* m, vector3* a) { int I,J,i,j,iend,jstart,jend; double d0,d1,d2,d,d_sq,factori,factorj; double invfact; vector3 Ri[B], Rj[B], Ai[B], Aj[B]; double Mi[B], Mj[B]; /* compute acceleration exploiting symmetry */ for (I=0; I
\n", argv[0]); return 1; } sscanf(argv[1],"%d",&N); sscanf(argv[2],"%lf",&Tend); sscanf(argv[3],"%d",&mod); sscanf(argv[4],"%lf",&dt); sscanf(argv[5],"%d",&numthreads); /* arrays for position, velocity, mass, and acceleration of the bodies */ vector3* r = new vector3[N]; vector3* v = new vector3[N]; double* m = new double[N]; vector3* a = new vector3[N]; /* loop counter */ int i; /* count the time steps done */ int k = 0; /* for measuring the elapsed time and calculating the MFLOP rate */ double start,stop,elapsed,flop; /* get initial values from one of the generator functions */ int seed = 42; collision(N,seed,r,v,m); /* initialise the acceleration */ for (i=0; i