Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a Scheme implementation that parallelizes?

Is there a R5RS-or-higher Scheme implementation that does parallelization? For example, if I say to do:

(map (lambda (x) 
        (pure-functional-stuff x))
     '(1 3 5 7 11 13))

it will process 1, 3, 5, and 7 simultaneously if the machine can do it? That's supposed to be one of the big advantages of functional programming, but I can't find a maintained, up-to-date Scheme that does it. I'd be fine with one that wouldn't parallelize it unless I assert that the function doesn't have side-effects.

like image 826
JasonFruit Avatar asked Jul 18 '10 21:07

JasonFruit


3 Answers

I'm a developer of Schemik and I think that it is the Scheme you are looking for. The project is still developed and maintained. Early this year, I released a version which improves compatibility with R5RS. Unfortunately, Schemik is a research project focused on the process of expression evaluation, thus, its standard library is still relatively small. Is there any particular functionality you miss in Schemik?

like image 158
pkrajca Avatar answered Nov 18 '22 01:11

pkrajca


Racket has futures that do something very similar to this, and will also have a second approach for parallelism in the near future (which will be called "places").

like image 20
Eli Barzilay Avatar answered Nov 18 '22 01:11

Eli Barzilay


It turns out that you don't really want the compiler to try to parallelize everything because then you end up wasting time coordinating efforts even when doing something simple like,

(map add1 '(1 2 3))

that would be faster to just do on one thread. However, many functional languages these days make it easy for you to make this parallel when "add1" is actually "really-long-computation". Each language has its own approach, but I'd recommend taking advantage of multiple cores in Racket using futures.

While the compiler deciding things automatically for you is nice, it's not a bad tradeoff to change a "map" to a "pmap" where you think it might help rather than deal with slowdowns in other places because the compiler was too ambitious.

Something as basic as

(define (pmap f xs)
  (map touch (map (λ(x) (future (λ() (f x)))) xs)))

can get you pretty far when used judiciously, but you should experiment with chunking up your data to feed to parallel threads.

like image 3
Anthony Avatar answered Nov 17 '22 23:11

Anthony