Skip to content
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

Closed
wants to merge 6 commits into from
Closed

Conversation

ethanpotthoff
Copy link

No description provided.

Comment on lines +80 to +81
{:next_is, value} ->
counter(value)
Copy link
Owner

@pragdave pragdave Oct 20, 2019

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]
Copy link
Owner

@pragdave pragdave Oct 20, 2019

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

Comment on lines +54 to +58
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)
Copy link
Owner

@pragdave pragdave Oct 20, 2019

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.

@pragdave pragdave closed this Oct 20, 2019
@@ -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)
Copy link
Owner

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)

-2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants