Actual source code: test2.c

slepc-3.21.1 2024-04-26
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 with different builds with a matrix loaded from a file"
 12:   " (matrices available in PETSc's distribution).\n\n";

 14: #include <slepcsvd.h>

 16: int main(int argc,char **argv)
 17: {
 18:   Mat            A;               /* operator matrix */
 19:   SVD            svd;             /* singular value problem solver context */
 20:   char           filename[PETSC_MAX_PATH_LEN];
 21:   const char     *prefix,*scalar,*ints,*floats;
 22:   PetscReal      tol=PETSC_SMALL;
 23:   PetscViewer    viewer;

 25:   PetscFunctionBeginUser;
 26:   PetscCall(SlepcInitialize(&argc,&argv,(char*)0,help));

 28:   /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 29:         Load the matrix for which the SVD must be computed
 30:      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
 31: #if defined(PETSC_USE_COMPLEX)
 32:   prefix = "nh";
 33:   scalar = "complex";
 34: #else
 35:   prefix = "ns";
 36:   scalar = "real";
 37: #endif
 38: #if defined(PETSC_USE_64BIT_INDICES)
 39:   ints   = "int64";
 40: #else
 41:   ints   = "int32";
 42: #endif
 43: #if defined(PETSC_USE_REAL_DOUBLE)
 44:   floats = "float64";
 45: #elif defined(PETSC_USE_REAL_SINGLE)
 46:   floats = "float32";
 47: #endif

 49:   PetscCall(PetscSNPrintf(filename,sizeof(filename),"%s/share/petsc/datafiles/matrices/%s-%s-%s-%s",PETSC_DIR,prefix,scalar,ints,floats));
 50:   PetscCall(PetscPrintf(PETSC_COMM_WORLD,"\nReading matrix from binary file...\n\n"));
 51:   PetscCall(PetscViewerBinaryOpen(PETSC_COMM_WORLD,filename,FILE_MODE_READ,&viewer));
 52:   PetscCall(MatCreate(PETSC_COMM_WORLD,&A));
 53:   PetscCall(MatSetFromOptions(A));
 54:   PetscCall(MatLoad(A,viewer));
 55:   PetscCall(PetscViewerDestroy(&viewer));

 57:   /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 58:                      Create the SVD solver
 59:      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
 60:   PetscCall(SVDCreate(PETSC_COMM_WORLD,&svd));
 61:   PetscCall(SVDSetOperators(svd,A,NULL));
 62:   PetscCall(SVDSetTolerances(svd,tol,PETSC_DEFAULT));
 63:   PetscCall(SVDSetFromOptions(svd));

 65:   /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 66:                 Compute the singular triplets and display solution
 67:      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
 68:   PetscCall(SVDSolve(svd));
 69:   PetscCall(SVDErrorView(svd,SVD_ERROR_RELATIVE,NULL));
 70:   PetscCall(SVDDestroy(&svd));
 71:   PetscCall(MatDestroy(&A));
 72:   PetscCall(SlepcFinalize());
 73:   return 0;
 74: }

 76: /*TEST

 78:    build:
 79:       requires: !__float128

 81:    test:
 82:       args: -svd_nsv 7 -svd_type {{lanczos trlanczos cross cyclic lapack randomized}}
 83:       requires: !single

 85:    testset:
 86:       args: -svd_nsv 7 -svd_mpd 11 -svd_type primme
 87:       requires: primme !single
 88:       output_file: output/test2_1.out
 89:       test:
 90:          suffix: 1_primme
 91:       test:
 92:          suffix: 1_primme_args
 93:          args: -svd_primme_blocksize 2 -svd_primme_method hybrid

 95: TEST*/