THERE WAS AN ERROR IN MY CODE. SORRY EVERYBODY. THE REASON WAS THAT THE TIME NEEDED FOR LARGER VALUE OF X IS LARGER.
This is my code:
fit_s = rand(100)
fit_d = rand(300)
LIM = 100
x = [2^i for i in range(-2,2,40)]
y = zeros(length(x))
Threads.@threads for i in 1:length(x)
y[i] = analytic(x[i], fit_s, fit_d, LIM)
end
print(i)
my_function uses the two inputs to produce the output. The problem is that it does not speed up the execution. With 1 threads it takes 27 s while with 8 threads 21 s(I'm considering only the time of the for loop). What can I do ? Thanks in advice.
Function
function alpha(i,n,m)
((n-i)/n)^m - ((n-i-1)/n)^m
end
function beta(i,n,m)
(1-i/n)^(m)
end
function gamma(s, d, fit_s, fit_d, LIM)
n_s = length(fit_s)
n_d = length(fit_d)
app = sort(fit_d, rev=true)[1:LIM]
F_DN = 0.
for i in 1:LIM
j = sum(fit_s .> app[i])
F_DN += alpha(i-1,n_d,d)*beta(j,n_s,s)
end
F_DN
end
function mine_poisson(m,i)
f = Poisson(m)
pdf(f, i)
end
function analytic(m, fit_s, fit_d, LIM)
Z = 1 - exp(-2*m)
F_DN = 0.
intm = trunc(Int, m + 0.5)
if m < 20
intervallo = 1:(intm + 20)
else
app = trunc(Int,m^0.5)*4
intervallo = (intm - app) : (intm+app)
end
for j in intervallo
for k in intervallo
p = mine_poisson(m, k)*mine_poisson(m, j) / Z
F_DN += gamma(j, k, fit_s, fit_d, LIM)*p
end
end
F_DN += exp(-m)*(1-exp(-m))/Z
end