Instead of the QuantEcon interpolation, please try out Interpolations.jl. To do this, first add in the library, and a convenience function (hopefully unnecessary if a recent PR is merged)
using Interpolations
function (itp::Interpolations.GriddedInterpolation{T,N,TCoefs,IT,K,pad})(args...)where {T,N,TCoefs,IT,K,pad}
itp[args...]
end
Then you should be able to replace the following
With something like
aux_inter = interpolate((f.a_values,), aux_exp, Gridded(Linear()))
Please tell us if there is a performance difference.
1 Like
Thank for your suggestion, Jesse. I’ve run the whole code with your proposed change and I get no speed time gain. Actually, it seems slightly slower, around 32 minutes.
@drarnau are you using ifort
or gfortran
? Can you share the Fortran code? There aren’t any technical details making this difference insurmountable (otherwise that would be a bug to report), but there definitely is some unexplained difference to try and find here.
My guess is that something is very off here. For example, you’re using a bunch of heap allocated arrays and I see a bunch of manual copy
operations. ifort
will sometimes stack-allocate those, in which case the right comparison will be to use StaticArrays.jl and this could account for the timing difference (I haven’t profiled those to see where your issue truly lies though). For reference on ifort
’s allocation behavior:
2 Likes
The other thing is to play around with a different root finder to replace the golden method. Since your calculations are so expensive, things that will decrease the number may be very helpful.
I would try https://github.com/JuliaMath/Roots.jl/blob/master/README.md with a few variations on the derivative free methods
1 Like
So far, I’m just trying to write a Julia version of this code. The file I’m linking is from a published paper and contains more stuff than what I’m trying to replicate. The program consists of many files. What I’m trying to replicate is in a folder called ss_codes. I compiled it both in gfortran and ifort and it was much faster than my Julia version. Actually, my Julia version it’s just a part of that program (the computationally intensive part).
What is the difference of using StaticArrays.jl with respect to what I’m using now? Could that improve the performance?
Thanks for your comment!