Date: 2016-07-24T16:46:26+00:00

Actual source code: dupl.c
petsc-3.7.3 2016-07-24
Report Typos and Errors

      2: #include <petsc/private/viewerimpl.h>  /*I "petscviewer.h" I*/

      6: /*@
      7:    PetscViewerGetSubViewer - Creates a new PetscViewer (same type as the old)
      8:     that lives on a subcommunicator

     10:     Collective on PetscViewer

     12:    Input Parameter:
     13: .  viewer - the PetscViewer to be reproduced

     15:    Output Parameter:
     16: .  outviewer - new PetscViewer

     18:    Level: advanced

     20:    Notes: Call PetscViewerRestoreSubViewer() to return this PetscViewer, NOT PetscViewerDestroy()

     22:      This is most commonly used to view a sequential object that is part of a
     23:     parallel object. For example block Jacobi PC view could use this to obtain a
     24:     PetscViewer that is used with the sequential KSP on one block of the preconditioner.

     26:    Concepts: PetscViewer^sequential version

     28: .seealso: PetscViewerSocketOpen(), PetscViewerASCIIOpen(), PetscViewerDrawOpen(), PetscViewerRestoreSubViewer()
     29: @*/
     30: PetscErrorCode  PetscViewerGetSubViewer(PetscViewer viewer,MPI_Comm comm,PetscViewer *outviewer)
     31: {
     33:   PetscMPIInt    size;

     38:   MPI_Comm_size(PetscObjectComm((PetscObject)viewer),&size);
     39:   if (size == 1) {
     40:     PetscObjectReference((PetscObject)viewer);
     41:     *outviewer = viewer;
     42:   } else if (viewer->ops->getsubviewer) {
     43:     (*viewer->ops->getsubviewer)(viewer,comm,outviewer);
     44:   } else SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_SUP,"Cannot get SubViewer PetscViewer for type %s",((PetscObject)viewer)->type_name);
     45:   PetscViewerASCIIPushSynchronized(viewer);
     46:   return(0);
     47: }

     51: /*@
     52:    PetscViewerRestoreSubViewer - Restores a new PetscViewer obtained with PetscViewerGetSubViewer().

     54:     Collective on PetscViewer

     56:    Input Parameters:
     57: +  viewer - the PetscViewer that was reproduced
     58: -  outviewer - new PetscViewer

     60:    Level: advanced

     62:    Notes: Call PetscViewerGetSubViewer() to get this PetscViewer, NOT PetscViewerCreate()

     64: .seealso: PetscViewerSocketOpen(), PetscViewerASCIIOpen(), PetscViewerDrawOpen(), PetscViewerGetSubViewer()
     65: @*/
     66: PetscErrorCode  PetscViewerRestoreSubViewer(PetscViewer viewer,MPI_Comm comm,PetscViewer *outviewer)
     67: {
     69:   PetscMPIInt    size;

     74:   MPI_Comm_size(PetscObjectComm((PetscObject)viewer),&size);
     75:   if (size == 1) {
     76:     PetscObjectDereference((PetscObject)viewer);
     77:     if (outviewer) *outviewer = NULL;
     78:   } else if (viewer->ops->restoresubviewer) {
     79:     (*viewer->ops->restoresubviewer)(viewer,comm,outviewer);
     80:   }
     81:   PetscViewerASCIIPopSynchronized(viewer);
     82:   return(0);
     83: }