Skip to content

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

Merged
merged 3 commits into from
Jul 2, 2019

Conversation

lindsayad
Copy link
Member

Methods added:

  • local_m
  • local_n
  • get_local_size
  • reset_preallocation

Methods added:
  - local_m
  - local_n
  - get_local_size
  - reset_preallocation
@lindsayad lindsayad requested a review from fdkong July 2, 2019 15:23
@lindsayad
Copy link
Member Author

If someone knows the other matrix types, then at least the size methods could be moved down into the base class and made virtual


auto ierr = MatGetLocalSize (_mat, &m, PETSC_NULL);
Copy link
Contributor

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.

Copy link
Member

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?

Copy link
Contributor

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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Version control

Copy link
Member Author

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

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

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right.

Copy link
Contributor

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

@lindsayad
Copy link
Member Author

Comments hopefully addressed

@lindsayad lindsayad merged commit 4494fb8 into libMesh:master Jul 2, 2019
@lindsayad lindsayad deleted the expand-petsc-interface branch July 2, 2019 19:40
template <typename T>
void PetscMatrix<T>::reset_preallocation()
{
#if !PETSC_VERSION_LESS_THAN(3,8,0)
Copy link
Contributor

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;
Copy link
Member

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??

Copy link
Contributor

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);

Copy link
Contributor

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()"

Copy link
Member Author

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 😄

Copy link
Member

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;
Copy link
Member

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()?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants