06 Aug 2013, 18:34

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
    Enum.map(fn (elem) ->
      spawn_link fn -> (me <- { self, fun.(elem) }) end
    Enum.map(fn (pid) ->
      receive do { ^pid, result } -> result 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?



08 Aug 2013, 19:06

Dave Thomas (342 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