I agree it would be easiest to show the bad code, but I don’t know how to identify it using @code_warntype.
Using Juno.profiler() as suggested by @goerch has let me find the functions and lines of code that take a lot of time. I will assume these lines are causing the bad code messages in @code_warntype.
This is my attempt at a MWE. foo3 is not what I expected, but the problematic lines are commented. I think these lines must take up a lot of resources while computing.
const num_nutrient = 2
const num_plant = 30
const index_food_web = num_nutrient+num_plant
function bigger_function(num_nutrient,num_plant,index_food_web)
function create_vec_parameter2()
q_one = rand(Normal(0.5,0.2))+1.0
bm = rand(index_food_web)
bioS = rand(index_food_web)
foodWeb = rand(index_food_web, index_food_web)
b = rand(size(foodWeb))
h = rand(size(foodWeb))
ω = zeros(length(bm))
return q_one,bm,bioS,foodWeb,b,h,ω
end
q_one,bm,bioS,foodWeb,b,h,ω = create_vec_parameter2()
function FF2(num_nutrient, bm, foodWeb, pred, prey, b,bioS, h, ω, q_one)
sumF = 0.0
for k in num_nutrient+1:length(bm)
if foodWeb[k, pred] !== 0.0
sumF = sumF+b[k, pred]*abs(bioS[k])^q_one #this is a problem line
end
end
return (((ω[pred]*b[prey, pred])^q_one)/(ω[pred]*h[pred]*sumF))/bm[pred]
end
function one_more_function(num_nutrient,num_plant,index_food_web,bioS,bm,b, h, ω, q_one)
foo = 0.0
for j in (num_nutrient+num_plant+1):(index_food_web)
foo = foo + bioS[j]*FF2(num_nutrient, bm, foodWeb, pred, prey, b,bioS, h, ω, q_one) #this is a bigger problem line
end
return foo
end
foo2 = one_more_function(num_nutrient,num_plant,index_food_web,bioS,bm,b, h, ω, q_one)
end
foo3 = bigger_function(num_nutrient,num_plant,index_food_web)