So, I decided to try to write an efficient Lisp version of your C
code, but the C code is broken.

  #include <stdio.h>
  
  const int n = 1000;
  const int nn = 1000*1000;
  static double mat[1000*1000];
  
  int main ()
  {
      int i, pos1, pos2;
      
      for (i=0; i<nn; i++)
        mat[i] = 1.0;
      
      for (i=0; i<10; i++)
        for (pos1=1; pos1<n-1; pos1++)
            for (pos2=pos1+n; pos2<pos1+(n-1)*n; pos2+=n)
                mat[pos2] = 0.11111111111111*
                    (mat[pos2-1001]+mat[pos2-1]+mat[pos2+999]+
                     mat[pos2-1000]+mat[pos2]+mat[pos2+1000]+
                     mat[pos2-999]+mat[pos2+1]+mat[pos2+1001]);
      printf("%f", mat[n+1]);
      
      return 0;
  }

The first time through the nested for loops, you try to set mat[2] to the value
   0.11111111111111 *
   mat[2-1001] + mat[2-1] + mat[2+999]  +
   mat[2-1000] + mat[2]   + mat[2+1000] +
   mat[2-999]  + mat[2+1] + mat[2+1001]

So, while there must be something accessible at memory locations
   (&mat)-(sizeof(double)*999),
   (&mat)-(sizeof(double)*998), and
   (&mat)-(sizeof(double)*997)

whatever result you're getting is garbage.  So, before you go
comparing the speed of the C and Lisp programs, you might want to make
sure the C program at least makes sense ;-)

-- 
           /|_     .-----------------------.                        
         ,'  .\  / | No to Imperialist war |                        
     ,--'    _,'   | Wage class war!       |                        
    /       /      `-----------------------'                        
   (   -.  |                               
   |     ) |                               
  (`-.  '--.)                              
   `. )----'                               

Reply via email to