Commits

Matt Knepley committed a00c6a8 Merge

Merge branch 'knepley/fix-plex-label-hash'

* knepley/fix-plex-label-hash:
DMLabel: Fix bug in clearing value for array representation
DMLabel: Fixed warning - Damn damn damn, messed up line selection
DMLabel: Added PetscHashIDelKey() - Fixed bug where I was passing a point for an iterator
DMLabel: PetscHashIGetKeys() was made a function - It now accepts a NULL argument

  • Participants
  • Parent commits 6d209c4, acf0c16

Comments (0)

Files changed (3)

File src/dm/impls/plex/plex.c

     PetscHashISize(h, numNewPoints);
     ierr = PetscSectionSetDof(*partSection, part, numNewPoints);CHKERRQ(ierr);
     ierr = PetscMalloc(numNewPoints * sizeof(PetscInt), &tmpPoints[part]);CHKERRQ(ierr);
-    if (numNewPoints) PetscHashIGetKeys(h, n, tmpPoints[part]); /* Should not need this conditional */
+    ierr =  PetscHashIGetKeys(h, &n, tmpPoints[part]);CHKERRQ(ierr);
     totPoints += numNewPoints;
   }
   ierr = ISRestoreIndices(origPartition, &points);CHKERRQ(ierr);

File src/dm/impls/plex/plexlabel.c

   ierr = PetscMalloc(off * sizeof(PetscInt), &label->points);CHKERRQ(ierr);
   off = 0;
   for (v = 0; v < label->numStrata; ++v) {
-    PetscInt size = 0;
-    PetscHashISize(label->ht[v], size);
-    if (size) {PetscHashIGetKeys(label->ht[v], off, label->points);}
+    ierr = PetscHashIGetKeys(label->ht[v], &off, label->points);CHKERRQ(ierr);
+    if (off != label->stratumOffsets[v+1]) SETERRQ3(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG, "Invalid number of contributed points %d from value %d should be %d", off-label->stratumOffsets[v], label->stratumValues[v], label->stratumOffsets[v+1]-label->stratumOffsets[v]);
     PetscHashIDestroy(label->ht[v]);
     ierr = PetscSortInt(label->stratumSizes[v], &label->points[label->stratumOffsets[v]]);CHKERRQ(ierr);
     if (label->bt) {
   }
   ierr = PetscFree(label->ht);CHKERRQ(ierr);
   label->ht = NULL;
-  if (off != label->stratumOffsets[label->numStrata]) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG, "Invalid number of points %d should be %d", off, label->stratumOffsets[label->numStrata]);
   label->arrayValid = PETSC_TRUE;
   PetscFunctionReturn(0);
 }
     /* Check whether point exists */
     ierr = PetscFindInt(point, label->stratumSizes[v], &label->points[label->stratumOffsets[v]], &p);CHKERRQ(ierr);
     if (p >= 0) {
-      ierr = PetscMemmove(&label->points[p], &label->points[p+1], (label->stratumSizes[v]-p-1) * sizeof(PetscInt));CHKERRQ(ierr);
+      ierr = PetscMemmove(&label->points[p+label->stratumOffsets[v]], &label->points[p+label->stratumOffsets[v]+1], (label->stratumSizes[v]-p-1) * sizeof(PetscInt));CHKERRQ(ierr);
       --label->stratumSizes[v];
       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);
       }
     }
   } else {
-    PetscBool has;
-
-    PetscHashIHasKey(label->ht[v], point, has);
-    if (has) {PetscHashIDel(label->ht[v], point);}
+    ierr = PetscHashIDelKey(label->ht[v], point);CHKERRQ(ierr);
   }
   PetscFunctionReturn(0);
 }

File src/sys/utils/hash.h

  _11_hi = kh_put(HASHI,(ht),(i),&_11_hr);                               \
  kh_val((ht),_11_hi) = (ii);                                            \
 }
+
+PETSC_STATIC_INLINE PetscErrorCode PetscHashIDelKey(PetscHashI ht, PetscInt key)
+{
+  khiter_t hi = kh_get(HASHI, ht, key);
+  if (hi != kh_end(ht)) kh_del(HASHI, ht, hi);
+  return 0;
+}
+
 /*
   arr is the integer array to put the indices to, n is the offset into arr to start putting the indices at.
   n is updated as the indices are put into arr, so n must be an lvalue.
  */
-#define PetscHashIGetKeys(ht,n,arr)                                     \
-{                                                                       \
-  PetscHashIIter _12_hi;                                                \
-  PetscInt _12_i;                                                       \
-  PetscHashIIterBegin((ht),_12_hi);                                     \
-  while (!PetscHashIIterAtEnd((ht),_12_hi)) {                            \
-    PetscHashIIterGetKey((ht),_12_hi,_12_i);                            \
-    (arr)[(n)++] = _12_i;                                               \
-    PetscHashIIterNext((ht),_12_hi);                                    \
-  }                                                                     \
+PETSC_STATIC_INLINE PetscErrorCode PetscHashIGetKeys(PetscHashI ht, PetscInt *n, PetscInt arr[])
+{
+  PetscHashIIter hi;
+  PetscInt       off = *n;
+
+  for (hi = kh_begin(ht); hi != kh_end(ht); ++hi) {
+    if (kh_exist(ht, hi) && !__ac_isdel(ht->flags, hi)) arr[off++] = kh_key(ht, hi);
+  }
+  *n = off;
+  return 0;
 }
 
 #define PetscHashIGetVals(ht,n,arr)                                     \