For Monte Carlo simulation with same code same algorithm, how fast is Julia compared with Fortran?

The reason why Julia users who don’t usually use const tell newcomers to “Make global variables const” is to recover performance with minimal changes to the code.

In fact, fixing types with const kills a lot of benefits of using Julia.

For example, if you use const to fix the type to Float64, you will not be able to use Measurements.jl, MonteCarloMeasurements.jl and Intervals.jl.

Not only that, but it also closes the way to introduce automatic differentiation for better performance.

Moreover, fixing the type to Array with const also makes it difficult to migrate to GPU-based computations using CuArray in CUDA.jl for higher performance.

Do not use const to fix types to ensure type stability.

A good and simple way to ensure type stability is to pass all of the information needed by a function (including global variables that contain the information shared with other functions) as arguments to the function each time.

In my personal opinion, higher education around the world teaches the opposite of this point in a harmful way. It keeps producing large numbers of people who are misled by it and don’t want to do the above.

If you actually write the code to pass all the information as arguments to a function every time, you will find that the effort is not significant and the benefits you get, independent of Julia, are huge. Don’t be afraid to try it.

The point is to create constructors for data shared by multiple functions. (cf. Function depending on the global variable inside module - #10 by genkuroki)

14 Likes