Date: 2021-02-01T14:42:08+00:00

Actual source code: test3.c
slepc-3.14.2 2021-02-01
Report Typos and Errors

      1: /*
      2:    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      3:    SLEPc - Scalable Library for Eigenvalue Problem Computations
      4:    Copyright (c) 2002-2020, 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 user-provided initial vectors.\n\n"
     12:   "The command line options are:\n"
     13:   "  -n <n>, where <n> = row dimension.\n"
     14:   "  -m <m>, where <m> = column dimension.\n\n";

     16: #include <slepcsvd.h>

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

     21:               |  1  1  1  1               |
     22:               | -1  1  1  1  1            |
     23:               |    -1  1  1  1  1         |
     24:           A = |       .  .  .  .  .       |
     25:               |          .  .  .  .  .    |
     26:               |            -1  1  1  1  1 |
     27:               |               -1  1  1  1 |

     29:  */

     31: int main(int argc,char **argv)
     32: {
     33:   Mat            A;               /* Grcar matrix */
     34:   SVD            svd;             /* singular value solver context */
     35:   Vec            v0,w0;           /* initial vectors */
     36:   PetscInt       N=35,M=30,Istart,Iend,i,col[5];
     37:   PetscScalar    value[] = { -1, 1, 1, 1, 1 };

     40:   SlepcInitialize(&argc,&argv,(char*)0,help);if (ierr) return ierr;
     41:   PetscOptionsGetInt(NULL,NULL,"-n",&N,NULL);
     42:   PetscOptionsGetInt(NULL,NULL,"-m",&M,NULL);
     43:   PetscPrintf(PETSC_COMM_WORLD,"\nSVD of a rectangular Grcar matrix, %Dx%D\n\n",N,M);

     45:   /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     46:         Generate the matrix
     47:      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */

     49:   MatCreate(PETSC_COMM_WORLD,&A);
     50:   MatSetSizes(A,PETSC_DECIDE,PETSC_DECIDE,N,M);
     51:   MatSetFromOptions(A);
     52:   MatSetUp(A);

     54:   MatGetOwnershipRange(A,&Istart,&Iend);
     55:   for (i=Istart;i<Iend;i++) {
     56:     col[0]=i-1; col[1]=i; col[2]=i+1; col[3]=i+2; col[4]=i+3;
     57:     if (i==0) {
     58:       MatSetValues(A,1,&i,PetscMin(4,M-i+1),col+1,value+1,INSERT_VALUES);
     59:     } else {
     60:       MatSetValues(A,1,&i,PetscMin(5,M-i+1),col,value,INSERT_VALUES);
     61:     }
     62:   }
     63:   MatAssemblyBegin(A,MAT_FINAL_ASSEMBLY);
     64:   MatAssemblyEnd(A,MAT_FINAL_ASSEMBLY);

     66:   /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     67:              Create the SVD context and solve the problem
     68:      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */

     70:   SVDCreate(PETSC_COMM_WORLD,&svd);
     71:   SVDSetOperator(svd,A);
     72:   SVDSetFromOptions(svd);

     74:   /*
     75:      Set the initial vectors. This is optional, if not done the initial
     76:      vectors are set to random values
     77:   */
     78:   MatCreateVecs(A,&v0,&w0);
     79:   VecSet(v0,1.0);
     80:   VecSet(w0,1.0);
     81:   SVDSetInitialSpaces(svd,1,&v0,1,&w0);

     83:   /*
     84:      Compute solution
     85:   */
     86:   SVDSolve(svd);
     87:   SVDErrorView(svd,SVD_ERROR_RELATIVE,NULL);

     89:   /*
     90:      Free work space
     91:   */
     92:   VecDestroy(&v0);
     93:   VecDestroy(&w0);
     94:   SVDDestroy(&svd);
     95:   MatDestroy(&A);
     96:   SlepcFinalize();
     97:   return ierr;
     98: }

    100: /*TEST

    102:    testset:
    103:       args: -svd_nsv 4
    104:       output_file: output/test3_1.out
    105:       filter: sed -e "s/22176/22175/" | sed -e "s/21798/21797/" | sed -e "s/16826/16825/" | sed -e "s/15129/15128/"
    106:       test:
    107:          suffix: 1_lanczos
    108:          args: -svd_type lanczos
    109:       test:
    110:          suffix: 1_lanczos_one
    111:          args: -svd_type lanczos -svd_lanczos_oneside
    112:       test:
    113:          suffix: 1_trlanczos
    114:          args: -svd_type trlanczos
    115:       test:
    116:          suffix: 1_trlanczos_one
    117:          args: -svd_type trlanczos -svd_trlanczos_oneside
    118:       test:
    119:          suffix: 1_trlanczos_one_mgs
    120:          args: -svd_type trlanczos -svd_trlanczos_oneside -bv_orthog_type mgs
    121:       test:
    122:          suffix: 1_trlanczos_one_always
    123:          args: -svd_type trlanczos -svd_trlanczos_oneside -bv_orthog_refine always
    124:       test:
    125:          suffix: 1_cross
    126:          args: -svd_type cross
    127:       test:
    128:          suffix: 1_cross_exp
    129:          args: -svd_type cross -svd_cross_explicitmatrix
    130:       test:
    131:          suffix: 1_cyclic
    132:          args: -svd_type cyclic
    133:       test:
    134:          suffix: 1_cyclic_exp
    135:          args: -svd_type cyclic -svd_cyclic_explicitmatrix
    136:       test:
    137:          suffix: 1_lapack
    138:          args: -svd_type lapack
    139:       test:
    140:          suffix: 1_primme
    141:          args: -svd_type primme
    142:          requires: primme

    144:    testset:
    145:       args: -svd_implicittranspose -svd_nsv 4 -svd_tol 1e-5
    146:       output_file: output/test3_1.out
    147:       filter: sed -e "s/22176/22175/" | sed -e "s/21798/21797/" | sed -e "s/16826/16825/" | sed -e "s/15129/15128/"
    148:       test:
    149:          suffix: 2_lanczos
    150:          args: -svd_type lanczos
    151:       test:
    152:          suffix: 2_lanczos_one
    153:          args: -svd_type lanczos -svd_lanczos_oneside
    154:       test:
    155:          suffix: 2_trlanczos
    156:          args: -svd_type trlanczos
    157:       test:
    158:          suffix: 2_trlanczos_one
    159:          args: -svd_type trlanczos -svd_trlanczos_oneside
    160:       test:
    161:          suffix: 2_trlanczos_one_mgs
    162:          args: -svd_type trlanczos -svd_trlanczos_oneside -bv_orthog_type mgs
    163:       test:
    164:          suffix: 2_trlanczos_one_always
    165:          args: -svd_type trlanczos -svd_trlanczos_oneside -bv_orthog_refine always
    166:       test:
    167:          suffix: 2_cross
    168:          args: -svd_type cross
    169:       test:
    170:          suffix: 2_cross_exp
    171:          args: -svd_type cross -svd_cross_explicitmatrix
    172:          requires: !complex
    173:       test:
    174:          suffix: 2_cyclic
    175:          args: -svd_type cyclic
    176:       test:
    177:          suffix: 2_lapack
    178:          args: -svd_type lapack

    180:    testset:
    181:       args: -svd_nsv 4 -mat_type aijcusparse
    182:       requires: cuda
    183:       output_file: output/test3_1.out
    184:       filter: sed -e "s/22176/22175/" | sed -e "s/21798/21797/" | sed -e "s/16826/16825/" | sed -e "s/15129/15128/"
    185:       test:
    186:          suffix: 3_cuda_lanczos
    187:          args: -svd_type lanczos
    188:       test:
    189:          suffix: 3_cuda_lanczos_one
    190:          args: -svd_type lanczos -svd_lanczos_oneside
    191:       test:
    192:          suffix: 3_cuda_trlanczos
    193:          args: -svd_type trlanczos
    194:       test:
    195:          suffix: 3_cuda_trlanczos_one
    196:          args: -svd_type trlanczos -svd_trlanczos_oneside
    197:       test:
    198:          suffix: 3_cuda_trlanczos_one_mgs
    199:          args: -svd_type trlanczos -svd_trlanczos_oneside -bv_orthog_type mgs
    200:       test:
    201:          suffix: 3_cuda_trlanczos_one_always
    202:          args: -svd_type trlanczos -svd_trlanczos_oneside -bv_orthog_refine always
    203:       test:
    204:          suffix: 3_cuda_cross
    205:          args: -svd_type cross
    206:       test:
    207:          suffix: 3_cuda_cyclic
    208:          args: -svd_type cyclic
    209:       test:
    210:          suffix: 3_cuda_cyclic_exp
    211:          args: -svd_type cyclic -svd_cyclic_explicitmatrix

    213:    test:
    214:       suffix: 4
    215:       args: -svd_type lapack -svd_nsv 4
    216:       output_file: output/test3_1.out
    217:       nsize: 2

    219:    test:
    220:       suffix: 5
    221:       args: -svd_nsv 4 -svd_view_values draw -svd_monitor_lg
    222:       requires: x
    223:       output_file: output/test3_1.out

    225: TEST*/