# [Haskell-cafe] Parallel executing of actions

Pepe Iborra mnislaih at gmail.com
Mon Apr 16 06:41:45 EDT 2007

On 16/04/2007, at 12:30, Mitar wrote:

> Hi!
>
> On 4/16/07, Bertram Felgenhauer
>> > Since all the threads block on a single MVar how do they run in
>> > parallel?
>>
>> The idea is that before the threads block on the MVar, they run their
>> action x to completion.
>
> The rendering crashes. I will have to precompute the values in threads
> someway and then sequentially draw it? Any suggestion how to do that?

Could it be that you are launching 400x300=120.000 new threads all at
once?
If you are not doing it already, it would be sensible to implement

This is what I use myself, don't worry about the unsafeness IF you
know that the sequence of computations doesn't matter:

\begin{code}
unsafeParMapM :: (a -> IO b) -> [a] -> IO [b]
unsafeParMapM f = return . parMap rwhnf (unsafePerformIO . f)

unsafeParMapMn :: Integral bound => bound -> (a -> IO b) -> [a] -> IO
[b]
unsafeParMapMn max f xx = return (map (unsafePerformIO . f) xx
using
parListChunk (fromIntegral max) rwhnf)

unsafeParSeqn :: Integral bound => bound -> [IO a] -> IO [a]
unsafeParSeqn max cc = return ((map unsafePerformIO cc)
using
parListChunk (fromIntegral max) rwhnf)
\begin{code}