[Haskell] Pugs gains SMP parallelism support.
Sebastian Sylvan
sylvan at student.chalmers.se
Mon Oct 23 07:12:52 EDT 2006
On 10/23/06, Taral <taralx at gmail.com> wrote:
> On 10/23/06, Sebastian Sylvan <sylvan at student.chalmers.se> wrote:
> > They probably are. However you get the overhead of creating the array
> > (when you don't really need O(1) random access) and every thread
> > signals the same semaphore which may lead to some congestion which
> > could slow things down.
>
> You do need O(1) random access for the writers to put their results in
> efficiently. And newArray_ should be faster than N copies of
> newEmptyMVar. It is true that I have one congestion point (the
> semaphone) instead of N (the mvars).
I'm not so sure that a newArray is faster than N copies of
newEmptyMVar, at any rate the [MVar] approach has *no* congestion
points (each thread will have it's very own place to put the result
without any blocking, there is no congestion) and there are no "index
out of bounds" checks going on that you get with arrays (could be this
that causes performance problems, and not congestion - though both
could potentially be a problem for large number of threads).
You could try having an array of MVars to get rid of the extra space
that the list takes, and use unsafeWrite etc. to get faster writes
back to the result array. Then do takeMVar on each item in the array
to get "block for N resources" behaviour without having a single
resource semaphore that could (profile!) suffer from congestion.
/S
--
Sebastian Sylvan
+46(0)736-818655
UIN: 44640862
More information about the Haskell
mailing list