[petsc-users] Passing a near nullspace through fieldsplit

Smith, Barry F. bsmith at mcs.anl.gov
Wed Apr 24 11:31:26 CDT 2019

> On Apr 24, 2019, at 11:02 AM, Tristan Konolige via petsc-users <petsc-users at mcs.anl.gov> wrote:
> Hello All,
> I’m trying to pass a near nullspace through PCFieldSplit (schur) to GAMG (on the schur complement matrix). If I use MatSetNearNullSpace on my matrix, the near nullspace isn’t propagated through to GAMG. If I attach the near nullspace to the IS used to define the splits, it still doesn’t propagate through to GAMG. Am I missing the correct way to do this?

   You are probably not missing anything. 

The movement of null spaces and near null spaces may not be exactly as needed for your use case. The code is in
src/ksp/pc/impls/fieldsplit/fieldsplit.c start to search for NullSpace  (you only find a couple cases) 

  if (!jac->pmat) {
    Vec xtmp;

    ierr = MatCreateVecs(pc->pmat,&xtmp,NULL);CHKERRQ(ierr);
    ierr = PetscMalloc1(nsplit,&jac->pmat);CHKERRQ(ierr);
    ierr = PetscMalloc2(nsplit,&jac->x,nsplit,&jac->y);CHKERRQ(ierr);
    for (i=0; i<nsplit; i++) {
ierr = PetscObjectQuery((PetscObject) ilink->is, "nearnullspace", (PetscObject*) &sp);CHKERRQ(ierr);
      if (sp) {
        ierr = MatSetNearNullSpace(jac->pmat[i], sp);CHKERRQ(ierr);

    so we see it transferring the null space from each is to the pmat for each is. Later in the code

  for (i=0; i<nsplit; i++) {
    MatNullSpace sp;

    ierr = PetscObjectQuery((PetscObject) ilink->is, "nullspace", (PetscObject*) &sp);CHKERRQ(ierr);
    if (sp) {
      ierr = MatSetNullSpace(jac->mat[i], sp);CHKERRQ(ierr);
    ilink = ilink->next;

it seems to be similarly transferring the null space to each mat. Further in the code is

if (jac->schur) {
} else {
      const char   *Dprefix;
      char         schurprefix[256], schurmatprefix[256];
      char         schurtestoption[256];
      MatNullSpace sp;
 /* Note: this is not true in general */
      ierr = MatGetNullSpace(jac->mat[1], &sp);CHKERRQ(ierr);
      if (sp) {
        ierr = MatSetNullSpace(jac->schur, sp);CHKERRQ(ierr);

  It seems to move the null space from mat[1] to jac->schur

  Now there may be other subroutines that get called that also transfer null spaces but I can't find them.

  You can try running in the debugger with a break point on MatGetNearNullSpace() MatSetNearNullSpace() to see where they are being passed around.

  I am not sure what matrix you are running GAMG on so it is unclear two me the path the near null space needs to take to get there. Is it jac->schur ?

   Good luck,


> Thanks,
> Tristan Konolige

More information about the petsc-users mailing list