Actual source code: dupl.c

petsc-3.12.5 2020-03-29
Report Typos and Errors

  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:     Between the calls to PetscViewerGetSubViewer() and PetscViewerRestoreSubViewer() the original
 26:     viewer should not be used

 28:     PETSCVIEWERDRAW and PETSCVIEWERBINARY only support returning a singleton viewer on rank 0,
 29:     all other ranks will return a NULL viewer

 31:   Developer Notes:
 32:     There is currently incomplete error checking that the user does not use the original viewer between the
 33:     the calls to PetscViewerGetSubViewer() and PetscViewerRestoreSubViewer(). If the user does there
 34:     could be errors in the viewing that go undetected or crash the code.

 36: .seealso: PetscViewerSocketOpen(), PetscViewerASCIIOpen(), PetscViewerDrawOpen(), PetscViewerRestoreSubViewer()
 37: @*/
 38: PetscErrorCode  PetscViewerGetSubViewer(PetscViewer viewer,MPI_Comm comm,PetscViewer *outviewer)
 39: {
 41:   PetscMPIInt    size;

 46:   MPI_Comm_size(PetscObjectComm((PetscObject)viewer),&size);
 47:   if (size == 1) {
 48:     PetscObjectReference((PetscObject)viewer);
 49:     *outviewer = viewer;
 50:   } else if (viewer->ops->getsubviewer) {
 51:     (*viewer->ops->getsubviewer)(viewer,comm,outviewer);
 52:   } else SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_SUP,"Cannot get SubViewer PetscViewer for type %s",((PetscObject)viewer)->type_name);
 53:   return(0);
 54: }

 56: /*@C
 57:    PetscViewerRestoreSubViewer - Restores a new PetscViewer obtained with PetscViewerGetSubViewer().

 59:     Collective on PetscViewer

 61:    Input Parameters:
 62: +  viewer - the PetscViewer that was reproduced
 63: -  outviewer - new PetscViewer

 65:    Level: advanced

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

 70: .seealso: PetscViewerSocketOpen(), PetscViewerASCIIOpen(), PetscViewerDrawOpen(), PetscViewerGetSubViewer()
 71: @*/
 72: PetscErrorCode  PetscViewerRestoreSubViewer(PetscViewer viewer,MPI_Comm comm,PetscViewer *outviewer)
 73: {
 75:   PetscMPIInt    size;


 80:   MPI_Comm_size(PetscObjectComm((PetscObject)viewer),&size);
 81:   if (size == 1) {
 82:     PetscObjectDereference((PetscObject)viewer);
 83:     if (outviewer) *outviewer = NULL;
 84:   } else if (viewer->ops->restoresubviewer) {
 85:     (*viewer->ops->restoresubviewer)(viewer,comm,outviewer);
 86:   }
 87:   return(0);
 88: }