parallelism or concurrency ? if they are different

From Real World Haskell my algorithm have to be parallelized as they don't do some kind of IO, they don't deal with the world, but where is it stated that it is possible to write them with par (I couldn't) ? More , I'm not caring that my computation is unrepeatable, for me it's fine that the runtime system gives me the cached results for same arguments computation. The fact that it doesn't ,and recompute
When I came to haskell, I arrived with a small and only evolutionary background in programming. First monad I met was MonadState StdGen m. Everything was in someway acceptable, I had no problem in explicitating the need for the generator. The lesson was referential transparency. To me referential tranparency is still obscure as a feature. Not using the monad , my functions pass around a generator, then they are repeatable, same generator , same computation. Years pass by, now evolutionary algorithms need to scale multicores. But multicore can be used with threads or par, the difference is that par is pure, because it respects referential transparency. But threads not. They are always unrespectful ? Or it's an implementation issue of preemptive choice? Can I have a baton to pass around like I had for random generator, so that the computation ends without IO (unsafe performed) , without breaking tranparency, something like (runIOThreads :: ThreadsIO a -> ThreadsBaton -> a) ? the function giving out something fuzzily different from before, is enough to coerce me to spit out IO values ? Finally, why and where the optimizer will substitute a value with its definition, so that it possibly get computed twice ? Thanks paolino

On Fri, 13 Feb 2009 11:09:35 +0100, Paolino
From Real World Haskell my algorithm have to be parallelized as they don't do some kind of IO, they don't deal with the world, but where is it stated that it is possible to write them with par (I couldn't) ? More , I'm not caring that my computation is unrepeatable, for me it's fine that the runtime system gives me the cached results for same arguments computation. The fact that it doesn't ,and recompute
When I came to haskell, I arrived with a small and only evolutionary background in programming. First monad I met was MonadState StdGen m. Everything was in someway acceptable, I had no problem in explicitating the need for the generator. The lesson was referential transparency. To me referential tranparency is still obscure as a feature. Not using the monad , my functions pass around a generator, then they are repeatable, same generator , same computation. Years pass by, now evolutionary algorithms need to scale multicores. But multicore can be used with threads or par, the difference is that par is pure, because it respects referential transparency. But threads not. They are always unrespectful ? Or it's an implementation issue of preemptive choice? Can I have a baton to pass around like I had for random generator, so that the computation ends without IO (unsafe performed) , without breaking tranparency, something like (runIOThreads :: ThreadsIO a -> ThreadsBaton -> a) ? the function giving out something fuzzily different from before, is enough to coerce me to spit out IO values ? Finally, why and where the optimizer will substitute a value with its definition, so that it possibly get computed twice ?
Thanks
paolino
I am not an expert in this matter, but as nobody answered sofar (perhaps people were frightened off by a lack of structure in your text), I will try to give some pointers: - You can start a function with parameters in a thread like this threadId <- forkIO (foo 42) where foo has type Int -> IO () - Communication between threads can be done with MVars, see: http://haskell.org/ghc/docs/latest/html/libraries/base/Control-Concurrent-MV... - You can find concurrency demos at: http://www.haskell.org/haskellwiki/Concurrency_demos - Links to articles about parallelism: http://www.haskell.org/haskellwiki/Blog_articles/Parallel - To prevent recomputing, read: http://www.haskell.org/haskellwiki/Memoization -- Regards, Henk-Jan van Tuyl -- http://functor.bamikanarie.com http://Van.Tuyl.eu/ --

thanks Henk-Jan, someone just helped me saying that my function is
pure as long as I make a cache of it, indexed on arguments. This
operationally proves that concurrent IO code can be purified with
unsafePerformIO, when it's semantic is not changed by that kind of
cache. Really doing the cache then it's an implementation choice. It
would be nice to have a suffix for this kind of functions, something
remembering the unrepeatability of them when not cached.
Sorry for my lacks of structure, I did my best.
paolino
2009/2/17, Henk-Jan van Tuyl
On Fri, 13 Feb 2009 11:09:35 +0100, Paolino
wrote: From Real World Haskell my algorithm have to be parallelized as they don't do some kind of IO, they don't deal with the world, but where is it stated that it is possible to write them with par (I couldn't) ? More , I'm not caring that my computation is unrepeatable, for me it's fine that the runtime system gives me the cached results for same arguments computation. The fact that it doesn't ,and recompute
When I came to haskell, I arrived with a small and only evolutionary background in programming. First monad I met was MonadState StdGen m. Everything was in someway acceptable, I had no problem in explicitating the need for the generator. The lesson was referential transparency. To me referential tranparency is still obscure as a feature. Not using the monad , my functions pass around a generator, then they are repeatable, same generator , same computation. Years pass by, now evolutionary algorithms need to scale multicores. But multicore can be used with threads or par, the difference is that par is pure, because it respects referential transparency. But threads not. They are always unrespectful ? Or it's an implementation issue of preemptive choice? Can I have a baton to pass around like I had for random generator, so that the computation ends without IO (unsafe performed) , without breaking tranparency, something like (runIOThreads :: ThreadsIO a -> ThreadsBaton -> a) ? the function giving out something fuzzily different from before, is enough to coerce me to spit out IO values ? Finally, why and where the optimizer will substitute a value with its definition, so that it possibly get computed twice ?
Thanks
paolino
I am not an expert in this matter, but as nobody answered sofar (perhaps people were frightened off by a lack of structure in your text), I will try to give some pointers:
- You can start a function with parameters in a thread like this threadId <- forkIO (foo 42) where foo has type Int -> IO ()
- Communication between threads can be done with MVars, see:
http://haskell.org/ghc/docs/latest/html/libraries/base/Control-Concurrent-MV...
- You can find concurrency demos at: http://www.haskell.org/haskellwiki/Concurrency_demos
- Links to articles about parallelism: http://www.haskell.org/haskellwiki/Blog_articles/Parallel
- To prevent recomputing, read: http://www.haskell.org/haskellwiki/Memoization
-- Regards, Henk-Jan van Tuyl
participants (2)
-
Henk-Jan van Tuyl
-
Paolino