3 ms·
This example is not really testing Fortran vs. Julia, but rather testing the speed of the math library you linked to. The most expensive part of the fortran co
by dfdz 5y ago
This example is not really testing Fortran vs. Julia, but rather testing the speed of the math library you linked to.
The most expensive part of the fortran code is evaluating sqrt and exp.
For example on a 5600X the current Fortran code (with n=10 000) takes about 2.7 seconds. If I change the definition of M to remove the special functions (M(i,j) = a(i)+ a(j) then it takes .3 seconds. (Using gfortran with -Ofast)
When the special functions are the issue, using the Intel Fortran compiler and Intel MKL will make the code about 2x faster (this is what Matlab or Julia is probably using)
- moelf 5y agoJulia ships with OpenBLAS, in some cases there are pure-Julia "blas-like" routine that can be as fast: https://github.com/mcabbott/Tullio.jl https://github.com/mcabbott/Tullio.jl
- celrod 5y agoOr much faster (at small sizes): https://github.com/JuliaLinearAlgebra/Octavian.jl https://github.com/JuliaLinearAlgebra/Octavian.jl
- eigenspace 5y agoAlso much faster at very large sizes :)
- celrod 5y ago`vsqrtpd` is an assembly instruction. `exp` and `sincos` are implemented in Julia. If you want to use a library to speed up the Julia code, checkout https://discourse.julialang.org/t/i-just-decided-to-migrate-from-python-fortran-to-julia-as-julia-was-faster-in-my-test/61188/19?u=elrod https://discourse.julialang.org/t/i-just-decided-to-migrate-... (but replace `@tvectorize` with `@tturbo`), which is code by eigenspace.
- dfdz 5y agoMy point is that for codes like this, the issue is not vectorization. Just evaluating the special functions exp and sqrt is taking 90% of the time. You can evaluate these special functions in parallel, but that is about it.