From a4c36f1b03a0777cca149185b213853622d6848c Mon Sep 17 00:00:00 2001 From: Mirek Kratochvil <miroslav.kratochvil@uni.lu> Date: Tue, 7 Jun 2022 09:53:32 +0200 Subject: [PATCH] fixes --- .../slides/distributed.md | 15 ++++++-- .../slides/index.md | 3 +- .../slides/language.md | 35 ++++++++----------- 3 files changed, 28 insertions(+), 25 deletions(-) diff --git a/2022/2022-06-08_JuliaForNewcomers/slides/distributed.md b/2022/2022-06-08_JuliaForNewcomers/slides/distributed.md index f3aa4d88..a1266a21 100644 --- a/2022/2022-06-08_JuliaForNewcomers/slides/distributed.md +++ b/2022/2022-06-08_JuliaForNewcomers/slides/distributed.md @@ -25,10 +25,17 @@ # Basic parallel processing -**Using Threads:** +**Using `Threads`:** 1. start Julia with parameter `-t N` -2. parallelize any loops with `Threads.@threads` +2. parallelize (some) loops with `Threads.@threads` + +```julia +a = zeros(100000) +Threads.@threads for i = eachindex(a) + a[i] = hardfunction(i) +end +``` **Using `Distributed`:** @@ -38,6 +45,8 @@ addprocs(N) newVector = pmap(function, oldVector) ``` +We will use the `Distributed` approach. + # How to design for parallelization? @@ -53,7 +62,7 @@ newVector = pmap(function, oldVector) - parallelize programs using `pmap` and `dmapreduce` (DistributedData.jl) - Decompose more advanced programs into *tasks with dependencies* - Dagger.jl - - `make -jN` is a surprisingly good tool for parallelization! + - `make -jN` may be a surprisingly good tool for parallelization! diff --git a/2022/2022-06-08_JuliaForNewcomers/slides/index.md b/2022/2022-06-08_JuliaForNewcomers/slides/index.md index 1bd50717..77e313d8 100644 --- a/2022/2022-06-08_JuliaForNewcomers/slides/index.md +++ b/2022/2022-06-08_JuliaForNewcomers/slides/index.md @@ -22,8 +22,9 @@ <style> code {border: 2pt dotted #f80; padding: .4ex; border-radius: .7ex; color:#444; } - pre code {border: 0;} + .reveal pre code {border: 0; font-size: 18pt; line-height:27pt;} em {color: #e02;} li {margin-bottom: 1ex;} div.leader {font-size:400%; font-weight:bold; margin: 1em;} + section {padding-bottom: 10em;} </style> diff --git a/2022/2022-06-08_JuliaForNewcomers/slides/language.md b/2022/2022-06-08_JuliaForNewcomers/slides/language.md index fc334924..e5d1d904 100644 --- a/2022/2022-06-08_JuliaForNewcomers/slides/language.md +++ b/2022/2022-06-08_JuliaForNewcomers/slides/language.md @@ -12,38 +12,28 @@ Expressions and types You can discover types of stuff using `typeof`. Common types: - `Bool` - ```julia false, true ``` - - `Char` - ```julia 'a', 'b', ... ``` - - `String` - ```julia "some random text" ``` - - `Int` - ```julia -1, 0, -1, … +1, 0, -1, ... ``` - - `Float64` - ```julia - 1.1, -1e6, ... + 1.1, 0, -1, ... ``` - # Types may have parameters (usually "contained type") - `Vector{Int}` @@ -76,7 +66,7 @@ false, true Types possess a single supertype, which allows you to easily group multiple types under e.g. `Real`, `Function`, `Type`, `Any`, ... -```julia +<pre style="font-size: 90%; line-height:120%;"><code class="language-julia hljs"> julia> Int Int64 @@ -94,9 +84,9 @@ Number julia> Int.super.super.super.super.super Any -``` -These are useful when restricting what can go into your functions! +</code></pre> +Useful for restricting your functions to work on reasonable subsets of inputs. @@ -345,12 +335,15 @@ person["age"] indexof(v::Vector) = Dict(v .=> eachindex(v)) ``` -- Sets are value-less dictionaries. +- Sets are value-less dictionaries (i.e., the elements are unique keys) ```julia -function unique(x) - elems = Set{eltype(x)}() - push!.(Ref(elems), x) - return collect(elems) -end +julia> x=Set([1,2,3,2,1]); +julia> println(x) +Set([2, 3, 1]) + +julia> push!(x,5); +julia> push!(x,5); +julia> println(x) +Set([5, 2, 3, 1]) ``` -- GitLab