Compare commits

7 Commits

Author SHA1 Message Date
Francesc Verdugo
7cae58c2e7 Change julia kernel version for MPI collectives notebook 2025-09-15 17:14:58 +02:00
Francesc Verdugo
ae6e14bc62 Enhancing solutions for julia_distributed notebook. 2025-09-08 11:30:14 +02:00
Francesc Verdugo
aa1b5ce0d7 Fix small explanation in Julia async 2025-09-08 10:25:20 +02:00
Francesc Verdugo
74b41c059e Adding figure 2025-09-05 15:13:56 +02:00
Francesc Verdugo
388a8d9f5a Rephrase exercise 3 in notebook julia_basics 2025-09-05 15:12:46 +02:00
Francesc Verdugo
50cb8fff17 Update notebooks to Julia 1.11.6 2025-08-27 10:52:14 +02:00
Francesc Verdugo
470bb36cc6 Minor improvements in the tutorial 2025-08-27 09:51:03 +02:00
14 changed files with 7426 additions and 99 deletions

View File

@@ -210,11 +210,11 @@ To install a package, we need to enter *package* mode. Remember that we entered
```julia ```julia
julia> ] julia> ]
``` ```
At this point, the prompt should have changed to `(@v1.10) pkg>` indicating that we are in package mode. The text between the parentheses indicates which is the active *project*, i.e., where packages are going to be installed. In this case, we are working with the global project associated with our Julia installation (which is Julia 1.10 in this example, but it can be another version in your case). At this point, the prompt should have changed to `(@v1.11) pkg>` indicating that we are in package mode. The text between the parentheses indicates which is the active *project*, i.e., where packages are going to be installed. In this case, we are working with the global project associated with our Julia installation (which is Julia 1.11 in this example, but it can be another version in your case).
To install the MPI package, type To install the MPI package, type
```julia ```julia
(@v1.10) pkg> add MPI (@v1.11) pkg> add MPI
``` ```
Congrats, you have installed MPI! Congrats, you have installed MPI!
@@ -222,7 +222,8 @@ Congrats, you have installed MPI!
Many Julia package names end with `.jl`. This is just a way of signaling that a package is written in Julia. When using such packages, the `.jl` needs to be omitted. In this case, we have installed the `MPI.jl` package even though we have only typed `MPI` in the REPL. Many Julia package names end with `.jl`. This is just a way of signaling that a package is written in Julia. When using such packages, the `.jl` needs to be omitted. In this case, we have installed the `MPI.jl` package even though we have only typed `MPI` in the REPL.
!!! note !!! note
The package you have installed 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](https://juliaparallel.org/MPI.jl/stable/configuration/) of `MPI.jl` for further details. The package you have installed is the Julia interface to MPI, called `MPI.jl`. Note that it is not an 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 an MPI library for you, but it is also possible to use an MPI library already available in your system. This is useful, e.g., when running on HPC clusters. See the [documentation](https://juliaparallel.org/MPI.jl/stable/configuration/) of `MPI.jl` for further details.
To check that the package was installed properly, exit package mode by pressing the backspace key several times, and run it again To check that the package was installed properly, exit package mode by pressing the backspace key several times, and run it again
@@ -241,7 +242,7 @@ $ mpiexec -np 4 julia hello_mpi.jl
But it will probably not work since the version of `mpiexec` needs to match with the MPI version we are using from Julia. Don't worry if you could not make it work! A more elegant way to run MPI code is from the Julia REPL directly, by using these commands: But it will probably not work since the version of `mpiexec` needs to match with the MPI version we are using from Julia. Don't worry if you could not make it work! A more elegant way to run MPI code is from the Julia REPL directly, by using these commands:
```julia ```julia
julia> using MPI julia> using MPI
julia> run(`$(mpiexec()) -np 4 julia hello_mpi.jl`) julia> run(`$(mpiexec()) -np 4 julia hello_mpi.jl`);
``` ```
Now, you should see output from 4 ranks. Now, you should see output from 4 ranks.
@@ -254,7 +255,7 @@ We have installed the `MPI` package globally and it will be available in all Jul
A project is simply a folder in your file system. To use a particular folder as your project, you need to *activate* it. This is done by entering package mode and using the `activate` command followed by the path to the folder you want to activate. A project is simply a folder in your file system. To use a particular folder as your project, you need to *activate* it. This is done by entering package mode and using the `activate` command followed by the path to the folder you want to activate.
```julia ```julia
(@v1.10) pkg> activate . (@v1.11) pkg> activate .
``` ```
The previous command will activate the current working directory. Note that the dot `.` is indeed the path to the current folder. The previous command will activate the current working directory. Note that the dot `.` is indeed the path to the current folder.
@@ -264,7 +265,7 @@ The prompt has changed to `(lessons) pkg>` indicating that we are in the project
You can activate a project directly when opening Julia from the terminal using the `--project` flag. The command `$ julia --project=.` will open Julia and activate a project in the current directory. You can also achieve the same effect by setting the environment variable `JULIA_PROJECT` with the path of the folder you want to activate. You can activate a project directly when opening Julia from the terminal using the `--project` flag. The command `$ julia --project=.` will open Julia and activate a project in the current directory. You can also achieve the same effect by setting the environment variable `JULIA_PROJECT` with the path of the folder you want to activate.
!!! note !!! note
The active project folder and the current working directory are two independent concepts! For instance, `(@v1.10) pkg> activate folderB` and then `julia> cd("folderA")`, will activate the project in `folderB` and change the current working directory to `folderA`. The active project folder and the current working directory are two independent concepts! For instance, `(@v1.11) pkg> activate folderB` and then `julia> cd("folderA")`, will activate the project in `folderB` and change the current working directory to `folderA`.
At this point all package-related operations will be local to the new project. For instance, install the `DataFrames` package. At this point all package-related operations will be local to the new project. For instance, install the `DataFrames` package.
@@ -282,7 +283,7 @@ Now, we can return to the global project to check that `DataFrames` has not been
```julia ```julia
(lessons) pkg> activate (lessons) pkg> activate
``` ```
The prompt is again `(@v1.10) pkg>` The prompt is again `(@v1.11) pkg>`
Now, try to use `DataFrames`. Now, try to use `DataFrames`.
@@ -306,13 +307,13 @@ In other words, `Project.toml` contains the packages relevant for the user, wher
You can see the path to the current `Project.toml` file by using the `status` operator (or `st` in its short form) while in package mode You can see the path to the current `Project.toml` file by using the `status` operator (or `st` in its short form) while in package mode
```julia ```julia
(@v1.10) pkg> status (@v1.11) pkg> status
``` ```
The information about the `Manifest.toml` can be inspected by passing the `-m` flag. The information about the `Manifest.toml` can be inspected by passing the `-m` flag.
```julia ```julia
(@v1.10) pkg> status -m (@v1.11) pkg> status -m
``` ```
### Installing packages from a project file ### Installing packages from a project file
@@ -336,7 +337,7 @@ julia> mkdir("newproject")
To install all the packages registered in this file you need to activate the folder containing your `Project.toml` file To install all the packages registered in this file you need to activate the folder containing your `Project.toml` file
```julia ```julia
(@v1.10) pkg> activate newproject (@v1.11) pkg> activate newproject
``` ```
and then *instantiating* it and then *instantiating* it
```julia ```julia
@@ -350,12 +351,12 @@ The instantiate command will download and install all listed packages and their
You can get help about a particular package operator by writing `help` in front of it You can get help about a particular package operator by writing `help` in front of it
```julia ```julia
(@v1.10) pkg> help activate (@v1.11) pkg> help activate
``` ```
You can get an overview of all package commands by typing `help` alone You can get an overview of all package commands by typing `help` alone
```julia ```julia
(@v1.10) pkg> help (@v1.11) pkg> help
``` ```
### Package operations in Julia code ### Package operations in Julia code
@@ -368,7 +369,7 @@ julia> Pkg.status()
``` ```
is equivalent to calling `status` in package mode. is equivalent to calling `status` in package mode.
```julia ```julia
(@v1.10) pkg> status (@v1.11) pkg> status
``` ```
### Creating you own package ### Creating you own package
@@ -379,7 +380,7 @@ or if you want to eventually [register your package](https://github.com/JuliaReg
The simplest way of generating a package (called `MyPackage`) is as follows. Open Julia, go to package mode, and type The simplest way of generating a package (called `MyPackage`) is as follows. Open Julia, go to package mode, and type
```julia ```julia
(@v1.10) pkg> generate MyPackage (@v1.11) pkg> generate MyPackage
``` ```
This will crate a minimal package consisting of a new folder `MyPackage` with two files: This will crate a minimal package consisting of a new folder `MyPackage` with two files:
@@ -395,7 +396,7 @@ This will crate a minimal package consisting of a new folder `MyPackage` with tw
You can add dependencies to the package by activating the `MyPackage` folder in package mode and adding new dependencies as always: You can add dependencies to the package by activating the `MyPackage` folder in package mode and adding new dependencies as always:
```julia ```julia
(@v1.10) pkg> activate MyPackage (@v1.11) pkg> activate MyPackage
(MyPackage) pkg> add MPI (MyPackage) pkg> add MPI
``` ```
@@ -406,7 +407,7 @@ This will add MPI to your package dependencies.
To use your package you first need to add it to a package environment of your choice. This is done by changing to package mode and typing `develop ` followed by the path to the folder containing the package. For instance: To use your package you first need to add it to a package environment of your choice. This is done by changing to package mode and typing `develop ` followed by the path to the folder containing the package. For instance:
```julia ```julia
(@v1.10) pkg> develop MyPackage (@v1.11) pkg> develop MyPackage
``` ```
!!! note !!! note

View File

@@ -10,7 +10,7 @@ Welcome to the interactive lecture notes of the [Programming Large-Scale Paralle
This page contains part of the course material of the Programming Large-Scale Parallel Systems course at VU Amsterdam. This page contains part of the course material of the Programming Large-Scale Parallel Systems course at VU Amsterdam.
We provide several lecture notes in jupyter notebook format, which will help you to learn how to design, analyze, and program parallel algorithms on multi-node computing systems. We provide several lecture notes in jupyter notebook format, which will help you to learn how to design, analyze, and program parallel algorithms on multi-node computing systems.
Further information about the course is found in the study guide Further information about the course is found in the study guide
([click here](https://studiegids.vu.nl/EN/courses/2023-2024/XM_40017#/)) and our Canvas page (for registered students). ([click here](https://studiegids.vu.nl/en/vakken/2025-2026/XM_40017#/)) and our Canvas page (for registered students).
!!! note !!! note
Material will be added incrementally to the website as the course advances. Material will be added incrementally to the website as the course advances.

View File

@@ -27,12 +27,17 @@ ex2(f,g) = x -> f(x) + g(x)
### Exercise 3 ### Exercise 3
```julia ```julia
using GLMakie
max_iters = 100
n = 1000 n = 1000
x = LinRange(-1.7,0.7,n) x = LinRange(-1.7,0.7,n)
y = LinRange(-1.2,1.2,n) y = LinRange(-1.2,1.2,n)
heatmap(x,y,(i,j)->mandel(i,j,max_iters)) values = zeros(n,n)
for j in 1:n
for i in 1:n
values[i,j] = surprise(x[i],y[j])
end
end
using GLMakie
heatmap(x,y,values)
``` ```
## Asynchronous programming in Julia ## Asynchronous programming in Julia
@@ -43,11 +48,12 @@ heatmap(x,y,(i,j)->mandel(i,j,max_iters))
```julia ```julia
f = () -> Channel{Int}(1) f = () -> Channel{Int}(1)
chnls = [ RemoteChannel(f,w) for w in workers() ] worker_ids = workers()
@sync for (iw,w) in enumerate(workers()) chnls = [ RemoteChannel(f,w) for w in worker_ids ]
@sync for (iw,w) in enumerate(worker_ids)
@spawnat w begin @spawnat w begin
chnl_snd = chnls[iw] chnl_snd = chnls[iw]
if w == 2 if iw == 1
chnl_rcv = chnls[end] chnl_rcv = chnls[end]
msg = 2 msg = 2
println("msg = $msg") println("msg = $msg")
@@ -65,23 +71,26 @@ chnls = [ RemoteChannel(f,w) for w in workers() ]
end end
``` ```
This is another possible solution. This is another possible solution that does not use remote channels.
```julia ```julia
@everywhere function work(msg) @everywhere function work(msg,iw,worker_ids)
println("msg = $msg") println("msg = $msg")
if myid() != nprocs() if iw < length(worker_ids)
next = myid() + 1 inext = iw+1
@fetchfrom next work(msg+1) next = worker_ids[iw+1]
@fetchfrom next work(msg+1,inext,worker_ids)
else else
@fetchfrom 2 println("msg = $msg") @fetchfrom worker_ids[1] println("msg = $msg")
end end
return nothing
end end
msg = 2 msg = 2
@fetchfrom 2 work(msg) iw = 1
worker_ids = workers()
@fetchfrom worker_ids[iw] work(msg,iw,worker_ids)
``` ```
## Matrix-matrix multiplication ## Matrix-matrix multiplication
### Exercise 1 ### Exercise 1

View File

@@ -620,15 +620,15 @@
], ],
"metadata": { "metadata": {
"kernelspec": { "kernelspec": {
"display_name": "Julia 1.9.0", "display_name": "Julia 1.11.6",
"language": "julia", "language": "julia",
"name": "julia-1.9" "name": "julia-1.11"
}, },
"language_info": { "language_info": {
"file_extension": ".jl", "file_extension": ".jl",
"mimetype": "application/julia", "mimetype": "application/julia",
"name": "julia", "name": "julia",
"version": "1.9.0" "version": "1.11.6"
} }
}, },
"nbformat": 4, "nbformat": 4,

View File

@@ -1131,15 +1131,15 @@
], ],
"metadata": { "metadata": {
"kernelspec": { "kernelspec": {
"display_name": "Julia 1.9.0", "display_name": "Julia 1.11.6",
"language": "julia", "language": "julia",
"name": "julia-1.9" "name": "julia-1.11"
}, },
"language_info": { "language_info": {
"file_extension": ".jl", "file_extension": ".jl",
"mimetype": "application/julia", "mimetype": "application/julia",
"name": "julia", "name": "julia",
"version": "1.9.0" "version": "1.11.6"
} }
}, },
"nbformat": 4, "nbformat": 4,

7324
notebooks/figures/mandel.svg Normal file

File diff suppressed because it is too large Load Diff

After

Width:  |  Height:  |  Size: 440 KiB

View File

@@ -1932,15 +1932,15 @@
], ],
"metadata": { "metadata": {
"kernelspec": { "kernelspec": {
"display_name": "Julia 1.10.0", "display_name": "Julia 1.11.6",
"language": "julia", "language": "julia",
"name": "julia-1.10" "name": "julia-1.11"
}, },
"language_info": { "language_info": {
"file_extension": ".jl", "file_extension": ".jl",
"mimetype": "application/julia", "mimetype": "application/julia",
"name": "julia", "name": "julia",
"version": "1.10.0" "version": "1.11.6"
} }
}, },
"nbformat": 4, "nbformat": 4,

