small medium large xlarge

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
    |> (elem) ->
      spawn_link fn -> (me <- { self, fun.(elem) }) end
    |> (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 (344 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.

Casual - sqr_pragsmall
09 Aug 2013, 02:40
Ryan Cromwell, Sr (4 posts)

Here’s my blog post on how I verified this

  You must be logged in to comment