Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Faster N-Body Benchmark Code

Name: FrozenVoid 2010-07-10 8:07

I'm benchmarking various files from http://shootout.alioth.debian.org
This is optimized version of GCC N-Body benchmark:
http://shootout.alioth.debian.org/u32/program.php?test=nbody&lang=gcc&id=1
I'd like everyone to test this code and report what timing you got and which machine/OS/GCC you have.
Each version contain flags used to compile it in comment.
http://pastebin.com/Z0Bt2ZKa  <--My Version
http://pastebin.com/5SEqrZ28 <--Original



__________________
Orbis terrarum delenda est

Name: Anonymous 2010-07-10 8:32

NO EXCEPTIONS

Name: Anonymous 2010-07-10 9:28

Whats the point in these benchmarks?
 my code is faster by 20 milliseconds, CFLAGS hurr durr.
The program is a useless toy anyway, its not like you going to use anything there for real apps.

Name: Anonymous 2010-07-10 9:47

>>3
Actually my thesis work is simulating the solar system to discover bodies that alter real life data by ±10-900 compared to the data generated from the simulation.

Name: Anonymous 2010-07-10 11:24

>>4
I want to read it.

Name: Anonymous 2010-07-10 12:00

>>5
So far it's inconclusive.

Name: Anonymous 2010-07-10 18:30

>>6
SO MY ANUS

Name: Anonymous 2010-07-10 19:03

*SEW

Name: Anonymous 2010-07-10 20:00

Don't help him

Name: Anonymous 2010-07-10 23:40

>>1
http://pastebin.com/Z0Bt2ZKa
OH MY GOD, MY EYES

Name: Anonymous 2010-07-11 2:55

>>10 It can be further reduced in size
#include "stdio.h"
#include "math.h"
#include "time.h"
#define P(S1,S2) ;dx=bodies[S1].x-bodies[S2].x;mag=dx*dx;dy=bodies[S1].y- bodies[S2].y;mag+=(dy*dy);dz=bodies[S1].z-bodies[S2].z;mag+=dz*dz;mag=0.01/(sqrt(mag)*mag);bodies[S1].vx-=dx*bodies[S2].mass*mag; bodies[S1].vy-=dy*bodies[S2].mass*mag;bodies[S1].vz-=dz*bodies[S2].mass*mag;bodies[S2].vx+=dx*bodies[S1].mass*mag;bodies[S2].vy+= dy*bodies[S1].mass*mag;bodies[S2].vz+=dz*bodies[S1].mass*mag;
#define L(V) ;bodies[V].x+=0.01*bodies[V].vx;bodies[V].y+=0.01 *bodies[V].vy;bodies[V].z+=0.01*bodies[V].vz;
struct planet{ double x,y,z,vx,vy,vz,mass;};
struct planet bodies[5]={{0,0,0,-0.0003876634071987,-0.0032753590371766,0.0000239357340800,39.47841760435742848212},{4.84143144246472090e+00,-1.16032004402742839e+00,-1.03622044471123109e-01,1.66007664274403694e-03*365.24,7.69901118419740425e-03*365.24,-6.90460016972063023e-05*365.24,9.54791938424326609e-04*39.47841760435742848212},{8.34336671824457987e+00,4.12479856412430479e+00,-4.03523417114321381e-01,-2.76742510726862411e-03*365.24,4.99852801234917238e-03*365.24,2.30417297573763929e-05*365.24,2.85885980666130812e-04*39.47841760435742848212},{1.28943695621391310e+01,-1.51111514016986312e+01,-2.23307578892655734e-01,2.96460137564761618e-03*365.24,2.37847173959480950e-03*365.24,-2.96589568540237556e-05* 365.24,4.36624404335156298e-05*39.47841760435742848212},{1.53796971148509165e+01,-2.59193146099879641e+01,1.79258772950371181e-01,2.68067772490389322e-03*365.24,1.62824170038242295e-03*365.24,-9.51592254519715870e-05*365.24,5.15138902046611451e-05*39.47841760435742848212}};
double energy(struct planet*bodies){double e=0.0,dx,dy,dz,dist;int i, j;struct planet*b2,*b;
for(i=0;i<5;i++){b=&(bodies[i]);e+=0.5*b->mass*(b->vx*b->vx+b->vy*b->vy+b->vz*b->vz);
for(j=i+1;j<5;j++){b2=&(bodies[j]); dx=b->x-b2->x;dy=b->y-b2->y; dz=b->z-b2->z;dist= sqrt(dx*dx+dy*dy+dz*dz);e-=(b->mass*b2->mass)/dist;}};return e;}
void main(int argc,char**argv){ int startc=clock();double dx,dy,dz,mag; int n=atoi(argv[1]);if(!n){n= 50000000;};
printf ("%.9f <-Offset momentum: %i iterations\n", energy( bodies),n);
while(n--){P(0,1);P(0,2);P(0,3);P(0,4);P(1,2);P(1,3);P(1,4);P(2,3);P(2,4);P(3,4);L(0);L(1);L(2);L(3);L(4);}
printf ("%.9f <-Final result\nElapsed:%li ms", energy(bodies),clock()-startc);};

Name: Anonymous 2010-07-11 6:31

>>10
This is the power of *. Please try to ignore troll posts.

Name: Anonymous 2010-07-11 14:22

>>11
#include "void.h"

Name: Anonymous 2010-07-13 2:52

First, a question: Is your mother a good or bad programmer?

Don't change these.
Name: Email:
Entire Thread Thread List