1 2 #include <petsc/private/viewerimpl.h> /*I "petscviewer.h" I*/ 3 4 /*@C 5 PetscViewerGetSubViewer - Creates a new `PetscViewer` (same type as the old) 6 that lives on a subcommunicator of the original viewer's communicator 7 8 Collective 9 10 Input Parameters: 11 + viewer - the `PetscViewer` to be reproduced 12 - comm - the sub communicator to use 13 14 Output Parameter: 15 . outviewer - new `PetscViewer` 16 17 Level: advanced 18 19 Notes: 20 The output of the subviewers is synchronized against the original viewer. For example, if a 21 viewer on two MPI processes is decomposed into two subviewers, the output from the first viewer is 22 all printed before the output from the second viewer. You must call `PetscViewerFlush()` after 23 the call to `PetscViewerRestoreSubViewer()`. 24 25 Call `PetscViewerRestoreSubViewer()` to destroy this `PetscViewer`, NOT `PetscViewerDestroy()` 26 27 This is most commonly used to view a sequential object that is part of a 28 parallel object. For example `PCView()` on a `PCBJACOBI` could use this to obtain a 29 `PetscViewer` that is used with the sequential `KSP` on one block of the preconditioner. 30 31 Between the calls to `PetscViewerGetSubViewer()` and `PetscViewerRestoreSubViewer()` the original 32 viewer should not be used 33 34 `PETSCVIEWERDRAW` and `PETSCVIEWERBINARY` only support returning a singleton viewer on MPI rank 0, 35 all other ranks will return a `NULL` viewer 36 37 Developer Notes: 38 There is currently incomplete error checking to ensure the user does not use the original viewer between the 39 the calls to `PetscViewerGetSubViewer()` and `PetscViewerRestoreSubViewer()`. If the user does there 40 could be errors in the viewing that go undetected or crash the code. 41 42 It would be nice if the call to `PetscViewerFlush()` was not required and was handled by 43 `PetscViewerRestoreSubViewer()` 44 45 .seealso: [](sec_viewers), `PetscViewer`, `PetscViewerSocketOpen()`, `PetscViewerASCIIOpen()`, `PetscViewerDrawOpen()`, `PetscViewerRestoreSubViewer()` 46 @*/ 47 PetscErrorCode PetscViewerGetSubViewer(PetscViewer viewer, MPI_Comm comm, PetscViewer *outviewer) 48 { 49 PetscFunctionBegin; 50 PetscValidHeaderSpecific(viewer, PETSC_VIEWER_CLASSID, 1); 51 PetscValidPointer(outviewer, 3); 52 PetscUseTypeMethod(viewer, getsubviewer, comm, outviewer); 53 PetscFunctionReturn(PETSC_SUCCESS); 54 } 55 56 /*@C 57 PetscViewerRestoreSubViewer - Restores a `PetscViewer` obtained with `PetscViewerGetSubViewer()`. 58 59 Collective 60 61 Input Parameters: 62 + viewer - the `PetscViewer` that was reproduced 63 . comm - the sub communicator 64 - outviewer - the subviewer to be returned 65 66 Level: advanced 67 68 .seealso: [](sec_viewers), `PetscViewer`, `PetscViewerSocketOpen()`, `PetscViewerASCIIOpen()`, `PetscViewerDrawOpen()`, `PetscViewerGetSubViewer()` 69 @*/ 70 PetscErrorCode PetscViewerRestoreSubViewer(PetscViewer viewer, MPI_Comm comm, PetscViewer *outviewer) 71 { 72 PetscFunctionBegin; 73 PetscValidHeaderSpecific(viewer, PETSC_VIEWER_CLASSID, 1); 74 75 PetscUseTypeMethod(viewer, restoresubviewer, comm, outviewer); 76 PetscFunctionReturn(PETSC_SUCCESS); 77 } 78