Basic questions about concurrency in Haskell

Hello all, I'm new to Haskell, but have a good background in LISP/Scheme and do mostly C/C++ programming on a daily basis. I'm learning Haskell mainly because it provides facilities for concurrency on the language level, and I'm mainly interested in implementing parallel or massively parallel algorithms with Haskell. I have two questions that bother me. 1. Does the Haskell compiler make sure that there is no page sharing between threads, in order to avoid cache thrashing between cpus (a real killer on large SMP or ccNUMA systems) ? If so, are there functions/options to control this ? 2. I started with the very simple nfib example given in the manual for Control.Parallel (Section 7.18). On my systems using multiple cores makes the code actually slower than just using a single core. While the manual cautions that this could be the case for certain algorithms, I'm wondering whether this is the desired behaviour for this example. I'm using ghc 6.10.4 right now. Thank you for your help getting me started here. Thomas

Hello Thomas, Wednesday, August 5, 2009, 9:59:00 PM, you wrote:
because it provides facilities for concurrency on the language level, and I'm mainly interested in implementing parallel or massively parallel algorithms with Haskell. I have two questions that bother me.
if you plan to implement high-performance low-level algos, haskell/ghc is definitely not the language you need. haskell concurrency features are great in erlang-style situations when you need to manage many threads that interacts in complex way. but don't expect to get any C-level performance
1. Does the Haskell compiler make sure that there is no page sharing between threads
no
2. I started with the very simple nfib example given in the manual for Control.Parallel (Section 7.18).
standard optimization for this example is to use par only for large enough n, otherwise you will lose much more time on synchronization. ghc doesn't parallelize code in some wizardry way, it just have 4 worker threads, for example, and each spark created with par, becomes one more job for these threads o execute -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com

On Wed, Aug 5, 2009 at 6:59 PM, Thomas Witzel
2. I started with the very simple nfib example given in the manual for Control.Parallel (Section 7.18). On my systems using multiple cores makes the code actually slower than just using a single core. While the manual cautions that this could be the case for certain algorithms, I'm wondering whether this is the desired behaviour for this example.
I'm using ghc 6.10.4 right now.
IIRC the development version of GHC has some major work to optimize concurrency, so it may be worth trying that. In particular I believe it executes sparks in batches, to reduce the overhead (which hopefully fixes your issue). -- Sebastian Sylvan
participants (3)
-
Bulat Ziganshin
-
Sebastian Sylvan
-
Thomas Witzel