Date: 2016-07-24T17:06:10+00:00

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

      1: #include <petsc/private/kspimpl.h>  /*I "petscksp.h" I*/
      2: #include <petscviewersaws.h>

      4: typedef struct {
      5:   PetscViewer    viewer;
      6:   PetscInt       neigs;
      7:   PetscReal      *eigi;
      8:   PetscReal      *eigr;
      9: } KSPMonitor_SAWs;

     13: /*@C
     14:    KSPMonitorSAWsCreate - create an SAWs monitor context

     16:    Collective

     18:    Input Arguments:
     19: .  ksp - KSP to monitor

     21:    Output Arguments:
     22: .  ctx - context for monitor

     24:    Level: developer

     26: .seealso: KSPMonitorSAWs(), KSPMonitorSAWsDestroy()
     27: @*/
     28: PetscErrorCode KSPMonitorSAWsCreate(KSP ksp,void **ctx)
     29: {
     30:   PetscErrorCode  ierr;
     31:   KSPMonitor_SAWs *mon;

     34:   PetscNewLog(ksp,&mon);
     35:   mon->viewer = PETSC_VIEWER_SAWS_(PetscObjectComm((PetscObject)ksp));
     36:   if (!mon->viewer) SETERRQ(PetscObjectComm((PetscObject)ksp),PETSC_ERR_PLIB,"Cannot create SAWs default viewer");
     37:   *ctx = (void*)mon;
     38:   return(0);
     39: }

     43: /*@C
     44:    KSPMonitorSAWsDestroy - destroy a monitor context created with KSPMonitorSAWsCreate()

     46:    Collective

     48:    Input Arguments:
     49: .  ctx - monitor context

     51:    Level: developer

     53: .seealso: KSPMonitorSAWsCreate()
     54: @*/
     55: PetscErrorCode KSPMonitorSAWsDestroy(void **ctx)
     56: {
     57:   KSPMonitor_SAWs *mon = (KSPMonitor_SAWs*)*ctx;
     58:   PetscErrorCode  ierr;

     61:   PetscFree2(mon->eigr,mon->eigi);
     62:   PetscFree(*ctx);
     63:   return(0);
     64: }

     68: /*@C
     69:    KSPMonitorSAWs - monitor solution using SAWs

     71:    Logically Collective on KSP

     73:    Input Parameters:
     74: +  ksp   - iterative context
     75: .  n     - iteration number
     76: .  rnorm - 2-norm (preconditioned) residual value (may be estimated).
     77: -  ctx -  PetscViewer of type SAWs

     79:    Level: advanced

     81: .keywords: KSP, CG, monitor, SAWs, singular values

     83: .seealso: KSPMonitorSingularValue(), KSPComputeExtremeSingularValues(), PetscViewerSAWsOpen()
     84: @*/
     85: PetscErrorCode KSPMonitorSAWs(KSP ksp,PetscInt n,PetscReal rnorm,void *ctx)
     86: {
     87:   PetscErrorCode  ierr;
     88:   KSPMonitor_SAWs *mon   = (KSPMonitor_SAWs*)ctx;
     89:   PetscReal       emax,emin;
     90:   PetscMPIInt     rank;

     94:   KSPComputeExtremeSingularValues(ksp,&emax,&emin);

     96:   PetscFree2(mon->eigr,mon->eigi);
     97:   PetscMalloc2(n,&mon->eigr,n,&mon->eigi);
     98:   if (n) {
     99:     KSPComputeEigenvalues(ksp,n,mon->eigr,mon->eigi,&mon->neigs);

    101:     MPI_Comm_rank(PETSC_COMM_WORLD,&rank);
    102:     if (!rank) {
    103:       SAWs_Delete("/PETSc/ksp_monitor_saws/eigr");
    104:       SAWs_Delete("/PETSc/ksp_monitor_saws/eigi");

    106:       PetscStackCallSAWs(SAWs_Register,("/PETSc/ksp_monitor_saws/rnorm",&ksp->rnorm,1,SAWs_READ,SAWs_DOUBLE));
    107:       PetscStackCallSAWs(SAWs_Register,("/PETSc/ksp_monitor_saws/neigs",&mon->neigs,1,SAWs_READ,SAWs_INT));
    108:       if (mon->neigs > 0) {
    109:         PetscStackCallSAWs(SAWs_Register,("/PETSc/ksp_monitor_saws/eigr",mon->eigr,mon->neigs,SAWs_READ,SAWs_DOUBLE));
    110:         PetscStackCallSAWs(SAWs_Register,("/PETSc/ksp_monitor_saws/eigi",mon->eigi,mon->neigs,SAWs_READ,SAWs_DOUBLE));
    111:       }
    112:       PetscInfo2(ksp,"KSP extreme singular values min=%g max=%g\n",(double)emin,(double)emax);
    113:       PetscSAWsBlock();
    114:     }
    115:   }
    116:   return(0);
    117: }