Is there some substitute of map which evaluates the list in parallel? I don’t need it to be lazy.
Something like: pmap :: (a -> b) -> [a] -> [b] letting me pmap expensive_function big_list and have all my cores at 100%.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Yes, see the parallel package:
will evaluate each element of the list in parallel via the
rdeepseqstrategy. Note the use ofparListChunkwith a good chunk value might give better performance if your elements are too cheap to get a benefit evaluating each one in parallel (because it saves on sparking for each element).EDIT: Based on your question I feel I should explain why this is an answer. It’s because Haskell is lazy! Consider the statement
Nothing has been evaluated. You’ve just created a thunk that maps
expensiveFunction. So how do we evaluate it in parallel?Now don’t use the
bslist in your future computations, instead use thecslist. IOW, you don’t need a parallel map, you can use the regular (lazy) maps and a parallel evaulation strategy.EDIT: And if you look around enough you’ll see the parMap function that does what I showed here but wrapped into one helper function.
In response to your comment, does the below code not work for you? it works for me.