1*5c6c1daeSBarry Smith 2*5c6c1daeSBarry Smith #include <petsc-private/viewerimpl.h> /*I "petscsys.h" I*/ 3*5c6c1daeSBarry Smith #include <stdarg.h> 4*5c6c1daeSBarry Smith 5*5c6c1daeSBarry Smith #define QUEUESTRINGSIZE 1024 6*5c6c1daeSBarry Smith 7*5c6c1daeSBarry Smith typedef struct _PrintfQueue *PrintfQueue; 8*5c6c1daeSBarry Smith struct _PrintfQueue { 9*5c6c1daeSBarry Smith char string[QUEUESTRINGSIZE]; 10*5c6c1daeSBarry Smith PrintfQueue next; 11*5c6c1daeSBarry Smith }; 12*5c6c1daeSBarry Smith 13*5c6c1daeSBarry Smith typedef struct { 14*5c6c1daeSBarry Smith FILE *fd; 15*5c6c1daeSBarry Smith PetscFileMode mode; /* The mode in which to open the file */ 16*5c6c1daeSBarry Smith char *filename; 17*5c6c1daeSBarry Smith PetscBool vecSeen; /* The flag indicating whether any vector has been viewed so far */ 18*5c6c1daeSBarry Smith PrintfQueue queue, queueBase; 19*5c6c1daeSBarry Smith int queueLength; 20*5c6c1daeSBarry Smith } PetscViewer_VU; 21*5c6c1daeSBarry Smith 22*5c6c1daeSBarry Smith #undef __FUNCT__ 23*5c6c1daeSBarry Smith #define __FUNCT__ "PetscViewerFileClose_VU" 24*5c6c1daeSBarry Smith static PetscErrorCode PetscViewerFileClose_VU(PetscViewer viewer) 25*5c6c1daeSBarry Smith { 26*5c6c1daeSBarry Smith PetscViewer_VU *vu = (PetscViewer_VU *) viewer->data; 27*5c6c1daeSBarry Smith PetscErrorCode ierr; 28*5c6c1daeSBarry Smith 29*5c6c1daeSBarry Smith PetscFunctionBegin; 30*5c6c1daeSBarry Smith if (vu->vecSeen) { 31*5c6c1daeSBarry Smith ierr = PetscViewerVUPrintDeferred(viewer, "};\n\n");CHKERRQ(ierr); 32*5c6c1daeSBarry Smith } 33*5c6c1daeSBarry Smith ierr = PetscViewerVUFlushDeferred(viewer);CHKERRQ(ierr); 34*5c6c1daeSBarry Smith ierr = PetscFClose(((PetscObject)viewer)->comm, vu->fd);CHKERRQ(ierr); 35*5c6c1daeSBarry Smith vu->fd = PETSC_NULL; 36*5c6c1daeSBarry Smith ierr = PetscFree(vu->filename);CHKERRQ(ierr); 37*5c6c1daeSBarry Smith PetscFunctionReturn(0); 38*5c6c1daeSBarry Smith } 39*5c6c1daeSBarry Smith 40*5c6c1daeSBarry Smith #undef __FUNCT__ 41*5c6c1daeSBarry Smith #define __FUNCT__ "PetscViewerDestroy_VU" 42*5c6c1daeSBarry Smith PetscErrorCode PetscViewerDestroy_VU(PetscViewer viewer) 43*5c6c1daeSBarry Smith { 44*5c6c1daeSBarry Smith PetscViewer_VU *vu = (PetscViewer_VU *) viewer->data; 45*5c6c1daeSBarry Smith PetscErrorCode ierr; 46*5c6c1daeSBarry Smith 47*5c6c1daeSBarry Smith PetscFunctionBegin; 48*5c6c1daeSBarry Smith ierr = PetscViewerFileClose_VU(viewer);CHKERRQ(ierr); 49*5c6c1daeSBarry Smith ierr = PetscFree(vu);CHKERRQ(ierr); 50*5c6c1daeSBarry Smith PetscFunctionReturn(0); 51*5c6c1daeSBarry Smith } 52*5c6c1daeSBarry Smith 53*5c6c1daeSBarry Smith #undef __FUNCT__ 54*5c6c1daeSBarry Smith #define __FUNCT__ "PetscViewerFlush_VU" 55*5c6c1daeSBarry Smith PetscErrorCode PetscViewerFlush_VU(PetscViewer viewer) 56*5c6c1daeSBarry Smith { 57*5c6c1daeSBarry Smith PetscViewer_VU *vu = (PetscViewer_VU *) viewer->data; 58*5c6c1daeSBarry Smith PetscMPIInt rank; 59*5c6c1daeSBarry Smith int err; 60*5c6c1daeSBarry Smith PetscErrorCode ierr; 61*5c6c1daeSBarry Smith 62*5c6c1daeSBarry Smith PetscFunctionBegin; 63*5c6c1daeSBarry Smith ierr = MPI_Comm_rank(((PetscObject)viewer)->comm, &rank);CHKERRQ(ierr); 64*5c6c1daeSBarry Smith if (!rank) { 65*5c6c1daeSBarry Smith err = fflush(vu->fd); 66*5c6c1daeSBarry Smith if (err) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_SYS,"fflush() failed on file"); 67*5c6c1daeSBarry Smith } 68*5c6c1daeSBarry Smith PetscFunctionReturn(0); 69*5c6c1daeSBarry Smith } 70*5c6c1daeSBarry Smith 71*5c6c1daeSBarry Smith EXTERN_C_BEGIN 72*5c6c1daeSBarry Smith #undef __FUNCT__ 73*5c6c1daeSBarry Smith #define __FUNCT__ "PetscViewerFileGetName_VU" 74*5c6c1daeSBarry Smith PetscErrorCode PetscViewerFileGetName_VU(PetscViewer viewer, const char **name) 75*5c6c1daeSBarry Smith { 76*5c6c1daeSBarry Smith PetscViewer_VU *vu = (PetscViewer_VU *) viewer->data; 77*5c6c1daeSBarry Smith 78*5c6c1daeSBarry Smith PetscFunctionBegin; 79*5c6c1daeSBarry Smith *name = vu->filename; 80*5c6c1daeSBarry Smith PetscFunctionReturn(0); 81*5c6c1daeSBarry Smith } 82*5c6c1daeSBarry Smith EXTERN_C_END 83*5c6c1daeSBarry Smith 84*5c6c1daeSBarry Smith EXTERN_C_BEGIN 85*5c6c1daeSBarry Smith #undef __FUNCT__ 86*5c6c1daeSBarry Smith #define __FUNCT__ "PetscViewerFileSetName_VU" 87*5c6c1daeSBarry Smith PetscErrorCode PetscViewerFileSetName_VU(PetscViewer viewer, const char name[]) 88*5c6c1daeSBarry Smith { 89*5c6c1daeSBarry Smith PetscViewer_VU *vu = (PetscViewer_VU *) viewer->data; 90*5c6c1daeSBarry Smith char fname[PETSC_MAX_PATH_LEN]; 91*5c6c1daeSBarry Smith int rank; 92*5c6c1daeSBarry Smith PetscErrorCode ierr; 93*5c6c1daeSBarry Smith 94*5c6c1daeSBarry Smith PetscFunctionBegin; 95*5c6c1daeSBarry Smith if (!name) PetscFunctionReturn(0); 96*5c6c1daeSBarry Smith ierr = PetscViewerFileClose_VU(viewer);CHKERRQ(ierr); 97*5c6c1daeSBarry Smith ierr = MPI_Comm_rank(((PetscObject)viewer)->comm, &rank);CHKERRQ(ierr); 98*5c6c1daeSBarry Smith if (rank != 0) PetscFunctionReturn(0); 99*5c6c1daeSBarry Smith ierr = PetscStrallocpy(name, &vu->filename);CHKERRQ(ierr); 100*5c6c1daeSBarry Smith ierr = PetscFixFilename(name, fname);CHKERRQ(ierr); 101*5c6c1daeSBarry Smith switch(vu->mode) { 102*5c6c1daeSBarry Smith case FILE_MODE_READ: 103*5c6c1daeSBarry Smith vu->fd = fopen(fname, "r"); 104*5c6c1daeSBarry Smith break; 105*5c6c1daeSBarry Smith case FILE_MODE_WRITE: 106*5c6c1daeSBarry Smith vu->fd = fopen(fname, "w"); 107*5c6c1daeSBarry Smith break; 108*5c6c1daeSBarry Smith case FILE_MODE_APPEND: 109*5c6c1daeSBarry Smith vu->fd = fopen(fname, "a"); 110*5c6c1daeSBarry Smith break; 111*5c6c1daeSBarry Smith case FILE_MODE_UPDATE: 112*5c6c1daeSBarry Smith vu->fd = fopen(fname, "r+"); 113*5c6c1daeSBarry Smith if (!vu->fd) { 114*5c6c1daeSBarry Smith vu->fd = fopen(fname, "w+"); 115*5c6c1daeSBarry Smith } 116*5c6c1daeSBarry Smith break; 117*5c6c1daeSBarry Smith case FILE_MODE_APPEND_UPDATE: 118*5c6c1daeSBarry Smith /* I really want a file which is opened at the end for updating, 119*5c6c1daeSBarry Smith not a+, which opens at the beginning, but makes writes at the end. 120*5c6c1daeSBarry Smith */ 121*5c6c1daeSBarry Smith vu->fd = fopen(fname, "r+"); 122*5c6c1daeSBarry Smith if (!vu->fd) { 123*5c6c1daeSBarry Smith vu->fd = fopen(fname, "w+"); 124*5c6c1daeSBarry Smith } else { 125*5c6c1daeSBarry Smith ierr = fseek(vu->fd, 0, SEEK_END);CHKERRQ(ierr); 126*5c6c1daeSBarry Smith } 127*5c6c1daeSBarry Smith break; 128*5c6c1daeSBarry Smith default: 129*5c6c1daeSBarry Smith SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG, "Invalid file mode %d", vu->mode); 130*5c6c1daeSBarry Smith } 131*5c6c1daeSBarry Smith 132*5c6c1daeSBarry Smith if (!vu->fd) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_FILE_OPEN, "Cannot open PetscViewer file: %s", fname); 133*5c6c1daeSBarry Smith #if defined(PETSC_USE_LOG) 134*5c6c1daeSBarry Smith PetscLogObjectState((PetscObject) viewer, "File: %s", name); 135*5c6c1daeSBarry Smith #endif 136*5c6c1daeSBarry Smith 137*5c6c1daeSBarry Smith PetscFunctionReturn(0); 138*5c6c1daeSBarry Smith } 139*5c6c1daeSBarry Smith EXTERN_C_END 140*5c6c1daeSBarry Smith 141*5c6c1daeSBarry Smith EXTERN_C_BEGIN 142*5c6c1daeSBarry Smith #undef __FUNCT__ 143*5c6c1daeSBarry Smith #define __FUNCT__ "PetscViewerCreate_VU" 144*5c6c1daeSBarry Smith PetscErrorCode PetscViewerCreate_VU(PetscViewer viewer) 145*5c6c1daeSBarry Smith { 146*5c6c1daeSBarry Smith PetscViewer_VU *vu; 147*5c6c1daeSBarry Smith PetscErrorCode ierr; 148*5c6c1daeSBarry Smith 149*5c6c1daeSBarry Smith PetscFunctionBegin; 150*5c6c1daeSBarry Smith ierr = PetscNewLog(viewer,PetscViewer_VU, &vu);CHKERRQ(ierr); 151*5c6c1daeSBarry Smith viewer->data = (void*) vu; 152*5c6c1daeSBarry Smith 153*5c6c1daeSBarry Smith viewer->ops->destroy = PetscViewerDestroy_VU; 154*5c6c1daeSBarry Smith viewer->ops->flush = PetscViewerFlush_VU; 155*5c6c1daeSBarry Smith viewer->ops->getsingleton = PETSC_NULL; 156*5c6c1daeSBarry Smith viewer->ops->restoresingleton = PETSC_NULL; 157*5c6c1daeSBarry Smith viewer->format = PETSC_VIEWER_DEFAULT; 158*5c6c1daeSBarry Smith viewer->iformat = 0; 159*5c6c1daeSBarry Smith 160*5c6c1daeSBarry Smith vu->fd = PETSC_NULL; 161*5c6c1daeSBarry Smith vu->mode = FILE_MODE_WRITE; 162*5c6c1daeSBarry Smith vu->filename = PETSC_NULL; 163*5c6c1daeSBarry Smith vu->vecSeen = PETSC_FALSE; 164*5c6c1daeSBarry Smith vu->queue = PETSC_NULL; 165*5c6c1daeSBarry Smith vu->queueBase = PETSC_NULL; 166*5c6c1daeSBarry Smith vu->queueLength = 0; 167*5c6c1daeSBarry Smith 168*5c6c1daeSBarry Smith ierr = PetscObjectComposeFunctionDynamic((PetscObject) viewer,"PetscViewerFileSetName_C", "PetscViewerFileSetName_VU", 169*5c6c1daeSBarry Smith PetscViewerFileSetName_VU);CHKERRQ(ierr); 170*5c6c1daeSBarry Smith ierr = PetscObjectComposeFunctionDynamic((PetscObject) viewer,"PetscViewerFileGetName_C", "PetscViewerFileGetName_VU", 171*5c6c1daeSBarry Smith PetscViewerFileGetName_VU);CHKERRQ(ierr); 172*5c6c1daeSBarry Smith 173*5c6c1daeSBarry Smith PetscFunctionReturn(0); 174*5c6c1daeSBarry Smith } 175*5c6c1daeSBarry Smith EXTERN_C_END 176*5c6c1daeSBarry Smith 177*5c6c1daeSBarry Smith #undef __FUNCT__ 178*5c6c1daeSBarry Smith #define __FUNCT__ "PetscViewerVUGetPointer" 179*5c6c1daeSBarry Smith /*@C 180*5c6c1daeSBarry Smith PetscViewerVUGetPointer - Extracts the file pointer from a VU PetscViewer. 181*5c6c1daeSBarry Smith 182*5c6c1daeSBarry Smith Not Collective 183*5c6c1daeSBarry Smith 184*5c6c1daeSBarry Smith Input Parameter: 185*5c6c1daeSBarry Smith . viewer - The PetscViewer 186*5c6c1daeSBarry Smith 187*5c6c1daeSBarry Smith Output Parameter: 188*5c6c1daeSBarry Smith . fd - The file pointer 189*5c6c1daeSBarry Smith 190*5c6c1daeSBarry Smith Level: intermediate 191*5c6c1daeSBarry Smith 192*5c6c1daeSBarry Smith Concepts: PetscViewer^file pointer 193*5c6c1daeSBarry Smith Concepts: file pointer^getting from PetscViewer 194*5c6c1daeSBarry Smith 195*5c6c1daeSBarry Smith .seealso: PetscViewerASCIIGetPointer() 196*5c6c1daeSBarry Smith @*/ 197*5c6c1daeSBarry Smith PetscErrorCode PetscViewerVUGetPointer(PetscViewer viewer, FILE **fd) 198*5c6c1daeSBarry Smith { 199*5c6c1daeSBarry Smith PetscViewer_VU *vu = (PetscViewer_VU *) viewer->data; 200*5c6c1daeSBarry Smith 201*5c6c1daeSBarry Smith PetscFunctionBegin; 202*5c6c1daeSBarry Smith PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1); 203*5c6c1daeSBarry Smith PetscValidPointer(fd,2); 204*5c6c1daeSBarry Smith *fd = vu->fd; 205*5c6c1daeSBarry Smith PetscFunctionReturn(0); 206*5c6c1daeSBarry Smith } 207*5c6c1daeSBarry Smith 208*5c6c1daeSBarry Smith #undef __FUNCT__ 209*5c6c1daeSBarry Smith #define __FUNCT__ "PetscViewerVUSetMode" 210*5c6c1daeSBarry Smith /*@C 211*5c6c1daeSBarry Smith PetscViewerVUSetMode - Sets the mode in which to open the file. 212*5c6c1daeSBarry Smith 213*5c6c1daeSBarry Smith Not Collective 214*5c6c1daeSBarry Smith 215*5c6c1daeSBarry Smith Input Parameters: 216*5c6c1daeSBarry Smith + viewer - The PetscViewer 217*5c6c1daeSBarry Smith - mode - The file mode 218*5c6c1daeSBarry Smith 219*5c6c1daeSBarry Smith Level: intermediate 220*5c6c1daeSBarry Smith 221*5c6c1daeSBarry Smith .keywords: Viewer, file, get, pointer 222*5c6c1daeSBarry Smith .seealso: PetscViewerASCIISetMode() 223*5c6c1daeSBarry Smith @*/ 224*5c6c1daeSBarry Smith PetscErrorCode PetscViewerVUSetMode(PetscViewer viewer, PetscFileMode mode) 225*5c6c1daeSBarry Smith { 226*5c6c1daeSBarry Smith PetscViewer_VU *vu = (PetscViewer_VU *) viewer->data; 227*5c6c1daeSBarry Smith 228*5c6c1daeSBarry Smith PetscFunctionBegin; 229*5c6c1daeSBarry Smith vu->mode = mode; 230*5c6c1daeSBarry Smith PetscFunctionReturn(0); 231*5c6c1daeSBarry Smith } 232*5c6c1daeSBarry Smith 233*5c6c1daeSBarry Smith #undef __FUNCT__ 234*5c6c1daeSBarry Smith #define __FUNCT__ "PetscViewerVUSetVecSeen" 235*5c6c1daeSBarry Smith /*@C 236*5c6c1daeSBarry Smith PetscViewerVUSetVecSeen - Sets the flag which indicates whether we have viewed 237*5c6c1daeSBarry Smith a vector. This is usually called internally rather than by a user. 238*5c6c1daeSBarry Smith 239*5c6c1daeSBarry Smith Not Collective 240*5c6c1daeSBarry Smith 241*5c6c1daeSBarry Smith Input Parameters: 242*5c6c1daeSBarry Smith + viewer - The PetscViewer 243*5c6c1daeSBarry Smith - vecSeen - The flag which indicates whether we have viewed a vector 244*5c6c1daeSBarry Smith 245*5c6c1daeSBarry Smith Level: advanced 246*5c6c1daeSBarry Smith 247*5c6c1daeSBarry Smith .keywords: Viewer, Vec 248*5c6c1daeSBarry Smith .seealso: PetscViewerVUGetVecSeen() 249*5c6c1daeSBarry Smith @*/ 250*5c6c1daeSBarry Smith PetscErrorCode PetscViewerVUSetVecSeen(PetscViewer viewer, PetscBool vecSeen) 251*5c6c1daeSBarry Smith { 252*5c6c1daeSBarry Smith PetscViewer_VU *vu = (PetscViewer_VU *) viewer->data; 253*5c6c1daeSBarry Smith 254*5c6c1daeSBarry Smith PetscFunctionBegin; 255*5c6c1daeSBarry Smith vu->vecSeen = vecSeen; 256*5c6c1daeSBarry Smith PetscFunctionReturn(0); 257*5c6c1daeSBarry Smith } 258*5c6c1daeSBarry Smith 259*5c6c1daeSBarry Smith #undef __FUNCT__ 260*5c6c1daeSBarry Smith #define __FUNCT__ "PetscViewerVUGetVecSeen" 261*5c6c1daeSBarry Smith /*@C 262*5c6c1daeSBarry Smith PetscViewerVUGetVecSeen - Gets the flag which indicates whether we have viewed 263*5c6c1daeSBarry Smith a vector. This is usually called internally rather than by a user. 264*5c6c1daeSBarry Smith 265*5c6c1daeSBarry Smith Not Collective 266*5c6c1daeSBarry Smith 267*5c6c1daeSBarry Smith Input Parameter: 268*5c6c1daeSBarry Smith . viewer - The PetscViewer 269*5c6c1daeSBarry Smith 270*5c6c1daeSBarry Smith Output Parameter: 271*5c6c1daeSBarry Smith . vecSeen - The flag which indicates whether we have viewed a vector 272*5c6c1daeSBarry Smith 273*5c6c1daeSBarry Smith Level: advanced 274*5c6c1daeSBarry Smith 275*5c6c1daeSBarry Smith .keywords: Viewer, Vec 276*5c6c1daeSBarry Smith .seealso: PetscViewerVUGetVecSeen() 277*5c6c1daeSBarry Smith @*/ 278*5c6c1daeSBarry Smith PetscErrorCode PetscViewerVUGetVecSeen(PetscViewer viewer, PetscBool *vecSeen) 279*5c6c1daeSBarry Smith { 280*5c6c1daeSBarry Smith PetscViewer_VU *vu = (PetscViewer_VU *) viewer->data; 281*5c6c1daeSBarry Smith 282*5c6c1daeSBarry Smith PetscFunctionBegin; 283*5c6c1daeSBarry Smith PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1); 284*5c6c1daeSBarry Smith PetscValidPointer(vecSeen,2); 285*5c6c1daeSBarry Smith *vecSeen = vu->vecSeen; 286*5c6c1daeSBarry Smith PetscFunctionReturn(0); 287*5c6c1daeSBarry Smith } 288*5c6c1daeSBarry Smith 289*5c6c1daeSBarry Smith #undef __FUNCT__ 290*5c6c1daeSBarry Smith #define __FUNCT__ "PetscViewerVUPrintDeferred" 291*5c6c1daeSBarry Smith /*@C 292*5c6c1daeSBarry Smith PetscViewerVUPrintDeferred - Prints to the deferred write cache instead of the file. 293*5c6c1daeSBarry Smith 294*5c6c1daeSBarry Smith Not Collective 295*5c6c1daeSBarry Smith 296*5c6c1daeSBarry Smith Input Parameters: 297*5c6c1daeSBarry Smith + viewer - The PetscViewer 298*5c6c1daeSBarry Smith - format - The format string 299*5c6c1daeSBarry Smith 300*5c6c1daeSBarry Smith Level: intermediate 301*5c6c1daeSBarry Smith 302*5c6c1daeSBarry Smith .keywords: Viewer, print, deferred 303*5c6c1daeSBarry Smith .seealso: PetscViewerVUFlushDeferred() 304*5c6c1daeSBarry Smith @*/ 305*5c6c1daeSBarry Smith PetscErrorCode PetscViewerVUPrintDeferred(PetscViewer viewer, const char format[], ...) 306*5c6c1daeSBarry Smith { 307*5c6c1daeSBarry Smith PetscViewer_VU *vu = (PetscViewer_VU *) viewer->data; 308*5c6c1daeSBarry Smith va_list Argp; 309*5c6c1daeSBarry Smith size_t fullLength; 310*5c6c1daeSBarry Smith PrintfQueue next; 311*5c6c1daeSBarry Smith PetscErrorCode ierr; 312*5c6c1daeSBarry Smith 313*5c6c1daeSBarry Smith PetscFunctionBegin; 314*5c6c1daeSBarry Smith ierr = PetscNew(struct _PrintfQueue, &next);CHKERRQ(ierr); 315*5c6c1daeSBarry Smith if (vu->queue) { 316*5c6c1daeSBarry Smith vu->queue->next = next; 317*5c6c1daeSBarry Smith vu->queue = next; 318*5c6c1daeSBarry Smith vu->queue->next = PETSC_NULL; 319*5c6c1daeSBarry Smith } else { 320*5c6c1daeSBarry Smith vu->queueBase = vu->queue = next; 321*5c6c1daeSBarry Smith } 322*5c6c1daeSBarry Smith vu->queueLength++; 323*5c6c1daeSBarry Smith 324*5c6c1daeSBarry Smith va_start(Argp, format); 325*5c6c1daeSBarry Smith ierr = PetscMemzero(next->string,QUEUESTRINGSIZE);CHKERRQ(ierr); 326*5c6c1daeSBarry Smith ierr = PetscVSNPrintf(next->string, QUEUESTRINGSIZE,format,&fullLength, Argp);CHKERRQ(ierr); 327*5c6c1daeSBarry Smith va_end(Argp); 328*5c6c1daeSBarry Smith PetscFunctionReturn(0); 329*5c6c1daeSBarry Smith } 330*5c6c1daeSBarry Smith 331*5c6c1daeSBarry Smith #undef __FUNCT__ 332*5c6c1daeSBarry Smith #define __FUNCT__ "PetscViewerVUFlushDeferred" 333*5c6c1daeSBarry Smith /*@C 334*5c6c1daeSBarry Smith PetscViewerVUFlushDeferred - Flushes the deferred write cache to the file. 335*5c6c1daeSBarry Smith 336*5c6c1daeSBarry Smith Not Collective 337*5c6c1daeSBarry Smith 338*5c6c1daeSBarry Smith Input Parameter: 339*5c6c1daeSBarry Smith + viewer - The PetscViewer 340*5c6c1daeSBarry Smith 341*5c6c1daeSBarry Smith Level: intermediate 342*5c6c1daeSBarry Smith 343*5c6c1daeSBarry Smith .keywords: Viewer, flush, deferred 344*5c6c1daeSBarry Smith .seealso: PetscViewerVUPrintDeferred() 345*5c6c1daeSBarry Smith @*/ 346*5c6c1daeSBarry Smith PetscErrorCode PetscViewerVUFlushDeferred(PetscViewer viewer) 347*5c6c1daeSBarry Smith { 348*5c6c1daeSBarry Smith PetscViewer_VU *vu = (PetscViewer_VU *) viewer->data; 349*5c6c1daeSBarry Smith PrintfQueue next = vu->queueBase; 350*5c6c1daeSBarry Smith PrintfQueue previous; 351*5c6c1daeSBarry Smith int i; 352*5c6c1daeSBarry Smith PetscErrorCode ierr; 353*5c6c1daeSBarry Smith 354*5c6c1daeSBarry Smith PetscFunctionBegin; 355*5c6c1daeSBarry Smith for (i = 0; i < vu->queueLength; i++) { 356*5c6c1daeSBarry Smith PetscFPrintf(((PetscObject)viewer)->comm, vu->fd, "%s", next->string); 357*5c6c1daeSBarry Smith previous = next; 358*5c6c1daeSBarry Smith next = next->next; 359*5c6c1daeSBarry Smith ierr = PetscFree(previous);CHKERRQ(ierr); 360*5c6c1daeSBarry Smith } 361*5c6c1daeSBarry Smith vu->queue = PETSC_NULL; 362*5c6c1daeSBarry Smith vu->queueLength = 0; 363*5c6c1daeSBarry Smith PetscFunctionReturn(0); 364*5c6c1daeSBarry Smith } 365