How can I speed up my own Matlab CFD code?

Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

How can I speed up my own Matlab CFD code?

Submitted Questions
The CPU is stuck at 20% using GMRES/backslash linear solver. Any idea on how I can make this more efficient? Or this is a given on MATLAB and one must write to the disk and do solves externally to ramp up CPU? Or is it my assembly which is bad?
Reply | Threaded
Open this post in threaded view
|

Re: How can I speed up my own Matlab CFD code?

Precise Simulation
Administrator
The Mumps linear solver would probably give a 10-20% boost, Paradiso possibly even more (as it seems to be the default direct linear solver in commercial solvers). Some other drop-in (multigrid) options might be Hypre and AMGCL (which both also have Matlab Mex wrappers).

If the linear solver has saturated the memory bandwidth of your system there is not much more you can do (as adding more cores will not speed up anything). Consumer systems are typically limited to dual memory channels, while servers AMD Epyc/Intel Xeon usually are 8-12 memory channels so scale better for multicore (intermediate with 4 channels AMD Threadripper/Ryzen AI Max 395+ systems could also help). For short experiments it is fairly inexpensive to set up tests with cloud servers (like AWS hpc7a EC2 instances or maybe also Hetzner). It could be fiddly to get Matlab and license servers to work though, maybe your code would actually run fine on Octave (which I think basically has the same linear solvers, SuiteSparse etc).
Reply | Threaded
Open this post in threaded view
|

Re: How can I speed up my own Matlab CFD code?

Precise Simulation
Administrator
In reply to this post by Submitted Questions
Regarding Matlab coder/parallel toolbox, unfortunately never had much success using Matlab coder or parallel toolbox to speed up FEA or CFD codes. Possibly Matlab coder could work if the CPU time spent in the basic Matlab loops/code (not library calls). However, if it spends time in the linear solver it could get worse as if I recall Matlab internally uses Umfpack/Suitesparse for backslash, but I don't think it was licensed for distributing with coder so they use a very basic linear solver (if it hasn't changed now).

Have you checked with the profiler what takes time in your implementation? Fenics uses PetSc which indeed is a very good linear solver, but I don't think there is a Matlab interface yet. Both Mumps and Paradiso include Mex interfaces (if you just want to try you can grab the compiled mumps.mex, rename to zip and unzip, or install the toolbox in Matlab and add path to the internal "/lib/mumps" folder).

If the time is spent more in matrix assembly, you could try using the Redbkit FSI library which includes C++ mex assembly functions for basic Navier-Stokes matrices.