mirror of
https://github.com/fverdugo/XM_40017.git
synced 2026-11-15 03:27:17 +01:00
Merge pull request #9 from fverdugo/francesc
Adding exercises to MPI tutorial
This commit is contained in:
4 files changed
+510
-31
No files matched your search
+1
-1
@@ -119,7 +119,7 @@ makedocs(;
|
||||
"Julia Basics" => "julia_basics.md",
|
||||
"Tasks and channels" => "julia_async.md",
|
||||
"Remote calls and remote channels" => "julia_distributed.md",
|
||||
# "MPI" => "mpi_tutorial.md",
|
||||
"MPI" => "mpi_tutorial.md",
|
||||
"Matrix Multiplication"=>"matrix_matrix.md",
|
||||
# "Jacobi" => "jacobi_method.md",
|
||||
# "ASP" => "asp.md",
|
||||
|
||||
@@ -19,6 +19,51 @@
|
||||
inkscape:export-ydpi="200">
|
||||
<defs
|
||||
id="defs2">
|
||||
<marker
|
||||
style="overflow:visible"
|
||||
id="marker4223"
|
||||
refX="0"
|
||||
refY="0"
|
||||
orient="auto"
|
||||
inkscape:stockid="Arrow2Mend"
|
||||
inkscape:isstock="true">
|
||||
<path
|
||||
transform="scale(-0.6)"
|
||||
d="M 8.7185878,4.0337352 -2.2072895,0.01601326 8.7185884,-4.0017078 c -1.7454984,2.3720609 -1.7354408,5.6174519 -6e-7,8.035443 z"
|
||||
style="fill:#0000ff;fill-opacity:1;fill-rule:evenodd;stroke:#0000ff;stroke-width:0.625;stroke-linejoin:round;stroke-opacity:1"
|
||||
id="path4221"
|
||||
inkscape:connector-curvature="0" />
|
||||
</marker>
|
||||
<marker
|
||||
inkscape:isstock="true"
|
||||
inkscape:stockid="Arrow2Mend"
|
||||
orient="auto"
|
||||
refY="0"
|
||||
refX="0"
|
||||
id="marker4031"
|
||||
style="overflow:visible"
|
||||
inkscape:collect="always">
|
||||
<path
|
||||
inkscape:connector-curvature="0"
|
||||
id="path4029"
|
||||
style="fill:#0000ff;fill-opacity:1;fill-rule:evenodd;stroke:#0000ff;stroke-width:0.625;stroke-linejoin:round;stroke-opacity:1"
|
||||
d="M 8.7185878,4.0337352 -2.2072895,0.01601326 8.7185884,-4.0017078 c -1.7454984,2.3720609 -1.7354408,5.6174519 -6e-7,8.035443 z"
|
||||
transform="scale(-0.6)" />
|
||||
</marker>
|
||||
<marker
|
||||
inkscape:stockid="Arrow2Mstart"
|
||||
orient="auto"
|
||||
refY="0.0"
|
||||
refX="0.0"
|
||||
id="Arrow2Mstart"
|
||||
style="overflow:visible"
|
||||
inkscape:isstock="true">
|
||||
<path
|
||||
id="path1465"
|
||||
style="fill-rule:evenodd;stroke-width:0.625;stroke-linejoin:round;stroke:#0000ff;stroke-opacity:1;fill:#0000ff;fill-opacity:1"
|
||||
d="M 8.7185878,4.0337352 L -2.2072895,0.016013256 L 8.7185884,-4.0017078 C 6.9730900,-1.6296469 6.9831476,1.6157441 8.7185878,4.0337352 z "
|
||||
transform="scale(0.6) translate(0,0)" />
|
||||
</marker>
|
||||
<marker
|
||||
inkscape:isstock="true"
|
||||
inkscape:stockid="Arrow2Mend"
|
||||
@@ -285,7 +330,7 @@
|
||||
<path
|
||||
transform="scale(-0.6)"
|
||||
d="M 8.7185878,4.0337352 -2.2072895,0.01601326 8.7185884,-4.0017078 c -1.7454984,2.3720609 -1.7354408,5.6174519 -6e-7,8.035443 z"
|
||||
style="fill:#000000;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:0.625;stroke-linejoin:round;stroke-opacity:1"
|
||||
style="fill:#0000ff;fill-opacity:1;fill-rule:evenodd;stroke:#0000ff;stroke-width:0.625;stroke-linejoin:round;stroke-opacity:1"
|
||||
id="path8527"
|
||||
inkscape:connector-curvature="0" />
|
||||
</marker>
|
||||
@@ -311,11 +356,12 @@
|
||||
refY="0"
|
||||
orient="auto"
|
||||
inkscape:stockid="Arrow2Mend"
|
||||
inkscape:isstock="true">
|
||||
inkscape:isstock="true"
|
||||
inkscape:collect="always">
|
||||
<path
|
||||
transform="scale(-0.6)"
|
||||
d="M 8.7185878,4.0337352 -2.2072895,0.01601326 8.7185884,-4.0017078 c -1.7454984,2.3720609 -1.7354408,5.6174519 -6e-7,8.035443 z"
|
||||
style="fill:#000000;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:0.625;stroke-linejoin:round;stroke-opacity:1"
|
||||
style="fill:#0000ff;fill-opacity:1;fill-rule:evenodd;stroke:#0000ff;stroke-width:0.625;stroke-linejoin:round;stroke-opacity:1"
|
||||
id="path8527-8"
|
||||
inkscape:connector-curvature="0" />
|
||||
</marker>
|
||||
@@ -327,16 +373,16 @@
|
||||
borderopacity="1.0"
|
||||
inkscape:pageopacity="0.0"
|
||||
inkscape:pageshadow="2"
|
||||
inkscape:zoom="0.9899495"
|
||||
inkscape:cx="3591.8372"
|
||||
inkscape:cy="1568.0458"
|
||||
inkscape:zoom="1.4"
|
||||
inkscape:cx="4981.0264"
|
||||
inkscape:cy="680.67174"
|
||||
inkscape:document-units="mm"
|
||||
inkscape:current-layer="layer1"
|
||||
inkscape:document-rotation="0"
|
||||
showgrid="false"
|
||||
inkscape:window-width="1856"
|
||||
inkscape:window-height="1016"
|
||||
inkscape:window-x="64"
|
||||
inkscape:window-width="2496"
|
||||
inkscape:window-height="1376"
|
||||
inkscape:window-x="1984"
|
||||
inkscape:window-y="27"
|
||||
inkscape:window-maximized="1"
|
||||
fit-margin-top="0"
|
||||
@@ -1889,5 +1935,228 @@
|
||||
style="fill:#0000ff;fill-opacity:1;fill-rule:evenodd;stroke:#0000ff;stroke-width:0.19798951;stroke-linejoin:round;stroke-opacity:1"
|
||||
d="m 975.70946,-223.09405 -1.84993,3.19013 -0.65743,-3.62865 c 0.64485,0.67413 1.65812,0.8481 2.50736,0.43852 z" />
|
||||
</g>
|
||||
<g
|
||||
id="g5148"
|
||||
inkscape:export-filename="/home/francesc/Downloads/g5148.png"
|
||||
inkscape:export-xdpi="200"
|
||||
inkscape:export-ydpi="200">
|
||||
<path
|
||||
style="fill:none;stroke:#000000;stroke-width:0.529167;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
|
||||
d="m 1359.9626,79.585912 h 20.9409"
|
||||
id="path978-3-6-3"
|
||||
sodipodi:nodetypes="cc"
|
||||
inkscape:connector-curvature="0" />
|
||||
<path
|
||||
inkscape:connector-curvature="0"
|
||||
sodipodi:nodetypes="cc"
|
||||
id="path1168-6-1-6"
|
||||
d="m 1314.5268,79.585912 h 20.9408"
|
||||
style="fill:none;stroke:#000000;stroke-width:0.529167;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
|
||||
<g
|
||||
transform="translate(1155.5468,183.31702)"
|
||||
id="g1148-7-5-75">
|
||||
<path
|
||||
inkscape:connector-curvature="0"
|
||||
id="path1063-5-5-3"
|
||||
d="m 129.89807,-136.23112 12.99038,7.5 17.32051,-10 -12.99038,-7.5 z"
|
||||
style="fill:#e6e6e6;stroke:#000000;stroke-width:0.79374999;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
|
||||
<path
|
||||
inkscape:connector-curvature="0"
|
||||
sodipodi:nodetypes="cccc"
|
||||
id="path1065-3-4-5"
|
||||
d="m 142.88845,-128.73112 v 39.999996 l 17.32051,-10 v -39.999996"
|
||||
style="fill:#e6e6e6;stroke:#000000;stroke-width:0.79374999;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
|
||||
<path
|
||||
inkscape:connector-curvature="0"
|
||||
sodipodi:nodetypes="ccc"
|
||||
id="path1067-56-7-62"
|
||||
d="m 129.89807,-136.23112 v 39.999996 l 12.99038,7.5"
|
||||
style="fill:#e6e6e6;stroke:#000000;stroke-width:0.79374999;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
|
||||
<path
|
||||
inkscape:connector-curvature="0"
|
||||
id="path1069-2-6-9"
|
||||
d="m 147.21857,-126.23112 v 15 l 4.33013,-2.5 v -15 l -4.33013,2.5"
|
||||
style="fill:#e6e6e6;stroke:#000000;stroke-width:0.529167;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
|
||||
<path
|
||||
inkscape:connector-curvature="0"
|
||||
id="path1071-91-5-1"
|
||||
d="m 145.48652,-96.231123 v 1.999999 l 12.99038,-7.499996 v -2 z"
|
||||
style="fill:#e6e6e6;stroke:#000000;stroke-width:0.529167;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
|
||||
<path
|
||||
inkscape:connector-curvature="0"
|
||||
id="path1073-2-6-2"
|
||||
d="m 145.48652,-100.23111 v 2.000003 l 12.99038,-7.500013 v -2 z"
|
||||
style="fill:#e6e6e6;stroke:#000000;stroke-width:0.529167;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
|
||||
<path
|
||||
inkscape:connector-curvature="0"
|
||||
id="path1075-7-9-7"
|
||||
d="m 145.48652,-104.23111 v 2 l 12.99038,-7.50001 v -2 z"
|
||||
style="fill:#e6e6e6;stroke:#000000;stroke-width:0.529167;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
|
||||
</g>
|
||||
<g
|
||||
transform="translate(1163.1327,183.31701)"
|
||||
id="g1157-09-3-0">
|
||||
<path
|
||||
inkscape:connector-curvature="0"
|
||||
id="path1086-3-7-93"
|
||||
d="m 169.05642,-136.23112 12.99038,7.5 17.32051,-10 -12.99038,-7.5 z"
|
||||
style="fill:#e6e6e6;stroke:#000000;stroke-width:0.79374999;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
|
||||
<path
|
||||
inkscape:connector-curvature="0"
|
||||
sodipodi:nodetypes="cccc"
|
||||
id="path1088-6-4-6"
|
||||
d="m 182.0468,-128.73112 v 39.999996 l 17.32051,-10 v -39.999996"
|
||||
style="fill:#e6e6e6;stroke:#000000;stroke-width:0.79374999;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
|
||||
<path
|
||||
inkscape:connector-curvature="0"
|
||||
sodipodi:nodetypes="ccc"
|
||||
id="path1090-0-5-0"
|
||||
d="m 169.05642,-136.23112 v 39.999996 l 12.99038,7.5"
|
||||
style="fill:#e6e6e6;stroke:#000000;stroke-width:0.79374999;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
|
||||
<path
|
||||
inkscape:connector-curvature="0"
|
||||
id="path1092-6-2-6"
|
||||
d="m 186.37692,-126.23112 v 15 l 4.33013,-2.5 v -15 l -4.33013,2.5"
|
||||
style="fill:#e6e6e6;stroke:#000000;stroke-width:0.529167;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
|
||||
<path
|
||||
inkscape:connector-curvature="0"
|
||||
id="path1094-2-5-2"
|
||||
d="m 184.64487,-96.231123 v 1.999999 l 12.99038,-7.499996 v -2 z"
|
||||
style="fill:#e6e6e6;stroke:#000000;stroke-width:0.529167;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
|
||||
<path
|
||||
inkscape:connector-curvature="0"
|
||||
id="path1096-6-4-6"
|
||||
d="m 184.64487,-100.23111 v 2.000003 l 12.99038,-7.500013 v -2 z"
|
||||
style="fill:#e6e6e6;stroke:#000000;stroke-width:0.529167;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
|
||||
<path
|
||||
inkscape:connector-curvature="0"
|
||||
id="path1098-1-7-1"
|
||||
d="m 184.64487,-104.23111 v 2 l 12.99038,-7.50001 v -2 z"
|
||||
style="fill:#e6e6e6;stroke:#000000;stroke-width:0.529167;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
|
||||
</g>
|
||||
<text
|
||||
y="15.986771"
|
||||
x="1244.8425"
|
||||
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:5.93749809px;line-height:1.25;font-family:Hack;-inkscape-font-specification:Hack;letter-spacing:0px;word-spacing:0px;white-space:pre;shape-inside:url(#rect1130-2);stroke-width:1.87007797"
|
||||
id="text1128-7-8-4-8"
|
||||
xml:space="preserve"><tspan
|
||||
style="stroke-width:1.87007797"
|
||||
id="tspan78-79-4-7"
|
||||
y="103.6842"
|
||||
x="1289.8303">rank 0<tspan
|
||||
id="tspan76-2-3-9"
|
||||
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-family:Hack;-inkscape-font-specification:Hack;stroke-width:1.87007797" /></tspan></text>
|
||||
<text
|
||||
y="15.986771"
|
||||
x="1294.8483"
|
||||
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:5.93749809px;line-height:1.25;font-family:Hack;-inkscape-font-specification:Hack;letter-spacing:0px;word-spacing:0px;white-space:pre;shape-inside:url(#rect1184);stroke-width:1.87007797"
|
||||
id="text1182-0-0-2"
|
||||
xml:space="preserve"><tspan
|
||||
style="stroke-width:1.87007797"
|
||||
id="tspan83-2-7-0"
|
||||
y="103.6842"
|
||||
x="1339.8361">rank 1<tspan
|
||||
id="tspan81-3-8-2"
|
||||
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-family:Hack;-inkscape-font-specification:Hack;stroke-width:1.87007797" /></tspan></text>
|
||||
<g
|
||||
id="g970-7-6-3"
|
||||
transform="translate(1209.6376,183.31701)">
|
||||
<path
|
||||
style="fill:#e6e6e6;stroke:#000000;stroke-width:0.79374999;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
|
||||
d="m 169.05642,-136.23112 12.99038,7.5 17.32051,-10 -12.99038,-7.5 z"
|
||||
id="path956-5-8-7"
|
||||
inkscape:connector-curvature="0" />
|
||||
<path
|
||||
style="fill:#e6e6e6;stroke:#000000;stroke-width:0.79374999;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
|
||||
d="m 182.0468,-128.73112 v 39.999996 l 17.32051,-10 v -39.999996"
|
||||
id="path958-92-8-5"
|
||||
sodipodi:nodetypes="cccc"
|
||||
inkscape:connector-curvature="0" />
|
||||
<path
|
||||
style="fill:#e6e6e6;stroke:#000000;stroke-width:0.79374999;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
|
||||
d="m 169.05642,-136.23112 v 39.999996 l 12.99038,7.5"
|
||||
id="path960-2-4-9"
|
||||
sodipodi:nodetypes="ccc"
|
||||
inkscape:connector-curvature="0" />
|
||||
<path
|
||||
style="fill:#e6e6e6;stroke:#000000;stroke-width:0.529167;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
|
||||
d="m 186.37692,-126.23112 v 15 l 4.33013,-2.5 v -15 l -4.33013,2.5"
|
||||
id="path962-8-3-2"
|
||||
inkscape:connector-curvature="0" />
|
||||
<path
|
||||
style="fill:#e6e6e6;stroke:#000000;stroke-width:0.529167;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
|
||||
d="m 184.64487,-96.231123 v 1.999999 l 12.99038,-7.499996 v -2 z"
|
||||
id="path964-9-1-2"
|
||||
inkscape:connector-curvature="0" />
|
||||
<path
|
||||
style="fill:#e6e6e6;stroke:#000000;stroke-width:0.529167;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
|
||||
d="m 184.64487,-100.23111 v 2.000003 l 12.99038,-7.500013 v -2 z"
|
||||
id="path966-7-4-8"
|
||||
inkscape:connector-curvature="0" />
|
||||
<path
|
||||
style="fill:#e6e6e6;stroke:#000000;stroke-width:0.529167;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
|
||||
d="m 184.64487,-104.23111 v 2 l 12.99038,-7.50001 v -2 z"
|
||||
id="path968-3-9-9"
|
||||
inkscape:connector-curvature="0" />
|
||||
</g>
|
||||
<text
|
||||
xml:space="preserve"
|
||||
id="text976-6-2-7"
|
||||
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:5.93749809px;line-height:1.25;font-family:Hack;-inkscape-font-specification:Hack;letter-spacing:0px;word-spacing:0px;white-space:pre;shape-inside:url(#rect1184);stroke-width:1.87007797"
|
||||
x="1342.9568"
|
||||
y="15.986771"><tspan
|
||||
x="1387.9445"
|
||||
y="103.6842"
|
||||
id="tspan974-1-0-3"
|
||||
style="stroke-width:1.87007797">rank 2</tspan></text>
|
||||
<text
|
||||
y="-54.098297"
|
||||
x="1247.6248"
|
||||
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:5.93749809px;line-height:1.25;font-family:Hack;-inkscape-font-specification:Hack;letter-spacing:0px;word-spacing:0px;white-space:pre;shape-inside:url(#rect1130-2);fill:#0000ff;stroke-width:1.87007797"
|
||||
id="text1128-7-8-7-3-7-0"
|
||||
xml:space="preserve"><tspan
|
||||
style="fill:#0000ff;stroke-width:1.87007797"
|
||||
id="tspan78-79-8-2-1-3"
|
||||
y="33.599152"
|
||||
x="1292.6124">msg</tspan></text>
|
||||
<path
|
||||
sodipodi:nodetypes="cc"
|
||||
inkscape:connector-curvature="0"
|
||||
id="path1386"
|
||||
d="m 1304.0316,27.773394 c 16.0706,-14.103005 27.5564,-13.085868 41.886,-0.615601"
|
||||
style="fill:none;stroke:#0000ff;stroke-width:0.76499999;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1;marker-end:url(#marker8529-3)" />
|
||||
<text
|
||||
y="-54.561871"
|
||||
x="1290.4174"
|
||||
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:5.93749809px;line-height:1.25;font-family:Hack;-inkscape-font-specification:Hack;letter-spacing:0px;word-spacing:0px;white-space:pre;shape-inside:url(#rect1130-2);fill:#0000ff;stroke-width:1.87007797"
|
||||
id="text1128-7-8-7-3-7-0-0"
|
||||
xml:space="preserve"><tspan
|
||||
style="fill:#0000ff;stroke-width:1.87007797"
|
||||
id="tspan78-79-8-2-1-3-6"
|
||||
y="33.135578"
|
||||
x="1335.405">msg+=1</tspan></text>
|
||||
<text
|
||||
y="-53.871326"
|
||||
x="1338.3951"
|
||||
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:5.93749809px;line-height:1.25;font-family:Hack;-inkscape-font-specification:Hack;letter-spacing:0px;word-spacing:0px;white-space:pre;shape-inside:url(#rect1130-2);fill:#0000ff;stroke-width:1.87007797"
|
||||
id="text1128-7-8-7-3-7-0-0-3"
|
||||
xml:space="preserve"><tspan
|
||||
style="fill:#0000ff;stroke-width:1.87007797"
|
||||
id="tspan78-79-8-2-1-3-6-2"
|
||||
y="33.826126"
|
||||
x="1383.3828">msg+=1</tspan></text>
|
||||
<path
|
||||
style="fill:none;stroke:#0000ff;stroke-width:0.76499999;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1;marker-end:url(#marker4031)"
|
||||
d="m 1354.3024,27.773394 c 16.0706,-14.103005 27.5564,-13.085868 41.886,-0.615601"
|
||||
id="path4027"
|
||||
inkscape:connector-curvature="0"
|
||||
sodipodi:nodetypes="cc" />
|
||||
<path
|
||||
sodipodi:nodetypes="cc"
|
||||
inkscape:connector-curvature="0"
|
||||
id="path4219"
|
||||
d="m 1402.8962,28.340358 c -14.7223,-30.9560949 -88.632,-34.6967981 -104.63,-1.371553"
|
||||
style="fill:none;stroke:#0000ff;stroke-width:0.76499999;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1;marker-end:url(#marker4223)" />
|
||||
</g>
|
||||
</g>
|
||||
</svg>
|
||||
|
Before Width: | Height: | Size: 110 KiB After Width: | Height: | Size: 125 KiB |
+139
-19
@@ -43,9 +43,9 @@
|
||||
"## What is MPI ?\n",
|
||||
"\n",
|
||||
"- MPI stands for the \"Message Passing Interface\"\n",
|
||||
"- It is a standardized library specification for communication between parallel processes in distributed memory systems.\n",
|
||||
"- It is a standardized library specification for communication between parallel processes in distributed-memory systems.\n",
|
||||
"- It is the gold-standard for distributed computing in HPC systems since the 90s\n",
|
||||
"- It is huge: the MPI standard has above 1k pages (see https://www.mpi-forum.org/docs/mpi-4.0/mpi40-report.pdf)\n",
|
||||
"- It is huge: the MPI standard has more than 1k pages (see https://www.mpi-forum.org/docs/mpi-4.0/mpi40-report.pdf)\n",
|
||||
"- There are several implementations of this standard (OpenMPI, MPICH, IntelMPI)\n",
|
||||
"- The interface is in C and FORTRAN (C++ was deprecated)\n",
|
||||
"- There are Julia bindings via the package MPI.jl https://github.com/JuliaParallel/MPI.jl"
|
||||
@@ -53,10 +53,12 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "133327e2",
|
||||
"id": "82e6e98f",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### Hello-world example"
|
||||
"### Installing MPI in Julia\n",
|
||||
"\n",
|
||||
"MPI can be installed as any other Julia package using the package manager."
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -69,6 +71,24 @@
|
||||
"] add MPI"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "abc6f017",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"<div class=\"alert alert-block alert-info\">\n",
|
||||
"<b>Note:</b> The package you have installed it is the Julia interface to MPI, called MPI.jl. Note that it is not a MPI library by itself. It is just a thin wrapper between MPI and Julia. To use this interface, you need an actual MPI library installed in your system such as OpenMPI or MPICH. Julia downloads and installs a MPI library for you, but it is also possible to use a MPI library already available in your system. This is useful, e.g., when running on HPC clusters. See the documentation of MPI.jl for further details. See more information in <a href=\"https://github.com/JuliaParallel/MPI.jl\">https://github.com/JuliaParallel/MPI.jl</a>\n",
|
||||
"</div>"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "133327e2",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### Hello-world example"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
@@ -138,7 +158,7 @@
|
||||
"source": [
|
||||
"### Hello world\n",
|
||||
"\n",
|
||||
"Julia code typically needs to be in a file to run in with MPI. Let's us write our hello world in a file:"
|
||||
"Julia code typically needs to be in a file to run it in with MPI. Let's us write our hello world in a file:"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -258,6 +278,16 @@
|
||||
"end"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "cb480322",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"<div class=\"alert alert-block alert-info\">\n",
|
||||
"<b>Note:</b> Note that the rank ids start with 0.\n",
|
||||
"</div>"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "6caa8d74",
|
||||
@@ -265,7 +295,7 @@
|
||||
"source": [
|
||||
"## MPI Communicators\n",
|
||||
"\n",
|
||||
"In MPI, a **communicator** represents a group of processes that can communicate with each other. `MPI_COMM_WORLD` (`MPI.COMM_WORLD` from Julia) is a built-in communicator that represents all processes available in the MPI program. Custom communicators can also be created to group processes based on specific requirements or logical divisions. The **rank** of a processor is a unique identifier assigned to each process within a communicator. It allows processes to distinguish and address each other in communication operations.\n",
|
||||
"In MPI, a **communicator** represents a group of processes that can communicate with each other. `MPI_COMM_WORLD` (`MPI.COMM_WORLD` from Julia) is a built-in communicator that represents all processes available in the MPI program. Custom communicators can also be created to group processes based on specific requirements or logical divisions. The **rank** of a processor is a unique (integer) identifier assigned to each process within a communicator. It allows processes to distinguish and address each other in communication operations.\n",
|
||||
"\n",
|
||||
"### Duplicating a communicator\n",
|
||||
"\n",
|
||||
@@ -296,7 +326,7 @@
|
||||
"source": [
|
||||
"### Scatter\n",
|
||||
"\n",
|
||||
"TODO explain what this code does"
|
||||
"The \"root\" rank contains a buffer (e.g., a vector) of values (one value for each rank in a communicator). Scatter sends one value to each rank (the root rank also receives a value). The root rank can be any process in a communicator."
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -345,7 +375,7 @@
|
||||
"source": [
|
||||
"### Gather\n",
|
||||
"\n",
|
||||
"TODO explain what this code does"
|
||||
"Each rank sends a message to the root rank (the root rank also sends a message to itself). The root rank receives all these values in a buffer (e.g. a vector)."
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -394,11 +424,14 @@
|
||||
"\n",
|
||||
"MPI also provides point-to-point communication directives for arbitrary communication between processes. Point-to-point communications are two-sided: there is a sender and a receiver. Here, we will discuss these basic directives:\n",
|
||||
"\n",
|
||||
"- `MPI.Isend`, and `MPI.Irecv!`\n",
|
||||
"- `MPI.Isend`, and `MPI.Irecv!` (*non-blocking directives*)\n",
|
||||
"- `MPI.Send`, and `MPI.Recv` (*blocking directives*)\n",
|
||||
"\n",
|
||||
"which are *non-blocking directives*.\n",
|
||||
"\n",
|
||||
"MPI also offers *blocking* directives with different blocking behaviors (communication modes). Blocking communication will be discussed later in the course.\n",
|
||||
"Non-blocking directives return immediately and return an `MPI.Request` object. This request object can be queried with functions like `MPI.Wait`. It is mandatory to wait on the request object before reading the receive buffer, or before writing again on the send buffer.\n",
|
||||
"\n",
|
||||
"For blocking directives, it is save to read/write from/to the receive/send buffer once the function has returned. By default, blocking directives might wait (or might not wait) for a matching send/receive. \n",
|
||||
"For fine control, MPI offers advanced *blocking* directives with different blocking behaviors (called communication modes, see section 3.9 of the MPI standard 4.0). Blocking communication will be discussed later in the course.\n",
|
||||
"\n"
|
||||
]
|
||||
},
|
||||
@@ -479,23 +512,110 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "5e8f6e6a",
|
||||
"id": "9dc6c3fb",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# License\n",
|
||||
"\n",
|
||||
"TODO: replace link to website\n",
|
||||
"\n",
|
||||
"This notebook is part of the course [Programming Large Scale Parallel Systems](http://localhost:8000/) at Vrije Universiteit Amsterdam and may be used under a [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/) license."
|
||||
"### Example (with blocking directives)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "c9364808",
|
||||
"id": "a046d7dd",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
"source": [
|
||||
"@everywhere workers() begin\n",
|
||||
" comm = MPI.Comm_dup(MPI.COMM_WORLD)\n",
|
||||
" rank = MPI.Comm_rank(comm)\n",
|
||||
" nranks = MPI.Comm_size(comm)\n",
|
||||
" snder = 0\n",
|
||||
" rcver = nranks-1\n",
|
||||
" buffer = Ref(0)\n",
|
||||
" if rank == snder\n",
|
||||
" msg = 10*(rank+2)\n",
|
||||
" println(\"I am sending: $msg\")\n",
|
||||
" buffer[] = msg\n",
|
||||
" MPI.Send(buffer,comm;dest=rcver,tag=0)\n",
|
||||
" MPI.Recv!(buffer,comm,source=rcver,tag=0)\n",
|
||||
" msg = buffer[]\n",
|
||||
" println(\"I have received: $msg\")\n",
|
||||
" end\n",
|
||||
" if rank == rcver\n",
|
||||
" MPI.Recv!(buffer,comm,source=snder,tag=0)\n",
|
||||
" msg = buffer[]\n",
|
||||
" println(\"I have received: $msg\")\n",
|
||||
" coef = (rank+2)\n",
|
||||
" msg = msg*coef\n",
|
||||
" println(\"I am sending: $msg\")\n",
|
||||
" buffer[] = msg\n",
|
||||
" MPI.Send(buffer,comm;dest=snder,tag=0)\n",
|
||||
" end\n",
|
||||
"end"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "d9bdfa02",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"<div class=\"alert alert-block alert-warning\">\n",
|
||||
"<b>Important:</b> Blocking directives might look simpler to use, but they can lead to dead locks if the sends and receives are not issued in the right order. Non-blocking directives can also lead to dead locks, but when waiting for the request, not when calling the send/receive functions.\n",
|
||||
"</div>"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "d02f935d",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Exercises"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "a8e1c623",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### Exercise 1\n",
|
||||
"\n",
|
||||
"Implement this simple algorithm: Rank 0 generates a message (an integer). Rank 0 sends the message to rank 1. Rank 1 receives the message, increments the message by 1, and sends the result to rank 2. Rank 2 receives the message, increments the message by 1, and sends the result to rank 3. Etc. The last rank sends back the message to rank 0 closing the ring. See the next figure. Implement the communications using MPI.\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"attachments": {
|
||||
"g5148.png": {
|
||||
"image/png": "iVBORw0KGgoAAAANSUhEUgAAA9MAAAMYCAYAAADIIrQyAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAAewgAAHsIBbtB1PgAAABl0RVh0U29mdHdhcmUAd3d3Lmlua3NjYXBlLm9yZ5vuPBoAACAASURBVHic7N15vBxVmf/xT93sZA9bIIRVlhCRJaBsshkEBEQQ3GVUBEfHEZefg7uoM4oizqDjgjqOAygCruyIIMou+76vgSwkkIQkZM/398epm9u3by9Vfbv79PJ9v171uumb7qqn+nZX1VPnnOckmJmZWQ6aCIwGxqTLBGBsweNxQA8wPn3BGGBYuoxJfzc+fc5IYBSQpOshXffwjMH0rqecRYDSf68FXin4vxXA8oLHS4A1Rc/tfc4SYHW6vlXAsnRZlf5udfqc5elrFoefybKM+2FmZtZ2ktgBmJmZNZcmARsWLMWPJ9A/MR5f8HhMiRVaeb0JeO+yGFhY9Lvi/y947GTczMxal5NpMzNrYxoKbApsDkxOl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BzoNtCBnUv1Q2jjgpNrMzBpJO5BvmquVoHNAm8eO3MzMzLqBRoNOBT2XM6l+AHQCrv5tZmb1pY1A/w1anfGEtCpNoqfGjtzMzMy6kYYTCo49kjOpvhN0VOzozcys7Wk46DOghTlOQpeAdowduZmZmRmhxss70+7ceZLq20CHxY7ezMzako4DPZHjpHMP6E2xLine truncated
|
||||
}
|
||||
},
|
||||
"cell_type": "markdown",
|
||||
"id": "d474d781",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"<div>\n",
|
||||
"<img src=\"attachment:g5148.png\" align=\"left\" width=\"320\"/>\n",
|
||||
"</div>"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "49adf214",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### Exercise 2\n",
|
||||
"\n",
|
||||
"Implement the same algorithm as in Exercise 1, but now without using MPI. Implement the communications using the native `Distributed` module provided by Julia. In this case, start using process 1 instead of rank 0."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "5e8f6e6a",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# License\n",
|
||||
"\n",
|
||||
"This notebook is part of the course [Programming Large Scale Parallel Systems](https://www.francescverdugo.com/XM_40017) at Vrije Universiteit Amsterdam and may be used under a [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/) license."
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
|
||||
@@ -291,6 +291,96 @@
|
||||
"rmprocs(workers())"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "508125f9",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### New ring example"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "7af4cfd0",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"@everywhere workers() begin\n",
|
||||
" using MPI\n",
|
||||
" MPI.Init()\n",
|
||||
" comm = MPI.Comm_dup(MPI.COMM_WORLD)\n",
|
||||
" rank = MPI.Comm_rank(comm)\n",
|
||||
" nranks = MPI.Comm_size(comm)\n",
|
||||
" buffer = Ref(0)\n",
|
||||
" if rank == 0\n",
|
||||
" msg = rand(1:10)\n",
|
||||
" buffer[] = msg\n",
|
||||
" println(\"msg = $(buffer[])\")\n",
|
||||
" MPI.Send(buffer,comm;dest=rank+1,tag=0)\n",
|
||||
" MPI.Recv!(buffer,comm;source=nranks-1,tag=0)\n",
|
||||
" println(\"msg = $(buffer[])\")\n",
|
||||
" else\n",
|
||||
" dest = (rank != nranks-1) ? rank+1 : 0\n",
|
||||
" MPI.Recv!(buffer,comm;source=rank-1,tag=0)\n",
|
||||
" buffer[] += 1\n",
|
||||
" println(\"msg = $(buffer[])\")\n",
|
||||
" MPI.Send(buffer,comm;dest,tag=0)\n",
|
||||
" end\n",
|
||||
"end"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "30ece423",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"ftrs = Vector{Future}(undef,nprocs())\n",
|
||||
"for p in 1:nprocs()\n",
|
||||
" ftrs[p] = @spawnat p RemoteChannel(()->Channel{Int}(1))\n",
|
||||
"end\n",
|
||||
"for p in 1:nprocs()\n",
|
||||
" @spawnat p begin \n",
|
||||
" chnl_snd = fetch(ftrs[p])\n",
|
||||
" source = (p != 1) ? p-1 : nprocs()\n",
|
||||
" chnl_rcv = fetch(ftrs[source])\n",
|
||||
" if p == 1\n",
|
||||
" msg = rand(1:10)\n",
|
||||
" @show msg\n",
|
||||
" put!(chnl_snd,msg)\n",
|
||||
" msg = take!(chnl_rcv)\n",
|
||||
" @show msg\n",
|
||||
" else\n",
|
||||
" msg = take!(chnl_rcv)\n",
|
||||
" msg += 1\n",
|
||||
" @show msg\n",
|
||||
" put!(chnl_snd,msg)\n",
|
||||
" end\n",
|
||||
" end\n",
|
||||
"end"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "761ce452",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"@everywhere function work(msg)\n",
|
||||
" msg += 1\n",
|
||||
" println(\"msg = $msg\")\n",
|
||||
" if myid() == nprocs()\n",
|
||||
" @spawnat 1 println(\"msg = $msg\")\n",
|
||||
" else\n",
|
||||
" next = myid() + 1\n",
|
||||
" @spawnat next work(msg)\n",
|
||||
" end\n",
|
||||
"end"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "19641daf",
|
||||
@@ -733,7 +823,7 @@
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "Julia 1.9.1",
|
||||
"display_name": "Julia 1.9.0",
|
||||
"language": "julia",
|
||||
"name": "julia-1.9"
|
||||
},
|
||||
@@ -741,7 +831,7 @@
|
||||
"file_extension": ".jl",
|
||||
"mimetype": "application/julia",
|
||||
"name": "julia",
|
||||
"version": "1.9.1"
|
||||
"version": "1.9.0"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
|
||||
Reference in new issue
Block a user