Skip to content

BUG: Matrix instantiation is more expensive than it needs to be #2978

Open
@connorjward

Description

@connorjward

When we compute the derivative of a reduced functional in the adjoint we assemble lots of matrices. Profiling an adjoint problem with lots of solves shows that we are spending a substantial amount of time in "MatZeroInitial". This event tracks the time spent in initially setting the values of a matrix to zero.

MatZeroInitial is an inherently expensive thing to do. We have to call MatSetValues for each set entry to insert zeros into the matrix. This is an expensive process to have to repeat for each matrix we create.

To improve performance I think we should be caching zeroed matrices rather than sparsities. That is, caching the matrix formed after MatZeroInitial. This would allow us to construct a new matrix simply with MatCopy which is a much cheaper thing to do.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions