Some improvements in the first notebooks

This commit is contained in:
Francesc Verdugo
2024-08-19 15:58:09 +02:00
parent 047d6feadb
commit 5abdc088d2
5 changed files with 307 additions and 203 deletions

View File

@@ -28,6 +28,56 @@
"Understanding these concepts is important to learn distributed computing later."
]
},
{
"cell_type": "markdown",
"id": "cde5ee75",
"metadata": {},
"source": [
"<div class=\"alert alert-block alert-info\">\n",
"<b>Note:</b> Do not forget to execute the next cell before starting this notebook! \n",
"</div>"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "0b0496c7",
"metadata": {},
"outputs": [],
"source": [
"function why_q1()\n",
" msg = \"\"\"\n",
" Evaluating compute_π(100_000_000) takes about 0.25 seconds on the teacher's laptop. Thus, the loop would take about 2.5 seconds since we are calling the function 10 times.\n",
" \"\"\"\n",
" println(msg)\n",
"end\n",
"function why_q2()\n",
" msg = \"\"\"\n",
" The time in doing the loop will be almost zero since the loop just schedules 10 tasks, which should be very fast.\n",
" \"\"\"\n",
" println(msg)\n",
"end\n",
"function why_q3()\n",
" msg = \"\"\"\n",
" It will take 2.5 seconds, like in question 1. The @sync macro forces to wait for all tasks we have generated with the @async macro. Since we have created 10 tasks and each of them takes about 0.25 seconds, the total time will be about 2.5 seconds.\n",
" \"\"\"\n",
" println(msg)\n",
"end\n",
"function why_q4()\n",
" msg = \"\"\"\n",
" It will take about 3 seconds. The channel has buffer size 4, thus the call to put!will not block. The call to take! will not block neither since there is a value stored in the channel. The taken value is 3 and therefore we will wait for 3 seconds.\n",
" \"\"\"\n",
" println(msg)\n",
"end\n",
"function why_q5()\n",
" msg = \"\"\"\n",
" The channel is not buffered and therefore the call to put! will block. The cell will run forever, since there is no other task that calls take! on this channel.\n",
" \"\"\"\n",
" println(msg)\n",
"end\n",
"println(\"🥳 Well done! \")"
]
},
{
"cell_type": "markdown",
"id": "caf64254",
@@ -726,6 +776,16 @@
"end"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d6b8382e",
"metadata": {},
"outputs": [],
"source": [
"why_q1()"
]
},
{
"cell_type": "markdown",
"id": "5f19d38c",
@@ -754,6 +814,16 @@
"end"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "edff9747",
"metadata": {},
"outputs": [],
"source": [
"why_q2()"
]
},
{
"cell_type": "markdown",
"id": "5041c355",
@@ -781,6 +851,16 @@
"end"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "87bc7c5c",
"metadata": {},
"outputs": [],
"source": [
"why_q3()"
]
},
{
"cell_type": "markdown",
"id": "841b690e",
@@ -821,6 +901,16 @@
"end"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "a18a0a7d",
"metadata": {},
"outputs": [],
"source": [
"why_q4()"
]
},
{
"cell_type": "markdown",
"id": "df663f11",
@@ -860,6 +950,26 @@
"end"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d8923fae",
"metadata": {},
"outputs": [],
"source": [
"why_q5()"
]
},
{
"cell_type": "markdown",
"id": "0ee77abe",
"metadata": {},
"source": [
"<div class=\"alert alert-block alert-info\">\n",
"<b>Note:</b> If for some reason a cell keeps running forever, we can stop it with Kernel > Interrupt or Kernel > Restart (see tabs above).\n",
"</div>"
]
},
{
"cell_type": "markdown",
"id": "a5d3730b",