fortran-vs-julia

Fortran-Julia syntax comparison and Maxwell Solver in 2D using Yee numerical scheme and MPI topology

GPL-3.0 License

Stars
17

Julia Syntax: Comparison with Fortran

This is a simple cheatsheet and some performance comparison for scientific programmers who are interested in discover Julia. It is not an exhaustive list. This page is inspired from A Cheatsheet for Fortran 2008 Syntax: Comparison with Python 3.

Maxwell parallel solver in 2D

Here an example of a Fortran to Julia translation. We use the Yee numerical scheme FDTD: Finite-Difference Time-Domain method and MPI topology. You can find a serial version and a parallel version using MPI library.

Test your MPI.jl installation with

$ mpirun -np 4 julia --project hello_mpi.jl
Hello world, I am 0 of 4
Hello world, I am 3 of 4
Hello world, I am 1 of 4
Hello world, I am 2 of 4

Performances (without disk IO)

On small program like this in Julia is really fast.

Serial computation

1200 x 1200 and 1000 iterations.

  • julia -O3 --check-bounds=no maxwell_serial.jl : 14 seconds
  • make && time ./maxwell_serial_fortran : 31 seconds

1200 x 1200 on 9 processors and 1000 iterations

  • make && time mpirun -np 9 ./maxwell_mpi_fortran : 7 seconds
  • mpirun -np 9 julia --project -O3 --check-bounds=no : 5 seconds

Plot the magnetic field

Uncomment the plot_fields call in Julia programs or change idiag value in input_data for fortran.

gnuplot bz.gnu