torstai 20. helmikuuta 2014

Julia for finite elements, part 2

A small update to the previous post. I'm starting to approach the vectorized MATLAB speed. The new results are as follows.


(The highest DOF case was omitted in Julia because my crappy 'n slow 5-minute mesh refiner hogged all the memory.) Some tricks to speed up the code:

  • Devectorize, devectorize, devectorize, ... Write everything that you possibly can using loops. Even some simple matrix-vector-multiplications if you do them inside loops.
  • Do not use too much array slicing or anonymous functions (or reduntant function calls) inside loops. This will slow things down since function calls seem to have some overhead.
  • Preallocate arrays if possible. Otherwise use 1D arrays and push!-command.
I'm happy with the results of my test: Expect some Julia-sorcery in the future! The next target is parallelization.

sunnuntai 16. helmikuuta 2014

Julia for finite elements

There has been lots of hype in the internet regarding Julia, JIT-compiled programming language for scientific computing. The surprising thing is that the compiler doesn't expect that the code is vectorized and quite often the devectorized versions are even faster. This weekend I ran some preliminary tests of 2D finite element bilinear form assembly code.


My Julia knowledge is very limited and I have learned everything during this weekend. However, still I get very promising improvements over the for-looped MATLAB code that we use for teaching finite elements at my university. The vectorized MATLAB code has been under development for 10 years and a similar code is used for research. With some tweaking of Julia code I'd probably be able to close the gap between the blue and red lines. As a conclusion, Julia project is definitely something that scientific computation people should be following closely.