Skip to content

Commit

Permalink
Added patch to petsc_matrix.C from Dmitry Karpeyev. This example now …
Browse files Browse the repository at this point in the history
…works properly in parallel.
  • Loading branch information
dknez committed Feb 25, 2015
1 parent 7f56f4f commit 247cc12
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/numerics/petsc_matrix.C
Expand Up @@ -30,7 +30,7 @@
#include "libmesh/dense_matrix.h"
#include "libmesh/petsc_vector.h"


#include "petsc-private/matimpl.h"

// For some reason, the blocked matrix API calls below seem to break with PETSC 3.2 & presumably earier.
// For example:
Expand Down Expand Up @@ -416,6 +416,20 @@ void PetscMatrix<T>::update_preallocation_and_zero ()
PetscErrorCode ierr = 0;

{
ierr = (*_mat->ops->destroy)(_mat);
LIBMESH_CHKERRABORT(ierr);
_mat->ops->destroy = NULL;
_mat->preallocated = PETSC_FALSE;
_mat->assembled = PETSC_FALSE;
_mat->assembled = PETSC_FALSE;
_mat->was_assembled = PETSC_FALSE;
++_mat->nonzerostate;
ierr = PetscObjectStateIncrease((PetscObject)_mat);
LIBMESH_CHKERRABORT(ierr);

ierr = MatSetType(_mat,MATAIJ);
LIBMESH_CHKERRABORT(ierr);

ierr = MatSeqAIJSetPreallocation (_mat,
0,
numeric_petsc_cast(n_nz.empty() ? NULL : &n_nz[0]));
Expand Down

8 comments on commit 247cc12

@jwpeterson
Copy link
Collaborator

Choose a reason for hiding this comment

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

Including stuff from petsc-private and tweaking a bunch of private member variables? Is this the best/only way to do this @karpeev? What versions of PETSc support this, etc?

@dknez
Copy link
Owner Author

@dknez dknez commented on 247cc12 Feb 25, 2015

Choose a reason for hiding this comment

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

@karpeev has added a new public function (called MatReset()) to petsc-dev, so that will resolve that issue once it's available. But it won't be available until the next PETSc release apparently.

@dkarpeyev
Copy link

@dkarpeyev dkarpeyev commented on 247cc12 Feb 25, 2015 via email

Choose a reason for hiding this comment

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

@dkarpeyev
Copy link

@dkarpeyev dkarpeyev commented on 247cc12 Feb 26, 2015 via email

Choose a reason for hiding this comment

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

@jwpeterson
Copy link
Collaborator

Choose a reason for hiding this comment

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

Thanks @karpeev for working on it.

I'm not sure exactly what to do about this PR... I don't really want to merge it as-is because I'm worried it will break somebody using an older version of PETSc with a slightly different matimpl.h. Maybe this is a non-issue, but there is the issue of knowing when it's safe to take the hack back out of libmesh, or should we just guard it with #ifdefs and keep it there forever?

@roystgnr any thoughts?

@dkarpeyev
Copy link

@dkarpeyev dkarpeyev commented on 247cc12 Feb 26, 2015 via email

Choose a reason for hiding this comment

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

@jwpeterson
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would just suggest waiting till we have petsc/maint patched and then
modifying this PR to remove the petsc-private parts and replacing the patch
with MatSetType(mat,MATBAIJ);MatSetType(mat,MATAIJ).

But then this example would not run for anyone not using petsc-maint...

@dkarpeyev
Copy link

@dkarpeyev dkarpeyev commented on 247cc12 Feb 26, 2015 via email

Choose a reason for hiding this comment

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

Please sign in to comment.