Date: 2016-03-29T14:58:43+00:00

Actual source code: test2.c
slepc-3.6.3 2016-03-29
Report Typos and Errors

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

      6:    This file is part of SLEPc.

      8:    SLEPc is free software: you can redistribute it and/or modify it under  the
      9:    terms of version 3 of the GNU Lesser General Public License as published by
     10:    the Free Software Foundation.

     12:    SLEPc  is  distributed in the hope that it will be useful, but WITHOUT  ANY
     13:    WARRANTY;  without even the implied warranty of MERCHANTABILITY or  FITNESS
     14:    FOR  A  PARTICULAR PURPOSE. See the GNU Lesser General Public  License  for
     15:    more details.

     17:    You  should have received a copy of the GNU Lesser General  Public  License
     18:    along with SLEPc. If not, see <http://www.gnu.org/licenses/>.
     19:    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     20: */

     22: static char help[] = "Test SVD with different builds with a matrix loaded from a file"
     23:   " (matrices available in PETSc's distribution).\n\n";

     25: #include <slepcsvd.h>

     29: int main(int argc,char **argv)
     30: {
     31:   Mat            A;               /* operator matrix */
     32:   SVD            svd;             /* singular value problem solver context */
     33:   char           filename[PETSC_MAX_PATH_LEN];
     34:   const char     *prefix,*scalar,*ints,*floats;
     35:   PetscReal      tol=1000*PETSC_MACHINE_EPSILON;
     36:   PetscViewer    viewer;

     39:   SlepcInitialize(&argc,&argv,(char*)0,help);

     41:   /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     42:         Load the matrix for which the SVD must be computed
     43:      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
     44: #if defined(PETSC_USE_COMPLEX)
     45:   prefix = "nh";
     46:   scalar = "complex";
     47: #else
     48:   prefix = "ns";
     49:   scalar = "real";
     50: #endif
     51: #if defined(PETSC_USE_64BIT_INDICES)
     52:   ints   = "int64";
     53: #else
     54:   ints   = "int32";
     55: #endif
     56: #if defined(PETSC_USE_REAL_DOUBLE)
     57:   floats = "float64";
     58: #elif defined(PETSC_USE_REAL_SINGLE)
     59:   floats = "float32";
     60: #endif

     62:   PetscSNPrintf(filename,PETSC_MAX_PATH_LEN,"%s/share/petsc/datafiles/matrices/%s-%s-%s-%s",PETSC_DIR,prefix,scalar,ints,floats);
     63:   PetscPrintf(PETSC_COMM_WORLD,"\nReading matrix from binary file...\n\n");
     64:   PetscViewerBinaryOpen(PETSC_COMM_WORLD,filename,FILE_MODE_READ,&viewer);
     65:   MatCreate(PETSC_COMM_WORLD,&A);
     66:   MatSetFromOptions(A);
     67:   MatLoad(A,viewer);
     68:   PetscViewerDestroy(&viewer);

     70:   /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     71:                      Create the SVD solver
     72:      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
     73:   SVDCreate(PETSC_COMM_WORLD,&svd);
     74:   SVDSetOperator(svd,A);
     75:   SVDSetTolerances(svd,tol,PETSC_DEFAULT);
     76:   SVDSetFromOptions(svd);

     78:   /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     79:                 Solve the eigensystem and display solution
     80:      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
     81:   SVDSolve(svd);
     82:   SVDErrorView(svd,SVD_ERROR_RELATIVE,NULL);
     83:   SVDDestroy(&svd);
     84:   MatDestroy(&A);
     85:   SlepcFinalize();
     86:   return 0;
     87: }