What’s the best way to implement parallel computing here? I’m new to it and Julia. I have eight physical cores.
The process function returns two dictionaries.
@time begin
param = "reaction" # reaction, mesh, diffusion
r_start = 0
r_end = 0.5
r_length = 10
parameter_range = range(r_start, r_end, length=r_length)
u_steps, speed_steps = process(param, parameter_range, ncores)
data = reduce(vcat, values(speed_steps))
Inside process, there is a for loop that iterates over parameter_range. This is where I can employ parallel computing as the order does not matter. At the end of each iteration, I add two results to two separate dictionaries.
function process(param, parameter_range, ncores)
a = 0
b = 20
T = 10
t_steps = 10^4
global solutions = Dict()
global speed = Dict()
for key in parameter_range
key = round(key, digits = 5)
if param == "reaction"
M = 512
D = 1
alpha = key
end
if param == "mesh"
alpha = -0.5
D = 1
M = key
end
if param == "diffusion"
alpha = 0.10
M = 512
D = key
end
k = T / t_steps
h = (b - a) / M
mu = k / h^2
boundary = "HN"
x = [h * i for i = 0:M]
t = [k * i for i = 0:t_steps]
# initial condition
u0 = initial_condition(x)
# crank matrices
local B_inv, P = crank(M, mu, D, boundary)
# time step
local time_steps = calc_new_step(B_inv, P, u0, D, k, t_steps, M, alpha)
p_title = string("reduced nagumo:", " ", "M = ", M, " ", "alpha = ", alpha, " ",
"k = ", k, " ", "diff = ", D)
Plots.contourf(x, t, time_steps, fill=true, c=:vik, title=p_title, xlabel="x", ylabel="t", dpi=300)
# saves the current plot:
global output_name = string(p_title, ".png")
global subfolder = joinpath(pwd(), string(param))
if ispath(subfolder) == 0
mkdir(subfolder)
end
output_loc = joinpath(subfolder, output_name)
savefig(output_loc)
complete = DataFrame(Transpose(time_steps),:auto)
solutions[key] = complete
speed_key = calc_speed(complete, h, k, M, alpha, D, param, key)
speed[key] = speed_key
end
return solutions, speed
end