hi.
i wrote a function, that does some long computation and counts time spent
on it.
then i call this function N times and sum times spent on computations.
then i call this functionin N times in X separate places in parallel and
again sum times spent on computations.
results are surprising. the more places we use the more summary time is.
point out: NOT time of execution, but summary time of N computations.
and before starting computations i waits till all worker places are started
(starting place takes long time and i know it).
on 16 core system, running 1 place:
time: 1164
running 2 places:
time: 1739
running 10 places:
time: 8825
code:
#lang racket
(require racket/place)
(provide main
child
)
(define (child ch)
(let ((n (place-channel-get ch)))
(let ((start (current-milliseconds)))
(cond
((number? n)
(place-channel-put
ch
(and (let loop ((res '()) (n n))
(if (= n 0)
(apply + res)
(loop (cons n res) (sub1 n))))
(- (current-milliseconds) start)))
(child ch))
((equal? n "ping")
(place-channel-put ch "pong")
(child ch))))))
(define (get-avail p res)
(cons
(let loop ((avail '()))
(if (null? avail)
(loop (filter-map
(lambda (pl)
(let ((r (sync/timeout 0 pl)))
(and r
(set! res (cons r res))
pl)))
p))
avail))
res))
(define (main . argv)
(let ((p (let loop ((n (string->number (car argv))) (r '()))
(if (= n 0)
r
(loop (sub1 n)
(cons (dynamic-place
(string->path "placestest.scm")
'child)
r)))))
(numbers '(325220 295205 285260
146030 58810 231409
260650 58890 299280
168250 57320 120210
226100 325260 320180
251680 37310 275680
111010 288300 183890
325220 295205 285260
146030 58810 231409
260650 58890 299280
168250 57320 120210
226100 325260 320180
251680 37310 275680
111010 288300 183890)))
(for-each (lambda (pl)
(place-channel-put pl "ping")
(place-channel-get pl))
p)
(printf "all places started, run~n")
(let ((results (let loop ((numbers numbers) (a (cons p '())))
(if (null? numbers)
(cdr a)
(loop (cdr numbers)
(let ((a (if (not (null? (car a)))
a
(get-avail p (cdr a)))))
(and (place-channel-put (car (car a)) (car
numbers))
(cons (cdr (car a))
(cdr a)))))))))
(let loop ((results results))
(if (= (length results) (length numbers))
(printf "time: ~a~n" (apply + results))
(loop (cdr (get-avail p results)))))
(for-each (lambda (pl) (place-channel-put pl #f)) p))
(for-each place-wait p)))
p.s. sorry for my bad english
--
You received this message because you are subscribed to the Google Groups
"Racket Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/racket-dev/0aa42db7-d653-4cc3-aa11-9c19e03edd26%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.