Date: 2013-07-02T14:38:14+00:00

Actual source code: dupl.c
petsc-3.4.2 2013-07-02

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

      6: /*@
      7:    PetscViewerGetSingleton - Creates a new PetscViewer (same type as the old)
      8:     that lives on a single processor (with MPI_comm PETSC_COMM_SELF)

     10:     Collective on PetscViewer

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

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

     18:    Level: advanced

     20:    Notes: Call PetscViewerRestoreSingleton() 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(), PetscViewerRestoreSingleton()
     29: @*/
     30: PetscErrorCode  PetscViewerGetSingleton(PetscViewer viewer,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->getsingleton) {
     43:     (*viewer->ops->getsingleton)(viewer,outviewer);
     44:   } else SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_SUP,"Cannot get singleton PetscViewer for type %s",((PetscObject)viewer)->type_name);
     45:   PetscViewerASCIISynchronizedAllow(viewer,PETSC_TRUE);
     46:   return(0);
     47: }

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

     54:     Collective on PetscViewer

     56:    Input Parameters:
     57: +  viewer - the PetscViewer to be duplicated
     58: -  outviewer - new PetscViewer

     60:    Level: advanced

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

     64: .seealso: PetscViewerSocketOpen(), PetscViewerASCIIOpen(), PetscViewerDrawOpen(), PetscViewerGetSingleton()
     65: @*/
     66: PetscErrorCode  PetscViewerRestoreSingleton(PetscViewer viewer,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 = 0;
     78:   } else if (viewer->ops->restoresingleton) {
     79:     (*viewer->ops->restoresingleton)(viewer,outviewer);
     80:   }
     81:   PetscViewerASCIISynchronizedAllow(viewer,PETSC_FALSE);
     82:   return(0);
     83: }

     87: /*@
     88:    PetscViewerGetSubcomm - Creates a new PetscViewer (same type as the old)
     89:     that lives on a subgroup of processors

     91:     Collective on PetscViewer

     93:    Input Parameter:
     94: +  viewer - the PetscViewer to be duplicated
     95: -  subcomm - MPI communicator

     97:    Output Parameter:
     98: .  outviewer - new PetscViewer

    100:    Level: advanced

    102:    Notes: Call PetscViewerRestoreSubcomm() to return this PetscViewer, NOT PetscViewerDestroy()

    104:      This is used to view a sequential or a parallel object that is part of a larger
    105:     parallel object. For example redundant PC view could use this to obtain a
    106:     PetscViewer that is used within a subcommunicator on one duplicated preconditioner.

    108:    Concepts: PetscViewer^sequential version

    110: .seealso: PetscViewerSocketOpen(), PetscViewerASCIIOpen(), PetscViewerDrawOpen(), PetscViewerRestoreSubcomm()
    111: @*/
    112: PetscErrorCode  PetscViewerGetSubcomm(PetscViewer viewer,MPI_Comm subcomm,PetscViewer *outviewer)
    113: {
    115:   PetscMPIInt    size;

    120:   MPI_Comm_size(PetscObjectComm((PetscObject)viewer),&size);
    121:   if (size == 1) {
    122:     PetscObjectReference((PetscObject)viewer);
    123:     *outviewer = viewer;
    124:   } else if (viewer->ops->getsubcomm) {
    125:     (*viewer->ops->getsubcomm)(viewer,subcomm,outviewer);
    126:   } else SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_SUP,"Cannot get subcommunicator PetscViewer for type %s",((PetscObject)viewer)->type_name);
    127:   return(0);
    128: }

    132: /*@
    133:    PetscViewerRestoreSubcomm - Restores a new PetscViewer obtained with PetscViewerGetSubcomm().

    135:     Collective on PetscViewer

    137:    Input Parameters:
    138: +  viewer - the PetscViewer to be duplicated
    139: .  subcomm - MPI communicator
    140: -  outviewer - new PetscViewer

    142:    Level: advanced

    144:    Notes: Call PetscViewerGetSubcomm() to get this PetscViewer, NOT PetscViewerCreate()

    146: .seealso: PetscViewerSocketOpen(), PetscViewerASCIIOpen(), PetscViewerDrawOpen(), PetscViewerGetSubcomm()
    147: @*/
    148: PetscErrorCode  PetscViewerRestoreSubcomm(PetscViewer viewer,MPI_Comm subcomm,PetscViewer *outviewer)
    149: {
    151:   PetscMPIInt    size;

    156:   MPI_Comm_size(PetscObjectComm((PetscObject)viewer),&size);
    157:   if (size == 1 || (outviewer && viewer == *outviewer)) {
    158:     PetscObjectDereference((PetscObject)viewer);
    159:     if (outviewer) *outviewer = 0;
    160:   } else if (viewer->ops->restoresubcomm) {
    161:     (*viewer->ops->restoresubcomm)(viewer,subcomm,outviewer);
    162:   }
    163:   return(0);
    164: }