-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Concurrency In Elixir Homework: Name:Ethan Potthoff ID:47353076 #1
Conversation
{:next_is, value} -> | ||
counter(value) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure why this is here: it doesn't seem to be invoked from anywhere
-1
end | ||
|
||
def new_counter(initial_value \\ 0) do | ||
# ... your code | ||
new_count = spawn Ex01, :counter, [initial_value] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a warning that new_count
is never used. In general, you should clear all warning in code (not just when submitting assignments)
-1
chunk_val = div(Enum.count(collection),process_count) | ||
chunks = Enum.chunk_every(collection, chunk_val) | ||
pids = Enum.map(chunks, fn chunk -> spawn(Ex03, :chunk_process, [chunk, function, self()]) end) | ||
result_list = Enum.map(pids, fn pid -> (receive do {^pid, value} -> value end) end) | ||
List.flatten(result_list) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was so close to being a pipeline:
collection
|> Enum.chunk_every(chunk_val)
|> Enum.map(fn chunk -> spawn(Ex03, :chunk_process, [chunk, function, self()]) end)
|> Enum.map(fn pid -> (receive do {^pid, value} -> value end) end)
|> List.flatten()
I'm deducting 4 here just because I did ask for one...
-4
No deduction, but you could have used Enum.flat_map
and saved having the List.flatten
call.
@@ -51,12 +51,17 @@ defmodule Ex03 do | |||
""" | |||
|
|||
def pmap(collection, process_count, function) do | |||
# your code goes here | |||
# I'm hoping to see a simple pipeline as the body of this function... | |||
chunk_val = div(Enum.count(collection),process_count) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The div
returns the wrong answer: div(10,4)
returns 2, which means you'd get 5 processes. It should be
div(Enum.count(collection) + process_count - 1, process_count)
No description provided.