Problem with parallel quicksort in erlang

I am facing problem with writing quicksort in erlang. What I am doing is I am spawning two processes and then blocking the current process till I get the response from both the left and right sub-arrays. Getting both these responses I send a message to its parent giving it the computed list. Parent ! {self(), Lone ++ [H] ++ Ltwo}

But I am getting error of gettting undef in both the sub-processes. Here is the code.

  quick(Parent, []) -> Parent ! {self(), []};
  quick(Parent, [H | T]) ->
      Pone = spawn_link(main, quick, [ self(), [ X || X <- T, H >= X ] ]) ,
      Ptwo = spawn_link(main, quick, [ self(), [ Y || Y <- T, H < Y ] ]) ,
      receive
          {Pone, Lone} ->
              receive
                  {Ptwo, Ltwo} -> Parent ! {self(), Lone ++ [H] ++ Ltwo}
              end;
          {Ptwo, Ltwo} ->
              receive
                  {Pone, Lone} -> Parent ! {self(), Lone ++ [H] ++ Ltwo}
              end
      end.

  sortquick(List) ->
      quick(self(), List).

called as:

main:sortquick([12,4,7,22,25]).
7
задан pranjal 12 May 2011 в 09:58
поделиться