-
Notifications
You must be signed in to change notification settings - Fork 0
/
Logistic_map_multiprocess.jl
48 lines (38 loc) · 1.12 KB
/
Logistic_map_multiprocess.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
using BenchmarkTools
using Plots
using Distributed
addprocs(2)
@everywhere using SharedArrays
@everywhere f(x, p) = p*x*(one(x)-x)
@everywhere function calc_attractor!(out, f, p, num_attract, warmup)
x = 0.25
for i in 1:warmup
x = f(x, p)
end
@inbounds out[1] = x
@inbounds for i in 1:num_attract-1
out[i+1] = f(out[i], p)
end
end
r = 2.9:0.001:4
n_cols = length(r)
n_rows = 150
pl_data_st = SharedArray{Float64}(n_rows, n_cols)
pl_data_st[1, :] .= 0.25
pl_data_dy = SharedArray{Float64}(n_rows, n_cols)
pl_data_dy[1, :] .= 0.25
# Multirocessing the data with pmap which schedules the jobs dynamically
@btime @sync pmap(i -> calc_attractor!(@view(pl_data_dy[:, i]), f, r[i], 150, 400), 1:n_cols)
pl_data_dy
function fill_pl_st()
@sync @distributed for i in 1:n_cols
calc_attractor!(@view(pl_data_st[:, i]), f, r[i], 150, 400)
end
end
@btime fill_pl_st()
pl_data_st
p = plot(xlims=(2.9,4), ylims=(0, 1), title="Bifurcation Plot", label=false)
for i in 1:n_rows
scatter!(r, pl_data_dy[i, :], label=false, color=:black, alpha=0.1) #can flip btn pl_data_dy and pl_data_st
end
p