Why using pmap is not giving me the desired speedup ?

Tushar Deshpande <>
Tue Nov 17 07:45:46 CET 2009


I'm a newcomer to the Erlang world. I'm trying
to learn parallel programming with Erlang.

I tried to use Joe Armstrong's 'pmap' implementation
to write a parallel quicksort.

I imagined that I would get some observable
speedup with parallel quicksort.

I executed parallel quicksort on my dual-core
notebook. I varied the erlang schedulers from
1 to 32.

I ran quicksort on several lists with lengths
1, 10, 100, 1000, 10000 and 100000.

Contrary to my expectations, parallel version
took more time to run. [The pmap gave
significant speedup for example on page
371 (ptests.erl) in the Joe Armstrong's book]

What could be the reason ?

Notice, that the pqsort is non-tail-recursive
function. Does this have anything to do
with my observations ?

Wouls someone please help me ?

Here's my quicksort implementation for
easy reference.

-import(lib_parallel, [ pmap/2]).

pqsort([]) ->
pqsort([Pivot|T]) ->
  L1 = [X || X <- T, X < Pivot],
  L2 = [X || X <- T, X >= Pivot],
  [Left,Right] = pmap(fun pqsort/1, [L1,L2]),
  Left ++ [Pivot] ++ Right.

qsort([]) ->
qsort([Pivot|T]) ->
  L1 = [X || X <- T, X < Pivot],
  L2 = [X || X <- T, X >= Pivot],
  Left = qsort(L1),
  Right = qsort(L2),
  Left ++ [Pivot] ++ Right.

Warm Regards,

Tushar Deshpande

More information about the erlang-questions mailing list