Question

I'm trying to write a ring benchmark where I have N processes and I send a message through them M times. I'd like to store the processes' pid in an ETS table.

-module(ringmets).

-compile(export_all).

start_m(N, M, Msg) ->
    ets:new(pid, [ordered_set, named_table]),
    List = start_proc(N, M),
    %tv:start(),
    [ets:insert(pid, {Pid, X}) || {Pid,X} <- lists:zip(lists:seq(1,N), List)],
    hd(List) ! {Msg, 1}.

start_proc(0, _M) ->
    [];
start_proc(N, M) ->
    [spawn(ring_m, loop, [M, N]) | start_proc(N-1, M)].

loop(-1, _N) ->
    ok;
loop(M, N) ->
    receive
        {Msg, CurrPid} ->
        case CurrPid == N of
            true -> Next = 1;
            false -> Next = CurrPid + 1
        end,
        LU = ets:lookup(pid, Next),
        NextPid = element(2, hd(LU)),
        NextPid ! {Msg, Next},
        loop(M-1, N)
    end.

call:

2> ringmets:start_m(5,5,ok).
{ok,1}
3>
=ERROR REPORT==== 22-Nov-2012::19:51:43 ===
Error in process <0.38.0> with exit value: {undef,[{ring_m,loop,[5,5]}]}


=ERROR REPORT==== 22-Nov-2012::19:51:43 ===
Error in process <0.42.0> with exit value: {undef,[{ring_m,loop,[5,1]}]}


=ERROR REPORT==== 22-Nov-2012::19:51:43 ===
Error in process <0.39.0> with exit value: {undef,[{ring_m,loop,[5,4]}]}


=ERROR REPORT==== 22-Nov-2012::19:51:43 ===
Error in process <0.41.0> with exit value: {undef,[{ring_m,loop,[5,2]}]}


=ERROR REPORT==== 22-Nov-2012::19:51:43 ===
Error in process <0.40.0> with exit value: {undef,[{ring_m,loop,[5,3]}]}

loop/2 is exported so I don't understand why I get this error.

Was it helpful?

Solution

your module is ringmets, not ring_m

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top