On 16/02/2013, at 7:48 PM, john skaller wrote:

> 
> On 16/02/2013, at 7:36 PM, john skaller wrote:
> 
>> So the bug is now fixed. And horribly, nbody is now working correctly
>> but is as slow as a very wet Sydney week.
> 
> 
> PROGRAM nbody
> Felix: clang -O2 327.793
> C: clang 3.3 -O2 21.724
> C: gcc 4.2.1 -O2 20.73
> Ocaml 3.11.1 31.57
> 
> Ooops .. that's not just sub-light speed .. that's downright sub-sonic :)

So now, the clue to the problem in the optimiser. I rewrote the
routine making everything a var (eager evaluation), and,
factoring out all common factors manually, including using
pointers like C does. The new Advance routine looks like this:


noinline proc Advance(dt: double){
   var i: int; var j:int;
   for i in 0 upto nbodies - 1 do
      var pi = &bodies.i;
      var bimass = pi*.mass;
      var delta = 0.0,0.0,0.0;
      for j in i+1 upto nbodies - 1 do
         var pj = &bodies.j;
         var bjmass : double = pj*.mass;
         var d : vec = pi*.pos - pj*.pos;
         var d2 : double = sqr d;
         var distance : double = sqrt d2;
         var d23 : double = dt / (distance * d2);
         var ddd : vec = d * d23;
         delta = delta + bjmass * ddd; 
         pj.vel <- pj*.vel + bimass * ddd;
      done;
      pi.vel <- pi*.vel - delta;
   done;

   for i in 0 upto nbodies - 1 do
      pi = &bodies.i;
      pi.pos <- pi*.pos + dt * pi*.vel;
   done;
}

And now:

~/felix>flx -O2 --static -c nb
~/felix>time ./nb
-0.169075164
-0.169059907

real    0m23.224s
user    0m23.196s
sys     0m0.021s

which is roughly the same speed as C and faster than Ocaml.

This is good, because now I can look at the generated code,
then "undo" various hand optimisations to see which ones make
a difference, and try to figure out how the compiler can do them.

I am guessing the "lazy evaluation" thing is causing the problem
by copying and evaluating big structures and then grabbing
only one part of them, then doing the same again for the next part.

--
john skaller
skal...@users.sourceforge.net
http://felix-lang.org




------------------------------------------------------------------------------
The Go Parallel Website, sponsored by Intel - in partnership with Geeknet, 
is your hub for all things parallel software development, from weekly thought 
leadership blogs to news, videos, case studies, tutorials, tech docs, 
whitepapers, evaluation guides, and opinion stories. Check out the most 
recent posts - join the conversation now. http://goparallel.sourceforge.net/
_______________________________________________
Felix-language mailing list
Felix-language@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/felix-language

Reply via email to