Hello,
on a simple task - multiply two matrices mat_a and mat_b https://github.com/glathoud/flatorize/blob/master/explore/scheme_matmul_comm... - I've been comparing 3 implementations, using interpretation and compilation.
To compile I used the line below. Is there a better way, at least a few straightforward optimization (options) ?
gsc -exe -o scheme_matmul_classic.bin tmp.scmDetails are below.
Best regards, Guillaume
1. Functional implementation: https://github.com/glathoud/flatorize/blob/master/explore/scheme_matmul_list...
2. Ugly imperative implementation: https://github.com/glathoud/flatorize/blob/master/explore/scheme_matmul_clas...
3. Flat implementation (for the specific matrix sizes): https://github.com/glathoud/flatorize/blob/master/explore/scheme_matmul342.s...
To run both tests (interpreted and compiled), I used this:
https://github.com/glathoud/flatorize/blob/master/explore/scheme_matmul.sh#L...
Results:
https://github.com/glathoud/flatorize/blob/master/explore/scheme_matmul.resu...
Afficher les réponses par date
Hallo,
On Tue, Apr 9, 2013 at 6:36 AM, Guillaume Lathoud glathoud@yahoo.fr wrote:
To compile I used the line below. Is there a better way, at least a few straightforward optimization (options) ?
Add this to the source file:
(declare (block) ; (not safe) (standard-bindings) (extended-bindings))
You can try with and without `(not safe)` and compare the results :)
Cheers, -- -alex http://unendli.ch/
Hallo again,
On Tue, Apr 9, 2013 at 9:32 AM, Alex Queiroz asandroq@gmail.com wrote:
Add this to the source file:
(declare (block) ; (not safe) (standard-bindings) (extended-bindings))
You can try with and without `(not safe)` and compare the results :)
Also, have you configured Gambit-C with `--enable-single-host --enable-gcc-opts`?
Cheers, -- -alex http://unendli.ch/
On 2013-04-09, at 12:36 AM, Guillaume Lathoud glathoud@yahoo.fr wrote:
Hello,
on a simple task - multiply two matrices mat_a and mat_b https://github.com/glathoud/flatorize/blob/master/explore/scheme_matmul_comm... - I've been comparing 3 implementations, using interpretation and compilation.
To compile I used the line below. Is there a better way, at least a few straightforward optimization (options) ? gsc -exe -o scheme_matmul_classic.bin tmp.scm Details are below.
Best regards, Guillaume
There are many things you can do to improve the performance of your code, but I wonder what you are trying to achieve. For instance, your code is multiplying matrices of small exact integers. Is this a given in your problem or you want the code to work also for floating point numbers? Also, do you want the code to conform to a specific standard of Scheme, or you are willing to adapt your code to a specific Scheme implementation? For Gambit you could store the numbers in a homogeneous numerical vector (e.g. s16vector, f64vector, etc) instead of a plain vector, and use fixnum specific operations for computing the indices of the matrix. Finally, you should avoid using assignments if you can use iteration variables instead. So, instead of
(let ((sum 0)) (let loop ((i 0)) (if (< i n) (begin (set! sum (+ sum i)) (loop (+ i 1))))) sum)
you should write
(let loop ((i 0) (sum 0)) (if (< i n) (loop (+ i 1) (+ sum i)) sum))
Marc