Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

stalin can not optimize stream

3 views
Skip to first unread message

niitsuma

unread,
May 17, 2010, 2:20:57 AM5/17/10
to
I rewrite this code in stream style

Re: A fast scheme implementation?
http://newsgroups.derkeiler.com/Archive/Comp/comp.lang.scheme/2007-12/msg00061.html
ftp://ftp.ecn.purdue.edu/qobi/integ.tgz

--------code----------
(define the-empty-stream '())

(define stream-null? null?)

(define (stream-car stream) (car stream))

(define (stream-cdr stream) (force (cdr stream)))

(define (stream-ref s n)
(if (= n 0)
(stream-car s)
(stream-ref (stream-cdr s) (- n 1))))

;; SICP prob 3.50 stream-map
(define (stream-map proc . argstreams)
(if (stream-null? (car argstreams))
the-empty-stream
(
;cons-stream
cons
(apply proc (map stream-car argstreams))
(delay (apply stream-map
(cons proc (map stream-cdr argstreams))))
)
))


;; SICP prob 3.55

(define (partial-sums s)
(cons
(stream-car s)
(delay
(add-streams (stream-cdr s)
(partial-sums s)))))


(define (add-streams s1 s2)
(stream-map + s1 s2))

(define (sum-of-squares-stream s1 s2)
(partial-sums (stream-map - s1 s2))
)

(define (integers-starting-from n)
(cons n (delay (integers-starting-from (+ n 1)))))

(define integers (integers-starting-from 1))

;;;;;;;end util;;;;;;;;;;

(define (integrate-1D L U F)
(let ((D (/ (- U L) 8.0)))
(* (+ (* (F L) 0.5)
(F (+ L D))
(F (+ L (* 2.0 D)))
(F (+ L (* 3.0 D)))
(F (+ L (* 4.0 D)))
(F (- U (* 3.0 D)))
(F (- U (* 2.0 D)))
(F (- U D))
(* (F U) 0.5))
D)))

(define (integrate-2D L1 U1 L2 U2 F)
(integrate-1D L2 U2 (lambda (y) (integrate-1D L1 U1 (lambda (x) (F x
y))) )))

(define (zark U V)
(integrate-2D 0.0 U 0.0 V (lambda (X Y) (* X Y)) ))


(define (zark-i I)
(zark (* I 1.0) (* I 2.0)))

(define r-stream
(stream-map zark-i integers))

(define (i-fun I)
(let ((I2 (* (* I I) 1.0))) (* I2 I2)))

(define i-stream
(stream-map i-fun integers))

(define r-total-stream
(partial-sums r-stream)
)

(define i-total-stream
(partial-sums r-stream)
)

(begin
(display (stream-ref
(sum-of-squares-stream r-total-stream i-total-stream) 1000))
(newline))

--------code end ----------

Th following result for this code shows
stalin does not optimize this code. Computation time is same to C

$ time ./integ-stream
0.0

real 0m1.612s
user 0m1.510s
sys 0m0.100s


$ time ./integ-c
0.000000

real 0m1.613s
user 0m1.610s
sys 0m0.010s

$ time ./integ
0.0

real 0m0.206s
user 0m0.200s
sys 0m0.000s

./run

talin Version
0.11
GCC Version
Using built-in specs.
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu
4.4.1-4ubuntu9' --with-bugurl=file:///usr/share/doc/gcc-4.4/
README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/
usr --enable-shared --enable-multiarch --enable-linker-build-id --with-
system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-
threads=posix --with-gxx-include-dir=/usr/include/c++/4.4 --program-
suffix=-4.4 --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug
--enable-objc-gc --disable-werror --with-arch-32=i486 --with-
tune=generic --enable-checking=release --build=x86_64-linux-gnu --
host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 4.4.1 (Ubuntu 4.4.1-4ubuntu9)
Stalin integ
0.0
0.190u 0.010s 0:00.19 105.2% 0+0k 0+0io 0pf+0w
Stalin integ-stream
0.0
1.520u 0.110s 0:01.63 100.0% 0+0k 0+0io 0pf+0w
Stalin integ2
0.0
0.050u 0.000s 0:00.01 500.0% 0+0k 0+0io 0pf+0w
Stalin integ3
0.0
0.300u 0.000s 0:00.26 115.3% 0+0k 0+0io 0pf+0w
GCC integ-c
0.000000
3.060u 0.000s 0:03.06 100.0% 0+0k 0+0io 0pf+0w
GCC integ2-c
0.000000
0.220u 0.000s 0:00.23 95.6% 0+0k 0+0io 0pf+0w

http://niitsuma.blogspot.com/2010/05/stalin-can-not-optimize-stream.html

niitsuma

unread,
May 17, 2010, 10:53:00 AM5/17/10
to
> (define i-total-stream
> (partial-sums r-stream)
> )

miss

(define i-total-stream
(partial-sums i-stream)
)

0 new messages