[erlang-questions] performance on multicore computer

Jiansen He <>
Sat Oct 23 01:07:39 CEST 2010


Thank you so much.

my program is actually 200 lines long.  I posted related parts as follows.


%% -- generate all sequences of length exactly n starting at index i or
later
%% gen_ :: Int -> Int -> [String] -> AssocList [String] Int
gen_ (_, _, [], From) -> From ! {seq, []};
gen_ (I, N, [H | T], From) ->
 if
    N > length([H | T]) -> From ! {seq, []};
    true ->
       gen_(I+1, N, T, self()),
       receive
         {seq, Seq} ->
           From ! {seq, insert({takeN(N, [H | T]), I}, Seq)};
         Msg ->
           io:format("unrecognized message in gen_/4: ~n")
       end
 end.

%% -- generate all sequences of length at most n
%% gen :: Int -> [String] -> AssocList [String] Int
gen(0, _, From) ->
    From ! {seq, []};
gen(N, L, From) ->
    spawn(concordance_1_1, gen_, [0, N, L, self()]),
    spawn(concordance_1_1, gen, [(N-1), L, self()]),
    gen_loop(2, [], From).

gen_loop(0, Seq, From) ->
    From ! {seq, Seq};
gen_loop(N, Seq, From) ->
    receive
      {seq, Seq_} ->
        gen_loop(N-1, merge(Seq, Seq_), From);
      Msg ->
           io:format("f unrecognized message in gen_loop/3: ")
    end.

In Haskell, I could simply write code like this:

-- generate all sequences of length at most n
gen :: Int -> [String] -> AssocList [String] Int
gen 0 _ = []
--gen n l = merge sqs_len_n sqs_up_to_n1
gen n l = sqs_len_n `par` sqs_up_to_n1 `pseq` (merge sqs_len_n sqs_up_to_n1)
            where sqs_up_to_n1 = (gen (n-1) l)
                       sqs_len_n = (gen' 0 n l)



Please let me know if you have difficulty to understand my code.  Many
thanks again.

Jiansen




On Fri, Oct 22, 2010 at 11:51 PM, Jesper Louis Andersen <
> wrote:

> On Sat, Oct 23, 2010 at 12:42 AM, Jiansen He <>
> wrote:
>
> > Erlang R14B (erts-5.8.1) [source] [smp:4:4] [rq:4] [async-threads:0]
> [hipe]
> > [kernel-poll:false]
>
> The smp:4:4 part should mean you have access to all (logical) CPUs.
>
> > My program should be parallel.  I have a similar Haskell program which
> could
> > consume 380% CPU!
>
> Haskell is different from Erlang, and its parallellism-constructions
> are much different. I wonder if you can give the program or at least
> tell us the strategy is uses for obtaining parallel evaluation. It may
> be here the problem lies (at least that is my hunch)
>
> --
> J.
>


More information about the erlang-questions mailing list