From bde47e8ff3fe1821e58f6f3e62680975ccdb1be6 Mon Sep 17 00:00:00 2001 From: fredrikr79 Date: Sun, 21 Sep 2025 17:59:23 +0200 Subject: [PATCH] clean-up --- main.ua | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/main.ua b/main.ua index 53a68a9..c1ae889 100644 --- a/main.ua +++ b/main.ua @@ -1,11 +1,25 @@ -f ← ˜÷1+1ⁿ2 -ι ← +⟜(\+↯⤙(˜÷⌵-)) # linspace -i! ← ÷⊃⧻/+ ^0 ι # integrate numerically (mean function value) -t! ← ⊙(&p×1e3⌵-)⊙now^0⊙now # time 1-ary function +# approximate pi by integrating 1/(1+x²) from 0 to 1, +# doing so in parallel with threading for a speed-up. -0 1 4 # interval [a, b] with n partitions (threads) -⊂⟜(\+↯⤙(˜÷⌵-)) # partition into n subintervals -⊃(t!(⧈₂/(i!f⊙⊙1e8)) # sequential: integrate each area -| t!(wait⧈₂/pool(i!f⊙⊙1e8)) # threading with n threads: this is faster +f ← ˜÷1+1ⁿ2 +# create interval [a, b) with n values +# interval ? a b n +ι ← ⍜-×⊙⊙(÷⟜⇡) +# integrate f on given interval +# integral ? f a b n +i! ← ÷⊃⧻/+ ^0 ι +# time a unary function +# ? f +t! ← ⊙(&p" ms"&pf×1e3⌵-)⊙now^0⊙now +# partition into n subintervals +# [subintervals a_b] ? a b n +p ← ⊂⟜(\+↯⤙(˜÷⌵-)) + +p 0 1 4 # n=4 threads +⊃(&p $ sequential: + t!(⧈₂/(i!f⊙⊙1e7)) +| &p $ parallel: + t!(wait⧈₂/pool(i!f⊙⊙1e7)) ) -×4÷⊃⧻/+ ◌ # discard one of the benchmarked calculations, collect result +&p $ error: +⌵-π×4÷⊃⧻/+ ◌