[petsc-dev] Recent changes in DMLabel

Lawrence Mitchell lawrence.mitchell at imperial.ac.uk
Thu Jul 7 10:29:04 CDT 2016


Dear all (but mostly Toby),

some recent changes in DMLabel changed the semantics of DMLabelHasPoint.

In particular, after ad8374f (DMLabel: switch internal storage from
array to IS), clearing a label value produces bad results.  Consider
the following:

#include <petsc.h>

int main(int argc, char **argv)
{
    PetscErrorCode ierr;
    DMLabel        label;
    PetscInt       val;
    PetscBool      flg;
    PetscInitialize(&argc, &argv, NULL, NULL);

    ierr = DMLabelCreate("foo", &label);CHKERRQ(ierr);

    ierr = DMLabelCreateIndex(label, 0, 1);CHKERRQ(ierr);
    ierr = DMLabelSetValue(label, 0, 1);CHKERRQ(ierr);
    ierr = DMLabelHasPoint(label, 0, &flg);CHKERRQ(ierr);
    ierr = DMLabelGetValue(label, 0, &val);CHKERRQ(ierr);
    PetscPrintf(PETSC_COMM_WORLD, "Label has point %d, value is %d\n",
flg, val);CHKERRQ(ierr);

    ierr = DMLabelClearValue(label, 0, 1);CHKERRQ(ierr);
    ierr = DMLabelHasPoint(label, 0, &flg);CHKERRQ(ierr);
    ierr = DMLabelGetValue(label, 0, &val);CHKERRQ(ierr);
    PetscPrintf(PETSC_COMM_WORLD, "Label has point %d, value is %d\n",
flg, val);CHKERRQ(ierr);

    PetscFinalize();
    return 0;
}

Before this change:

$ ./bork
Label has point 1, value is 1
Label has point 0, value is -1

After the change:

$ ./bork
Label has point 1, value is 1
Label has point 1, value is -1

So you can see that although the point has been cleared from the point
of view of GetValue, it has not if I use HasPoint.

The problem appears to be that the invalidation of the label after
ClearValue no longer clears the PetscBT entry that exists if an index
has been created.

Perhaps the following patch is right?

diff --git a/src/dm/label/dmlabel.c b/src/dm/label/dmlabel.c
index 8d170c6..2c7f7c2 100644
--- a/src/dm/label/dmlabel.c
+++ b/src/dm/label/dmlabel.c
@@ -665,7 +665,13 @@ PetscErrorCode DMLabelClearValue(DMLabel label,
PetscInt point, PetscInt value)
     if (label->stratumValues[v] == value) break;
   }
   if (v >= label->numStrata) PetscFunctionReturn(0);
-  if (label->validIS[v]) {ierr =
DMLabelMakeInvalid_Private(label,v);CHKERRQ(ierr);}
+  if (label->validIS[v]) {
+    ierr = DMLabelMakeInvalid_Private(label,v);CHKERRQ(ierr);
+  }
+  if (label->bt) {
+    if ((point < label->pStart) || (point >= label->pEnd))
SETERRQ3(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Label point %D is
not in [%D, %D)", point, label->pStart, label->pEnd);
+    ierr = PetscBTClear(label->bt, point - label->pStart);CHKERRQ(ierr);
+  }
   ierr = PetscHashIDelKey(label->ht[v], point);CHKERRQ(ierr);
   PetscFunctionReturn(0);
 }


Cheers,

Lawrence

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 490 bytes
Desc: OpenPGP digital signature
URL: <http://lists.mcs.anl.gov/pipermail/petsc-dev/attachments/20160707/7288ba85/attachment.sig>


More information about the petsc-dev mailing list