06 Aug 2013, 18:34
Generic-user-small

Miguel Barcos (1 post)

Hi all,

Total Elixir N00b here…

I copied the pmap sample code from page 2.

defmodule Parallel do
  def pmap(collection, fun) do
    me = self
    collection
    |>
    Enum.map(fn (elem) ->
      spawn_link fn -> (me <- { self, fun.(elem) }) end
    end)
    |>
    Enum.map(fn (pid) ->
      receive do { ^pid, result } -> result end
    end)
  end
end

I then changed the invocation such that the range was much bigger (1..100000)

When I ran :

result = Parallel.pmap 1..100000, &(&1 * &1)

I expected ALL the cores on my MBP to light up, but that didn’t seem to be the case. There seemed to be a quick, initial burst on all cores and then, any one core was working (but only one) for quite a while until it finished.

Am I missing something? Do I have the wrong expectation? Is that just the wrong way to check?

Thanks,

Miguel

08 Aug 2013, 19:06
Dave_gnome_head_isolated_pragsmall

Dave Thomas (338 posts)

It’s probably just too fast. Try running a CPU-instensive task. On my machine, asking it to calculate the Fibonacci numbers from 35 to 45 using the slow recursive definition burns up all the cores.

09 Aug 2013, 02:40
Casual - sqr_pragsmall

Ryan Cromwell, Sr (4 posts)

Here’s my blog post on how I verified this http://cromwellhaus.com/2013/07/triangle-kata-in-elixir-using-erlang-processes-for-parallel-maps/

  You must be logged in to comment