Skip to content
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

Remove PETScWrappers deprecations #9937

Merged
merged 4 commits into from Jul 27, 2022

Conversation

masterleinad
Copy link
Member

Deprecated in #2749 and some time before #6986.

@agrayver
Copy link
Contributor

agrayver commented Apr 22, 2020

I'm actually using these quite extensively, including for some rectangular structural matrices (i.e. without an associated FE space). Once this is merged, the only remaining constructor will require a SparsityPattern.

How do I replace somehing like PETScWrappers::MPI::SparseMatrix(comm, rows, columns, local_rows, local_columns, nnz_per_row) with a SparsityPattern requiring constructor?

It seems it will require constructing SparsityPattern manually before initializing the matrix.

@masterleinad
Copy link
Member Author

masterleinad commented Apr 22, 2020

It seems it will require constructing SparsityPattern manually before initializing the matrix.

Yes, this has been deprecated for a couple of years already without any complaints.

@agrayver
Copy link
Contributor

agrayver commented Apr 23, 2020

Perhaps I miss something.

If I can create a PETSc matrix by using PETScWrappers::MPI::SparseMatrix(comm, m, n, local_rows, local_columns, nnz_per_row) (which calls legitimate MatCreateAIJ), what would I gain by using SparsityPattern instead? In fact, using SparsityPattern requires additional memory, time and code because I will have to loop through all rows/cols and add entries to a SparsityPattern followed by matrix initialization and actual assembly.

I specifically mean matrices, which are not square system matrices, but other objects.

@masterleinad masterleinad added this to the Release 9.2 milestone Apr 25, 2020
@masterleinad
Copy link
Member Author

@dealii/dealii Can someone that uses PETSc some more can chime in here?

@drwells
Copy link
Member

drwells commented Apr 30, 2020

I'll take a look.

@drwells drwells self-assigned this Apr 30, 2020
@drwells
Copy link
Member

drwells commented May 6, 2020

Sorry for the delays - I promise I will get to this soon!

@drwells
Copy link
Member

drwells commented May 7, 2020

We have talked about support for this kind of operation in other places (if I recall correctly we want to support wrapping Mat and Vec without being responsible for setting up or destroying them).

@agrayver We deprecated this since we wanted to make the interface to all of our sparse matrix classes the same. Would a matrix view that owns a Mat (and lets the user set it up as they want) work for you?

@agrayver
Copy link
Contributor

agrayver commented May 8, 2020

@drwells thanks for looking at it.

Would a matrix view that owns a Mat (and lets the user set it up as they want) work for you?

Yes, it would. Is there such a mechanism?

@agrayver
Copy link
Contributor

agrayver commented May 8, 2020

More specifically, do you mean one could add a constructor like?

PETScWrappers::MPI::SparseMatrix(Mat& mat)

If this is ok, I could add such constructor quickly.

Copy link
Member

@kronbichler kronbichler left a comment

Choose a reason for hiding this comment

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

I agree with this and would be happy to take a follow-up PR that adds a constructor. @drwells do you agree?

@bangerth
Copy link
Member

bangerth commented May 8, 2020

It's not that easy. The model right now is that the class actually owns the pointer and its destructor is responsible for destroying the object. If you pass in a Mat pointer, you need to also define who now owns the object? I have to admit that I don't particularly like the model where a class may or may not own an object.

Separately, Mat is conceptually a "pointer to base class". You'd have to ensure that it really does correspond to a sparse matrix.

@tjhei
Copy link
Member

tjhei commented May 8, 2020

you need to also define who now owns the object?

I think we could modify the PETSc internal reference count using PetscObjectReference / PetscObjectDereference. The last call to MatDestroy will then delete it.

@agrayver
Copy link
Contributor

agrayver commented May 8, 2020

I think we could modify the PETSc internal reference count using PetscObjectReference / PetscObjectDereference. The last call to MatDestroy will then delete it.

Yes, this seems a fully legit way that is used in PETSc examples, e.g.:

https://www.mcs.anl.gov/petsc/petsc-current/src/ts/tutorials/ex3.c.html

@masterleinad
Copy link
Member Author

Alright. @agrayver you were saying that you could add a constructor quickly? We can then decide what we want to have in the release and what not.

@bangerth
Copy link
Member

bangerth commented May 8, 2020

Huh, I had no idea that PETSc does reference counting on its objects...

@drwells
Copy link
Member

drwells commented May 8, 2020

Its not that obvious from the names (or PETSc's documentation) but @agrayver is absolutely right. PETSc does reference count:

PetscErrorCode MatDestroy(Mat *A)
{
  PetscErrorCode ierr;

  PetscFunctionBegin;
  if (!*A) PetscFunctionReturn(0);
  PetscValidHeaderSpecific(*A,MAT_CLASSID,1);
  if (--((PetscObject)(*A))->refct > 0) {*A = NULL; PetscFunctionReturn(0);}
...

I am not sure that we have enough time to do this before the release: we would also need to check that older versions of PETSc implement this logic, add tests for the new feature, etc. I believe it would be best to preserve the status quo (i.e., not merge this patch [1]) and then fix things once the release is out (in fact, I have 'update PETSc stuff' on my hackathon list).

I really like the idea of adding views to PETSc objects this way - this is much better than what I had in mind!

[1] By this patch I mean the present PR.

@bangerth
Copy link
Member

bangerth commented May 8, 2020

Yes, let's not address accepting external Mat and Vec objects before the release. This requires a while of testing, I think.

@masterleinad
Copy link
Member Author

For me, the question is whether we still want to merge this pull request for the release or not.

@drwells
Copy link
Member

drwells commented May 8, 2020

Shall we vote? I think we should not merge this PR yet.

@tjhei
Copy link
Member

tjhei commented May 8, 2020

I think we should not merge this PR yet.

Same here, let's not break anything right before the release.

@masterleinad
Copy link
Member Author

Fine. Let's just remove it from the milestone then.

@masterleinad masterleinad removed this from the Release 9.2 milestone May 8, 2020
@bangerth bangerth added this to the Release 9.3 milestone May 8, 2020
@peterrum
Copy link
Member

peterrum commented May 1, 2021

I just quote the above statement and adjust the milestone:

Same here, let's not break anything right before the release.

@peterrum peterrum modified the milestones: Release 9.3, Release 10.0 May 1, 2021
@peterrum peterrum modified the milestones: Release 9.4, Release 9.5 Apr 22, 2022
@peterrum
Copy link
Member

Do we want to tackle this shortly after next release?

@masterleinad
Copy link
Member Author

I would be happy if we could finally clean this up.

@agrayver
Copy link
Contributor

agrayver commented May 2, 2022

Since I was the one who used these wrappers, just wanted to say that I have found an alternative way of doing things and do not need them anymore.

@masterleinad
Copy link
Member Author

I merged this pull request with master to resolve merge conflicts. Apparently, we already merged most of the changes in #12288.

@masterleinad
Copy link
Member Author

This should be ready now.

@drwells drwells merged commit 664a66f into dealii:master Jul 27, 2022
mkghadban pushed a commit to OpenFCST/dealii that referenced this pull request Sep 8, 2022
…recation

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

Successfully merging this pull request may close these issues.

None yet

8 participants