15c6c1daeSBarry Smith 2af0996ceSBarry Smith #include <petsc/private/viewerimpl.h> /*I "petscviewer.h" I*/ 35c6c1daeSBarry Smith 4b3fa1ec5SBarry Smith /*@C 53f08860eSBarry Smith PetscViewerGetSubViewer - Creates a new PetscViewer (same type as the old) 63f08860eSBarry Smith that lives on a subcommunicator 75c6c1daeSBarry Smith 85c6c1daeSBarry Smith Collective on PetscViewer 95c6c1daeSBarry Smith 105c6c1daeSBarry Smith Input Parameter: 113f08860eSBarry Smith . viewer - the PetscViewer to be reproduced 125c6c1daeSBarry Smith 135c6c1daeSBarry Smith Output Parameter: 145c6c1daeSBarry Smith . outviewer - new PetscViewer 155c6c1daeSBarry Smith 165c6c1daeSBarry Smith Level: advanced 175c6c1daeSBarry Smith 1895452b02SPatrick Sanan Notes: 1995452b02SPatrick Sanan Call PetscViewerRestoreSubViewer() to return this PetscViewer, NOT PetscViewerDestroy() 205c6c1daeSBarry Smith 215c6c1daeSBarry Smith This is most commonly used to view a sequential object that is part of a 225c6c1daeSBarry Smith parallel object. For example block Jacobi PC view could use this to obtain a 235c6c1daeSBarry Smith PetscViewer that is used with the sequential KSP on one block of the preconditioner. 245c6c1daeSBarry Smith 25*e5afcf28SBarry Smith Between the calls to PetscViewerGetSubViewer() and PetscViewerRestoreSubViewer() the original 26*e5afcf28SBarry Smith viewer should not be used 27*e5afcf28SBarry Smith 28*e5afcf28SBarry Smith PETSCVIEWERDRAW and PETSCVIEWERBINARY only support returning a singleton viewer on rank 0, 29*e5afcf28SBarry Smith all other ranks will return a NULL viewer 30*e5afcf28SBarry Smith 31*e5afcf28SBarry Smith Developer Notes: 32*e5afcf28SBarry Smith There is currently incomplete error checking that the user does not use the original viewer between the 33*e5afcf28SBarry Smith the calls to PetscViewerGetSubViewer() and PetscViewerRestoreSubViewer(). If the user does there 34*e5afcf28SBarry Smith could be errors in the viewing that go undetected or crash the code. 35*e5afcf28SBarry Smith 365c6c1daeSBarry Smith Concepts: PetscViewer^sequential version 375c6c1daeSBarry Smith 383f08860eSBarry Smith .seealso: PetscViewerSocketOpen(), PetscViewerASCIIOpen(), PetscViewerDrawOpen(), PetscViewerRestoreSubViewer() 395c6c1daeSBarry Smith @*/ 403f08860eSBarry Smith PetscErrorCode PetscViewerGetSubViewer(PetscViewer viewer,MPI_Comm comm,PetscViewer *outviewer) 415c6c1daeSBarry Smith { 425c6c1daeSBarry Smith PetscErrorCode ierr; 435c6c1daeSBarry Smith PetscMPIInt size; 445c6c1daeSBarry Smith 455c6c1daeSBarry Smith PetscFunctionBegin; 465c6c1daeSBarry Smith PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1); 475c6c1daeSBarry Smith PetscValidPointer(outviewer,2); 48ce94432eSBarry Smith ierr = MPI_Comm_size(PetscObjectComm((PetscObject)viewer),&size);CHKERRQ(ierr); 495c6c1daeSBarry Smith if (size == 1) { 505c6c1daeSBarry Smith ierr = PetscObjectReference((PetscObject)viewer);CHKERRQ(ierr); 515c6c1daeSBarry Smith *outviewer = viewer; 52559f443fSBarry Smith } else if (viewer->ops->getsubviewer) { 53559f443fSBarry Smith ierr = (*viewer->ops->getsubviewer)(viewer,comm,outviewer);CHKERRQ(ierr); 543f08860eSBarry Smith } else SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_SUP,"Cannot get SubViewer PetscViewer for type %s",((PetscObject)viewer)->type_name); 555c6c1daeSBarry Smith PetscFunctionReturn(0); 565c6c1daeSBarry Smith } 575c6c1daeSBarry Smith 58b3fa1ec5SBarry Smith /*@C 593f08860eSBarry Smith PetscViewerRestoreSubViewer - Restores a new PetscViewer obtained with PetscViewerGetSubViewer(). 605c6c1daeSBarry Smith 615c6c1daeSBarry Smith Collective on PetscViewer 625c6c1daeSBarry Smith 635c6c1daeSBarry Smith Input Parameters: 643f08860eSBarry Smith + viewer - the PetscViewer that was reproduced 655c6c1daeSBarry Smith - outviewer - new PetscViewer 665c6c1daeSBarry Smith 675c6c1daeSBarry Smith Level: advanced 685c6c1daeSBarry Smith 6995452b02SPatrick Sanan Notes: 7095452b02SPatrick Sanan Call PetscViewerGetSubViewer() to get this PetscViewer, NOT PetscViewerCreate() 715c6c1daeSBarry Smith 723f08860eSBarry Smith .seealso: PetscViewerSocketOpen(), PetscViewerASCIIOpen(), PetscViewerDrawOpen(), PetscViewerGetSubViewer() 735c6c1daeSBarry Smith @*/ 743f08860eSBarry Smith PetscErrorCode PetscViewerRestoreSubViewer(PetscViewer viewer,MPI_Comm comm,PetscViewer *outviewer) 755c6c1daeSBarry Smith { 765c6c1daeSBarry Smith PetscErrorCode ierr; 775c6c1daeSBarry Smith PetscMPIInt size; 785c6c1daeSBarry Smith 795c6c1daeSBarry Smith PetscFunctionBegin; 805c6c1daeSBarry Smith PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1); 815c6c1daeSBarry Smith 82ce94432eSBarry Smith ierr = MPI_Comm_size(PetscObjectComm((PetscObject)viewer),&size);CHKERRQ(ierr); 835c6c1daeSBarry Smith if (size == 1) { 845c6c1daeSBarry Smith ierr = PetscObjectDereference((PetscObject)viewer);CHKERRQ(ierr); 85c6228bbaSLisandro Dalcin if (outviewer) *outviewer = NULL; 86559f443fSBarry Smith } else if (viewer->ops->restoresubviewer) { 87559f443fSBarry Smith ierr = (*viewer->ops->restoresubviewer)(viewer,comm,outviewer);CHKERRQ(ierr); 885c6c1daeSBarry Smith } 895c6c1daeSBarry Smith PetscFunctionReturn(0); 905c6c1daeSBarry Smith } 915c6c1daeSBarry Smith 92