Where can I find some high performance Julia code?

Sorry for this stupid and general question.

I am a Fortran guy and new to Julia. I am translating my Fortran code to Julia, and to make a direct comparison between the speed of modern Fortran and Julia.
But I want to make the comparison fair. I do not want to compare a fast Fortran code with my baby level Julia code. I wish to write the Julia code as fast as I can. So the Fortran .vs. Julia comparison can be reasonable.

Therefore, I just wonder, could anyone recommend perhaps some public Github or Gitlab repos with high performance Julia code? I feel learning from those code can be helpful. Reading the Julia documents still is a little too abstract for me.

Thanks in advance!

3 Likes

Welcome! Domain matters here. What kind of Fortran code are you looking to translate

Sorry for the direct ping but I think you need to get the perspective of @lmiq, who is probably the most enthusiastic and succesful Fortran convert I know around here. Actually maybe if you go through some of his past posts you can already find some wisdom with regards to what Fortran programmers need to look out for.

3 Likes

I am not an expert here. Many people recommend reading the Julia Performance Tips

Also loops in Julia are not slow - which might be good for a Fortran programmer.
So use FOR loops!

https://docs.julialang.org/en/v1/manual/performance-tips/

1 Like

I suspect SpecialFunctions.jl contains some examples of highly optimized code (using Horner’s rule, etc) written in pure Julia.

The obvious one is: GitHub - JuliaLang/julia: The Julia Programming Language - Most of Julia’s Base module and standard libraries are written in pure Julia with performance in mind. The code is both readable and well-commented (imo).

Just as a random example, here’s a high-performance implementation of trigonometric functions, that is written entirely in Julia. (Parts are translated from C, apparently.)

At the Julia REPL, you can type things like @edit sin(0.0) in order to see the code for a specific function with a specific type of argument.

2 Likes

My advice would be to choose one specific relatively small and self-contained program or function you have in Fortran and start translating it to Julia. If the performance is not similar to the Fortran code, post it here, ask for advice. As a general rule, you should be able to write code in Julia that is as fast as the Fortran code (and vice-versa).

Julia shines, from the perspective of a Fortran developer, not because of the performance you get from very well written code in both languages. That is the same. Julia will give generic functions, a very nice programming experience (you need to use Revise and use a proper development workflow), and many tools that allow you to improve the algorithms you are developing much easily than you (I, in fact) were able to do in Fortran. Also, the package manager and documentation integration is fantastic for distributing and documenting the code.

In my path learning Julia I have written some notes: Home · JuliaNotes.jl

This in particular looks at one specific important aspect (mutability vs. immutability of variables) from a what I perceived coming from Fortran: Immutable variables · JuliaNotes.jl

But, I insist, start trying and ask for advice here. People here are really helpful.

18 Likes

You can check Home · LoopVectorization.jl. LoopVectorization is a package that enables very fast for loops. The docs have some examples of how fast it can run and how easy it is to use. LoopVectorization might be a bit cheating since it uses a lot of LLVM intrinsics instead of just julia operations, although it is just julia code so it might be fine.

1 Like

Perhaps have a look at som really performant linear algebra code
https://github.com/YingboMa/RecursiveFactorization.jl/

2 Likes

I ported some FORTRAN algorithms to Julia in the SatelliteToolbox.jl

For the specific case of IGRF, we have a direct translation, but considering some points related to Julia language:

https://github.com/JuliaSpace/SatelliteToolbox.jl/blob/master/src/earth/geomagnetic_field_models/igrf/igrf13/igrf13syn.jl

And a more Julian approach:

https://github.com/JuliaSpace/SatelliteToolbox.jl/blob/master/src/earth/geomagnetic_field_models/igrf/igrf.jl

You can easily find the FORTRAN version of IGRF on the Internet.

3 Likes

Thank you.
It is a Monte Carlo (MC) code in expectation maximization (EM) algorithm.
in EM, there are loops(iterations) in order to update the parameters, in each iteration, MC is involved in evaluating the integrals for updating the parameters.

I agree with leandromartinez98 that you should generally not see any or much performance gain by converting your Fortran code to Julia (unless there are significant algorithmic differences, which could go either way). You may also want to get help from the Fortran discourse community or get help from experts on the Intel Fortran forum to improve your existing Fortran codebase.

1 Like

They’re just microbenchmarks, but here are the Fortran benchmarks used and here is the compilation command.

Microbenchmarks may not necessarily be representative of an application, but RecursiveFactorization.jl is an example of a larger program making good use out of it and beating OpenBLAS in performance.

2 Likes