xref: /petsc/src/sys/classes/viewer/impls/vu/petscvu.c (revision b00a91154f763f12aa55f3d53a3f2776f15f49e3)
15c6c1daeSBarry Smith 
25c6c1daeSBarry Smith #include <petsc-private/viewerimpl.h>  /*I     "petscsys.h"   I*/
35c6c1daeSBarry Smith 
45c6c1daeSBarry Smith #define QUEUESTRINGSIZE 1024
55c6c1daeSBarry Smith 
65c6c1daeSBarry Smith typedef struct _PrintfQueue *PrintfQueue;
75c6c1daeSBarry Smith struct _PrintfQueue {
85c6c1daeSBarry Smith   char        string[QUEUESTRINGSIZE];
95c6c1daeSBarry Smith   PrintfQueue next;
105c6c1daeSBarry Smith };
115c6c1daeSBarry Smith 
125c6c1daeSBarry Smith typedef struct {
135c6c1daeSBarry Smith   FILE          *fd;
145c6c1daeSBarry Smith   PetscFileMode mode;     /* The mode in which to open the file */
155c6c1daeSBarry Smith   char          *filename;
165c6c1daeSBarry Smith   PetscBool     vecSeen;  /* The flag indicating whether any vector has been viewed so far */
175c6c1daeSBarry Smith   PrintfQueue   queue, queueBase;
185c6c1daeSBarry Smith   int           queueLength;
195c6c1daeSBarry Smith } PetscViewer_VU;
205c6c1daeSBarry Smith 
215c6c1daeSBarry Smith #undef __FUNCT__
225c6c1daeSBarry Smith #define __FUNCT__ "PetscViewerFileClose_VU"
235c6c1daeSBarry Smith static PetscErrorCode PetscViewerFileClose_VU(PetscViewer viewer)
245c6c1daeSBarry Smith {
255c6c1daeSBarry Smith   PetscViewer_VU *vu = (PetscViewer_VU*) viewer->data;
265c6c1daeSBarry Smith   PetscErrorCode ierr;
275c6c1daeSBarry Smith 
285c6c1daeSBarry Smith   PetscFunctionBegin;
295c6c1daeSBarry Smith   if (vu->vecSeen) {
305c6c1daeSBarry Smith     ierr = PetscViewerVUPrintDeferred(viewer, "};\n\n");CHKERRQ(ierr);
315c6c1daeSBarry Smith   }
325c6c1daeSBarry Smith   ierr   = PetscViewerVUFlushDeferred(viewer);CHKERRQ(ierr);
33ce94432eSBarry Smith   ierr   = PetscFClose(PetscObjectComm((PetscObject)viewer), vu->fd);CHKERRQ(ierr);
340298fd71SBarry Smith   vu->fd = NULL;
355c6c1daeSBarry Smith   ierr   = PetscFree(vu->filename);CHKERRQ(ierr);
365c6c1daeSBarry Smith   PetscFunctionReturn(0);
375c6c1daeSBarry Smith }
385c6c1daeSBarry Smith 
395c6c1daeSBarry Smith #undef __FUNCT__
405c6c1daeSBarry Smith #define __FUNCT__ "PetscViewerDestroy_VU"
415c6c1daeSBarry Smith PetscErrorCode PetscViewerDestroy_VU(PetscViewer viewer)
425c6c1daeSBarry Smith {
435c6c1daeSBarry Smith   PetscViewer_VU *vu = (PetscViewer_VU*) viewer->data;
445c6c1daeSBarry Smith   PetscErrorCode ierr;
455c6c1daeSBarry Smith 
465c6c1daeSBarry Smith   PetscFunctionBegin;
475c6c1daeSBarry Smith   ierr = PetscViewerFileClose_VU(viewer);CHKERRQ(ierr);
485c6c1daeSBarry Smith   ierr = PetscFree(vu);CHKERRQ(ierr);
495c6c1daeSBarry Smith   PetscFunctionReturn(0);
505c6c1daeSBarry Smith }
515c6c1daeSBarry Smith 
525c6c1daeSBarry Smith #undef __FUNCT__
535c6c1daeSBarry Smith #define __FUNCT__ "PetscViewerFlush_VU"
545c6c1daeSBarry Smith PetscErrorCode PetscViewerFlush_VU(PetscViewer viewer)
555c6c1daeSBarry Smith {
565c6c1daeSBarry Smith   PetscViewer_VU *vu = (PetscViewer_VU*) viewer->data;
575c6c1daeSBarry Smith   PetscMPIInt    rank;
585c6c1daeSBarry Smith   int            err;
595c6c1daeSBarry Smith   PetscErrorCode ierr;
605c6c1daeSBarry Smith 
615c6c1daeSBarry Smith   PetscFunctionBegin;
62ce94432eSBarry Smith   ierr = MPI_Comm_rank(PetscObjectComm((PetscObject)viewer), &rank);CHKERRQ(ierr);
635c6c1daeSBarry Smith   if (!rank) {
645c6c1daeSBarry Smith     err = fflush(vu->fd);
655c6c1daeSBarry Smith     if (err) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_SYS,"fflush() failed on file");
665c6c1daeSBarry Smith   }
675c6c1daeSBarry Smith   PetscFunctionReturn(0);
685c6c1daeSBarry Smith }
695c6c1daeSBarry Smith 
705c6c1daeSBarry Smith #undef __FUNCT__
715c6c1daeSBarry Smith #define __FUNCT__ "PetscViewerFileGetName_VU"
725c6c1daeSBarry Smith PetscErrorCode  PetscViewerFileGetName_VU(PetscViewer viewer, const char **name)
735c6c1daeSBarry Smith {
745c6c1daeSBarry Smith   PetscViewer_VU *vu = (PetscViewer_VU*) viewer->data;
755c6c1daeSBarry Smith 
765c6c1daeSBarry Smith   PetscFunctionBegin;
775c6c1daeSBarry Smith   *name = vu->filename;
785c6c1daeSBarry Smith   PetscFunctionReturn(0);
795c6c1daeSBarry Smith }
805c6c1daeSBarry Smith 
815c6c1daeSBarry Smith #undef __FUNCT__
825c6c1daeSBarry Smith #define __FUNCT__ "PetscViewerFileSetName_VU"
835c6c1daeSBarry Smith PetscErrorCode  PetscViewerFileSetName_VU(PetscViewer viewer, const char name[])
845c6c1daeSBarry Smith {
855c6c1daeSBarry Smith   PetscViewer_VU *vu = (PetscViewer_VU*) viewer->data;
865c6c1daeSBarry Smith   char           fname[PETSC_MAX_PATH_LEN];
875c6c1daeSBarry Smith   int            rank;
885c6c1daeSBarry Smith   PetscErrorCode ierr;
895c6c1daeSBarry Smith 
905c6c1daeSBarry Smith   PetscFunctionBegin;
915c6c1daeSBarry Smith   if (!name) PetscFunctionReturn(0);
925c6c1daeSBarry Smith   ierr = PetscViewerFileClose_VU(viewer);CHKERRQ(ierr);
93ce94432eSBarry Smith   ierr = MPI_Comm_rank(PetscObjectComm((PetscObject)viewer), &rank);CHKERRQ(ierr);
945c6c1daeSBarry Smith   if (rank != 0) PetscFunctionReturn(0);
955c6c1daeSBarry Smith   ierr = PetscStrallocpy(name, &vu->filename);CHKERRQ(ierr);
965c6c1daeSBarry Smith   ierr = PetscFixFilename(name, fname);CHKERRQ(ierr);
975c6c1daeSBarry Smith   switch (vu->mode) {
985c6c1daeSBarry Smith   case FILE_MODE_READ:
995c6c1daeSBarry Smith     vu->fd = fopen(fname, "r");
1005c6c1daeSBarry Smith     break;
1015c6c1daeSBarry Smith   case FILE_MODE_WRITE:
1025c6c1daeSBarry Smith     vu->fd = fopen(fname, "w");
1035c6c1daeSBarry Smith     break;
1045c6c1daeSBarry Smith   case FILE_MODE_APPEND:
1055c6c1daeSBarry Smith     vu->fd = fopen(fname, "a");
1065c6c1daeSBarry Smith     break;
1075c6c1daeSBarry Smith   case FILE_MODE_UPDATE:
1085c6c1daeSBarry Smith     vu->fd = fopen(fname, "r+");
109a297a907SKarl Rupp     if (!vu->fd) vu->fd = fopen(fname, "w+");
1105c6c1daeSBarry Smith     break;
1115c6c1daeSBarry Smith   case FILE_MODE_APPEND_UPDATE:
1125c6c1daeSBarry Smith     /* I really want a file which is opened at the end for updating,
1135c6c1daeSBarry Smith        not a+, which opens at the beginning, but makes writes at the end.
1145c6c1daeSBarry Smith     */
1155c6c1daeSBarry Smith     vu->fd = fopen(fname, "r+");
116a297a907SKarl Rupp     if (!vu->fd) vu->fd = fopen(fname, "w+");
117a297a907SKarl Rupp     else {
1185c6c1daeSBarry Smith       ierr = fseek(vu->fd, 0, SEEK_END);CHKERRQ(ierr);
1195c6c1daeSBarry Smith     }
1205c6c1daeSBarry Smith     break;
1215c6c1daeSBarry Smith   default:
1225c6c1daeSBarry Smith     SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG, "Invalid file mode %d", vu->mode);
1235c6c1daeSBarry Smith   }
1245c6c1daeSBarry Smith 
1255c6c1daeSBarry Smith   if (!vu->fd) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_FILE_OPEN, "Cannot open PetscViewer file: %s", fname);
1265c6c1daeSBarry Smith #if defined(PETSC_USE_LOG)
1275c6c1daeSBarry Smith   PetscLogObjectState((PetscObject) viewer, "File: %s", name);
1285c6c1daeSBarry Smith #endif
1295c6c1daeSBarry Smith   PetscFunctionReturn(0);
1305c6c1daeSBarry Smith }
1315c6c1daeSBarry Smith 
1325c6c1daeSBarry Smith #undef __FUNCT__
1335c6c1daeSBarry Smith #define __FUNCT__ "PetscViewerCreate_VU"
1348cc058d9SJed Brown PETSC_EXTERN PetscErrorCode PetscViewerCreate_VU(PetscViewer viewer)
1355c6c1daeSBarry Smith {
1365c6c1daeSBarry Smith   PetscViewer_VU *vu;
1375c6c1daeSBarry Smith   PetscErrorCode ierr;
1385c6c1daeSBarry Smith 
1395c6c1daeSBarry Smith   PetscFunctionBegin;
140*b00a9115SJed Brown   ierr         = PetscNewLog(viewer,&vu);CHKERRQ(ierr);
1415c6c1daeSBarry Smith   viewer->data = (void*) vu;
1425c6c1daeSBarry Smith 
1435c6c1daeSBarry Smith   viewer->ops->destroy          = PetscViewerDestroy_VU;
1445c6c1daeSBarry Smith   viewer->ops->flush            = PetscViewerFlush_VU;
1450298fd71SBarry Smith   viewer->ops->getsingleton     = NULL;
1460298fd71SBarry Smith   viewer->ops->restoresingleton = NULL;
1475c6c1daeSBarry Smith 
1480298fd71SBarry Smith   vu->fd          = NULL;
1495c6c1daeSBarry Smith   vu->mode        = FILE_MODE_WRITE;
1500298fd71SBarry Smith   vu->filename    = NULL;
1515c6c1daeSBarry Smith   vu->vecSeen     = PETSC_FALSE;
1520298fd71SBarry Smith   vu->queue       = NULL;
1530298fd71SBarry Smith   vu->queueBase   = NULL;
1545c6c1daeSBarry Smith   vu->queueLength = 0;
1555c6c1daeSBarry Smith 
156bdf89e91SBarry Smith   ierr = PetscObjectComposeFunction((PetscObject) viewer,"PetscViewerFileSetName_C",PetscViewerFileSetName_VU);CHKERRQ(ierr);
157bdf89e91SBarry Smith   ierr = PetscObjectComposeFunction((PetscObject) viewer,"PetscViewerFileGetName_C",PetscViewerFileGetName_VU);CHKERRQ(ierr);
1585c6c1daeSBarry Smith   PetscFunctionReturn(0);
1595c6c1daeSBarry Smith }
1605c6c1daeSBarry Smith 
1615c6c1daeSBarry Smith #undef __FUNCT__
1625c6c1daeSBarry Smith #define __FUNCT__ "PetscViewerVUGetPointer"
1635c6c1daeSBarry Smith /*@C
1645c6c1daeSBarry Smith   PetscViewerVUGetPointer - Extracts the file pointer from a VU PetscViewer.
1655c6c1daeSBarry Smith 
1665c6c1daeSBarry Smith   Not Collective
1675c6c1daeSBarry Smith 
1685c6c1daeSBarry Smith   Input Parameter:
1695c6c1daeSBarry Smith . viewer - The PetscViewer
1705c6c1daeSBarry Smith 
1715c6c1daeSBarry Smith   Output Parameter:
1725c6c1daeSBarry Smith . fd     - The file pointer
1735c6c1daeSBarry Smith 
1745c6c1daeSBarry Smith   Level: intermediate
1755c6c1daeSBarry Smith 
1765c6c1daeSBarry Smith   Concepts: PetscViewer^file pointer
1775c6c1daeSBarry Smith   Concepts: file pointer^getting from PetscViewer
1785c6c1daeSBarry Smith 
1795c6c1daeSBarry Smith .seealso: PetscViewerASCIIGetPointer()
1805c6c1daeSBarry Smith @*/
1815c6c1daeSBarry Smith PetscErrorCode  PetscViewerVUGetPointer(PetscViewer viewer, FILE **fd)
1825c6c1daeSBarry Smith {
1835c6c1daeSBarry Smith   PetscViewer_VU *vu = (PetscViewer_VU*) viewer->data;
1845c6c1daeSBarry Smith 
1855c6c1daeSBarry Smith   PetscFunctionBegin;
1865c6c1daeSBarry Smith   PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1);
1875c6c1daeSBarry Smith   PetscValidPointer(fd,2);
1885c6c1daeSBarry Smith   *fd = vu->fd;
1895c6c1daeSBarry Smith   PetscFunctionReturn(0);
1905c6c1daeSBarry Smith }
1915c6c1daeSBarry Smith 
1925c6c1daeSBarry Smith #undef __FUNCT__
1935c6c1daeSBarry Smith #define __FUNCT__ "PetscViewerVUSetMode"
1945c6c1daeSBarry Smith /*@C
1955c6c1daeSBarry Smith   PetscViewerVUSetMode - Sets the mode in which to open the file.
1965c6c1daeSBarry Smith 
1975c6c1daeSBarry Smith   Not Collective
1985c6c1daeSBarry Smith 
1995c6c1daeSBarry Smith   Input Parameters:
2005c6c1daeSBarry Smith + viewer - The PetscViewer
2015c6c1daeSBarry Smith - mode   - The file mode
2025c6c1daeSBarry Smith 
2035c6c1daeSBarry Smith   Level: intermediate
2045c6c1daeSBarry Smith 
2055c6c1daeSBarry Smith .keywords: Viewer, file, get, pointer
2065c6c1daeSBarry Smith .seealso: PetscViewerASCIISetMode()
2075c6c1daeSBarry Smith @*/
2085c6c1daeSBarry Smith PetscErrorCode  PetscViewerVUSetMode(PetscViewer viewer, PetscFileMode mode)
2095c6c1daeSBarry Smith {
2105c6c1daeSBarry Smith   PetscViewer_VU *vu = (PetscViewer_VU*) viewer->data;
2115c6c1daeSBarry Smith 
2125c6c1daeSBarry Smith   PetscFunctionBegin;
2135c6c1daeSBarry Smith   vu->mode = mode;
2145c6c1daeSBarry Smith   PetscFunctionReturn(0);
2155c6c1daeSBarry Smith }
2165c6c1daeSBarry Smith 
2175c6c1daeSBarry Smith #undef __FUNCT__
2185c6c1daeSBarry Smith #define __FUNCT__ "PetscViewerVUSetVecSeen"
2195c6c1daeSBarry Smith /*@C
2205c6c1daeSBarry Smith   PetscViewerVUSetVecSeen - Sets the flag which indicates whether we have viewed
2215c6c1daeSBarry Smith   a vector. This is usually called internally rather than by a user.
2225c6c1daeSBarry Smith 
2235c6c1daeSBarry Smith   Not Collective
2245c6c1daeSBarry Smith 
2255c6c1daeSBarry Smith   Input Parameters:
2265c6c1daeSBarry Smith + viewer  - The PetscViewer
2275c6c1daeSBarry Smith - vecSeen - The flag which indicates whether we have viewed a vector
2285c6c1daeSBarry Smith 
2295c6c1daeSBarry Smith   Level: advanced
2305c6c1daeSBarry Smith 
2315c6c1daeSBarry Smith .keywords: Viewer, Vec
2325c6c1daeSBarry Smith .seealso: PetscViewerVUGetVecSeen()
2335c6c1daeSBarry Smith @*/
2345c6c1daeSBarry Smith PetscErrorCode  PetscViewerVUSetVecSeen(PetscViewer viewer, PetscBool vecSeen)
2355c6c1daeSBarry Smith {
2365c6c1daeSBarry Smith   PetscViewer_VU *vu = (PetscViewer_VU*) viewer->data;
2375c6c1daeSBarry Smith 
2385c6c1daeSBarry Smith   PetscFunctionBegin;
2395c6c1daeSBarry Smith   vu->vecSeen = vecSeen;
2405c6c1daeSBarry Smith   PetscFunctionReturn(0);
2415c6c1daeSBarry Smith }
2425c6c1daeSBarry Smith 
2435c6c1daeSBarry Smith #undef __FUNCT__
2445c6c1daeSBarry Smith #define __FUNCT__ "PetscViewerVUGetVecSeen"
2455c6c1daeSBarry Smith /*@C
2465c6c1daeSBarry Smith   PetscViewerVUGetVecSeen - Gets the flag which indicates whether we have viewed
2475c6c1daeSBarry Smith   a vector. This is usually called internally rather than by a user.
2485c6c1daeSBarry Smith 
2495c6c1daeSBarry Smith   Not Collective
2505c6c1daeSBarry Smith 
2515c6c1daeSBarry Smith   Input Parameter:
2525c6c1daeSBarry Smith . viewer  - The PetscViewer
2535c6c1daeSBarry Smith 
2545c6c1daeSBarry Smith   Output Parameter:
2555c6c1daeSBarry Smith . vecSeen - The flag which indicates whether we have viewed a vector
2565c6c1daeSBarry Smith 
2575c6c1daeSBarry Smith   Level: advanced
2585c6c1daeSBarry Smith 
2595c6c1daeSBarry Smith .keywords: Viewer, Vec
2605c6c1daeSBarry Smith .seealso: PetscViewerVUGetVecSeen()
2615c6c1daeSBarry Smith @*/
2625c6c1daeSBarry Smith PetscErrorCode  PetscViewerVUGetVecSeen(PetscViewer viewer, PetscBool  *vecSeen)
2635c6c1daeSBarry Smith {
2645c6c1daeSBarry Smith   PetscViewer_VU *vu = (PetscViewer_VU*) viewer->data;
2655c6c1daeSBarry Smith 
2665c6c1daeSBarry Smith   PetscFunctionBegin;
2675c6c1daeSBarry Smith   PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1);
2685c6c1daeSBarry Smith   PetscValidPointer(vecSeen,2);
2695c6c1daeSBarry Smith   *vecSeen = vu->vecSeen;
2705c6c1daeSBarry Smith   PetscFunctionReturn(0);
2715c6c1daeSBarry Smith }
2725c6c1daeSBarry Smith 
2735c6c1daeSBarry Smith #undef __FUNCT__
2745c6c1daeSBarry Smith #define __FUNCT__ "PetscViewerVUPrintDeferred"
2755c6c1daeSBarry Smith /*@C
2765c6c1daeSBarry Smith   PetscViewerVUPrintDeferred - Prints to the deferred write cache instead of the file.
2775c6c1daeSBarry Smith 
2785c6c1daeSBarry Smith   Not Collective
2795c6c1daeSBarry Smith 
2805c6c1daeSBarry Smith   Input Parameters:
2815c6c1daeSBarry Smith + viewer - The PetscViewer
2825c6c1daeSBarry Smith - format - The format string
2835c6c1daeSBarry Smith 
2845c6c1daeSBarry Smith   Level: intermediate
2855c6c1daeSBarry Smith 
2865c6c1daeSBarry Smith .keywords: Viewer, print, deferred
2875c6c1daeSBarry Smith .seealso: PetscViewerVUFlushDeferred()
2885c6c1daeSBarry Smith @*/
2895c6c1daeSBarry Smith PetscErrorCode  PetscViewerVUPrintDeferred(PetscViewer viewer, const char format[], ...)
2905c6c1daeSBarry Smith {
2915c6c1daeSBarry Smith   PetscViewer_VU *vu = (PetscViewer_VU*) viewer->data;
2925c6c1daeSBarry Smith   va_list        Argp;
2935c6c1daeSBarry Smith   size_t         fullLength;
2945c6c1daeSBarry Smith   PrintfQueue    next;
2955c6c1daeSBarry Smith   PetscErrorCode ierr;
2965c6c1daeSBarry Smith 
2975c6c1daeSBarry Smith   PetscFunctionBegin;
298*b00a9115SJed Brown   ierr = PetscNew(&next);CHKERRQ(ierr);
2995c6c1daeSBarry Smith   if (vu->queue) {
3005c6c1daeSBarry Smith     vu->queue->next = next;
3015c6c1daeSBarry Smith     vu->queue       = next;
3020298fd71SBarry Smith     vu->queue->next = NULL;
3035c6c1daeSBarry Smith   } else {
3045c6c1daeSBarry Smith     vu->queueBase   = vu->queue = next;
3055c6c1daeSBarry Smith   }
3065c6c1daeSBarry Smith   vu->queueLength++;
3075c6c1daeSBarry Smith 
3085c6c1daeSBarry Smith   va_start(Argp, format);
3095c6c1daeSBarry Smith   ierr = PetscMemzero(next->string,QUEUESTRINGSIZE);CHKERRQ(ierr);
3105c6c1daeSBarry Smith   ierr = PetscVSNPrintf(next->string, QUEUESTRINGSIZE,format,&fullLength, Argp);CHKERRQ(ierr);
3115c6c1daeSBarry Smith   va_end(Argp);
3125c6c1daeSBarry Smith   PetscFunctionReturn(0);
3135c6c1daeSBarry Smith }
3145c6c1daeSBarry Smith 
3155c6c1daeSBarry Smith #undef __FUNCT__
3165c6c1daeSBarry Smith #define __FUNCT__ "PetscViewerVUFlushDeferred"
3175c6c1daeSBarry Smith /*@C
3185c6c1daeSBarry Smith   PetscViewerVUFlushDeferred - Flushes the deferred write cache to the file.
3195c6c1daeSBarry Smith 
3205c6c1daeSBarry Smith   Not Collective
3215c6c1daeSBarry Smith 
3225c6c1daeSBarry Smith   Input Parameter:
3235c6c1daeSBarry Smith + viewer - The PetscViewer
3245c6c1daeSBarry Smith 
3255c6c1daeSBarry Smith   Level: intermediate
3265c6c1daeSBarry Smith 
3275c6c1daeSBarry Smith .keywords: Viewer, flush, deferred
3285c6c1daeSBarry Smith .seealso: PetscViewerVUPrintDeferred()
3295c6c1daeSBarry Smith @*/
3305c6c1daeSBarry Smith PetscErrorCode  PetscViewerVUFlushDeferred(PetscViewer viewer)
3315c6c1daeSBarry Smith {
3325c6c1daeSBarry Smith   PetscViewer_VU *vu  = (PetscViewer_VU*) viewer->data;
3335c6c1daeSBarry Smith   PrintfQueue    next = vu->queueBase;
3345c6c1daeSBarry Smith   PrintfQueue    previous;
3355c6c1daeSBarry Smith   int            i;
3365c6c1daeSBarry Smith   PetscErrorCode ierr;
3375c6c1daeSBarry Smith 
3385c6c1daeSBarry Smith   PetscFunctionBegin;
3395c6c1daeSBarry Smith   for (i = 0; i < vu->queueLength; i++) {
340ce94432eSBarry Smith     PetscFPrintf(PetscObjectComm((PetscObject)viewer), vu->fd, "%s", next->string);
3415c6c1daeSBarry Smith     previous = next;
3425c6c1daeSBarry Smith     next     = next->next;
3435c6c1daeSBarry Smith     ierr     = PetscFree(previous);CHKERRQ(ierr);
3445c6c1daeSBarry Smith   }
3450298fd71SBarry Smith   vu->queue       = NULL;
3465c6c1daeSBarry Smith   vu->queueLength = 0;
3475c6c1daeSBarry Smith   PetscFunctionReturn(0);
3485c6c1daeSBarry Smith }
349