Actual source code: dupl.c
petsc-3.10.5 2019-03-28
2: #include <petsc/private/viewerimpl.h>
4: /*@C
5: PetscViewerGetSubViewer - Creates a new PetscViewer (same type as the old)
6: that lives on a subcommunicator
8: Collective on PetscViewer
10: Input Parameter:
11: . viewer - the PetscViewer to be reproduced
13: Output Parameter:
14: . outviewer - new PetscViewer
16: Level: advanced
18: Notes:
19: Call PetscViewerRestoreSubViewer() to return this PetscViewer, NOT PetscViewerDestroy()
21: This is most commonly used to view a sequential object that is part of a
22: parallel object. For example block Jacobi PC view could use this to obtain a
23: PetscViewer that is used with the sequential KSP on one block of the preconditioner.
25: Concepts: PetscViewer^sequential version
27: .seealso: PetscViewerSocketOpen(), PetscViewerASCIIOpen(), PetscViewerDrawOpen(), PetscViewerRestoreSubViewer()
28: @*/
29: PetscErrorCode PetscViewerGetSubViewer(PetscViewer viewer,MPI_Comm comm,PetscViewer *outviewer)
30: {
32: PetscMPIInt size;
37: MPI_Comm_size(PetscObjectComm((PetscObject)viewer),&size);
38: if (size == 1) {
39: PetscObjectReference((PetscObject)viewer);
40: *outviewer = viewer;
41: } else if (viewer->ops->getsubviewer) {
42: (*viewer->ops->getsubviewer)(viewer,comm,outviewer);
43: } else SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_SUP,"Cannot get SubViewer PetscViewer for type %s",((PetscObject)viewer)->type_name);
44: PetscViewerASCIIPushSynchronized(viewer);
45: return(0);
46: }
48: /*@C
49: PetscViewerRestoreSubViewer - Restores a new PetscViewer obtained with PetscViewerGetSubViewer().
51: Collective on PetscViewer
53: Input Parameters:
54: + viewer - the PetscViewer that was reproduced
55: - outviewer - new PetscViewer
57: Level: advanced
59: Notes:
60: Call PetscViewerGetSubViewer() to get this PetscViewer, NOT PetscViewerCreate()
62: .seealso: PetscViewerSocketOpen(), PetscViewerASCIIOpen(), PetscViewerDrawOpen(), PetscViewerGetSubViewer()
63: @*/
64: PetscErrorCode PetscViewerRestoreSubViewer(PetscViewer viewer,MPI_Comm comm,PetscViewer *outviewer)
65: {
67: PetscMPIInt size;
72: MPI_Comm_size(PetscObjectComm((PetscObject)viewer),&size);
73: if (size == 1) {
74: PetscObjectDereference((PetscObject)viewer);
75: if (outviewer) *outviewer = NULL;
76: } else if (viewer->ops->restoresubviewer) {
77: (*viewer->ops->restoresubviewer)(viewer,comm,outviewer);
78: }
79: PetscViewerASCIIPopSynchronized(viewer);
80: return(0);
81: }