/* Function that creates a dataset for testing 0 (spherical octant) 1 (uniform cude) */ void create_dataset(float *X, int N, int dist){ switch(dist){ case 0: cube(X, N); break; case 1: plummer(X, N); break; default: plummer(X, N); break; break; } }
nemo_main() { anisorad = getdparam("anisorad"); mcutoff = getdparam("mcutoff"); ntab = MXTB; plummer(); writemodel(getparam("out")); }
/** * main program */ int main (int argc, char** argv) { /* hold positions, velocities, masses, and accelerations for the bodies */ double3 *x; double3 *v; double *m; double3 *a; /* temporary buffer given to leapfrog() so it can store the old acceleration values there */ double3 *temp; /* loop counter */ int i; /* count the time steps done */ int k = 0; /* base name for the output files */ char base[]="test1"; /* buffer to construct the whole output filename in */ char name[256]; /* handle for the output file */ FILE *file; /* accumulated simulation time and time step size. These will be modified when reading initial values from a file */ double t = 0, dt = 1E-3; /* for measuring the elapsed time and calculating the MFLOP rate */ double start,stop,elapsed,flop; /* number of bodies (read from commandline) */ int n; /* number of time steps to do (read from commandline) */ int timesteps; /* when to measure MFLOP rate and write output files: every mod time steps (read from commandline) */ int mod; int B; /** * parse commandline arguments */ if (argc!=5) { printf("usage: nbody_vanilla <nbodies> <timesteps> <every> <Blocksize>\n"); return 1; } sscanf(argv[1],"%d",&n); sscanf(argv[2],"%d",×teps); sscanf(argv[3],"%d",&mod); sscanf(argv[4],"%d",&B); #if 0 /* get initial value from a data file */ file = fopen("plummer10000.vtk","r"); if (file==NULL) { printf("could not open file --- aborting\n"); return 1; } /* peek into the file to find out the number of bodies */ n = get_vtk_numbodies(file); rewind(file); /* allocate memory accordingly */ x = calloc(n,sizeof(double3)); v = calloc(n,sizeof(double3)); m = calloc(n,sizeof(double)); /* read everything */ read_vtk_file_double(file,n,x,v,m,&t,&dt); fclose(file); printf("loaded %d bodies\n",n); #else /* get initial values from one of the generator functions */ x = calloc(n,sizeof(double3)); v = calloc(n,sizeof(double3)); m = calloc(n,sizeof(double)); plummer(n,17,x,v,m); #endif /** * allocate and initialise the acceleration and the buffer for leapfrog */ a = calloc(n,sizeof(double3)); for (i=0; i<n; i++) a[i][0] = a[i][1] = a[i][2] = 0.0; acceleration(n,x,m,a,B); temp = calloc(n,sizeof(double3)); /* write out the initial values */ sprintf(name,"%s_%06d.vtk",base,k/mod); // printf("writing %s \n",name); file = fopen(name,"w"); write_vtk_file_double(file,n,x,v,m,t,dt); fclose(file); /* start the time measurement */ start = get_time(); for (k=1; k<timesteps; k++) { /* do one timestep and increment elapsed simulated time */ leapfrog(n,dt,x,v,m,a,temp); t += dt; if (k%mod==0) { /* write statistics */ stop = get_time(); elapsed = stop-start; /* 13*n*(n-1)+24*n+3 FLOP from leaprog(), 1 from the t+=dt above */ flop = mod*(13.0*n*(n-1.0)+24.0*n+4.0); // printf("%g seconds for %g ops = %g MFLOPS\n", printf("%g\n",flop/elapsed/1E6); /* write output file */ sprintf(name,"%s_%06d.vtk",base,k/mod); // printf("writing %s \n",name); file = fopen(name,"w"); write_vtk_file_double(file,n,x,v,m,t,dt); fclose(file); /* restart the timer */ start = get_time(); } } /* Don't bother freeing the allocated buffers since the program is going to end and the operating system will reclaim all of its memory anyway */ return 0; }