FEM Assembly and Solver Benchmarks

FEM Assembly and Solver Benchmarks

Although not very popular to undertake, and sometimes outright controversial, benchmarks and benchmarking is often very useful in order to be able to make fair and informed decisions about software codes, libraries, and choice of programming languages.

With this in mind, several Finite Element Analysis (FEA) simulation codes and their implementations are here compared using the fundamental sparse matrix vector multiplication, finite element matrix assembly, and linear solver operations. The following five different simulation codes are evaluated

  • FEATool Multiphysics - Finite Element Analysis Toolbox entirely written in vectorized and optimized MATLAB m-script code

  • FEM2D - Finite Element library and reference implementation in Fortran 77

  • FEniCS Project - computing platform for solving general partial differential equations (PDE) with Python and C++
  • Julia FEM - basic Finite Element implementation in the Julia language ( Julia is a programming language that aims to solve the one-language problem, that is high-performance while at the same time being interpreted and easy to work with)

  • SFEA (Stencil based Finite Element Analysis) - a high-performance stencil based finite element method (FEM) solver written in Fortran 90 (this solver comes very close to the memory bandwidth limit and therefore gives an indication of the upper performance limit)

All test and timings were performed on a typical workstation system with an Intel Core i7-3820 CPU running Linux in single threaded/serial mode. The Fortran codes were compiled with the Intel Fortran compiler.

Test 1 - Sparse Matrix Vector Product

1/hFEAToolFEM2DJulia FEMSFEA
MATLABFortranJuliaFortran
1280.00200.030
2560.0020.0010.0310
5120.0060.0050.0340.001
10240.0210.0240.050.002
20480.0850.1970.080.009
40960.4110.250.034

For the sparse matrix vector product benchmark test we can see that FEM2D (CSR sparse format), FEATool (MATLAB/triplet sparse format), and Julia (CSC sparse format) perform similarly especially for moderate grid sizes. The stencil based SFEA approach is about a magnitude faster which is to be expected since memory access is near optimal. FEniCS did not support matrix and vector operations on a high level at the time of testing, so no data is included for FEniCS here.

Test 2 - Finite Element Matrix Assembly

1/hFEAToolFEM2DFEniCSJulia FEM
MATLABFortranPython/C++Julia
1280.050.050.050.24
2560.140.130.120.57
5120.430.420.311.7
10241.71.51.16.5
204876526
409624105

For FEM matrix assembly, the vectorized and optimized MATLAB code used by FEATool is actually just as fast as the FEM2D Fortran code (which already is a very good end efficient reference implementation). FEniCS is a little bit faster but this is to be expected since FEM2D and FEATool both use quadrilateral shape functions which are more expensive to assemble than the linear triangular ones used by FEniCS and Julia. The performance of Julia is unfortunately not very good here but this could be due to a non-optimized implementation. The SFEA code is not included since being stencil based FEM assembly costs virtually nothing.

Test 3 - Linear Solver for the Poisson Equation

1/hFEAToolFEM2DFEniCSJulia FEMSFEA
MATLAB
Umfpack
Fortran
GMG
Python/C++
PETSc
Julia
CHOLMOD?
Fortran
GMG
1280.3680.0250.190.180.049
2561.7180.050.790.3220.064
5127.4060.214.650.90.11
102447.6461.134.13.40.16
2048338.146-14.60.49
409663832.9
819220

In the final test the Poisson equation is solved on the unit square with unit source term and zero homogeneous Dirichlet boundary conditions everywhere. The default linear solver of each code is used throughout the tests. FEM2D and SFEA employ a geometric multigrid solver, FEATool (MATLAB) uses Umfpack/SuiteSparse, and FEniCS uses PETSc. From the timings we can see that the Umfpack and PETSc direct sparse solvers performed about the same, with a slight advantage for PETSc (although failed for the 1/h=2048 grid). As the problem sizes increases we can see that the GMG solvers scale significantly better than the direct solvers, with the stencil based SFEA approach being about a magnitude faster (about 700 times faster than Umfpack on the 1/h=2048 grid with 4.2 million unknowns/degrees of freedom). It is not quite clear which solver Julia uses but due to the performance figures which are on par with the FEM2D Geometric MultiGrid (GMG) solver we suspect it detects that the problem can be solved faster with Cholesky factorization and uses a corresponding solver.

Summary

We have looked at how five different finite element implementations perform on three fundamental test cases. For sparse matrix vector operations the codes performed very similar with exception of the stencil based approach which was a magnitude faster.

For matrix assembly it was quite surprising just how good performance one can get from a properly vectorized and optimized MATLAB implementation, showing the same performance as a reference implementation in compiled Fortran.

Regarding the solvers Geometric MultiGrid (GMG) unsurprisingly beats direct solvers when grid sizes increased. Here also the stencil based approach was faster by a magnitude or more.

These few tests have shown that it seems entirely possible to write high-performance FEM simulation codes in almost any programming language. What seems more important for performance is the choice of data structures (sparse versus stencil) and algorithm (direct or iterative solvers). The outlier might be Julia for which it currently is not fully clear how it will perform, but due to being a new language it clearly does show some potential.

A follow up benchmark which tests the whole solution process can be found in the corresponding FEM benchmark comparison post.