Matrix Assembly Efficiency in PyTrilinos
Created by: michael-a-hansen
Hello,
I have some questions about efficiently filling and updating a matrix with tools available to PyTrilinos
. The problem I'm solving is very nonlinear and while the Jacobian matrix structure is fixed (block tri-diagonal with large blocks), the elements themselves need to be recomputed frequently. Scraping tutorials and examples has led me to code such as the following, where InsertGlobalValues
is called on an EpetraCrsMatrix
in a Python loop over the rows. However, I observe this code is usually around 60x slower than assembling a Scipy
sparse matrix via direct specification of full coordinate form.
Given a fixed Jacobian matrix structure, and capabilities available in PyTrilinos
,
- Is there a faster way to assemble the matrix than
A.InsertGlobalValues
onEpetraCrsMatrix
? I thinkVbrMatrix
may be helpful for my block structure but I haven't found aPyTrilinos
example. - Given a
FillComplete
d matrix, is there an efficient way to replace its elements?
my_map = Epetra.Map(ndof, 0, comm)
A = Epetra.CrsMatrix(Epetra.Copy, my_map, 0)
for row, (cols, vals) in enumerate(rowmap): # cols and vals are _all_ elements in the row
A.InsertGlobalValues(row, vals, cols)
A.FillComplete()
Environment
- Trilinos cloned at commit
b2341eff32 [Thu Oct 12 10:07:25 2017 -0600]
, built all packages includingPyTrilinos
. - Python3.6
- Mac OS X 10.12.16,
Apple LLVM version 8.1.0 (clang-802.0.42)
, gcc 4.2.1 - Running in serial