3

I noticed this post, where spalloc and sparse are recommended for efficient assembly in Matlab. I personally use sparse assembling for simple cases.

However, when it comes to the case of coupled PDE, say, 3-PDE coupled, then the scalar unknown becomes a $3\times 3$ tensor. In this case, I can't figure out a way to exploit sparse(), and have to use for-loops to assemble.

When the final assembled sparse matrix is as large as $30\text{k}\times 30\text{k}$(on PC), the assembling process becomes really slow (~10min), while the final matrix solving step is still fast(~less than 3 seconds).

Is there any suggestion? Any generic solution is appreciated (not necessarily Matlab)

Anton Menshov
  • 8,672
  • 7
  • 38
  • 94
lorniper
  • 593
  • 4
  • 13
  • The point of that comment is to pre-generate row and column indices and the corresponding values as linear arrays which you then pass to sparse(). You do this in for-loops. So you should be able to replace your existing for-loops with ones that generate the indices and then pass the whole group to sparse(). – Bill Barth Aug 05 '14 at 11:58
  • @BillBarth thanks, then for c/c++ implementation, what kind of procedure is used for assembling? – lorniper Aug 05 '14 at 12:14
  • Well, you need a sparse library. PETSc, for example, has examples of how to do so. – Bill Barth Aug 05 '14 at 12:34
  • 2
    For a system of PDE, it is more common to use a block sparse matrix format, which saves you a lot of memory and time in assembling the matrix. These are implemented in PETSc but not in matlab, so if you're getting to big matrices you may want to make the switch to new software. – Daniel Shapero Aug 05 '14 at 15:58
  • Assembly through generating row and column indices is definitely the way to go. If you need to save memory (i.e. number of non-zero entries is large), you could try using (my) technique of writing the indices to disk and assembling the sparse matrix directly in memory. – Dylan Richard Muir Aug 06 '14 at 20:34

0 Answers0