Dear Julia users,
Is there a way to improve performance of this kind of code without devectorizing (use loops). All variables are 2d arrays. I solve a PDE problem with finite differences method. Thanks for your help
Don’t use diff, that creates temporary arrays. Don’t use multiple lines of .+=, ./=, etcetera — you want a single fused loop for cache efficiency. Don’t use * and + and / when you want .* and .+ and ./ in order to fuse the loops.
(But honestly, this is the sort of thing that is probably more readable if you just write a loop, and there is no performance reason not to do so in Julia.)
Thanks for your answer, i rewrite the code following your advices and it is better. With loops the code is faster. If i understood well, in julia the fortran-like syntax is better than the
matlab-like syntax. Unfortunately, the code i wanted to translate is in matlab
I really like Julia as a language but fortran is still faster for what i am doing (for now).
Thank you very much for help, the last link will help
My code is here https://github.com/pnavaro/M2Dpt.jl
I will try to beat fortran and matlab during next few days.
I agree this may be clearer & faster with loops, or functions containing the loops. But sometimes it’s good to have something which matches the old code almost line-for-line.
You may want to try @uviews from UnsafeArrays.jl for creating lots of views you’ll only use once.