As part of an explanation of Julia’s import in facilitating & speeding the process of bringing someone on into an ongoing larger project and getting them up to speed, I am looking for examples of the same function written in C++ or Fortran (recent versions of each) and written in Julia.
Helpful examples would be where the C++/Fortran is “scary” or not at all clear without prior implementation familiarity, while the Julia version is as a walk in the park on a lovely Spring day. It is helpful if the longest versions are displayable as half-page (top or bottom half) float or in less space. Excerpts from larger functions are ok, if the excerpted parts are purpose matched and the Julia version is self-evident.
Below that post of mine, Chris Elrod posted another version of the same thing which is more elegant (in both languages), although the Fortran implementation in his case is directly thought to be interfaced with Julia, so some syntax is not natural for Fortran in general.
@JeffreySarnoff Whatever example you pick, please do not use Fortran as a punchbag by presenting some archaic F77 or F90 code, just because so many people are unaware of modern Fortran syntax (I believe the example provided in the comments by @lmiq suffers from a similar syndrome) Use Fortran 2018 syntax, otherwise, such unfair language comparisons are examples of scientific dishonesty, in my opinion. Also, please learn about and consider all Fortran/C++ compiler optimization flags before presenting a benchmark.
One particular strength of Julia compared to Fortran or C is that once you have written your function, you can AD thorough it, or perhaps send Sympy symbols through it. I use this “feature” daily and my productivity would be tremendously impacted by not having it.
A simple thing like switching from Float64 to Float32 or BigFloat is also something incredibly powerful.
Yes, it does. That is why I mentioned the rewrite of Chris Elrod, which is much more aware of the modern Fortran syntax, and he is also the one person to provide the correct compiler flags.
One thing to keep in mind, though, is that a lot of people using Fortran use Fortran77 and Fortran90 syntax yet, and comparing the examples fairly will not only showcase Julia, but also be a lesson on the newer Fortran syntax for these people. One might wander if these people (like me) would prefer the effort to learn a new syntax of Fortran or move to another language.
Something tells me this will take some work. Should we encourage side discussions/open a repo to make sure things are fairly compared and people are working together?
I have created a repository for this purpose (with the understanding that it may be transferred at a later date). Any member of the community who would like commit privileges can have them – just ask me on this thread https://github.com/JeffreySarnoff/ComparisonsWithJulia/issues/1
I would not do that. Old fortran code is not applicable here.
These are intended for visual comparison, others with real (modern) Fortran/C++ expertise have worked through and published careful comparative benchmarking results. One focused on communication: http://hunoldscience.net/paper/julia_hpc_paper_sahu_2020.pdf. If you know of others, do share.
The key here being that you could easily switch the type of the parameters in your problem to BigFloat and then the ODE library was able to solve the problem with a higher precision. An ODE library written in fortran would have to provide explicit support for solving problems with BigFloat, whereas in julia this comes for free.
Scroll down a bit, it’s hidden due to limited text box size. In any case my example still uses boost and as @simonschoelly said this stuff is in std nowadays, so I (or someone else) should probably adapt it accordingly.
Defining the comparison operator in C++ looked scary to me. But after the spaceship operator in C++20 it could be an example that it’s actually easier in C++…