Actual source code: ex107.c

  1: static char help[] = "Tests DMPlexPointQueue growth when its entries wrap around the end of its storage\n\n";

  3: #include <petscdmplex.h>

  5: static PetscErrorCode TestQueue(PetscInt size)
  6: {
  7:   DMPlexPointQueue queue;
  8:   PetscInt         p;

 10:   PetscFunctionBeginUser;
 11:   PetscCall(DMPlexPointQueueCreate(size, &queue));
 12:   PetscCall(PetscPrintf(PETSC_COMM_SELF, "Initial size %" PetscInt_FMT ":", size));
 13:   for (PetscInt i = 0; i < 4; ++i) PetscCall(DMPlexPointQueueEnqueue(queue, i));
 14:   for (PetscInt i = 0; i < 2; ++i) {
 15:     PetscCall(DMPlexPointQueueDequeue(queue, &p));
 16:     PetscCall(PetscPrintf(PETSC_COMM_SELF, " %" PetscInt_FMT, p));
 17:   }
 18:   // 2 and 3 are at positions 2 and 3 of a storage of size 4, so 4 and 5 wrap to positions 0 and 1 and 6 makes the full queue grow
 19:   for (PetscInt i = 4; i < 7; ++i) PetscCall(DMPlexPointQueueEnqueue(queue, i));
 20:   while (!DMPlexPointQueueEmpty(queue)) {
 21:     PetscCall(DMPlexPointQueueDequeue(queue, &p));
 22:     PetscCall(PetscPrintf(PETSC_COMM_SELF, " %" PetscInt_FMT, p));
 23:   }
 24:   PetscCall(PetscPrintf(PETSC_COMM_SELF, "\n"));
 25:   PetscCall(DMPlexPointQueueDestroy(&queue));
 26:   PetscFunctionReturn(PETSC_SUCCESS);
 27: }

 29: int main(int argc, char **argv)
 30: {
 31:   PetscFunctionBeginUser;
 32:   PetscCall(PetscInitialize(&argc, &argv, NULL, help));
 33:   PetscCall(TestQueue(0));
 34:   PetscCall(TestQueue(4));
 35:   PetscCall(PetscFinalize());
 36:   return 0;
 37: }

 39: /*TEST

 41:   test:

 43: TEST*/