View File

@@ -738,7 +738,8 @@
"\n", "\n",
"- `put!` will wait for a `take!` if there is not space left in the channel's buffer.\n", "- `put!` will wait for a `take!` if there is not space left in the channel's buffer.\n",
"- `take!` will wait for a `put!` if there is no data to be consumed in the channel.\n", "- `take!` will wait for a `put!` if there is no data to be consumed in the channel.\n",
"- Both `put!` and `take!` will raise an error if the channel is closed." "- `put!` will raise an error if the channel is closed.\n",
"- `take!` will raise an error if the channel is closed *and* empty."
] ]
}, },
{ {
@@ -1015,15 +1016,15 @@
], ],
"metadata": { "metadata": {
"kernelspec": { "kernelspec": {
"display_name": "Julia 1.10.0", "display_name": "Julia 1.11.6",
"language": "julia", "language": "julia",
"name": "julia-1.10" "name": "julia-1.11"
}, },
"language_info": { "language_info": {
"file_extension": ".jl", "file_extension": ".jl",
"mimetype": "application/julia", "mimetype": "application/julia",
"name": "julia", "name": "julia",
"version": "1.10.0" "version": "1.11.6"
} }
}, },
"nbformat": 4, "nbformat": 4,

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -1590,15 +1590,15 @@
], ],
"metadata": { "metadata": {
"kernelspec": { "kernelspec": {
"display_name": "Julia 1.10.0", "display_name": "Julia 1.11.6",
"language": "julia", "language": "julia",
"name": "julia-1.10" "name": "julia-1.11"
}, },
"language_info": { "language_info": {
"file_extension": ".jl", "file_extension": ".jl",
"mimetype": "application/julia", "mimetype": "application/julia",
"name": "julia", "name": "julia",
"version": "1.10.0" "version": "1.11.6"
} }
}, },
"nbformat": 4, "nbformat": 4,

