[clean-list] Matrix timings

Sven-Bodo Scholz sbs@informatik.uni-kiel.de
Thu, 1 Nov 2001 14:09:47 +0100


On Thu, Nov 01, 2001 at 09:34:47AM +0100, Siegfried Gonzi wrote:
> Sven-Bodo Scholz sbs@informatik.uni-kiel.de, writes:
> 
> >Clean-solution: John's solution posted Nov 2000 (complete version at the end of this posting)
> 
> >all timings on a SUN UltraSPARC 450MHz:
> 
> >size     Clean-time (s)        SAC-time (s)
> 
> >300x300      0.8                  0.3
> >1000x1000   63.5                 33.4
> 
> 
> This is way better (for Clean) than I might expect. I thought for a
> really tuned (heavily inlined) C code the figures would be different
> (more in favor of C). I assume your C code is inlined. (I could not
> really follow it; typically C, exactly?). Repeat the above with readable
> (simple, straightforward C code and the scene will slightly change).

Well - this is not C; it is SAC. All arrays are state-less! They are data structures
in the same way as scalars are; all memory management is done implicitly. Whether modification
operations can be implemented destructively or not is decided at runtime; conceptually
any "array modification" yields an entirely new array as a result.

The code I presented is complete already. There is no hidden / inlined C-code.


double[*] matmul( double[*] A, double[*] B)  
{
  /* matmul takes two arbitrarily shaped arrays A and B with double elements */

  BT = transpose( B);

  C = with( . <= [i,j] <= .)
      genarray( [ shape(A)[[0]], shape(B)[[1]] ], sum( A[[i]] * BT[[j]]));

      /*
       * with-loops are the array comprehensions in SAC. This WL computes
       * an array of shape  [ shape(A)[[0]], shape(B)[[1]] ]  , i.e.,
       * the number of rows of the result equals the number of rows of the
       * array A : shape(A)[[0]]  and the number of columns of the result
       * equals the number of columns of the second argument : shape(B)[[1]]
       * An element at position [i,j] is computed by the expression
       *    sum( A[[i]] * BT[[j]])   where A[[i]] selects the ith row of A
       * and BT[[j]] selects the jth row of BT, i.e., the jth column of B.
       * Multiplication is overloaded to arbitrarily shaped arrays and
       * sum is a WL-defined library function which sums up all elements
       * of its argument array.
       */

  return( C);
}


> 
> The above results makes Clean (at least for me) even more
> sympathically).

This was not ment as to diminish the achievments of Clean !! Instead, it 
shows that even more elegant notions AND better performance (in the context of
arrays and array operations !) can be achieved within the functional framework.
Another motivation for this test was that I wanted to see how these figures
compare to the other approaches mentioned.

> [PS: Why do you believe -- on your homepage -- SAC is a functional
> language? Okay, I did not scrutinize it too much, because when I see a
> disguised C syntax I have to cancel.]

To cut it short: because the semantics of SAC relies on context-free
substitutions. Although I would love to elaborate this point to some more
detail, I think we should discuss this either directly via email or via the
SAC-mailing-list.


  Sven-Bodo

-- 
Sven-Bodo Scholz                        University of Kiel            
email: sbs@informatik.uni-kiel.de       Department of Computer Science
http://www.informatik.uni-kiel.de/~sbs/ Herman-Rodewald-Strasse 3, 24118 Kiel  
Phone: +49-431-880-4482              	Germany