<div dir="ltr"><div>Here's an Erlang version, with lots of grains of salt added: AFAIK 
Erlang doesn't provide bigint expt and sqrt, so they had to be added to 
the Erlang src. And Erlang isn't exactly known for numerical 
performance. With that in mind, here goes:<br><br>-module(fib).<br>-export([main/1]).<br>-mode(compile).<br><br>expt(_, 0) -> 1;<br>expt(A, 1) -> A;<br>expt(A, B) -> A * expt(A, B-1).<br><br>isqrt(Num, M, N) when abs(M - N) =< 1 -><br>    if  N * N =< Num -> N;<br>        true         -> N - 1<br>    end;<br><br>isqrt(Num, _, N) -><br>    isqrt(Num, N, (N + Num div N) div 2).<br><br>integer_sqrt(Value) when Value >= 0 -> isqrt(Value, 1, (1 + Value) div 2).<br><br>short_delay(Value) -> integer_sqrt(Value).<br><br>range(I, J) -> lists:seq(I, J-1).<br><br>tfib(0, GV) -> short_delay(GV), 1;<br>tfib(1, GV) -> short_delay(GV), 1;<br>tfib(N, GV) -><br>    short_delay(GV),<br>    Pid = self(),<br>    spawn(fun() -> Pid ! tfib(N-2, GV) end),<br>    Y = tfib(N-1, GV),<br>    receive<br>        Result -> Result + Y<br>    end.<br><br>goloop(0) -> ok;<br>goloop(ThreadsRemaining) -><br>    receive<br>        _ -> goloop(ThreadsRemaining - 1)<br>    end.<br><br>go(N, Repeat, Granularity) -><br>    Pid = self(),<br>    GV = expt(11, Granularity),<br>    Threads = [spawn(fun() -> Pid ! tfib(N, GV) end) || _ <- range(0, Repeat)],<br>    goloop(length(Threads)).<br><br>main(_) -><br>    go(15, 100,    0),<br>    go(15,  20, 1001).<br><br><br>$ time escript fib.erl<br><br>real    1m22.728s<br>user    7m54.460s<br>sys    0m0.396s<br><br><br></div>Ran on a six-core machine, Erlang used up all cores up to nearly 100%.<br><div><br></div>Leif</div><div class="gmail_extra"><br><div class="gmail_quote">2017-03-11 1:45 GMT+01:00 Marc Feeley <span dir="ltr"><<a href="mailto:feeley@iro.umontreal.ca" target="_blank">feeley@iro.umontreal.ca</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I considered Ruby… but then learned that MRI only implements green threads…<br>
<br>
Thanks for the suggestions for other languages… Perl actually supports threads? Who would have thought!<br>
<br>
Can I ask for your help in translating the benchmark program?<br>
<br>
The actual computation performed by the “short-delay” procedure doesn’t matter, but it should take about 50 microseconds (in order to isolate the performance related to the implementation of threads).<br>
<br>
Marc<br>
<br>
;;; Compute fib using threads.<br>
<br>
(declare (standard-bindings) (fixnum) (not safe) (block))<br>
<br>
(define big 0)<br>
<br>
(define (granularity-set! g)<br>
  (set! big (expt 11 g)))<br>
<br>
(define (short-delay)<br>
  (integer-sqrt big))<br>
<br>
(define (tfib n)<br>
  (short-delay)<br>
  (if (< n 2)<br>
      1<br>
      (let* ((x (thread-start! (make-thread (lambda () (tfib (- n 2))))))<br>
             (y (tfib (- n 1))))<br>
          (+ (thread-join! x) y))))<br>
<br>
(define (range i j)<br>
  (let loop ((j (- j 1)) (lst '()))<br>
    (if (< j i)<br>
        lst<br>
        (loop (- j 1) (cons j lst)))))<br>
<br>
(define (go n repeat)<br>
  (let ((threads<br>
         (map (lambda (i) (make-thread (lambda () (tfib n))))<br>
              (range 0 repeat))))<br>
    (for-each thread-start! threads)<br>
    (map thread-join! threads)))<br>
<br>
(granularity-set! 0)<br>
<br>
(go 15 100)<br>
<br>
(granularity-set! 1001) ;; granularity of about 50us per thread<br>
<br>
(go 15 20)<br>
<br>
<br>
> On Mar 10, 2017, at 7:30 PM, C K Kashyap <<a href="mailto:ckkashyap@gmail.com">ckkashyap@gmail.com</a>> wrote:<br>
><br>
> Super!!!<br>
> Perl 5 may be a good candidate as well.<br>
> Regards,<br>
> Kashyap<br>
><br>
> On Fri, Mar 10, 2017 at 4:28 PM, Bradley Lucier <<a href="mailto:lucier@math.purdue.edu">lucier@math.purdue.edu</a>> wrote:<br>
> Would a multi-threaded http server test what you want to test?<br>
><br>
> Brad<br>
> ______________________________<wbr>_________________<br>
> Gambit-list mailing list<br>
> <a href="mailto:Gambit-list@iro.umontreal.ca">Gambit-list@iro.umontreal.ca</a><br>
> <a href="https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list" rel="noreferrer" target="_blank">https://webmail.iro.umontreal.<wbr>ca/mailman/listinfo/gambit-<wbr>list</a><br>
><br>
<br>
______________________________<wbr>_________________<br>
Gambit-list mailing list<br>
<a href="mailto:Gambit-list@iro.umontreal.ca">Gambit-list@iro.umontreal.ca</a><br>
<a href="https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list" rel="noreferrer" target="_blank">https://webmail.iro.umontreal.<wbr>ca/mailman/listinfo/gambit-<wbr>list</a><br>
</blockquote></div><br></div>