Actual source code: test3.c

slepc-3.11.2 2019-07-30
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 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:       requires: !single
105:       output_file: output/test3_1.out
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:       requires: !single
147:       output_file: output/test3_1.out
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:       test:
185:          suffix: 3_cuda_lanczos
186:          args: -svd_type lanczos
187:       test:
188:          suffix: 3_cuda_lanczos_one
189:          args: -svd_type lanczos -svd_lanczos_oneside
190:       test:
191:          suffix: 3_cuda_trlanczos
192:          args: -svd_type trlanczos
193:       test:
194:          suffix: 3_cuda_trlanczos_one
195:          args: -svd_type trlanczos -svd_trlanczos_oneside
196:       test:
197:          suffix: 3_cuda_trlanczos_one_mgs
198:          args: -svd_type trlanczos -svd_trlanczos_oneside -bv_orthog_type mgs
199:       test:
200:          suffix: 3_cuda_trlanczos_one_always
201:          args: -svd_type trlanczos -svd_trlanczos_oneside -bv_orthog_refine always
202:       test:
203:          suffix: 3_cuda_cross
204:          args: -svd_type cross
205:       test:
206:          suffix: 3_cuda_cyclic
207:          args: -svd_type cyclic
208:       test:
209:          suffix: 3_cuda_cyclic_exp
210:          args: -svd_type cyclic -svd_cyclic_explicitmatrix

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

219: TEST*/