views:

205

answers:

4

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.

+2  A: 

I just found Schemik

http://schemik.sourceforge.net/

which seems to be maintained to at least 2009, though I don't know if it's R5RS.

Peter G.
It confuses me that it claims to be a "dialect of Scheme and Common Lisp". Do they mean, "a dialect of Lisp"?
JasonFruit
It does approach R5RS, though I had to dig through commit comments to find that out. Seriously underdocumented, as a whole, and it has a bus factor of 1, but it has potential.
JasonFruit
+3  A: 

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").

Eli Barzilay
I'll read up on Racket's futures. I hadn't noticed them.
JasonFruit
+2  A: 

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.

Anthony
+4  A: 

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?

pkrajca
I'm digging into it now. I don't know for sure yet, but it looks promising.
JasonFruit
It does what I need for right now --- thanks! I've been wanting to try something that works this way.
JasonFruit

related questions