parallel strategies for foldMap?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

parallel strategies for foldMap?

Johannes Waldmann-2
Dear Cafe,

I wonder if there is some accepted wisdom (and implementation)
to support parallel  foldMap  in some uniform way.

It should probably be tuneable for the case that mappend is
less or more expensive than the function to apply in the elements.

I can do the following, but it does not parallelize the mappends:

import qualified Data.Foldable as F
import Control.Parallel.Strategies

foldMapPar :: (Foldable f, Monoid b) => Int -> (a -> b) -> f a -> b
foldMapPar block f xs =
  F.fold ( map f (F.toList xs) `using` parBuffer block rseq )

In my application, the Foldable thingy is an unbalanced tree.

- J.W.

( the above is a genuine question, while the following
is a genuine announcement: don't miss the early registration
deadline for "Haskell in Leipzig" https://hal2017.softbase.org/ )

_______________________________________________
Haskell-Cafe mailing list
To (un)subscribe, modify options or view archives go to:
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Only members subscribed via the mailman list are allowed to post.