fverdugo / PartitionedArrays.jl

Large-scale, distributed, sparse linear algebra in Julia.
MIT License
119 stars 14 forks source link

Error when generting copies of PSParseMatrix (as needed by NLSolve) #122

Closed principejavier closed 1 year ago

principejavier commented 1 year ago

Solving a nonlinear problem with PartitionedArrays+GridapDistributed+Gridap with NLSolve requires a copy of the Jacobian (a PSparseMatrix) at this point: https://github.com/JuliaNLSolvers/NLSolversBase.jl/blob/78af38393b14992ea996899c6486d971b5bfa612/src/objective_types/oncedifferentiable.jl#L231

The issue can be reproduced using the distributed linear system in the examples, i.e. https://www.francescverdugo.com/PartitionedArrays.jl/dev/examples/#Distributed-sparse-linear-solve and simply copy(A).

This copy generates an error in the implementation of similar at https://github.com/fverdugo/PartitionedArrays.jl/blob/dc1a3b900f79e0057c33a2e5d913045f91c8ffdd/src/p_sparse_matrix.jl#L400 After fix it, I get

julia> copy(A)
ERROR: Scalar indexing on PSparseMatrix is not allowed for performance reasons.

I guess the solution is to overwrite Base.copy with a map over ranks and local copy. Is it @fverdugo ?

JordiManyer commented 1 year ago

@principejavier The first part is addressed in #121 . The second part is indeed caused by a missing method. We probably want to implement copyto! for PSParseMatrix. You can find a temporary fix here. I'll add the missing method to the PR I already have, hopefully @fverdugo can have a look soon.

principejavier commented 1 year ago

I see, thanks @JordiManyer!