Date: 2020-01-13T12:01:06+00:00

Actual source code: test13.c
slepc-3.12.2 2020-01-13
Report Typos and Errors

      1: /*
      2:    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      3:    SLEPc - Scalable Library for Eigenvalue Problem Computations
      4:    Copyright (c) 2002-2019, 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 interface to external package PRIMME.\n\n"
     12:   "The command line options are:\n"
     13:   "  -m <m>, where <m> = matrix rows.\n"
     14:   "  -n <n>, where <n> = matrix columns (defaults to m+2).\n\n";

     16: #include <slepcsvd.h>

     18: /*
     19:    This example computes the singular values of a rectangular bidiagonal matrix

     21:               |  1  2                     |
     22:               |     1  2                  |
     23:               |        1  2               |
     24:           A = |          .  .             |
     25:               |             .  .          |
     26:               |                1  2       |
     27:               |                   1  2    |
     28:  */

     30: int main(int argc,char **argv)
     31: {
     32:   Mat             A;
     33:   SVD             svd;
     34:   PetscInt        m=20,n,Istart,Iend,i,k=6,col[2],bs;
     35:   PetscScalar     value[] = { 1, 2 };
     36:   PetscBool       flg;
     37:   SVDPRIMMEMethod meth;
     38:   PetscErrorCode  ierr;

     40:   SlepcInitialize(&argc,&argv,(char*)0,help);if (ierr) return ierr;
     41:   PetscOptionsGetInt(NULL,NULL,"-m",&m,NULL);
     42:   PetscOptionsGetInt(NULL,NULL,"-n",&n,&flg);
     43:   if (!flg) n=m+2;
     44:   PetscOptionsGetInt(NULL,NULL,"-k",&k,NULL);
     45:   PetscPrintf(PETSC_COMM_WORLD,"\nRectangular bidiagonal matrix, m=%D n=%D\n\n",m,n);

     47:   /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     48:         Generate the matrix
     49:      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */

     51:   MatCreate(PETSC_COMM_WORLD,&A);
     52:   MatSetSizes(A,PETSC_DECIDE,PETSC_DECIDE,m,n);
     53:   MatSetFromOptions(A);
     54:   MatSetUp(A);
     55:   MatGetOwnershipRange(A,&Istart,&Iend);
     56:   for (i=Istart;i<Iend;i++) {
     57:     col[0]=i; col[1]=i+1;
     58:     if (i<n-1) {
     59:       MatSetValues(A,1,&i,2,col,value,INSERT_VALUES);
     60:     } else if (i==n-1) {
     61:       MatSetValue(A,i,col[0],value[0],INSERT_VALUES);
     62:     }
     63:   }
     64:   MatAssemblyBegin(A,MAT_FINAL_ASSEMBLY);
     65:   MatAssemblyEnd(A,MAT_FINAL_ASSEMBLY);

     67:   /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     68:         Compute singular values
     69:      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */

     71:   SVDCreate(PETSC_COMM_WORLD,&svd);
     72:   SVDSetOperator(svd,A);
     73:   SVDSetType(svd,SVDPRIMME);
     74:   SVDPRIMMESetBlockSize(svd,4);
     75:   SVDPRIMMESetMethod(svd,SVD_PRIMME_HYBRID);
     76:   SVDSetFromOptions(svd);

     78:   SVDSolve(svd);
     79:   SVDPRIMMEGetBlockSize(svd,&bs);
     80:   SVDPRIMMEGetMethod(svd,&meth);
     81:   PetscPrintf(PETSC_COMM_WORLD," PRIMME: using block size %D, method %s\n",bs,SVDPRIMMEMethods[meth]);

     83:   /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     84:                     Display solution and clean up
     85:      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
     86:   SVDErrorView(svd,SVD_ERROR_RELATIVE,PETSC_VIEWER_STDOUT_WORLD);
     87:   SVDDestroy(&svd);
     88:   MatDestroy(&A);
     89:   SlepcFinalize();
     90:   return ierr;
     91: }

     93: /*TEST

     95:    build:
     96:       requires: primme

     98:    test:
     99:       suffix: 1
    100:       args: -svd_nsv 4
    101:       requires: primme

    103: TEST*/