Date: 2022-03-31T15:29:22+00:00

Actual source code: test5.c
slepc-3.17.0 2022-03-31
Report Typos and Errors

      1: /*
      2:    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      3:    SLEPc - Scalable Library for Eigenvalue Problem Computations
      4:    Copyright (c) 2002-, Universitat Politecnica de Valencia, Spain

      6:    This file is part of SLEPc.
      7:    SLEPc is distributed under a 2-clause BSD license (see LICENSE).
      8:    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      9: */

     11: static char help[] = "Test SVD view and monitor functionality.\n\n";

     13: #include <slepcsvd.h>

     15: int main(int argc,char **argv)
     16: {
     17:   Mat            A;
     18:   SVD            svd;
     19:   PetscReal      *sigma,sval;
     20:   PetscInt       n=6,Istart,Iend,i,nconv;
     21:   PetscBool      checkfile;
     22:   char           filename[PETSC_MAX_PATH_LEN];
     23:   PetscViewer    viewer;

     25:   SlepcInitialize(&argc,&argv,(char*)0,help);
     26:   PetscOptionsGetInt(NULL,NULL,"-n",&n,NULL);
     27:   PetscPrintf(PETSC_COMM_WORLD,"\nSVD of diagonal matrix, n=%" PetscInt_FMT "\n\n",n);

     29:   /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     30:         Generate the matrix
     31:      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
     32:   MatCreate(PETSC_COMM_WORLD,&A);
     33:   MatSetSizes(A,PETSC_DECIDE,PETSC_DECIDE,n,n);
     34:   MatSetFromOptions(A);
     35:   MatSetUp(A);
     36:   MatGetOwnershipRange(A,&Istart,&Iend);
     37:   for (i=Istart;i<Iend;i++) MatSetValue(A,i,i,i+1,INSERT_VALUES);
     38:   MatAssemblyBegin(A,MAT_FINAL_ASSEMBLY);
     39:   MatAssemblyEnd(A,MAT_FINAL_ASSEMBLY);

     41:   /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     42:                      Create the SVD solver
     43:      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
     44:   SVDCreate(PETSC_COMM_WORLD,&svd);
     45:   PetscObjectSetName((PetscObject)svd,"svd");
     46:   SVDSetOperators(svd,A,NULL);
     47:   SVDSetFromOptions(svd);

     49:   /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     50:                 Compute the singular triplets and display solution
     51:      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
     52:   SVDSolve(svd);
     53:   SVDErrorView(svd,SVD_ERROR_RELATIVE,NULL);

     55:   /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     56:                    Check file containing the singular values
     57:      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
     58:   PetscOptionsGetString(NULL,NULL,"-checkfile",filename,sizeof(filename),&checkfile);
     59:   if (checkfile) {
     60:     SVDGetConverged(svd,&nconv);
     61:     PetscMalloc1(nconv,&sigma);
     62:     PetscViewerBinaryOpen(PETSC_COMM_WORLD,filename,FILE_MODE_READ,&viewer);
     63:     PetscViewerBinaryRead(viewer,sigma,nconv,NULL,PETSC_REAL);
     64:     PetscViewerDestroy(&viewer);
     65:     for (i=0;i<nconv;i++) {
     66:       SVDGetSingularTriplet(svd,i,&sval,NULL,NULL);
     68:     }
     69:     PetscFree(sigma);
     70:   }

     72:   SVDDestroy(&svd);
     73:   MatDestroy(&A);
     74:   SlepcFinalize();
     75:   return 0;
     76: }

     78: /*TEST

     80:    test:
     81:       suffix: 1
     82:       args: -svd_error_relative ::ascii_info_detail -svd_view_values -svd_monitor_conv -svd_error_absolute ::ascii_matlab -svd_monitor_all -svd_converged_reason -svd_view
     83:       filter: grep -v "tolerance" | grep -v "problem type" | sed -e "s/1.999999/2.000000/" | sed -e "s/2.000001/2.000000/" | sed -e "s/[0-9]\.[0-9]*e-\([0-9]*\)/removed/g"
     84:       requires: !single

     86:    test:
     87:       suffix: 2
     88:       args: -svd_nsv 4 -svd_view_values binary:myvalues.bin -checkfile myvalues.bin
     89:       requires: double

     91:    test:
     92:       suffix: 3
     93:       args: -svd_type trlanczos -svd_error_relative ::ascii_info_detail -svd_view_values -svd_monitor_conv -svd_error_absolute ::ascii_matlab -svd_monitor_all -svd_converged_reason -svd_view
     94:       filter: grep -v "tolerance" | grep -v "problem type" | sed -e "s/1.999999/2.000000/" | sed -e "s/2.000001/2.000000/" | sed -e "s/[0-9]\.[0-9]*e-\([0-9]*\)/removed/g"
     95:       requires: !single

     97:    test:
     98:       suffix: 4
     99:       args: -svd_monitor draw::draw_lg -svd_monitor_all draw::draw_lg -svd_view_values draw -draw_save mysingu.ppm -draw_virtual
    100:       requires: !single

    102: TEST*/