LCOV - code coverage report
Current view: top level - svd/interface - svddefault.c (source / functions) Hit Total Coverage
Test: SLEPc Lines: 50 53 94.3 %
Date: 2021-08-02 00:32:28 Functions: 6 6 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
       3             :    SLEPc - Scalable Library for Eigenvalue Problem Computations
       4             :    Copyright (c) 2002-2021, Universitat Politecnica de Valencia, Spain
       5             : 
       6             :    This file is part of SLEPc.
       7             :    SLEPc is distributed under a 2-clause BSD license (see LICENSE).
       8             :    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
       9             : */
      10             : /*
      11             :    Simple default routines for common SVD operations
      12             : */
      13             : 
      14             : #include <slepc/private/svdimpl.h>      /*I "slepcsvd.h" I*/
      15             : 
      16             : /*
      17             :   SVDConvergedAbsolute - Checks convergence absolutely.
      18             : */
      19          59 : PetscErrorCode SVDConvergedAbsolute(SVD svd,PetscReal sigma,PetscReal res,PetscReal *errest,void *ctx)
      20             : {
      21          59 :   PetscFunctionBegin;
      22          59 :   *errest = res;
      23          59 :   PetscFunctionReturn(0);
      24             : }
      25             : 
      26             : /*
      27             :   SVDConvergedRelative - Checks convergence relative to the singular value.
      28             : */
      29        2634 : PetscErrorCode SVDConvergedRelative(SVD svd,PetscReal sigma,PetscReal res,PetscReal *errest,void *ctx)
      30             : {
      31        2634 :   PetscFunctionBegin;
      32        2634 :   *errest = res/sigma;
      33        2634 :   PetscFunctionReturn(0);
      34             : }
      35             : 
      36             : /*
      37             :   SVDConvergedNorm - Checks convergence relative to the matrix norms.
      38             : */
      39          57 : PetscErrorCode SVDConvergedNorm(SVD svd,PetscReal sigma,PetscReal res,PetscReal *errest,void *ctx)
      40             : {
      41          57 :   PetscFunctionBegin;
      42          57 :   *errest = res/SlepcAbs(svd->nrma,svd->nrmb);
      43          57 :   PetscFunctionReturn(0);
      44             : }
      45             : 
      46             : /*
      47             :   SVDConvergedMaxIt - Always returns Inf to force reaching the maximum number of iterations.
      48             : */
      49           1 : PetscErrorCode SVDConvergedMaxIt(SVD svd,PetscReal sigma,PetscReal res,PetscReal *errest,void *ctx)
      50             : {
      51           1 :   PetscFunctionBegin;
      52           1 :   *errest = PETSC_MAX_REAL;
      53           1 :   PetscFunctionReturn(0);
      54             : }
      55             : 
      56             : /*@C
      57             :    SVDStoppingBasic - Default routine to determine whether the outer singular value
      58             :    solver iteration must be stopped.
      59             : 
      60             :    Collective on svd
      61             : 
      62             :    Input Parameters:
      63             : +  svd    - singular value solver context obtained from SVDCreate()
      64             : .  its    - current number of iterations
      65             : .  max_it - maximum number of iterations
      66             : .  nconv  - number of currently converged singular triplets
      67             : .  nsv    - number of requested singular triplets
      68             : -  ctx    - context (not used here)
      69             : 
      70             :    Output Parameter:
      71             : .  reason - result of the stopping test
      72             : 
      73             :    Notes:
      74             :    A positive value of reason indicates that the iteration has finished successfully
      75             :    (converged), and a negative value indicates an error condition (diverged). If
      76             :    the iteration needs to be continued, reason must be set to SVD_CONVERGED_ITERATING
      77             :    (zero).
      78             : 
      79             :    SVDStoppingBasic() will stop if all requested singular values are converged, or if
      80             :    the maximum number of iterations has been reached.
      81             : 
      82             :    Use SVDSetStoppingTest() to provide your own test instead of using this one.
      83             : 
      84             :    Level: advanced
      85             : 
      86             : .seealso: SVDSetStoppingTest(), SVDConvergedReason, SVDGetConvergedReason()
      87             : @*/
      88        1909 : PetscErrorCode SVDStoppingBasic(SVD svd,PetscInt its,PetscInt max_it,PetscInt nconv,PetscInt nsv,SVDConvergedReason *reason,void *ctx)
      89             : {
      90        1909 :   PetscErrorCode ierr;
      91             : 
      92        1909 :   PetscFunctionBegin;
      93        1909 :   *reason = SVD_CONVERGED_ITERATING;
      94        1909 :   if (nconv >= nsv) {
      95          79 :     ierr = PetscInfo2(svd,"Singular value solver finished successfully: %D singular triplets converged at iteration %D\n",nconv,its);CHKERRQ(ierr);
      96          79 :     *reason = SVD_CONVERGED_TOL;
      97        1830 :   } else if (its >= max_it) {
      98           0 :     if (svd->conv == SVD_CONV_MAXIT) *reason = SVD_CONVERGED_MAXIT;
      99             :     else {
     100           0 :       *reason = SVD_DIVERGED_ITS;
     101           0 :       ierr = PetscInfo1(svd,"Singular value solver iteration reached maximum number of iterations (%D)\n",its);CHKERRQ(ierr);
     102             :     }
     103             :   }
     104        1909 :   PetscFunctionReturn(0);
     105             : }
     106             : 
     107             : /*@
     108             :    SVDSetWorkVecs - Sets a number of work vectors into an SVD object.
     109             : 
     110             :    Collective on svd
     111             : 
     112             :    Input Parameters:
     113             : +  svd    - singular value solver context
     114             : .  nleft  - number of work vectors of dimension equal to left singular vector
     115             : -  nright - number of work vectors of dimension equal to right singular vector
     116             : 
     117             :    Developers Note:
     118             :    This is SLEPC_EXTERN because it may be required by user plugin SVD
     119             :    implementations.
     120             : 
     121             :    Level: developer
     122             : @*/
     123         646 : PetscErrorCode SVDSetWorkVecs(SVD svd,PetscInt nleft,PetscInt nright)
     124             : {
     125         646 :   PetscErrorCode ierr;
     126         646 :   Vec            t;
     127             : 
     128         646 :   PetscFunctionBegin;
     129         646 :   PetscValidHeaderSpecific(svd,SVD_CLASSID,1);
     130        1292 :   PetscValidLogicalCollectiveInt(svd,nleft,2);
     131        1292 :   PetscValidLogicalCollectiveInt(svd,nright,3);
     132         646 :   if (nleft <= 0) SETERRQ1(PetscObjectComm((PetscObject)svd),PETSC_ERR_ARG_OUTOFRANGE,"nleft must be > 0: nleft = %D",nleft);
     133         646 :   if (nright <= 0) SETERRQ1(PetscObjectComm((PetscObject)svd),PETSC_ERR_ARG_OUTOFRANGE,"nright must be > 0: nright = %D",nright);
     134         646 :   if (svd->nworkl < nleft) {
     135         165 :     ierr = VecDestroyVecs(svd->nworkl,&svd->workl);CHKERRQ(ierr);
     136         165 :     svd->nworkl = nleft;
     137         165 :     if (svd->isgeneralized) { ierr = SVDCreateLeftTemplate(svd,&t);CHKERRQ(ierr); }
     138         108 :     else { ierr = MatCreateVecsEmpty(svd->OP,NULL,&t);CHKERRQ(ierr); }
     139         165 :     ierr = VecDuplicateVecs(t,nleft,&svd->workl);CHKERRQ(ierr);
     140         165 :     ierr = VecDestroy(&t);CHKERRQ(ierr);
     141         468 :     ierr = PetscLogObjectParents(svd,nleft,svd->workl);CHKERRQ(ierr);
     142             :   }
     143         646 :   if (svd->nworkr < nright) {
     144         165 :     ierr = VecDestroyVecs(svd->nworkr,&svd->workr);CHKERRQ(ierr);
     145         165 :     svd->nworkr = nright;
     146         165 :     ierr = MatCreateVecsEmpty(svd->OP,&t,NULL);CHKERRQ(ierr);
     147         165 :     ierr = VecDuplicateVecs(t,nright,&svd->workr);CHKERRQ(ierr);
     148         165 :     ierr = VecDestroy(&t);CHKERRQ(ierr);
     149         468 :     ierr = PetscLogObjectParents(svd,nright,svd->workr);CHKERRQ(ierr);
     150             :   }
     151         646 :   PetscFunctionReturn(0);
     152             : }
     153             : 

Generated by: LCOV version 1.14