Posts

Showing posts from May, 2020

A Quick Aside

So some early testing of a better optimised GasCode program suggests that code like: ∫▽●V[i] = 0.0 Is really badly optimised. Instead, you're better off using ∫▽●V = zeros(ncells) Or potentially @inbounds @sync @distributed for i in 1:ncells ∫▽●V[i] = 0.0 end If you're using the Distributed package Note that if you don't include the @sync in this style of distributed loop, you don't actually update the array.

More on Performance

Image
Let's scale things back, and look at a simple example - brute force calculation of Pi. We can do this using the following formula: This is easy enough to code up in various languages: C++ #include <iostream> #include <stdio.h> static long nsteps = 10000000000; int main() { long i; double x, pisum = 0.0; double mypi; double pi = 3.141592653589793; double step = 1.0/(double)nsteps; for (i=0;i<nsteps;i++) { x = (i+0.5)*step; pisum = pisum + 4.0/(1.0+x*x); } mypi = pisum * step; printf("%20.16f\n", mypi); printf("%20.16e\n", mypi - pi); } Fortran program calculate_pi use, intrinsic :: iso_fortran_env USE OMP_LIB implicit none integer(kind=INT64), parameter :: nsteps = 10000000000_INT64 integer(kind=INT64) :: i real(kind=REAL64) :: stepsize, x, pisum real(kind=REAL64) :: t1, t2 real(kind=REAL64) :: mypi, diff real(kind=REAL64) :: pi = 3.141...

Julia Performance

Image
So, we have basic, Lagrangian-only versions of GasCode written in Fortran, Python and Julia, so we can take a look at their relative performance. For these comparisons, I'll use the spherical Sod problem on a 50x50 mesh: This problem is being used simply because it's the hard-coded one, and I've not added a mesh reader to the Python or Fortran versions of the code yet. Input options are as follows: # EoS gamma = 1.4 # Artificial Viscosity CL = 0.5 CQ = 0.75 # Mesh Extents x0 = 0.0 x1 = 1.0 y0 = 0.0 y1 = 1.0 # Timestep, etc. t0 = 0.0 tend = 0.205 dtinit = 0.0001 dtmax = 0.01 growth = 1.02 # Mesh resolution nregions = 1 meshx = 50 meshy = 50 # Debug settings debug_step_count = 0   # Set to zero to disable debugging # Cutoffs rhocutoff = 1.0e-6 I.e. basic monotonic Q, and no anti-hourglass. Using these settings, and running the Fortran code along with the most simple (/naive) versions of the Julia and Python codes, we get the following runtimes for just the Lagrangian ...