Closed JordiManyer closed 11 months ago
My concern is the following: Is this efficient?
It depends on how A[i,j]
is implemented for the particular type of AbstractSparseMatrix
(e.g., SparseMatrixCSC
)
nz_index
is a function which we have defined, and that uses binary search to locate an element within a sparse column (CSC) or row (CSR) . Thus, O(log(n))
complexity. I would say this is the best you can do, and not sure whether A[i,j]
does or not.
In any case, I think that if we match the local numbering of the FE space DOFs and that of the local linear system, then LocalView
will no longer be needed.
btw I agree there is a bug, and should be solved in Gridap
Hi @JordiManyer
A[i,j] = v also uses binary search for A::SparseMatricCSC
Hi @amartinhuertas , @fverdugo , I'll then go ahead and fix the bug in Gridap.
@amartinhuertas I have found a potential inefficiency in the in-place assembly of distributed linear systems.
Some context:
In Gridap, we declare the function
Algebra.add_entry
, which is used to assemble an(i,j,v)
triplet into different structures (counters, COOs and matrices). As usual, there are different specializations of this function. In particular, we have different functions forAbstractMatrix
andAbstractSparseMatrix
:BUG 1: As we can see, for
AbstractMatrix
we callcombine(aij,v)
whereas forAbstractSparseMatrix
we callcombine(v,aij)
. This leads to different behaviors whencombine
is not commutative. For instance,(a,b) -> a
would create different matrices depending on the type.Due to the above bug, I have also uncovered something I believe is quite bad: When in-place assembling distributed matrices, we assemble the local contributions by using a local view of the global matrix. This view is given by the function
local_views(A,rows,cols)
, which returns an object of typeThis means that the local portion of a
PSparseMatrix
will be assembled as anAbstractMatrix
, and NOT as anAbstractSparseMatrix
, therefore triggering theadd_entry!
version forAbstractMatrix
, which tries to access the matrix entry directly instead of using a sparse-specific access pattern likenz_index(A,i,j)
.My concern is the following: Is this efficient?