-
Notifications
You must be signed in to change notification settings - Fork 292
Expand PetscMatrix interface #2169
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Methods added: - local_m - local_n - get_local_size - reset_preallocation
If someone knows the other matrix types, then at least the size methods could be moved down into the base class and made virtual |
src/numerics/petsc_matrix.C
Outdated
|
||
auto ierr = MatGetLocalSize (_mat, &m, PETSC_NULL); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor issue: we just simply use NULL in PETSc right now. We were using PETSC_NULL, but not any more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Haha, really? I guess we should actually be changing them all to nullptr
now but I don't really care either way. Was PETSC_NULL
ever not NULL
? What issue was it used to address?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have no idea whey we were using PETSC_NULL. I still have a lot of PETSC_NULL in my PhD code:-)
In PETSc, we have this:
#define PETSC_NULL NULL
But most of PETSc code is using NULL
Cody forced me to use nullptr
for PETSc code in MOOSE.
{ | ||
libmesh_assert (this->initialized()); | ||
|
||
auto ierr = MatResetPreallocation(_mat); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Version control
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ugh @fdkong you told me the wrong version number here. Hence the test failures on idaholab/moose#13682. Looks like it should be 3.9.0 based on git tag --contains
. I'm guessing you just made a typo sigh.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://www.mcs.anl.gov/petsc/petsc-3.9/docs/manualpages/Mat/MatResetPreallocation.html
It is in 3.9. I am confused here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
!PETSC_VERSION_LESS_THAN(3,8,0)
means >= 3.8.0, i.e. including 3.8.0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need >=3.9.0
Comments hopefully addressed |
template <typename T> | ||
void PetscMatrix<T>::reset_preallocation() | ||
{ | ||
#if !PETSC_VERSION_LESS_THAN(3,8,0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh I see.
#if !PETSC_VERSION_LESS_THAN(3,9,0)
8-->9
I was thinking about 9. Why I gave you 8
/** | ||
* Get the number of columns owned by this process | ||
*/ | ||
numeric_index_type local_n () const; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm confused by this one. My first interpretation here is "the total number of columns with non-empty entries in the sparsity pattern in rows owned by this process", but I'm not actually sure how PETSc would determine that - we give them n_nz and n_oz rather than complete sparsity info, right? And without the latter there's no way to immediately determine which non-empty columns from which rows overlap? So is this method only well-defined for matrices that have already been assembled??
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is not related to nnz, noz or matrix assembly. It is a layout thing. It is something we tell PETSc to use in libMesh.
In PetscMatrix::init()
, we have something like
ierr = MatSetSizes(_mat, m_local, n_local, m_global, n_global);
LIBMESH_CHKERR(ierr);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"n_local"
is "local_n()"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @fdkong. This is what I had determined through experimentation this morning 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That certainly clears it up! Thanks!
/** | ||
* Get the number of rows owned by this process | ||
*/ | ||
numeric_index_type local_m () const; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we bump this up to the parent class and make the default implementation row_stop()-row_start()
?
Methods added: