1
$\begingroup$

I have a Matlab code computing the solution to an eigenvalue PDE. It consists of two parts: assembly of the stiffness/rigidity matrices and solving a generalized eigenvalue problem. I mention that the assembly is done using vectorized code in Matlab. It is likely that I would need to run the program on a quite large database of test-cases (a few million cases). In this case, performance in terms of computational time becomes noticeable.

I was wondering what could be the gain if I tried to code the algorithm in C/C++ ? (not sure I am capable of that... :) but I want to weigh the potential benefits)

I guess assembly could go faster, but the eigenvalue solver is pretty efficient in Matlab.

What is your experience with situations like this? Can coding in a faster language give important computation time reduction compared to Matlab?


More details on the problem as requested:

  • eigenvalue computation for the Laplace-Beltrami operator on a portion of the sphere
  • I use Lagrange P1 finite elements on a triangular mesh of the surface domain
  • example of Matlab computation time for roughly 780000 points (degrees of freedom): assembly 3 seconds, eigenvalue computation 26 seconds

Apparently, the significant part of the computation is finding the eigenvalue. Maybe using SlepC could help with this... (In some old manual I saw a SlepC interface for Matlab, but not in the new ones...)

$\endgroup$
  • $\begingroup$ what do you vary with your database? the shape of the domain? $\endgroup$ – Bort Jan 31 '18 at 14:53
  • $\begingroup$ Yes, the shape of the domain changes. $\endgroup$ – Beni Bogosel Jan 31 '18 at 15:02
  • 4
    $\begingroup$ Assuming that you've profiled your code and have found that assembly takes a significant amount of time, you might consider writing a MEX file in C/C++ and call it from Matlab. If you're proficient at C/C++, you will likely be able to realize a substantial speedup during assembly (I'm not going to guess at a magnitude without knowing your code). This allows you to keep the majority of your code in Matlab and just speed up the slow parts incrementally. $\endgroup$ – Tyler Olsen Jan 31 '18 at 15:50
  • 2
    $\begingroup$ Have you seen this note by Davis on creating sparse matrices in matlab? blogs.mathworks.com/loren/2007/03/01/… $\endgroup$ – Bill Greene Jan 31 '18 at 18:55
  • $\begingroup$ @BillGreene Thank you for the note. I was aware of the use of sparse matrices, and the assembly procedure uses this sparse formulation. $\endgroup$ – Beni Bogosel Jan 31 '18 at 20:04

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.