Hi,
I am trying to apply multi-threading to a for loop running a Monte Carlo simulation, but unsuccessfully.
So, let’s consider the following simple example:
using Base.Threads
a = 0
b = zeros(10,1)
Threads.@threads for i in 1:10
a = a+1
b[i] = rand
end
When I run this piece of code, I get the following errors:
Error thrown in threaded loop on thread 0: UndefVarError(var=:a)
Error thrown in threaded loop on thread 1: UndefVarError(var=:a)
Does anyone know how to solve this?
Also, I was wondering if I should somehow specify the number of threads at the beginning of the code.
Thank you in advance!