mirror of
https://gitlab.rlp.net/mobitar/julia_course.git
synced 2024-09-14 12:47:20 +00:00
70 lines
2.1 KiB
Julia
70 lines
2.1 KiB
Julia
### A Pluto.jl notebook ###
|
|
# v0.19.42
|
|
|
|
using Markdown
|
|
using InteractiveUtils
|
|
|
|
# ╔═╡ 95f0a7c8-b065-11ec-0bd4-a9be6aca0c47
|
|
md"""
|
|
# Workflow outside notebooks
|
|
Create a project directory somewhere in your file system. Now, `cd` into this project directory and create a project environment. Add some packages to this environment.
|
|
|
|
Now, create two Julia files in this directory:
|
|
- `main.jl`
|
|
- `sub.jl`
|
|
|
|
Write a function in the `sub.jl` file. Include this code in the `main.jl` file using the following inside `main.jl`:
|
|
|
|
include("sub.jl")
|
|
|
|
Now, define a new function in `main.jl` that uses the function from `sub.jl`. Use `Measurements.jl` for some error calculation in one of these functions.
|
|
|
|
Run Julia with the `--project` argument.
|
|
|
|
Include only the `main.jl` file. Now run the function defined in `main.jl`.
|
|
"""
|
|
|
|
# ╔═╡ c2bbace2-3585-4a40-b54f-d466dd735716
|
|
md"""
|
|
# Startup
|
|
Create the file `~/.julia/config/startup.jl`. Add the following lines into this file:
|
|
|
|
```julia
|
|
using OhMyREPL
|
|
using Revise
|
|
```
|
|
|
|
Make sure that the two packages are in your global environment.
|
|
|
|
Now launch Julia and test the syntax highlighting provided by `OhMyREPL`.
|
|
|
|
Include a file using `includet` (not `include`) to test that Revise is also imported at startup.
|
|
"""
|
|
|
|
# ╔═╡ 53bbb6c2-b264-4892-8e18-af8a1a5d5c2d
|
|
md"""
|
|
# Multithreading
|
|
Open the tasks notebook of the first course day. Copy your function for the task about the squaring difference.
|
|
|
|
Now, calculate all squaring differences for $i \in [1, N]$ with $N = 1000$ and store the results in a vector.
|
|
|
|
Do this calculation without and with multithreading. What is the difference?
|
|
|
|
Can you optimize more? Do some benchmarking!
|
|
|
|
Plot the "squaring difference" of `i` against `i`.
|
|
|
|
**Hints:**
|
|
- Verify that `Threads.nthreads()` returns a number bigger than one.
|
|
- You have to import needed packages.
|
|
"""
|
|
|
|
# ╔═╡ 98112d63-c9df-4f4d-b961-ad26c76dd118
|
|
# Your code starts here
|
|
|
|
|
|
# ╔═╡ Cell order:
|
|
# ╟─95f0a7c8-b065-11ec-0bd4-a9be6aca0c47
|
|
# ╟─c2bbace2-3585-4a40-b54f-d466dd735716
|
|
# ╟─53bbb6c2-b264-4892-8e18-af8a1a5d5c2d
|
|
# ╠═98112d63-c9df-4f4d-b961-ad26c76dd118
|