clean-up
This commit is contained in:
32
main.ua
32
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÷⊃⧻/+ ◌
|
||||
|
||||
Reference in New Issue
Block a user