chenxm1986 / cktso

Pursuing the best performance of linear solver in circuit simulation
19 stars 3 forks source link

Helper function for the case when B is an identity matrix #9

Open mzy2240 opened 1 year ago

mzy2240 commented 1 year ago

When the system is relatively large(e.g. B is 20000 * 20000), creating (and allocating) such an identity matrix takes almost the same time as factoring and solving the system(benchmarked in Julia). Is it possible to provide a helper function, so that we could simply pass the sparse matrix A and an allocated space B? I feel like this scenario is quite common in the numerical computation.

mzy2240 commented 1 year ago

image The function solve_system includes creating the identity matrix, so almost takes the same time.

chenxm1986 commented 1 year ago

I don't understand your question. What do you mean by "an allocated space B"? You can allocate B just once and simply reuse B in multiple solvings.

mzy2240 commented 1 year ago

Allocating alone is fine, but allocating and creating a huge identity matrix together is relatively time-consuming (see the benchmark above). And such an identity matrix may not be re-usable, cause if in-place operation is preferred (reuse the B matrix allocation) then the identity matrix will be gone.

mzy2240 commented 1 year ago

We already have CKTSO_L_SolveMV which is very handy, and I would like to see if we can have something like CKTSO_L_InverseMV which solves Ax = I underneath (I imagine the API would be similar).

chenxm1986 commented 1 year ago

I see. You want a function to solve the inverse of the matrix, without explicitly inputing the identity matrix, because creating the identity matrix is costly.

mzy2240 commented 1 year ago

Exactly

chenxm1986 commented 1 year ago

Do you really need to solve the inversion of a sparse matrix? This problem has better native solutions. Using LU factorization and solving N linear systems is a bad solution and it is not adopted in practice, as it will make the inversion fully dense and the performance is not good.

mzy2240 commented 1 year ago

Yeah I fully understand, however, the formula requires to have row-wise operation (zero out a row) on the inverse of the matrix, which seems to be inevitable to have an explicit inversion.