4 ms·
Show HN: Parex – Simple Elixir module for parallel execution
- asa400 11y agoVery cool. I love seeing stuff like this: simple things that illustrate how easy it is to get going with concurrent programming in Elixir/Erlang.
- whichdan 11y agoIn your parallel code sample, hang2 is only 1000ms instead of 5000ms. This is very cool though!
- hacker314159 11y agothanks for the catch!
- koudelka 11y agoThe Task module is great for this kind of thing, too. http://elixir-lang.org/docs/v1.0/elixir/Task.html http://elixir-lang.org/docs/v1.0/elixir/Task.html [ add: fn() -> 1+2 end, hang1: fn() -> :timer.sleep(1000) end, hang2: fn() -> :timer.sleep(5000) end ] |> Enum.map(fn {k, t} -> {k, Task.async(t)} end) |> Enum.map(fn {k, t} -> {k, Task.await(t, :infinity)} end)
- shepardrtc 11y agoSo this is having a single (Erlang VM) process run code on as many cores as it can? Is this designed for a sequential program so that you don't have to split it up into processes? I'm still learning Erlang/Elixir, so I apologize if this is a stupid question.
- hacker314159 11y agoI think so. Elixir runs on erlang. And according to this SO post, it does run on all cores: http://stackoverflow.com/questions/7005759/erlang-on-multicore-cpu http://stackoverflow.com/questions/7005759/erlang-on-multico...
- Xixi 11y agoNot the author, but if you read the code of the library (~35 LOC) you will understand exactly what it does: it spawns a process (an Erlang process, not a system process) for each of the task, and then gather the results in an array. Whether the code is executed on many cores or not is completely orthogonal to this library. Indeed it is a property of the Erlang VM: you can configure it to run on only one system process, or many. That said, if you are looking for computing performances, Erlang/Elixir is probably not the language of choice: it is optimized for latency and fault tolerance, not to maximize raw cpu usage.
- deleted 11y ago[deleted]