mirror of
https://github.com/fverdugo/XM_40017.git
synced 2025-11-11 18:24:24 +01:00
build based on e6474b1
This commit is contained in:
parent
96c390a5bf
commit
b69d0e7340
@ -1 +1 @@
|
||||
{"documenter":{"julia_version":"1.9.3","generation_timestamp":"2023-10-16T12:03:36","documenter_version":"1.1.1"}}
|
||||
{"documenter":{"julia_version":"1.10.4","generation_timestamp":"2024-08-19T14:06:53","documenter_version":"1.5.0"}}
|
||||
255
dev/LEQ.ipynb
255
dev/LEQ.ipynb
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
273
dev/asp.ipynb
273
dev/asp.ipynb
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
1
dev/assets/themes/catppuccin-frappe.css
Normal file
1
dev/assets/themes/catppuccin-frappe.css
Normal file
File diff suppressed because one or more lines are too long
1
dev/assets/themes/catppuccin-latte.css
Normal file
1
dev/assets/themes/catppuccin-latte.css
Normal file
File diff suppressed because one or more lines are too long
1
dev/assets/themes/catppuccin-macchiato.css
Normal file
1
dev/assets/themes/catppuccin-macchiato.css
Normal file
File diff suppressed because one or more lines are too long
1
dev/assets/themes/catppuccin-mocha.css
Normal file
1
dev/assets/themes/catppuccin-mocha.css
Normal file
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -7333,11 +7333,12 @@ a.anchor-link {
|
||||
if (!diagrams.length) {
|
||||
return;
|
||||
}
|
||||
const mermaid = (await import("https://cdnjs.cloudflare.com/ajax/libs/mermaid/10.5.0/mermaid.esm.min.mjs")).default;
|
||||
const mermaid = (await import("https://cdnjs.cloudflare.com/ajax/libs/mermaid/10.7.0/mermaid.esm.min.mjs")).default;
|
||||
const parser = new DOMParser();
|
||||
|
||||
mermaid.initialize({
|
||||
maxTextSize: 100000,
|
||||
maxEdges: 100000,
|
||||
startOnLoad: false,
|
||||
fontFamily: window
|
||||
.getComputedStyle(document.body)
|
||||
@ -7408,7 +7409,8 @@ a.anchor-link {
|
||||
let results = null;
|
||||
let output = null;
|
||||
try {
|
||||
const { svg } = await mermaid.render(id, raw, el);
|
||||
let { svg } = await mermaid.render(id, raw, el);
|
||||
svg = cleanMermaidSvg(svg);
|
||||
results = makeMermaidImage(svg);
|
||||
output = document.createElement("figure");
|
||||
results.map(output.appendChild, output);
|
||||
@ -7423,6 +7425,38 @@ a.anchor-link {
|
||||
parent.appendChild(output);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Post-process to ensure mermaid diagrams contain only valid SVG and XHTML.
|
||||
*/
|
||||
function cleanMermaidSvg(svg) {
|
||||
return svg.replace(RE_VOID_ELEMENT, replaceVoidElement);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* A regular expression for all void elements, which may include attributes and
|
||||
* a slash.
|
||||
*
|
||||
* @see https://developer.mozilla.org/en-US/docs/Glossary/Void_element
|
||||
*
|
||||
* Of these, only `<br>` is generated by Mermaid in place of `\n`,
|
||||
* but _any_ "malformed" tag will break the SVG rendering entirely.
|
||||
*/
|
||||
const RE_VOID_ELEMENT =
|
||||
/<\s*(area|base|br|col|embed|hr|img|input|link|meta|param|source|track|wbr)\s*([^>]*?)\s*>/gi;
|
||||
|
||||
/**
|
||||
* Ensure a void element is closed with a slash, preserving any attributes.
|
||||
*/
|
||||
function replaceVoidElement(match, tag, rest) {
|
||||
rest = rest.trim();
|
||||
if (!rest.endsWith('/')) {
|
||||
rest = `${rest} /`;
|
||||
}
|
||||
return `<${tag} ${rest}>`;
|
||||
}
|
||||
|
||||
void Promise.all([...diagrams].map(renderOneMarmaid));
|
||||
});
|
||||
</script>
|
||||
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -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",
|
||||
@ -37,7 +87,7 @@
|
||||
"\n",
|
||||
"### Creating a task\n",
|
||||
"\n",
|
||||
"Technically, a task in Julia is a *symmetric co-routine*. More informally, a task is a piece of computation work that can be started (scheduled) at some point in the future, and that can be interrupted and resumed. To create a task, we first need to create a function that represents the work to be done in the task. In next cell, we generate a task that generates and sums two matrices."
|
||||
"Technically, a task in Julia is a *symmetric* [*co-routine*](https://en.wikipedia.org/wiki/Coroutine). More informally, a task is a piece of computational work that can be started (scheduled) at some point in the future, and that can be interrupted and resumed. To create a task, we first need to create a function that represents the work to be done in the task. In next cell, we generate a task that generates and sums two matrices."
|
||||
]
|
||||
},
|
||||
{
|
||||
@ -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",
|
||||
@ -873,15 +983,15 @@
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "Julia 1.9.0",
|
||||
"display_name": "Julia 1.10.0",
|
||||
"language": "julia",
|
||||
"name": "julia-1.9"
|
||||
"name": "julia-1.10"
|
||||
},
|
||||
"language_info": {
|
||||
"file_extension": ".jl",
|
||||
"mimetype": "application/julia",
|
||||
"name": "julia",
|
||||
"version": "1.9.0"
|
||||
"version": "1.10.0"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
|
||||
File diff suppressed because one or more lines are too long
@ -7333,11 +7333,12 @@ a.anchor-link {
|
||||
if (!diagrams.length) {
|
||||
return;
|
||||
}
|
||||
const mermaid = (await import("https://cdnjs.cloudflare.com/ajax/libs/mermaid/10.5.0/mermaid.esm.min.mjs")).default;
|
||||
const mermaid = (await import("https://cdnjs.cloudflare.com/ajax/libs/mermaid/10.7.0/mermaid.esm.min.mjs")).default;
|
||||
const parser = new DOMParser();
|
||||
|
||||
mermaid.initialize({
|
||||
maxTextSize: 100000,
|
||||
maxEdges: 100000,
|
||||
startOnLoad: false,
|
||||
fontFamily: window
|
||||
.getComputedStyle(document.body)
|
||||
@ -7408,7 +7409,8 @@ a.anchor-link {
|
||||
let results = null;
|
||||
let output = null;
|
||||
try {
|
||||
const { svg } = await mermaid.render(id, raw, el);
|
||||
let { svg } = await mermaid.render(id, raw, el);
|
||||
svg = cleanMermaidSvg(svg);
|
||||
results = makeMermaidImage(svg);
|
||||
output = document.createElement("figure");
|
||||
results.map(output.appendChild, output);
|
||||
@ -7423,6 +7425,38 @@ a.anchor-link {
|
||||
parent.appendChild(output);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Post-process to ensure mermaid diagrams contain only valid SVG and XHTML.
|
||||
*/
|
||||
function cleanMermaidSvg(svg) {
|
||||
return svg.replace(RE_VOID_ELEMENT, replaceVoidElement);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* A regular expression for all void elements, which may include attributes and
|
||||
* a slash.
|
||||
*
|
||||
* @see https://developer.mozilla.org/en-US/docs/Glossary/Void_element
|
||||
*
|
||||
* Of these, only `<br>` is generated by Mermaid in place of `\n`,
|
||||
* but _any_ "malformed" tag will break the SVG rendering entirely.
|
||||
*/
|
||||
const RE_VOID_ELEMENT =
|
||||
/<\s*(area|base|br|col|embed|hr|img|input|link|meta|param|source|track|wbr)\s*([^>]*?)\s*>/gi;
|
||||
|
||||
/**
|
||||
* Ensure a void element is closed with a slash, preserving any attributes.
|
||||
*/
|
||||
function replaceVoidElement(match, tag, rest) {
|
||||
rest = rest.trim();
|
||||
if (!rest.endsWith('/')) {
|
||||
rest = `${rest} /`;
|
||||
}
|
||||
return `<${tag} ${rest}>`;
|
||||
}
|
||||
|
||||
void Promise.all([...diagrams].map(renderOneMarmaid));
|
||||
});
|
||||
</script>
|
||||
@ -7506,13 +7540,70 @@ a.anchor-link {
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="jp-Cell jp-MarkdownCell jp-Notebook-cell" id="cell-id=cde5ee75">
|
||||
<div class="jp-Cell-inputWrapper" tabindex="0">
|
||||
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
|
||||
</div>
|
||||
<div class="jp-InputArea jp-Cell-inputArea"><div class="jp-InputPrompt jp-InputArea-prompt">
|
||||
</div><div class="jp-RenderedHTMLCommon jp-RenderedMarkdown jp-MarkdownOutput" data-mime-type="text/markdown">
|
||||
<div class="alert alert-block alert-info">
|
||||
<b>Note:</b> Do not forget to execute the next cell before starting this notebook!
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs" id="cell-id=0b0496c7">
|
||||
<div class="jp-Cell-inputWrapper" tabindex="0">
|
||||
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
|
||||
</div>
|
||||
<div class="jp-InputArea jp-Cell-inputArea">
|
||||
<div class="jp-InputPrompt jp-InputArea-prompt">In [ ]:</div>
|
||||
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
|
||||
<div class="cm-editor cm-s-jupyter">
|
||||
<div class="highlight hl-julia"><pre><span></span><span class="k">function</span><span class="w"> </span><span class="n">why_q1</span><span class="p">()</span>
|
||||
<span class="w"> </span><span class="n">msg</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s">"""</span>
|
||||
<span class="s"> 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.</span>
|
||||
<span class="s"> """</span>
|
||||
<span class="w"> </span><span class="n">println</span><span class="p">(</span><span class="n">msg</span><span class="p">)</span>
|
||||
<span class="k">end</span>
|
||||
<span class="k">function</span><span class="w"> </span><span class="n">why_q2</span><span class="p">()</span>
|
||||
<span class="w"> </span><span class="n">msg</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s">"""</span>
|
||||
<span class="s"> The time in doing the loop will be almost zero since the loop just schedules 10 tasks, which should be very fast.</span>
|
||||
<span class="s"> """</span>
|
||||
<span class="w"> </span><span class="n">println</span><span class="p">(</span><span class="n">msg</span><span class="p">)</span>
|
||||
<span class="k">end</span>
|
||||
<span class="k">function</span><span class="w"> </span><span class="n">why_q3</span><span class="p">()</span>
|
||||
<span class="w"> </span><span class="n">msg</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s">"""</span>
|
||||
<span class="s"> 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.</span>
|
||||
<span class="s"> """</span>
|
||||
<span class="w"> </span><span class="n">println</span><span class="p">(</span><span class="n">msg</span><span class="p">)</span>
|
||||
<span class="k">end</span>
|
||||
<span class="k">function</span><span class="w"> </span><span class="n">why_q4</span><span class="p">()</span>
|
||||
<span class="w"> </span><span class="n">msg</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s">"""</span>
|
||||
<span class="s"> 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.</span>
|
||||
<span class="s"> """</span>
|
||||
<span class="w"> </span><span class="n">println</span><span class="p">(</span><span class="n">msg</span><span class="p">)</span>
|
||||
<span class="k">end</span>
|
||||
<span class="k">function</span><span class="w"> </span><span class="n">why_q5</span><span class="p">()</span>
|
||||
<span class="w"> </span><span class="n">msg</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s">"""</span>
|
||||
<span class="s"> 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.</span>
|
||||
<span class="s"> """</span>
|
||||
<span class="w"> </span><span class="n">println</span><span class="p">(</span><span class="n">msg</span><span class="p">)</span>
|
||||
<span class="k">end</span>
|
||||
<span class="n">println</span><span class="p">(</span><span class="s">"🥳 Well done! "</span><span class="p">)</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="jp-Cell jp-MarkdownCell jp-Notebook-cell" id="cell-id=caf64254">
|
||||
<div class="jp-Cell-inputWrapper" tabindex="0">
|
||||
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
|
||||
</div>
|
||||
<div class="jp-InputArea jp-Cell-inputArea"><div class="jp-InputPrompt jp-InputArea-prompt">
|
||||
</div><div class="jp-RenderedHTMLCommon jp-RenderedMarkdown jp-MarkdownOutput" data-mime-type="text/markdown">
|
||||
<h2 id="Tasks">Tasks<a class="anchor-link" href="#Tasks">¶</a></h2><h3 id="Creating--a-task">Creating a task<a class="anchor-link" href="#Creating--a-task">¶</a></h3><p>Technically, a task in Julia is a <em>symmetric co-routine</em>. More informally, a task is a piece of computation work that can be started (scheduled) at some point in the future, and that can be interrupted and resumed. To create a task, we first need to create a function that represents the work to be done in the task. In next cell, we generate a task that generates and sums two matrices.</p>
|
||||
<h2 id="Tasks">Tasks<a class="anchor-link" href="#Tasks">¶</a></h2><h3 id="Creating--a-task">Creating a task<a class="anchor-link" href="#Creating--a-task">¶</a></h3><p>Technically, a task in Julia is a <em>symmetric</em> <a href="https://en.wikipedia.org/wiki/Coroutine"><em>co-routine</em></a>. More informally, a task is a piece of computational work that can be started (scheduled) at some point in the future, and that can be interrupted and resumed. To create a task, we first need to create a function that represents the work to be done in the task. In next cell, we generate a task that generates and sums two matrices.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@ -8397,6 +8488,20 @@ d) near 0*t </code></pre>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs" id="cell-id=d6b8382e">
|
||||
<div class="jp-Cell-inputWrapper" tabindex="0">
|
||||
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
|
||||
</div>
|
||||
<div class="jp-InputArea jp-Cell-inputArea">
|
||||
<div class="jp-InputPrompt jp-InputArea-prompt">In [ ]:</div>
|
||||
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
|
||||
<div class="cm-editor cm-s-jupyter">
|
||||
<div class="highlight hl-julia"><pre><span></span><span class="n">why_q1</span><span class="p">()</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="jp-Cell jp-MarkdownCell jp-Notebook-cell" id="cell-id=5f19d38c">
|
||||
<div class="jp-Cell-inputWrapper" tabindex="0">
|
||||
@ -8430,6 +8535,20 @@ d) near 0*t </code></pre>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs" id="cell-id=edff9747">
|
||||
<div class="jp-Cell-inputWrapper" tabindex="0">
|
||||
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
|
||||
</div>
|
||||
<div class="jp-InputArea jp-Cell-inputArea">
|
||||
<div class="jp-InputPrompt jp-InputArea-prompt">In [ ]:</div>
|
||||
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
|
||||
<div class="cm-editor cm-s-jupyter">
|
||||
<div class="highlight hl-julia"><pre><span></span><span class="n">why_q2</span><span class="p">()</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="jp-Cell jp-MarkdownCell jp-Notebook-cell" id="cell-id=5041c355">
|
||||
<div class="jp-Cell-inputWrapper" tabindex="0">
|
||||
@ -8463,6 +8582,20 @@ d) near 0*t </code></pre>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs" id="cell-id=87bc7c5c">
|
||||
<div class="jp-Cell-inputWrapper" tabindex="0">
|
||||
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
|
||||
</div>
|
||||
<div class="jp-InputArea jp-Cell-inputArea">
|
||||
<div class="jp-InputPrompt jp-InputArea-prompt">In [ ]:</div>
|
||||
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
|
||||
<div class="cm-editor cm-s-jupyter">
|
||||
<div class="highlight hl-julia"><pre><span></span><span class="n">why_q3</span><span class="p">()</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="jp-Cell jp-MarkdownCell jp-Notebook-cell" id="cell-id=841b690e">
|
||||
<div class="jp-Cell-inputWrapper" tabindex="0">
|
||||
@ -8513,6 +8646,20 @@ d) 3 seconds</code></pre>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs" id="cell-id=a18a0a7d">
|
||||
<div class="jp-Cell-inputWrapper" tabindex="0">
|
||||
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
|
||||
</div>
|
||||
<div class="jp-InputArea jp-Cell-inputArea">
|
||||
<div class="jp-InputPrompt jp-InputArea-prompt">In [ ]:</div>
|
||||
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
|
||||
<div class="cm-editor cm-s-jupyter">
|
||||
<div class="highlight hl-julia"><pre><span></span><span class="n">why_q4</span><span class="p">()</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="jp-Cell jp-MarkdownCell jp-Notebook-cell" id="cell-id=df663f11">
|
||||
<div class="jp-Cell-inputWrapper" tabindex="0">
|
||||
@ -8562,6 +8709,33 @@ d) 3 seconds</code></pre>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs" id="cell-id=d8923fae">
|
||||
<div class="jp-Cell-inputWrapper" tabindex="0">
|
||||
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
|
||||
</div>
|
||||
<div class="jp-InputArea jp-Cell-inputArea">
|
||||
<div class="jp-InputPrompt jp-InputArea-prompt">In [ ]:</div>
|
||||
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
|
||||
<div class="cm-editor cm-s-jupyter">
|
||||
<div class="highlight hl-julia"><pre><span></span><span class="n">why_q5</span><span class="p">()</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="jp-Cell jp-MarkdownCell jp-Notebook-cell" id="cell-id=0ee77abe">
|
||||
<div class="jp-Cell-inputWrapper" tabindex="0">
|
||||
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
|
||||
</div>
|
||||
<div class="jp-InputArea jp-Cell-inputArea"><div class="jp-InputPrompt jp-InputArea-prompt">
|
||||
</div><div class="jp-RenderedHTMLCommon jp-RenderedMarkdown jp-MarkdownOutput" data-mime-type="text/markdown">
|
||||
<div class="alert alert-block alert-info">
|
||||
<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).
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="jp-Cell jp-MarkdownCell jp-Notebook-cell" id="cell-id=a5d3730b">
|
||||
<div class="jp-Cell-inputWrapper" tabindex="0">
|
||||
|
||||
@ -147,6 +147,44 @@
|
||||
"foo()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "d18e679d",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### A very easy first exercise\n",
|
||||
"\n",
|
||||
"Run the following cell. It contains definitions used later in the notebook."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "81678b3d",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"function why_q1()\n",
|
||||
" msg = \"\"\"\n",
|
||||
" In the first line, we assign a variable to a value. In the second line, we assign another variable to the same value. Thus, we have 2 variables associated with the same value. In line 3, we associate y to a new value (re-assignment). Thus, we have 2 variables associated with 2 different values. Variable x is still associated with its original value. Thus, the value at the final line is x=1.\n",
|
||||
" \"\"\"\n",
|
||||
" println(msg)\n",
|
||||
"end\n",
|
||||
"function why_q2()\n",
|
||||
" msg = \"\"\"\n",
|
||||
" It will be 1 for very similar reasons as in the previous questions: we are reassigning a local variable, not the global variable defined outside the function.\n",
|
||||
" \"\"\"\n",
|
||||
" println(msg)\n",
|
||||
"end\n",
|
||||
"function why_q3()\n",
|
||||
" msg = \"\"\"\n",
|
||||
" It will be 6. In the returned function f2, x is equal to 2. Thus, when calling f2(3) we compute 2*3.\n",
|
||||
" \"\"\"\n",
|
||||
" println(msg)\n",
|
||||
"end\n",
|
||||
"println(\"🥳 Well done! \")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "92112bd1",
|
||||
@ -467,6 +505,24 @@
|
||||
"x"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "a2f94960",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Run next cell to get an explanation of this question."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "fc562337",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"why_q1()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "4d2cb752",
|
||||
@ -586,6 +642,24 @@
|
||||
"x"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "f69108c2",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Run next cell to get an explanation of this question."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "05c62aa3",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"why_q2()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "4fc5eb9b",
|
||||
@ -1068,6 +1142,24 @@
|
||||
"x"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "062ff145",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Run next cell to get an explanation of this question."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "6bf7818e",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"why_q3()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "bc8e9bcf",
|
||||
@ -1649,15 +1741,15 @@
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "Julia 1.9.0",
|
||||
"display_name": "Julia 1.10.0",
|
||||
"language": "julia",
|
||||
"name": "julia-1.9"
|
||||
"name": "julia-1.10"
|
||||
},
|
||||
"language_info": {
|
||||
"file_extension": ".jl",
|
||||
"mimetype": "application/julia",
|
||||
"name": "julia",
|
||||
"version": "1.9.0"
|
||||
"version": "1.10.0"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
|
||||
File diff suppressed because one or more lines are too long
@ -7333,11 +7333,12 @@ a.anchor-link {
|
||||
if (!diagrams.length) {
|
||||
return;
|
||||
}
|
||||
const mermaid = (await import("https://cdnjs.cloudflare.com/ajax/libs/mermaid/10.5.0/mermaid.esm.min.mjs")).default;
|
||||
const mermaid = (await import("https://cdnjs.cloudflare.com/ajax/libs/mermaid/10.7.0/mermaid.esm.min.mjs")).default;
|
||||
const parser = new DOMParser();
|
||||
|
||||
mermaid.initialize({
|
||||
maxTextSize: 100000,
|
||||
maxEdges: 100000,
|
||||
startOnLoad: false,
|
||||
fontFamily: window
|
||||
.getComputedStyle(document.body)
|
||||
@ -7408,7 +7409,8 @@ a.anchor-link {
|
||||
let results = null;
|
||||
let output = null;
|
||||
try {
|
||||
const { svg } = await mermaid.render(id, raw, el);
|
||||
let { svg } = await mermaid.render(id, raw, el);
|
||||
svg = cleanMermaidSvg(svg);
|
||||
results = makeMermaidImage(svg);
|
||||
output = document.createElement("figure");
|
||||
results.map(output.appendChild, output);
|
||||
@ -7423,6 +7425,38 @@ a.anchor-link {
|
||||
parent.appendChild(output);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Post-process to ensure mermaid diagrams contain only valid SVG and XHTML.
|
||||
*/
|
||||
function cleanMermaidSvg(svg) {
|
||||
return svg.replace(RE_VOID_ELEMENT, replaceVoidElement);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* A regular expression for all void elements, which may include attributes and
|
||||
* a slash.
|
||||
*
|
||||
* @see https://developer.mozilla.org/en-US/docs/Glossary/Void_element
|
||||
*
|
||||
* Of these, only `<br>` is generated by Mermaid in place of `\n`,
|
||||
* but _any_ "malformed" tag will break the SVG rendering entirely.
|
||||
*/
|
||||
const RE_VOID_ELEMENT =
|
||||
/<\s*(area|base|br|col|embed|hr|img|input|link|meta|param|source|track|wbr)\s*([^>]*?)\s*>/gi;
|
||||
|
||||
/**
|
||||
* Ensure a void element is closed with a slash, preserving any attributes.
|
||||
*/
|
||||
function replaceVoidElement(match, tag, rest) {
|
||||
rest = rest.trim();
|
||||
if (!rest.endsWith('/')) {
|
||||
rest = `${rest} /`;
|
||||
}
|
||||
return `<${tag} ${rest}>`;
|
||||
}
|
||||
|
||||
void Promise.all([...diagrams].map(renderOneMarmaid));
|
||||
});
|
||||
</script>
|
||||
@ -7635,6 +7669,49 @@ a.anchor-link {
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="jp-Cell jp-MarkdownCell jp-Notebook-cell" id="cell-id=d18e679d">
|
||||
<div class="jp-Cell-inputWrapper" tabindex="0">
|
||||
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
|
||||
</div>
|
||||
<div class="jp-InputArea jp-Cell-inputArea"><div class="jp-InputPrompt jp-InputArea-prompt">
|
||||
</div><div class="jp-RenderedHTMLCommon jp-RenderedMarkdown jp-MarkdownOutput" data-mime-type="text/markdown">
|
||||
<h3 id="A-very-easy-first-exercise">A very easy first exercise<a class="anchor-link" href="#A-very-easy-first-exercise">¶</a></h3><p>Run the following cell. It contains definitions used later in the notebook.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs" id="cell-id=81678b3d">
|
||||
<div class="jp-Cell-inputWrapper" tabindex="0">
|
||||
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
|
||||
</div>
|
||||
<div class="jp-InputArea jp-Cell-inputArea">
|
||||
<div class="jp-InputPrompt jp-InputArea-prompt">In [ ]:</div>
|
||||
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
|
||||
<div class="cm-editor cm-s-jupyter">
|
||||
<div class="highlight hl-julia"><pre><span></span><span class="k">function</span><span class="w"> </span><span class="n">why_q1</span><span class="p">()</span>
|
||||
<span class="w"> </span><span class="n">msg</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s">"""</span>
|
||||
<span class="s"> In the first line, we assign a variable to a value. In the second line, we assign another variable to the same value. Thus, we have 2 variables associated with the same value. In line 3, we associate y to a new value (re-assignment). Thus, we have 2 variables associated with 2 different values. Variable x is still associated with its original value. Thus, the value at the final line is x=1.</span>
|
||||
<span class="s"> """</span>
|
||||
<span class="w"> </span><span class="n">println</span><span class="p">(</span><span class="n">msg</span><span class="p">)</span>
|
||||
<span class="k">end</span>
|
||||
<span class="k">function</span><span class="w"> </span><span class="n">why_q2</span><span class="p">()</span>
|
||||
<span class="w"> </span><span class="n">msg</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s">"""</span>
|
||||
<span class="s"> It will be 1 for very similar reasons as in the previous questions: we are reassigning a local variable, not the global variable defined outside the function.</span>
|
||||
<span class="s"> """</span>
|
||||
<span class="w"> </span><span class="n">println</span><span class="p">(</span><span class="n">msg</span><span class="p">)</span>
|
||||
<span class="k">end</span>
|
||||
<span class="k">function</span><span class="w"> </span><span class="n">why_q3</span><span class="p">()</span>
|
||||
<span class="w"> </span><span class="n">msg</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s">"""</span>
|
||||
<span class="s"> It will be 6. In the returned function f2, x is equal to 2. Thus, when calling f2(3) we compute 2*3.</span>
|
||||
<span class="s"> """</span>
|
||||
<span class="w"> </span><span class="n">println</span><span class="p">(</span><span class="n">msg</span><span class="p">)</span>
|
||||
<span class="k">end</span>
|
||||
<span class="n">println</span><span class="p">(</span><span class="s">"🥳 Well done! "</span><span class="p">)</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="jp-Cell jp-MarkdownCell jp-Notebook-cell" id="cell-id=92112bd1">
|
||||
<div class="jp-Cell-inputWrapper" tabindex="0">
|
||||
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
|
||||
@ -8049,6 +8126,31 @@ a.anchor-link {
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="jp-Cell jp-MarkdownCell jp-Notebook-cell" id="cell-id=a2f94960">
|
||||
<div class="jp-Cell-inputWrapper" tabindex="0">
|
||||
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
|
||||
</div>
|
||||
<div class="jp-InputArea jp-Cell-inputArea"><div class="jp-InputPrompt jp-InputArea-prompt">
|
||||
</div><div class="jp-RenderedHTMLCommon jp-RenderedMarkdown jp-MarkdownOutput" data-mime-type="text/markdown">
|
||||
<p>Run next cell to get an explanation of this question.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs" id="cell-id=fc562337">
|
||||
<div class="jp-Cell-inputWrapper" tabindex="0">
|
||||
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
|
||||
</div>
|
||||
<div class="jp-InputArea jp-Cell-inputArea">
|
||||
<div class="jp-InputPrompt jp-InputArea-prompt">In [ ]:</div>
|
||||
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
|
||||
<div class="cm-editor cm-s-jupyter">
|
||||
<div class="highlight hl-julia"><pre><span></span><span class="n">why_q1</span><span class="p">()</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="jp-Cell jp-MarkdownCell jp-Notebook-cell" id="cell-id=4d2cb752">
|
||||
<div class="jp-Cell-inputWrapper" tabindex="0">
|
||||
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
|
||||
@ -8200,6 +8302,31 @@ a.anchor-link {
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="jp-Cell jp-MarkdownCell jp-Notebook-cell" id="cell-id=f69108c2">
|
||||
<div class="jp-Cell-inputWrapper" tabindex="0">
|
||||
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
|
||||
</div>
|
||||
<div class="jp-InputArea jp-Cell-inputArea"><div class="jp-InputPrompt jp-InputArea-prompt">
|
||||
</div><div class="jp-RenderedHTMLCommon jp-RenderedMarkdown jp-MarkdownOutput" data-mime-type="text/markdown">
|
||||
<p>Run next cell to get an explanation of this question.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs" id="cell-id=05c62aa3">
|
||||
<div class="jp-Cell-inputWrapper" tabindex="0">
|
||||
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
|
||||
</div>
|
||||
<div class="jp-InputArea jp-Cell-inputArea">
|
||||
<div class="jp-InputPrompt jp-InputArea-prompt">In [ ]:</div>
|
||||
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
|
||||
<div class="cm-editor cm-s-jupyter">
|
||||
<div class="highlight hl-julia"><pre><span></span><span class="n">why_q2</span><span class="p">()</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="jp-Cell jp-MarkdownCell jp-Notebook-cell" id="cell-id=4fc5eb9b">
|
||||
<div class="jp-Cell-inputWrapper" tabindex="0">
|
||||
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
|
||||
@ -8825,6 +8952,31 @@ a.anchor-link {
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="jp-Cell jp-MarkdownCell jp-Notebook-cell" id="cell-id=062ff145">
|
||||
<div class="jp-Cell-inputWrapper" tabindex="0">
|
||||
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
|
||||
</div>
|
||||
<div class="jp-InputArea jp-Cell-inputArea"><div class="jp-InputPrompt jp-InputArea-prompt">
|
||||
</div><div class="jp-RenderedHTMLCommon jp-RenderedMarkdown jp-MarkdownOutput" data-mime-type="text/markdown">
|
||||
<p>Run next cell to get an explanation of this question.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs" id="cell-id=6bf7818e">
|
||||
<div class="jp-Cell-inputWrapper" tabindex="0">
|
||||
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
|
||||
</div>
|
||||
<div class="jp-InputArea jp-Cell-inputArea">
|
||||
<div class="jp-InputPrompt jp-InputArea-prompt">In [ ]:</div>
|
||||
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
|
||||
<div class="cm-editor cm-s-jupyter">
|
||||
<div class="highlight hl-julia"><pre><span></span><span class="n">why_q3</span><span class="p">()</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="jp-Cell jp-MarkdownCell jp-Notebook-cell" id="cell-id=bc8e9bcf">
|
||||
<div class="jp-Cell-inputWrapper" tabindex="0">
|
||||
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
|
||||
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -7333,11 +7333,12 @@ a.anchor-link {
|
||||
if (!diagrams.length) {
|
||||
return;
|
||||
}
|
||||
const mermaid = (await import("https://cdnjs.cloudflare.com/ajax/libs/mermaid/10.5.0/mermaid.esm.min.mjs")).default;
|
||||
const mermaid = (await import("https://cdnjs.cloudflare.com/ajax/libs/mermaid/10.7.0/mermaid.esm.min.mjs")).default;
|
||||
const parser = new DOMParser();
|
||||
|
||||
mermaid.initialize({
|
||||
maxTextSize: 100000,
|
||||
maxEdges: 100000,
|
||||
startOnLoad: false,
|
||||
fontFamily: window
|
||||
.getComputedStyle(document.body)
|
||||
@ -7408,7 +7409,8 @@ a.anchor-link {
|
||||
let results = null;
|
||||
let output = null;
|
||||
try {
|
||||
const { svg } = await mermaid.render(id, raw, el);
|
||||
let { svg } = await mermaid.render(id, raw, el);
|
||||
svg = cleanMermaidSvg(svg);
|
||||
results = makeMermaidImage(svg);
|
||||
output = document.createElement("figure");
|
||||
results.map(output.appendChild, output);
|
||||
@ -7423,6 +7425,38 @@ a.anchor-link {
|
||||
parent.appendChild(output);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Post-process to ensure mermaid diagrams contain only valid SVG and XHTML.
|
||||
*/
|
||||
function cleanMermaidSvg(svg) {
|
||||
return svg.replace(RE_VOID_ELEMENT, replaceVoidElement);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* A regular expression for all void elements, which may include attributes and
|
||||
* a slash.
|
||||
*
|
||||
* @see https://developer.mozilla.org/en-US/docs/Glossary/Void_element
|
||||
*
|
||||
* Of these, only `<br>` is generated by Mermaid in place of `\n`,
|
||||
* but _any_ "malformed" tag will break the SVG rendering entirely.
|
||||
*/
|
||||
const RE_VOID_ELEMENT =
|
||||
/<\s*(area|base|br|col|embed|hr|img|input|link|meta|param|source|track|wbr)\s*([^>]*?)\s*>/gi;
|
||||
|
||||
/**
|
||||
* Ensure a void element is closed with a slash, preserving any attributes.
|
||||
*/
|
||||
function replaceVoidElement(match, tag, rest) {
|
||||
rest = rest.trim();
|
||||
if (!rest.endsWith('/')) {
|
||||
rest = `${rest} /`;
|
||||
}
|
||||
return `<${tag} ${rest}>`;
|
||||
}
|
||||
|
||||
void Promise.all([...diagrams].map(renderOneMarmaid));
|
||||
});
|
||||
</script>
|
||||
|
||||
File diff suppressed because one or more lines are too long
@ -7333,11 +7333,12 @@ a.anchor-link {
|
||||
if (!diagrams.length) {
|
||||
return;
|
||||
}
|
||||
const mermaid = (await import("https://cdnjs.cloudflare.com/ajax/libs/mermaid/10.5.0/mermaid.esm.min.mjs")).default;
|
||||
const mermaid = (await import("https://cdnjs.cloudflare.com/ajax/libs/mermaid/10.7.0/mermaid.esm.min.mjs")).default;
|
||||
const parser = new DOMParser();
|
||||
|
||||
mermaid.initialize({
|
||||
maxTextSize: 100000,
|
||||
maxEdges: 100000,
|
||||
startOnLoad: false,
|
||||
fontFamily: window
|
||||
.getComputedStyle(document.body)
|
||||
@ -7408,7 +7409,8 @@ a.anchor-link {
|
||||
let results = null;
|
||||
let output = null;
|
||||
try {
|
||||
const { svg } = await mermaid.render(id, raw, el);
|
||||
let { svg } = await mermaid.render(id, raw, el);
|
||||
svg = cleanMermaidSvg(svg);
|
||||
results = makeMermaidImage(svg);
|
||||
output = document.createElement("figure");
|
||||
results.map(output.appendChild, output);
|
||||
@ -7423,6 +7425,38 @@ a.anchor-link {
|
||||
parent.appendChild(output);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Post-process to ensure mermaid diagrams contain only valid SVG and XHTML.
|
||||
*/
|
||||
function cleanMermaidSvg(svg) {
|
||||
return svg.replace(RE_VOID_ELEMENT, replaceVoidElement);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* A regular expression for all void elements, which may include attributes and
|
||||
* a slash.
|
||||
*
|
||||
* @see https://developer.mozilla.org/en-US/docs/Glossary/Void_element
|
||||
*
|
||||
* Of these, only `<br>` is generated by Mermaid in place of `\n`,
|
||||
* but _any_ "malformed" tag will break the SVG rendering entirely.
|
||||
*/
|
||||
const RE_VOID_ELEMENT =
|
||||
/<\s*(area|base|br|col|embed|hr|img|input|link|meta|param|source|track|wbr)\s*([^>]*?)\s*>/gi;
|
||||
|
||||
/**
|
||||
* Ensure a void element is closed with a slash, preserving any attributes.
|
||||
*/
|
||||
function replaceVoidElement(match, tag, rest) {
|
||||
rest = rest.trim();
|
||||
if (!rest.endsWith('/')) {
|
||||
rest = `${rest} /`;
|
||||
}
|
||||
return `<${tag} ${rest}>`;
|
||||
}
|
||||
|
||||
void Promise.all([...diagrams].map(renderOneMarmaid));
|
||||
});
|
||||
</script>
|
||||
|
||||
1848
dev/julia_mpi.ipynb
Normal file
1848
dev/julia_mpi.ipynb
Normal file
File diff suppressed because one or more lines are too long
17
dev/julia_mpi/index.html
Normal file
17
dev/julia_mpi/index.html
Normal file
File diff suppressed because one or more lines are too long
9589
dev/julia_mpi_src/index.html
Normal file
9589
dev/julia_mpi_src/index.html
Normal file
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -7333,11 +7333,12 @@ a.anchor-link {
|
||||
if (!diagrams.length) {
|
||||
return;
|
||||
}
|
||||
const mermaid = (await import("https://cdnjs.cloudflare.com/ajax/libs/mermaid/10.5.0/mermaid.esm.min.mjs")).default;
|
||||
const mermaid = (await import("https://cdnjs.cloudflare.com/ajax/libs/mermaid/10.7.0/mermaid.esm.min.mjs")).default;
|
||||
const parser = new DOMParser();
|
||||
|
||||
mermaid.initialize({
|
||||
maxTextSize: 100000,
|
||||
maxEdges: 100000,
|
||||
startOnLoad: false,
|
||||
fontFamily: window
|
||||
.getComputedStyle(document.body)
|
||||
@ -7408,7 +7409,8 @@ a.anchor-link {
|
||||
let results = null;
|
||||
let output = null;
|
||||
try {
|
||||
const { svg } = await mermaid.render(id, raw, el);
|
||||
let { svg } = await mermaid.render(id, raw, el);
|
||||
svg = cleanMermaidSvg(svg);
|
||||
results = makeMermaidImage(svg);
|
||||
output = document.createElement("figure");
|
||||
results.map(output.appendChild, output);
|
||||
@ -7423,6 +7425,38 @@ a.anchor-link {
|
||||
parent.appendChild(output);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Post-process to ensure mermaid diagrams contain only valid SVG and XHTML.
|
||||
*/
|
||||
function cleanMermaidSvg(svg) {
|
||||
return svg.replace(RE_VOID_ELEMENT, replaceVoidElement);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* A regular expression for all void elements, which may include attributes and
|
||||
* a slash.
|
||||
*
|
||||
* @see https://developer.mozilla.org/en-US/docs/Glossary/Void_element
|
||||
*
|
||||
* Of these, only `<br>` is generated by Mermaid in place of `\n`,
|
||||
* but _any_ "malformed" tag will break the SVG rendering entirely.
|
||||
*/
|
||||
const RE_VOID_ELEMENT =
|
||||
/<\s*(area|base|br|col|embed|hr|img|input|link|meta|param|source|track|wbr)\s*([^>]*?)\s*>/gi;
|
||||
|
||||
/**
|
||||
* Ensure a void element is closed with a slash, preserving any attributes.
|
||||
*/
|
||||
function replaceVoidElement(match, tag, rest) {
|
||||
rest = rest.trim();
|
||||
if (!rest.endsWith('/')) {
|
||||
rest = `${rest} /`;
|
||||
}
|
||||
return `<${tag} ${rest}>`;
|
||||
}
|
||||
|
||||
void Promise.all([...diagrams].map(renderOneMarmaid));
|
||||
});
|
||||
</script>
|
||||
|
||||
@ -219,10 +219,10 @@
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"<div class=\"alert alert-block alert-info\">\n",
|
||||
"<b>Note:</b> The matrix-matrix multiplication naively implemented with 3 nested loops as above is known to be very inefficient (memory bound). Libraries such as BLAS provide much more efficient implementations, which are the ones used in practice (e.g., by the `*` operator in Julia). We consider, our hand-written implementation as a simple way of expressing the algorithm we are interested in.\n",
|
||||
"<b>Note:</b> The matrix-matrix multiplication naively implemented with 3 nested loops as above is known to be very inefficient (memory bound). Libraries such as BLAS provide much more efficient implementations, which are the ones used in practice (e.g., by the `*` operator in Julia). We consider our hand-written implementation as a simple way of expressing the algorithm we are interested in.\n",
|
||||
"</div>\n",
|
||||
"\n",
|
||||
"Run the following cell to compare the performance of our hand-written function with respect to the built in function `mul!`\n"
|
||||
"Run the following cell to compare the performance of our hand-written function with respect to the built in function `mul!`.\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
@ -1060,107 +1060,6 @@
|
||||
"println(\"Efficiency = \", 100*(T1/TP)/P, \"%\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "fa8d7f40",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### Exercise 2"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "0e7c607e",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"The implementation of algorithm 1 is very impractical. One needs as many processors as entries in the result matrix C. For 1000 times 1000 matrix one would need a supercomputer with one million processes! We can easily fix this problem by using less processors and spawning the computation of an entry in any of the available processes.\n",
|
||||
"See the following code:"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "023b20d1",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"function matmul_dist_1_v2!(C, A, B)\n",
|
||||
" m = size(C,1)\n",
|
||||
" n = size(C,2)\n",
|
||||
" l = size(A,2)\n",
|
||||
" @assert size(A,1) == m\n",
|
||||
" @assert size(B,2) == n\n",
|
||||
" @assert size(B,1) == l\n",
|
||||
" z = zero(eltype(C))\n",
|
||||
" @sync for j in 1:n\n",
|
||||
" for i in 1:m\n",
|
||||
" Ai = A[i,:]\n",
|
||||
" Bj = B[:,j]\n",
|
||||
" ftr = @spawnat :any begin\n",
|
||||
" Cij = z\n",
|
||||
" for k in 1:l\n",
|
||||
" @inbounds Cij += Ai[k]*Bj[k]\n",
|
||||
" end\n",
|
||||
" Cij\n",
|
||||
" end\n",
|
||||
" @async C[i,j] = fetch(ftr)\n",
|
||||
" end\n",
|
||||
" end\n",
|
||||
" C\n",
|
||||
"end"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "52005ca1",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"With this new implementation, we can multiply matrices of arbitrary size with a fixed number of workers. Test it:"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "c1d3595b",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"using Test\n",
|
||||
"N = 50\n",
|
||||
"A = rand(N,N)\n",
|
||||
"B = rand(N,N)\n",
|
||||
"C = similar(A)\n",
|
||||
"@test matmul_dist_1_v2!(C,A,B) ≈ A*B"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "ab609c18",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Run the next cell to check the performance of this implementation. Note that we are far away from the optimal speed up. Why? To answer this question compute the theoretical communication over computation ratio for this implementation and reason about the obtained result. Hint: the number of times a worker is spawned in this implementation is N^2/P on average."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "d7d31710",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"N = 100\n",
|
||||
"A = rand(N,N)\n",
|
||||
"B = rand(N,N)\n",
|
||||
"C = similar(A)\n",
|
||||
"P = nworkers()\n",
|
||||
"T1 = @belapsed matmul_seq!(C,A,B)\n",
|
||||
"C = similar(A)\n",
|
||||
"TP = @belapsed matmul_dist_1_v2!(C,A,B)\n",
|
||||
"println(\"Speedup = \", T1/TP)\n",
|
||||
"println(\"Optimal speedup = \", P)\n",
|
||||
"println(\"Efficiency = \", 100*(T1/TP)/P, \"%\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "8e171362",
|
||||
@ -1175,15 +1074,15 @@
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "Julia 1.9.0",
|
||||
"display_name": "Julia 1.10.0",
|
||||
"language": "julia",
|
||||
"name": "julia-1.9"
|
||||
"name": "julia-1.10"
|
||||
},
|
||||
"language_info": {
|
||||
"file_extension": ".jl",
|
||||
"mimetype": "application/julia",
|
||||
"name": "julia",
|
||||
"version": "1.9.0"
|
||||
"version": "1.10.0"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
|
||||
File diff suppressed because one or more lines are too long
@ -7333,11 +7333,12 @@ a.anchor-link {
|
||||
if (!diagrams.length) {
|
||||
return;
|
||||
}
|
||||
const mermaid = (await import("https://cdnjs.cloudflare.com/ajax/libs/mermaid/10.5.0/mermaid.esm.min.mjs")).default;
|
||||
const mermaid = (await import("https://cdnjs.cloudflare.com/ajax/libs/mermaid/10.7.0/mermaid.esm.min.mjs")).default;
|
||||
const parser = new DOMParser();
|
||||
|
||||
mermaid.initialize({
|
||||
maxTextSize: 100000,
|
||||
maxEdges: 100000,
|
||||
startOnLoad: false,
|
||||
fontFamily: window
|
||||
.getComputedStyle(document.body)
|
||||
@ -7408,7 +7409,8 @@ a.anchor-link {
|
||||
let results = null;
|
||||
let output = null;
|
||||
try {
|
||||
const { svg } = await mermaid.render(id, raw, el);
|
||||
let { svg } = await mermaid.render(id, raw, el);
|
||||
svg = cleanMermaidSvg(svg);
|
||||
results = makeMermaidImage(svg);
|
||||
output = document.createElement("figure");
|
||||
results.map(output.appendChild, output);
|
||||
@ -7423,6 +7425,38 @@ a.anchor-link {
|
||||
parent.appendChild(output);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Post-process to ensure mermaid diagrams contain only valid SVG and XHTML.
|
||||
*/
|
||||
function cleanMermaidSvg(svg) {
|
||||
return svg.replace(RE_VOID_ELEMENT, replaceVoidElement);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* A regular expression for all void elements, which may include attributes and
|
||||
* a slash.
|
||||
*
|
||||
* @see https://developer.mozilla.org/en-US/docs/Glossary/Void_element
|
||||
*
|
||||
* Of these, only `<br>` is generated by Mermaid in place of `\n`,
|
||||
* but _any_ "malformed" tag will break the SVG rendering entirely.
|
||||
*/
|
||||
const RE_VOID_ELEMENT =
|
||||
/<\s*(area|base|br|col|embed|hr|img|input|link|meta|param|source|track|wbr)\s*([^>]*?)\s*>/gi;
|
||||
|
||||
/**
|
||||
* Ensure a void element is closed with a slash, preserving any attributes.
|
||||
*/
|
||||
function replaceVoidElement(match, tag, rest) {
|
||||
rest = rest.trim();
|
||||
if (!rest.endsWith('/')) {
|
||||
rest = `${rest} /`;
|
||||
}
|
||||
return `<${tag} ${rest}>`;
|
||||
}
|
||||
|
||||
void Promise.all([...diagrams].map(renderOneMarmaid));
|
||||
});
|
||||
</script>
|
||||
@ -7742,9 +7776,9 @@ a.anchor-link {
|
||||
<div class="jp-InputArea jp-Cell-inputArea"><div class="jp-InputPrompt jp-InputArea-prompt">
|
||||
</div><div class="jp-RenderedHTMLCommon jp-RenderedMarkdown jp-MarkdownOutput" data-mime-type="text/markdown">
|
||||
<div class="alert alert-block alert-info">
|
||||
<b>Note:</b> The matrix-matrix multiplication naively implemented with 3 nested loops as above is known to be very inefficient (memory bound). Libraries such as BLAS provide much more efficient implementations, which are the ones used in practice (e.g., by the `*` operator in Julia). We consider, our hand-written implementation as a simple way of expressing the algorithm we are interested in.
|
||||
<b>Note:</b> The matrix-matrix multiplication naively implemented with 3 nested loops as above is known to be very inefficient (memory bound). Libraries such as BLAS provide much more efficient implementations, which are the ones used in practice (e.g., by the `*` operator in Julia). We consider our hand-written implementation as a simple way of expressing the algorithm we are interested in.
|
||||
</div>
|
||||
<p>Run the following cell to compare the performance of our hand-written function with respect to the built in function <code>mul!</code></p>
|
||||
<p>Run the following cell to compare the performance of our hand-written function with respect to the built in function <code>mul!</code>.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@ -8757,131 +8791,6 @@ d) O(N²/P) communication and O(N³/P) computation</code></pre>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="jp-Cell jp-MarkdownCell jp-Notebook-cell" id="cell-id=fa8d7f40">
|
||||
<div class="jp-Cell-inputWrapper" tabindex="0">
|
||||
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
|
||||
</div>
|
||||
<div class="jp-InputArea jp-Cell-inputArea"><div class="jp-InputPrompt jp-InputArea-prompt">
|
||||
</div><div class="jp-RenderedHTMLCommon jp-RenderedMarkdown jp-MarkdownOutput" data-mime-type="text/markdown">
|
||||
<h3 id="Exercise-2">Exercise 2<a class="anchor-link" href="#Exercise-2">¶</a></h3>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="jp-Cell jp-MarkdownCell jp-Notebook-cell" id="cell-id=0e7c607e">
|
||||
<div class="jp-Cell-inputWrapper" tabindex="0">
|
||||
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
|
||||
</div>
|
||||
<div class="jp-InputArea jp-Cell-inputArea"><div class="jp-InputPrompt jp-InputArea-prompt">
|
||||
</div><div class="jp-RenderedHTMLCommon jp-RenderedMarkdown jp-MarkdownOutput" data-mime-type="text/markdown">
|
||||
<p>The implementation of algorithm 1 is very impractical. One needs as many processors as entries in the result matrix C. For 1000 times 1000 matrix one would need a supercomputer with one million processes! We can easily fix this problem by using less processors and spawning the computation of an entry in any of the available processes.
|
||||
See the following code:</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs" id="cell-id=023b20d1">
|
||||
<div class="jp-Cell-inputWrapper" tabindex="0">
|
||||
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
|
||||
</div>
|
||||
<div class="jp-InputArea jp-Cell-inputArea">
|
||||
<div class="jp-InputPrompt jp-InputArea-prompt">In [ ]:</div>
|
||||
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
|
||||
<div class="cm-editor cm-s-jupyter">
|
||||
<div class="highlight hl-julia"><pre><span></span><span class="k">function</span><span class="w"> </span><span class="n">matmul_dist_1_v2!</span><span class="p">(</span><span class="n">C</span><span class="p">,</span><span class="w"> </span><span class="n">A</span><span class="p">,</span><span class="w"> </span><span class="n">B</span><span class="p">)</span>
|
||||
<span class="w"> </span><span class="n">m</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">size</span><span class="p">(</span><span class="n">C</span><span class="p">,</span><span class="mi">1</span><span class="p">)</span>
|
||||
<span class="w"> </span><span class="n">n</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">size</span><span class="p">(</span><span class="n">C</span><span class="p">,</span><span class="mi">2</span><span class="p">)</span>
|
||||
<span class="w"> </span><span class="n">l</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">size</span><span class="p">(</span><span class="n">A</span><span class="p">,</span><span class="mi">2</span><span class="p">)</span>
|
||||
<span class="w"> </span><span class="nd">@assert</span><span class="w"> </span><span class="n">size</span><span class="p">(</span><span class="n">A</span><span class="p">,</span><span class="mi">1</span><span class="p">)</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="n">m</span>
|
||||
<span class="w"> </span><span class="nd">@assert</span><span class="w"> </span><span class="n">size</span><span class="p">(</span><span class="n">B</span><span class="p">,</span><span class="mi">2</span><span class="p">)</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="n">n</span>
|
||||
<span class="w"> </span><span class="nd">@assert</span><span class="w"> </span><span class="n">size</span><span class="p">(</span><span class="n">B</span><span class="p">,</span><span class="mi">1</span><span class="p">)</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="n">l</span>
|
||||
<span class="w"> </span><span class="n">z</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">zero</span><span class="p">(</span><span class="n">eltype</span><span class="p">(</span><span class="n">C</span><span class="p">))</span>
|
||||
<span class="w"> </span><span class="nd">@sync</span><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="n">j</span><span class="w"> </span><span class="k">in</span><span class="w"> </span><span class="mi">1</span><span class="o">:</span><span class="n">n</span>
|
||||
<span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="n">i</span><span class="w"> </span><span class="k">in</span><span class="w"> </span><span class="mi">1</span><span class="o">:</span><span class="n">m</span>
|
||||
<span class="w"> </span><span class="n">Ai</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">A</span><span class="p">[</span><span class="n">i</span><span class="p">,</span><span class="o">:</span><span class="p">]</span>
|
||||
<span class="w"> </span><span class="n">Bj</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">B</span><span class="p">[</span><span class="o">:</span><span class="p">,</span><span class="n">j</span><span class="p">]</span>
|
||||
<span class="w"> </span><span class="n">ftr</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nd">@spawnat</span><span class="w"> </span><span class="ss">:any</span><span class="w"> </span><span class="k">begin</span>
|
||||
<span class="w"> </span><span class="n">Cij</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">z</span>
|
||||
<span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="n">k</span><span class="w"> </span><span class="k">in</span><span class="w"> </span><span class="mi">1</span><span class="o">:</span><span class="n">l</span>
|
||||
<span class="w"> </span><span class="nd">@inbounds</span><span class="w"> </span><span class="n">Cij</span><span class="w"> </span><span class="o">+=</span><span class="w"> </span><span class="n">Ai</span><span class="p">[</span><span class="n">k</span><span class="p">]</span><span class="o">*</span><span class="n">Bj</span><span class="p">[</span><span class="n">k</span><span class="p">]</span>
|
||||
<span class="w"> </span><span class="k">end</span>
|
||||
<span class="w"> </span><span class="n">Cij</span>
|
||||
<span class="w"> </span><span class="k">end</span>
|
||||
<span class="w"> </span><span class="nd">@async</span><span class="w"> </span><span class="n">C</span><span class="p">[</span><span class="n">i</span><span class="p">,</span><span class="n">j</span><span class="p">]</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">fetch</span><span class="p">(</span><span class="n">ftr</span><span class="p">)</span>
|
||||
<span class="w"> </span><span class="k">end</span>
|
||||
<span class="w"> </span><span class="k">end</span>
|
||||
<span class="w"> </span><span class="n">C</span>
|
||||
<span class="k">end</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="jp-Cell jp-MarkdownCell jp-Notebook-cell" id="cell-id=52005ca1">
|
||||
<div class="jp-Cell-inputWrapper" tabindex="0">
|
||||
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
|
||||
</div>
|
||||
<div class="jp-InputArea jp-Cell-inputArea"><div class="jp-InputPrompt jp-InputArea-prompt">
|
||||
</div><div class="jp-RenderedHTMLCommon jp-RenderedMarkdown jp-MarkdownOutput" data-mime-type="text/markdown">
|
||||
<p>With this new implementation, we can multiply matrices of arbitrary size with a fixed number of workers. Test it:</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs" id="cell-id=c1d3595b">
|
||||
<div class="jp-Cell-inputWrapper" tabindex="0">
|
||||
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
|
||||
</div>
|
||||
<div class="jp-InputArea jp-Cell-inputArea">
|
||||
<div class="jp-InputPrompt jp-InputArea-prompt">In [ ]:</div>
|
||||
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
|
||||
<div class="cm-editor cm-s-jupyter">
|
||||
<div class="highlight hl-julia"><pre><span></span><span class="k">using</span><span class="w"> </span><span class="n">Test</span>
|
||||
<span class="n">N</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">50</span>
|
||||
<span class="n">A</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">rand</span><span class="p">(</span><span class="n">N</span><span class="p">,</span><span class="n">N</span><span class="p">)</span>
|
||||
<span class="n">B</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">rand</span><span class="p">(</span><span class="n">N</span><span class="p">,</span><span class="n">N</span><span class="p">)</span>
|
||||
<span class="n">C</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">similar</span><span class="p">(</span><span class="n">A</span><span class="p">)</span>
|
||||
<span class="nd">@test</span><span class="w"> </span><span class="n">matmul_dist_1_v2!</span><span class="p">(</span><span class="n">C</span><span class="p">,</span><span class="n">A</span><span class="p">,</span><span class="n">B</span><span class="p">)</span><span class="w"> </span><span class="o">≈</span><span class="w"> </span><span class="n">A</span><span class="o">*</span><span class="n">B</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="jp-Cell jp-MarkdownCell jp-Notebook-cell" id="cell-id=ab609c18">
|
||||
<div class="jp-Cell-inputWrapper" tabindex="0">
|
||||
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
|
||||
</div>
|
||||
<div class="jp-InputArea jp-Cell-inputArea"><div class="jp-InputPrompt jp-InputArea-prompt">
|
||||
</div><div class="jp-RenderedHTMLCommon jp-RenderedMarkdown jp-MarkdownOutput" data-mime-type="text/markdown">
|
||||
<p>Run the next cell to check the performance of this implementation. Note that we are far away from the optimal speed up. Why? To answer this question compute the theoretical communication over computation ratio for this implementation and reason about the obtained result. Hint: the number of times a worker is spawned in this implementation is N^2/P on average.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs" id="cell-id=d7d31710">
|
||||
<div class="jp-Cell-inputWrapper" tabindex="0">
|
||||
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
|
||||
</div>
|
||||
<div class="jp-InputArea jp-Cell-inputArea">
|
||||
<div class="jp-InputPrompt jp-InputArea-prompt">In [ ]:</div>
|
||||
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
|
||||
<div class="cm-editor cm-s-jupyter">
|
||||
<div class="highlight hl-julia"><pre><span></span><span class="n">N</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">100</span>
|
||||
<span class="n">A</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">rand</span><span class="p">(</span><span class="n">N</span><span class="p">,</span><span class="n">N</span><span class="p">)</span>
|
||||
<span class="n">B</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">rand</span><span class="p">(</span><span class="n">N</span><span class="p">,</span><span class="n">N</span><span class="p">)</span>
|
||||
<span class="n">C</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">similar</span><span class="p">(</span><span class="n">A</span><span class="p">)</span>
|
||||
<span class="n">P</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">nworkers</span><span class="p">()</span>
|
||||
<span class="n">T1</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nd">@belapsed</span><span class="w"> </span><span class="n">matmul_seq!</span><span class="p">(</span><span class="n">C</span><span class="p">,</span><span class="n">A</span><span class="p">,</span><span class="n">B</span><span class="p">)</span>
|
||||
<span class="n">C</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">similar</span><span class="p">(</span><span class="n">A</span><span class="p">)</span>
|
||||
<span class="n">TP</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nd">@belapsed</span><span class="w"> </span><span class="n">matmul_dist_1_v2!</span><span class="p">(</span><span class="n">C</span><span class="p">,</span><span class="n">A</span><span class="p">,</span><span class="n">B</span><span class="p">)</span>
|
||||
<span class="n">println</span><span class="p">(</span><span class="s">"Speedup = "</span><span class="p">,</span><span class="w"> </span><span class="n">T1</span><span class="o">/</span><span class="n">TP</span><span class="p">)</span>
|
||||
<span class="n">println</span><span class="p">(</span><span class="s">"Optimal speedup = "</span><span class="p">,</span><span class="w"> </span><span class="n">P</span><span class="p">)</span>
|
||||
<span class="n">println</span><span class="p">(</span><span class="s">"Efficiency = "</span><span class="p">,</span><span class="w"> </span><span class="mi">100</span><span class="o">*</span><span class="p">(</span><span class="n">T1</span><span class="o">/</span><span class="n">TP</span><span class="p">)</span><span class="o">/</span><span class="n">P</span><span class="p">,</span><span class="w"> </span><span class="s">"%"</span><span class="p">)</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="jp-Cell jp-MarkdownCell jp-Notebook-cell" id="cell-id=8e171362">
|
||||
<div class="jp-Cell-inputWrapper" tabindex="0">
|
||||
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
|
||||
|
||||
File diff suppressed because one or more lines are too long
@ -7333,11 +7333,12 @@ a.anchor-link {
|
||||
if (!diagrams.length) {
|
||||
return;
|
||||
}
|
||||
const mermaid = (await import("https://cdnjs.cloudflare.com/ajax/libs/mermaid/10.5.0/mermaid.esm.min.mjs")).default;
|
||||
const mermaid = (await import("https://cdnjs.cloudflare.com/ajax/libs/mermaid/10.7.0/mermaid.esm.min.mjs")).default;
|
||||
const parser = new DOMParser();
|
||||
|
||||
mermaid.initialize({
|
||||
maxTextSize: 100000,
|
||||
maxEdges: 100000,
|
||||
startOnLoad: false,
|
||||
fontFamily: window
|
||||
.getComputedStyle(document.body)
|
||||
@ -7408,7 +7409,8 @@ a.anchor-link {
|
||||
let results = null;
|
||||
let output = null;
|
||||
try {
|
||||
const { svg } = await mermaid.render(id, raw, el);
|
||||
let { svg } = await mermaid.render(id, raw, el);
|
||||
svg = cleanMermaidSvg(svg);
|
||||
results = makeMermaidImage(svg);
|
||||
output = document.createElement("figure");
|
||||
results.map(output.appendChild, output);
|
||||
@ -7423,6 +7425,38 @@ a.anchor-link {
|
||||
parent.appendChild(output);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Post-process to ensure mermaid diagrams contain only valid SVG and XHTML.
|
||||
*/
|
||||
function cleanMermaidSvg(svg) {
|
||||
return svg.replace(RE_VOID_ELEMENT, replaceVoidElement);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* A regular expression for all void elements, which may include attributes and
|
||||
* a slash.
|
||||
*
|
||||
* @see https://developer.mozilla.org/en-US/docs/Glossary/Void_element
|
||||
*
|
||||
* Of these, only `<br>` is generated by Mermaid in place of `\n`,
|
||||
* but _any_ "malformed" tag will break the SVG rendering entirely.
|
||||
*/
|
||||
const RE_VOID_ELEMENT =
|
||||
/<\s*(area|base|br|col|embed|hr|img|input|link|meta|param|source|track|wbr)\s*([^>]*?)\s*>/gi;
|
||||
|
||||
/**
|
||||
* Ensure a void element is closed with a slash, preserving any attributes.
|
||||
*/
|
||||
function replaceVoidElement(match, tag, rest) {
|
||||
rest = rest.trim();
|
||||
if (!rest.endsWith('/')) {
|
||||
rest = `${rest} /`;
|
||||
}
|
||||
return `<${tag} ${rest}>`;
|
||||
}
|
||||
|
||||
void Promise.all([...diagrams].map(renderOneMarmaid));
|
||||
});
|
||||
</script>
|
||||
|
||||
File diff suppressed because one or more lines are too long
@ -7333,11 +7333,12 @@ a.anchor-link {
|
||||
if (!diagrams.length) {
|
||||
return;
|
||||
}
|
||||
const mermaid = (await import("https://cdnjs.cloudflare.com/ajax/libs/mermaid/10.5.0/mermaid.esm.min.mjs")).default;
|
||||
const mermaid = (await import("https://cdnjs.cloudflare.com/ajax/libs/mermaid/10.7.0/mermaid.esm.min.mjs")).default;
|
||||
const parser = new DOMParser();
|
||||
|
||||
mermaid.initialize({
|
||||
maxTextSize: 100000,
|
||||
maxEdges: 100000,
|
||||
startOnLoad: false,
|
||||
fontFamily: window
|
||||
.getComputedStyle(document.body)
|
||||
@ -7408,7 +7409,8 @@ a.anchor-link {
|
||||
let results = null;
|
||||
let output = null;
|
||||
try {
|
||||
const { svg } = await mermaid.render(id, raw, el);
|
||||
let { svg } = await mermaid.render(id, raw, el);
|
||||
svg = cleanMermaidSvg(svg);
|
||||
results = makeMermaidImage(svg);
|
||||
output = document.createElement("figure");
|
||||
results.map(output.appendChild, output);
|
||||
@ -7423,6 +7425,38 @@ a.anchor-link {
|
||||
parent.appendChild(output);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Post-process to ensure mermaid diagrams contain only valid SVG and XHTML.
|
||||
*/
|
||||
function cleanMermaidSvg(svg) {
|
||||
return svg.replace(RE_VOID_ELEMENT, replaceVoidElement);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* A regular expression for all void elements, which may include attributes and
|
||||
* a slash.
|
||||
*
|
||||
* @see https://developer.mozilla.org/en-US/docs/Glossary/Void_element
|
||||
*
|
||||
* Of these, only `<br>` is generated by Mermaid in place of `\n`,
|
||||
* but _any_ "malformed" tag will break the SVG rendering entirely.
|
||||
*/
|
||||
const RE_VOID_ELEMENT =
|
||||
/<\s*(area|base|br|col|embed|hr|img|input|link|meta|param|source|track|wbr)\s*([^>]*?)\s*>/gi;
|
||||
|
||||
/**
|
||||
* Ensure a void element is closed with a slash, preserving any attributes.
|
||||
*/
|
||||
function replaceVoidElement(match, tag, rest) {
|
||||
rest = rest.trim();
|
||||
if (!rest.endsWith('/')) {
|
||||
rest = `${rest} /`;
|
||||
}
|
||||
return `<${tag} ${rest}>`;
|
||||
}
|
||||
|
||||
void Promise.all([...diagrams].map(renderOneMarmaid));
|
||||
});
|
||||
</script>
|
||||
|
||||
BIN
dev/objects.inv
Normal file
BIN
dev/objects.inv
Normal file
Binary file not shown.
546
dev/pdes.ipynb
546
dev/pdes.ipynb
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
425
dev/tsp.ipynb
425
dev/tsp.ipynb
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Loading…
x
Reference in New Issue
Block a user