| F?rster_vom_Silberwald 2004-10-26, 9:00 am |
| One thing worth to mention is the fact that Bigloo will serve you very
well provided one comply to some rules. The following two code snippets
demonstrate that Stalin is indeed a good code analyzer.
The following is a code snippet from a code which solves for simple
ordinary first order differential equations.**
But that is not the problem here; important is the fact that one has to
use a bit of a different technique in order to make the best out of
Bigloo programming, provided he is after performance.
1. Stalin snippet:
==
(define (eul-alpha n h delx u K R gamma-i A B)
(let* ((alpha-i (/ (&vr R 0)
(&vr B 0))))
(let loop-alpha ((i 2) (erg (list alpha-i)))
(if (= i (+ n 1))
(o==> (list->vector (reverse erg)))
(begin
(let ((indx (- i 1)))
(set! alpha-i (/ (- (&vr R indx)
(* (&vr A indx) alpha-i))
(+ (&vr B indx)
(* (&vr A indx)
(&vr gamma-i (- indx 1))))))
(loop-alpha (+ i 1) (cons alpha-i erg))))))))
==
2. The Bigloo snippet:
==
(define-macro (/. x y)
`(cond-expand
(bigloo (/fl ,x ,y))
(else (/ ,x ,y))))
; etc. macros here
(define (eul-alpha n h delx u K R gamma-i A B)
(let ((erg (make-vector n 0.0))
(alpha-i (/. (v& R 0)
(v& B 0))))
(vector-set! erg 0 alpha-i)
(do ((i 2 (+ i 1)))
((= i (+ n 1)))
(let ((indx (- i 1)))
(set! alpha-i
(/. (-. (v& R indx)
(*. (v& A indx) alpha-i))
(+. (v& B indx)
(*. (v& A indx)
(v& gamma-i (- indx 1))))))
(vector-set! erg indx alpha-i)))
(o==> erg)))
==
As you see: in order to get to the same performance as under Stalin one
has to use in Bigloo: a) pre-dimensionized vectors b) Bigloo operators.
The latter macros concerning the operators have been made so as to use
the code -- for test reasons -- under Stalin too.
Although, you see: in Stalin you use: a) consing-lists (list is
converted to a vector upon exit) b) normal operators.
If I had used the same Stalin code (the one with consing lists) under
Bigloo I would have had to wait much, much longer for the result. I do
not know why Stalin automatically transforms the list-consing code to
something similar to the vector code (see Bigloo code snippet).
And no: I would in no way cancel Bigloo in favor of Stalin. Bigloo
provides me much, much more; since one knows about some Bigloo tricks
and the Stalin performance advantage vanishes, at least in that special
"differential equation solver". Documentatin of ones own Bigloo code
with some basic types is at top of my list!
Förster vom Silberwald
** I made also a C++ version, because to my surprise the Bigloo output
and the Stalin output differ (same code)! However, the Bigloo output and
C++ output are the same! I implementted the solver after an example in a
book about atmospheric physics; one of the book examples provided me
only the initial particle concentration but not the result. Hence I am
not aware whether the Bigloo and C++ version is in error or Stalin. I am
still not sure whether my code converges eventually. But nevertheless: I
thought they -- Bigloo and Stalin, respectively -- rely on the same
internal (numerical) C layout - or don't they?
|