Skip to content

Instantly share code, notes, and snippets.

View carstenbauer's full-sized avatar
🐰
Deep in the rabbit hole

Carsten Bauer carstenbauer

🐰
Deep in the rabbit hole
View GitHub Profile
@carstenbauer
carstenbauer / makie.jl
Last active March 21, 2023 11:40
Makie Animation Pi
function pi_animation()
N = 1000
Random.seed!(123)
# setup figure
f = Figure(resolution = (1000,400))
dart_fig = f[1,1]
dart_ax = Axis(dart_fig, aspect=1, title="Monte-Carlo-Simulation")
approx_fig = f[1,2]
approx_ax = Axis(approx_fig, title="Quality of Approximation")
@carstenbauer
carstenbauer / pi_error.jl
Last active March 21, 2023 16:52
Monte Carlo Pi Error
function run_experiment(N; saverate=1)
hits = 0
dist = Uniform(-1,1)
is = Int64[]
pis = Float64[]
for i in 1:N
x, y = rand(dist), rand(dist)
# speed-up computation by omiting sqrt
if (x^2 + y^2) <= 1
# Equations:
# ∂P/∂t = -k(∂Vx/∂x + ∂Vy/∂y)
# ∂Vx/∂t = -1/ρ ∂P/∂x
# ∂Vy/∂t = -1/ρ ∂P/∂y
# => Update rules:
# Vx = Vx - Δt/ρ ΔP/Δx
# Vy = Vy - Δt/ρ ΔP/Δy
# P = P - Δt*k (Δ(Vx)/Δx + Δ(Vy)/Δy)
@carstenbauer
carstenbauer / matvec_parallel.jl
Last active March 20, 2024 10:33
parallel matrix-vector multiplication
using Test: @test
using Base.Threads: nthreads
using BenchmarkTools: @btime
using OhMyThreads: @tasks, tmap!, tmapreduce, chunks
using ThreadPinning
pinthreads(:cores)
# naive, math implementation
function matvec_row!(y, A, x)
fill!(y, zero(length(y)))