build based on 1d6a3b6

This commit is contained in:
Documenter.jl
2024-09-12 09:27:51 +00:00
parent cafb7d0b46
commit 21f1789b28
26 changed files with 154 additions and 66 deletions

View File

@@ -283,7 +283,7 @@
"metadata": {},
"outputs": [],
"source": [
"fun = () -> compute_π(4_000_000_000)\n",
"fun = () -> @show compute_π(4_000_000_000)\n",
"t = Task(fun)"
]
},
@@ -359,7 +359,7 @@
"metadata": {},
"outputs": [],
"source": [
"fun = () -> compute_π_yield(3_000_000_000)\n",
"fun = () -> @show compute_π_yield(3_000_000_000)\n",
"t = Task(fun)\n",
"schedule(t)"
]
@@ -729,6 +729,18 @@
"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",
"id": "9ddd66ca",
@@ -746,7 +758,7 @@
"metadata": {},
"outputs": [],
"source": [
"t = @elapsed compute_π(100_000_000)"
"t = @elapsed @show compute_π(140_000_000)"
]
},
{
@@ -772,7 +784,7 @@
"outputs": [],
"source": [
"@time for i in 1:10\n",
" compute_π(100_000_000)\n",
" @show compute_π(140_000_000)\n",
"end"
]
},
@@ -810,7 +822,7 @@
"outputs": [],
"source": [
"@time for i in 1:10\n",
" @async compute_π(100_000_000)\n",
" @async @show compute_π(140_000_000)\n",
"end"
]
},
@@ -847,7 +859,7 @@
"outputs": [],
"source": [
"@time @sync for i in 1:10\n",
" @async compute_π(100_000_000)\n",
" @async @show compute_π(140_000_000)\n",
"end"
]
},
@@ -970,6 +982,22 @@
"</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",
"id": "a5d3730b",