mirror of
https://github.com/fverdugo/XM_40017.git
synced 2025-11-08 19:54:25 +01:00
Rather minor changes in async and distributed notebooks
This commit is contained in:
parent
1e46702781
commit
bb965d7496
@ -283,7 +283,7 @@
|
|||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"fun = () -> compute_π(4_000_000_000)\n",
|
"fun = () -> @show compute_π(4_000_000_000)\n",
|
||||||
"t = Task(fun)"
|
"t = Task(fun)"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@ -359,7 +359,7 @@
|
|||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"fun = () -> compute_π_yield(3_000_000_000)\n",
|
"fun = () -> @show compute_π_yield(3_000_000_000)\n",
|
||||||
"t = Task(fun)\n",
|
"t = Task(fun)\n",
|
||||||
"schedule(t)"
|
"schedule(t)"
|
||||||
]
|
]
|
||||||
@ -729,6 +729,18 @@
|
|||||||
"take!(chnl)"
|
"take!(chnl)"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"id": "8a1ef849",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"In summary:\n",
|
||||||
|
"\n",
|
||||||
|
"- `put!` will wait for a `take!` if there is not space left in the channel's buffer.\n",
|
||||||
|
"- `take!` will wait for a `put!` if there is no data to be consumed in the channel.\n",
|
||||||
|
"- Both `put!` and `take!` will raise an error if the channel is closed."
|
||||||
|
]
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "markdown",
|
"cell_type": "markdown",
|
||||||
"id": "9ddd66ca",
|
"id": "9ddd66ca",
|
||||||
@ -746,7 +758,7 @@
|
|||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"t = @elapsed compute_π(100_000_000)"
|
"t = @elapsed @show compute_π(140_000_000)"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -772,7 +784,7 @@
|
|||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"@time for i in 1:10\n",
|
"@time for i in 1:10\n",
|
||||||
" compute_π(100_000_000)\n",
|
" @show compute_π(140_000_000)\n",
|
||||||
"end"
|
"end"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@ -810,7 +822,7 @@
|
|||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"@time for i in 1:10\n",
|
"@time for i in 1:10\n",
|
||||||
" @async compute_π(100_000_000)\n",
|
" @async @show compute_π(140_000_000)\n",
|
||||||
"end"
|
"end"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@ -847,7 +859,7 @@
|
|||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"@time @sync for i in 1:10\n",
|
"@time @sync for i in 1:10\n",
|
||||||
" @async compute_π(100_000_000)\n",
|
" @async @show compute_π(140_000_000)\n",
|
||||||
"end"
|
"end"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@ -970,6 +982,22 @@
|
|||||||
"</div>"
|
"</div>"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"id": "dfab0c90",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"## Summary\n",
|
||||||
|
"\n",
|
||||||
|
"In order to start \"thinking in parallel\" you first need to be familiar with concepts of asynchronous programming, in particular tasks. In this notebook, we have seen the basics of working with tasks. Some key points to remember:\n",
|
||||||
|
"\n",
|
||||||
|
"- How to create, schedule, and fetch from a task.\n",
|
||||||
|
"- Tasks run asynchronously, but not in parallel. You can have a single core CPU and still be able to work with several tasks.\n",
|
||||||
|
"- Channels are used to communicate data between tasks.\n",
|
||||||
|
"- Adding data (`put!`) or taking data (`take!`) from a channel might wait depending on the channel state. Be careful to avoid dead locks.\n",
|
||||||
|
"\n"
|
||||||
|
]
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "markdown",
|
"cell_type": "markdown",
|
||||||
"id": "a5d3730b",
|
"id": "a5d3730b",
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
Loading…
x
Reference in New Issue
Block a user