-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Added minimal code example to Channels, fix #14312 #17674
Conversation
@@ -492,6 +492,27 @@ and size 10. The channel exists on worker ``pid``\ . | |||
Methods ``put!``\ , ``take!``\ , ``fetch``\ , ``isready`` and ``wait`` on a ``RemoteChannel`` are proxied onto | |||
the backing store on the remote process. | |||
|
|||
As an example, we can construct a ``RemoteChannel`` to a worker, ``put!``\ an index inside, then ``take!``\ it out:: |
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 \
should only be needed if there's punctuation, spaces should be fine
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.
You can see I don't know RST very well.
I wonder if we should separate the distributed and parallel computing sections of this page. There are many lower-level primitives that we have for general purpose distributed computing, whereas many users of parallel computing are perhaps content with |
Maybe some of this belongs to the |
I don't think this example is ideal because you are showing that the master process can Maybe something like this: addprocs(5)
channels = Dict(worker => RemoteChannel() for worker in workers())
@everywhere take_and_print!(c) = println(take!(c))
for worker in workers()
put!(channels[worker], worker)
remotecall_fetch(take_and_print!, worker, channels[worker])
end Which should output:
|
That's a great point, @mweastwood. Why don't we include both, so that people can generalize from the easy case (master puts and takes) to the harder one? |
@@ -492,6 +492,46 @@ and size 10. The channel exists on worker ``pid``\ . | |||
Methods ``put!``\ , ``take!``\ , ``fetch``\ , ``isready`` and ``wait`` on a ``RemoteChannel`` are proxied onto | |||
the backing store on the remote process. | |||
|
|||
As an example, we can construct a ``RemoteChannel`` to a worker, ``put!`` an index inside, then ``take!`` it out: | |||
|
|||
.. doctest:: |
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 think the doctest format is a little pickier than this, most of them look for julia>
on the inputs then non-prefixed output like you'd get at the repl
Thanks for doing this (again!). I was thinking that we could take the same |
As written with all the remote channels refer to channels on the master only. The workers seem incidental. An example implementation of
Would like it simplified further though. I find Alan's suggestion of not having example code blocks more than a single page quite relevant for easier readabilty. We could then rewrite this once again using Alternatively, we could go with an example of a simple web service that distributes computation among workers. This would refer to package |
I took another shot at a simple example for Channels.
Does this work better for a beginner reading the section on Channels? Note that this does not cover RemoteChannels. |
I might show the full example and then go through line by line (might be easier to read for a newbie) explaining what the more complex blocks do. Then you can say "for more information about Might be nice also to show some sample output. I think the example is great, and |
Delete the line "wait(process)" to remove a livelock failure |
@vtjnash how can that trigger a livelock failure? Just to understand what is happening under the hood. |
It puts upstream pressure on the writer to prevent it from exiting since there is no active reader to consume the data |
The same example above done with
|
A better example for |
Also consider adding the following : The above examples show how channels can be used for inter-task communication, and remote channels for inter-process communication. They are well suited for building work pipelines or distributing work across tasks and processes. It is to be noted that for simpler scenarios, For example, md5 calculations can be performed locally with
or distributed with
|
The examples we have now are great! This PR has been totally superseded. |
cc @amitmurthy