View File

@@ -1138,15 +1138,15 @@
], ],
"metadata": { "metadata": {
"kernelspec": { "kernelspec": {
"display_name": "Julia 1.10.0", "display_name": "Julia 1.11.6",
"language": "julia", "language": "julia",
"name": "julia-1.10" "name": "julia-1.11"
}, },
"language_info": { "language_info": {
"file_extension": ".jl", "file_extension": ".jl",
"mimetype": "application/julia", "mimetype": "application/julia",
"name": "julia", "name": "julia",
"version": "1.10.0" "version": "1.11.6"
} }
}, },
"nbformat": 4, "nbformat": 4,

View File

@@ -944,15 +944,15 @@
], ],
"metadata": { "metadata": {
"kernelspec": { "kernelspec": {
"display_name": "Julia 1.9.0", "display_name": "Julia 1.11.6",
"language": "julia", "language": "julia",
"name": "julia-1.9" "name": "julia-1.11"
}, },
"language_info": { "language_info": {
"file_extension": ".jl", "file_extension": ".jl",
"mimetype": "application/julia", "mimetype": "application/julia",
"name": "julia", "name": "julia",
"version": "1.9.0" "version": "1.11.6"
} }
}, },
"nbformat": 4, "nbformat": 4,

View File

@@ -1217,15 +1217,15 @@
], ],
"metadata": { "metadata": {
"kernelspec": { "kernelspec": {
"display_name": "Julia 1.10.0", "display_name": "Julia 1.11.6",
"language": "julia", "language": "julia",
"name": "julia-1.10" "name": "julia-1.11"
}, },
"language_info": { "language_info": {
"file_extension": ".jl", "file_extension": ".jl",
"mimetype": "application/julia", "mimetype": "application/julia",
"name": "julia", "name": "julia",
"version": "1.10.0" "version": "1.11.6"
} }
}, },
"nbformat": 4, "nbformat": 4,