Actual source code: ex27.c
1: static char help[] = "Reads a PETSc matrix and vector from a file and solves the normal equations.\n\n";
3: /*
4: Include "petscksp.h" so that we can use KSP solvers. Note that this file
5: automatically includes:
6: petscsys.h - base PETSc routines petscvec.h - vectors
7: petscmat.h - matrices
8: petscis.h - index sets
9: petscpc.h - preconditioners
10: */
11: #include <petscksp.h>
12: #include <petscviewerhdf5.h>
14: static PetscErrorCode VecLoadIfExists_Private(Vec b, PetscViewer fd, PetscBool *has)
15: {
16: PetscBool hdf5 = PETSC_FALSE;
18: PetscFunctionBeginUser;
19: PetscCall(PetscObjectTypeCompare((PetscObject)fd, PETSCVIEWERHDF5, &hdf5));
20: if (hdf5) {
21: #if PetscDefined(HAVE_HDF5)
22: PetscCall(PetscViewerHDF5HasObject(fd, (PetscObject)b, has));
23: if (*has) PetscCall(VecLoad(b, fd));
24: #else
25: SETERRQ(PETSC_COMM_WORLD, PETSC_ERR_SUP, "PETSc must be configured with HDF5 to use this feature");
26: #endif
27: } else {
28: PetscErrorCode ierrp;
29: PetscCall(PetscPushErrorHandler(PetscReturnErrorHandler, NULL));
30: ierrp = VecLoad(b, fd);
31: PetscCall(PetscPopErrorHandler());
32: *has = ierrp ? PETSC_FALSE : PETSC_TRUE;
33: }
34: PetscFunctionReturn(PETSC_SUCCESS);
35: }
37: int main(int argc, char **args)
38: {
39: KSP ksp; /* linear solver context */
40: Mat A, N; /* matrix */
41: Vec x, b, r, Ab, v[2]; /* approx solution, RHS, residual */
42: PetscViewer fd; /* viewer */
43: char file[PETSC_MAX_PATH_LEN] = ""; /* input file name */
44: char file_x0[PETSC_MAX_PATH_LEN] = ""; /* name of input file with initial guess */
45: char A_name[128] = "A", b_name[128] = "b", x0_name[128] = "x0"; /* name of the matrix, RHS and initial guess */
46: KSPType ksptype;
47: PetscBool has;
48: PetscInt its, n, m;
49: PetscReal norm;
50: PetscBool nonzero_guess = PETSC_TRUE;
51: PetscBool solve_normal = PETSC_FALSE;
52: PetscBool solve_augmented = PETSC_FALSE;
53: PetscBool truncate = PETSC_FALSE;
54: PetscBool explicit_transpose = PETSC_FALSE;
55: PetscBool hdf5 = PETSC_FALSE;
56: PetscBool test_custom_layout = PETSC_FALSE;
57: PetscBool sbaij = PETSC_FALSE;
58: PetscMPIInt rank, size;
60: PetscFunctionBeginUser;
61: PetscCall(PetscInitialize(&argc, &args, NULL, help));
62: PetscCallMPI(MPI_Comm_rank(PETSC_COMM_WORLD, &rank));
63: PetscCallMPI(MPI_Comm_size(PETSC_COMM_WORLD, &size));
64: /*
65: Determine files from which we read the linear system
66: (matrix, right-hand side and initial guess vector).
67: */
68: PetscCall(PetscOptionsGetString(NULL, NULL, "-f", file, sizeof(file), NULL));
69: PetscCall(PetscOptionsGetBool(NULL, NULL, "-truncate", &truncate, NULL));
70: if (!truncate) PetscCall(PetscOptionsGetString(NULL, NULL, "-f_x0", file_x0, sizeof(file_x0), NULL));
71: PetscCall(PetscOptionsGetString(NULL, NULL, "-A_name", A_name, sizeof(A_name), NULL));
72: PetscCall(PetscOptionsGetString(NULL, NULL, "-b_name", b_name, sizeof(b_name), NULL));
73: PetscCall(PetscOptionsGetString(NULL, NULL, "-x0_name", x0_name, sizeof(x0_name), NULL));
74: /*
75: Decide whether to solve the original system (-solve_normal 0)
76: or the normal equation (-solve_normal 1).
77: */
78: PetscCall(PetscOptionsGetBool(NULL, NULL, "-solve_normal", &solve_normal, NULL));
79: if (!solve_normal) PetscCall(PetscOptionsGetBool(NULL, NULL, "-solve_augmented", &solve_augmented, NULL));
80: if (solve_augmented) {
81: PetscCall(PetscOptionsGetBool(NULL, NULL, "-explicit_transpose", &explicit_transpose, NULL));
82: PetscCall(PetscOptionsGetBool(NULL, NULL, "-sbaij", &sbaij, NULL));
83: }
84: /*
85: Decide whether to use the HDF5 reader.
86: */
87: PetscCall(PetscOptionsGetBool(NULL, NULL, "-hdf5", &hdf5, NULL));
88: /*
89: Decide whether custom matrix layout will be tested.
90: */
91: PetscCall(PetscOptionsGetBool(NULL, NULL, "-test_custom_layout", &test_custom_layout, NULL));
93: /* -----------------------------------------------------------
94: Beginning of linear solver
95: ----------------------------------------------------------- */
97: /* - - - - - - - - - - - New Stage - - - - - - - - - - - - -
98: Load system
99: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
101: /*
102: Open binary file. Note that we use FILE_MODE_READ to indicate
103: reading from this file.
104: */
105: if (hdf5) {
106: #if PetscDefined(HAVE_HDF5)
107: PetscCall(PetscViewerHDF5Open(PETSC_COMM_WORLD, file, FILE_MODE_READ, &fd));
108: PetscCall(PetscViewerPushFormat(fd, PETSC_VIEWER_HDF5_MAT));
109: #else
110: SETERRQ(PETSC_COMM_WORLD, PETSC_ERR_SUP, "PETSc must be configured with HDF5 to use this feature");
111: #endif
112: } else {
113: PetscCall(PetscViewerBinaryOpen(PETSC_COMM_WORLD, file, FILE_MODE_READ, &fd));
114: }
116: /*
117: Load the matrix.
118: Matrix type is set automatically but you can override it by MatSetType() prior to MatLoad().
119: Do that only if you really insist on the given type.
120: */
121: PetscCall(MatCreate(PETSC_COMM_WORLD, &A));
122: PetscCall(PetscObjectSetName((PetscObject)A, A_name));
123: PetscCall(MatSetFromOptions(A));
124: PetscCall(MatLoad(A, fd));
125: if (truncate) {
126: Mat P, B;
127: PetscInt M, N;
128: PetscCall(MatGetLocalSize(A, &m, &n));
129: PetscCall(MatGetSize(A, &M, &N));
130: PetscCall(MatCreateFromOptions(PETSC_COMM_WORLD, NULL, 1, m, PETSC_DECIDE, M, N / 1.5, &P));
131: PetscCall(MatGetOwnershipRangeColumn(P, &m, &n));
132: for (; m < n; ++m) PetscCall(MatSetValue(P, m, m, 1.0, INSERT_VALUES));
133: PetscCall(MatAssemblyBegin(P, MAT_FINAL_ASSEMBLY));
134: PetscCall(MatAssemblyEnd(P, MAT_FINAL_ASSEMBLY));
135: PetscCall(MatShift(P, 1.0));
136: PetscCall(MatMatMult(A, P, MAT_INITIAL_MATRIX, PETSC_DETERMINE, &B));
137: PetscCall(MatDestroy(&P));
138: PetscCall(MatDestroy(&A));
139: A = B;
140: }
141: if (test_custom_layout && size > 1) {
142: /* Perturb the local sizes and create the matrix anew */
143: PetscInt m1, n1;
144: PetscCall(MatGetLocalSize(A, &m, &n));
145: m = rank ? m - 1 : m + size - 1;
146: n = (rank == size - 1) ? n + size - 1 : n - 1;
147: PetscCall(MatDestroy(&A));
148: PetscCall(MatCreate(PETSC_COMM_WORLD, &A));
149: PetscCall(PetscObjectSetName((PetscObject)A, A_name));
150: PetscCall(MatSetSizes(A, m, n, PETSC_DECIDE, PETSC_DECIDE));
151: PetscCall(MatSetFromOptions(A));
152: PetscCall(MatLoad(A, fd));
153: PetscCall(MatGetLocalSize(A, &m1, &n1));
154: PetscCheck(m1 == m && n1 == n, PETSC_COMM_WORLD, PETSC_ERR_PLIB, "resulting sizes differ from requested ones: %" PetscInt_FMT " %" PetscInt_FMT " != %" PetscInt_FMT " %" PetscInt_FMT, m1, n1, m, n);
155: }
156: PetscCall(MatGetLocalSize(A, &m, &n));
158: /*
159: Load the RHS vector if it is present in the file, otherwise use a vector of all ones.
160: */
161: PetscCall(MatCreateVecs(A, &x, &b));
162: PetscCall(PetscObjectSetName((PetscObject)b, b_name));
163: PetscCall(VecSetFromOptions(b));
164: PetscCall(VecLoadIfExists_Private(b, fd, &has));
165: if (!has) {
166: PetscScalar one = 1.0;
167: PetscCall(PetscPrintf(PETSC_COMM_WORLD, "Failed to load RHS, so use a vector of all ones.\n"));
168: PetscCall(VecSetFromOptions(b));
169: PetscCall(VecSet(b, one));
170: }
172: /*
173: Load the initial guess vector if it is present in the file, otherwise use a vector of all zeros.
174: */
175: PetscCall(PetscObjectSetName((PetscObject)x, x0_name));
176: PetscCall(VecSetFromOptions(x));
177: if (!truncate) {
178: /* load file_x0 if it is specified, otherwise try to reuse file */
179: if (file_x0[0]) {
180: PetscCall(PetscViewerDestroy(&fd));
181: if (hdf5) {
182: #if PetscDefined(HAVE_HDF5)
183: PetscCall(PetscViewerHDF5Open(PETSC_COMM_WORLD, file_x0, FILE_MODE_READ, &fd));
184: #endif
185: } else {
186: PetscCall(PetscViewerBinaryOpen(PETSC_COMM_WORLD, file_x0, FILE_MODE_READ, &fd));
187: }
188: }
189: PetscCall(VecLoadIfExists_Private(x, fd, &has));
190: } else has = PETSC_FALSE;
191: if (truncate || !has) {
192: PetscCall(PetscPrintf(PETSC_COMM_WORLD, "Failed to load initial guess, so use a vector of all zeros.\n"));
193: PetscCall(VecSet(x, 0.0));
194: nonzero_guess = PETSC_FALSE;
195: }
196: PetscCall(PetscViewerDestroy(&fd));
198: PetscCall(VecDuplicate(x, &Ab));
200: /* - - - - - - - - - - - New Stage - - - - - - - - - - - - -
201: Setup solve for system
202: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
204: PetscCall(MatCreateNormalHermitian(A, &N));
205: PetscCall(MatMultHermitianTranspose(A, b, Ab));
207: /*
208: Create linear solver; set operators; set runtime options.
209: */
210: PetscCall(KSPCreate(PETSC_COMM_WORLD, &ksp));
212: if (solve_normal) {
213: PetscCall(KSPSetOperators(ksp, N, N));
214: } else if (solve_augmented) {
215: Mat array[4], C, S;
216: Vec view;
217: PetscInt M, n;
218: PetscReal diag;
220: PetscCall(MatDestroy(&N));
221: PetscCall(MatGetSize(A, &M, NULL));
222: PetscCall(MatGetLocalSize(A, NULL, &n));
223: PetscCall(MatCreateConstantDiagonal(PETSC_COMM_WORLD, m, m, M, M, -1.0, array));
224: array[1] = A;
225: if (!explicit_transpose) PetscCall(MatCreateHermitianTranspose(A, array + 2));
226: else PetscCall(MatHermitianTranspose(A, MAT_INITIAL_MATRIX, array + 2));
227: PetscCall(PetscOptionsGetReal(NULL, NULL, "-nonzero_A11", &diag, &has));
228: if (has) PetscCall(MatCreateConstantDiagonal(PETSC_COMM_WORLD, n, n, PETSC_DECIDE, PETSC_DECIDE, diag, array + 3));
229: else array[3] = NULL;
230: PetscCall(MatCreateNest(PETSC_COMM_WORLD, 2, NULL, 2, NULL, array, &C));
231: if (!sbaij) PetscCall(MatNestSetVecType(C, VECNEST));
232: PetscCall(MatCreateVecs(C, v + 1, v));
233: if (!sbaij) {
234: PetscCall(VecNestGetSubVec(v[0], 0, &view));
235: PetscCall(VecCopy(b, view));
236: PetscCall(VecNestGetSubVec(v[1], 1, &view));
237: PetscCall(VecCopy(x, view));
238: PetscCall(KSPSetOperators(ksp, C, C));
239: } else {
240: const PetscScalar *read;
241: PetscScalar *write;
242: PetscCall(VecGetArrayRead(b, &read));
243: PetscCall(VecGetArrayWrite(v[0], &write));
244: for (PetscInt i = 0; i < m; ++i) write[i] = read[i];
245: PetscCall(VecRestoreArrayWrite(v[0], &write));
246: PetscCall(VecRestoreArrayRead(b, &read));
247: PetscCall(VecGetArrayRead(x, &read));
248: PetscCall(VecGetArrayWrite(v[1], &write));
249: for (PetscInt i = 0; i < n; ++i) write[m + i] = read[i];
250: PetscCall(VecRestoreArrayWrite(v[1], &write));
251: PetscCall(VecRestoreArrayRead(x, &read));
252: PetscCall(MatConvert(C, MATSBAIJ, MAT_INITIAL_MATRIX, &S));
253: PetscCall(KSPSetOperators(ksp, S, S));
254: PetscCall(MatDestroy(&S));
255: }
256: PetscCall(MatDestroy(&C));
257: PetscCall(MatDestroy(array));
258: PetscCall(MatDestroy(array + 2));
259: PetscCall(MatDestroy(array + 3));
260: } else {
261: PC pc;
262: PetscCall(KSPSetType(ksp, KSPLSQR));
263: PetscCall(KSPGetPC(ksp, &pc));
264: PetscCall(PCSetType(pc, PCNONE));
265: PetscCall(KSPSetOperators(ksp, A, N));
266: }
267: PetscCall(KSPSetInitialGuessNonzero(ksp, nonzero_guess));
268: PetscCall(KSPSetFromOptions(ksp));
270: /*
271: Here we explicitly call KSPSetUp() and KSPSetUpOnBlocks() to
272: enable more precise profiling of setting up the preconditioner.
273: These calls are optional, since both will be called within
274: KSPSolve() if they haven't been called already.
275: */
276: PetscCall(KSPSetUp(ksp));
277: PetscCall(KSPSetUpOnBlocks(ksp));
279: /*
280: Solve system
281: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
283: /*
284: Solve linear system
285: */
286: if (solve_normal) {
287: PetscCall(KSPSolve(ksp, Ab, x));
288: } else if (solve_augmented) {
289: KSP *subksp;
290: PC pc;
291: Mat C;
292: Vec view;
293: PetscBool flg;
295: PetscCall(KSPGetPC(ksp, &pc));
296: PetscCall(PetscObjectTypeCompare((PetscObject)pc, PCFIELDSPLIT, &flg));
297: if (flg) {
298: PetscCall(KSPGetOperators(ksp, &C, NULL));
299: PetscCall(PCFieldSplitGetSubKSP(pc, NULL, &subksp));
300: PetscCall(KSPGetPC(subksp[1], &pc));
301: PetscCall(PetscObjectTypeCompare((PetscObject)pc, PCHPDDM, &flg));
302: if (flg) {
303: #if PetscDefined(HAVE_HPDDM) && PetscDefined(HAVE_DYNAMIC_LIBRARIES) && PetscDefined(USE_SHARED_LIBRARIES)
304: Mat aux, S, **array;
305: IS is;
307: PetscCall(MatCreate(PETSC_COMM_SELF, &aux));
308: PetscCall(ISCreate(PETSC_COMM_SELF, &is));
309: PetscCall(PCHPDDMSetAuxiliaryMat(pc, is, aux, NULL, NULL)); /* dummy objects just to cover corner cases in PCSetUp() */
310: PetscCall(ISDestroy(&is));
311: PetscCall(MatDestroy(&aux));
312: PetscCall(MatNestGetSubMats(C, NULL, NULL, &array));
313: PetscCall(MatCreateSchurComplement(array[0][0], array[0][0], array[0][1], array[1][0], array[1][1], &S));
314: PetscCall(MatSetOptionsPrefix(S, "fieldsplit_1_"));
315: PetscCall(KSPSetOperators(subksp[1], S, S));
316: PetscCall(MatDestroy(&S));
317: PetscCall(PCSetFromOptions(pc));
318: #endif
319: }
320: PetscCall(PetscFree(subksp));
321: }
322: PetscCall(KSPSolve(ksp, v[0], v[1]));
323: if (!sbaij) {
324: PetscCall(VecNestGetSubVec(v[1], 1, &view));
325: PetscCall(VecCopy(view, x));
326: } else {
327: const PetscScalar *read;
328: PetscScalar *write;
329: PetscCall(MatGetLocalSize(A, &m, &n));
330: PetscCall(VecGetArrayRead(v[1], &read));
331: PetscCall(VecGetArrayWrite(x, &write));
332: for (PetscInt i = 0; i < n; ++i) write[i] = read[m + i];
333: PetscCall(VecRestoreArrayWrite(x, &write));
334: PetscCall(VecRestoreArrayRead(v[1], &read));
335: }
336: } else {
337: PetscCall(KSPSolve(ksp, b, x));
338: }
339: PetscCall(PetscObjectSetName((PetscObject)x, "x"));
341: /* - - - - - - - - - - - New Stage - - - - - - - - - - - - -
342: Check error, print output, free data structures.
343: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
345: /*
346: Check error
347: */
348: PetscCall(VecDuplicate(b, &r));
349: PetscCall(MatMult(A, x, r));
350: PetscCall(VecAXPY(r, -1.0, b));
351: PetscCall(VecNorm(r, NORM_2, &norm));
352: PetscCall(KSPGetIterationNumber(ksp, &its));
353: PetscCall(KSPGetType(ksp, &ksptype));
354: PetscCall(PetscPrintf(PETSC_COMM_WORLD, "KSP type: %s\n", ksptype));
355: PetscCall(PetscPrintf(PETSC_COMM_WORLD, "Number of iterations = %3" PetscInt_FMT "\n", its));
356: PetscCall(PetscPrintf(PETSC_COMM_WORLD, "Residual norm %g\n", (double)norm));
358: /*
359: Free work space. All PETSc objects should be destroyed when they
360: are no longer needed.
361: */
362: PetscCall(MatDestroy(&A));
363: PetscCall(VecDestroy(&b));
364: PetscCall(MatDestroy(&N));
365: PetscCall(VecDestroy(&Ab));
366: PetscCall(VecDestroy(&r));
367: PetscCall(VecDestroy(&x));
368: if (solve_augmented) {
369: PetscCall(VecDestroy(v));
370: PetscCall(VecDestroy(v + 1));
371: }
372: PetscCall(KSPDestroy(&ksp));
373: PetscCall(PetscFinalize());
374: return 0;
375: }
377: /*TEST
379: test:
380: suffix: 1
381: requires: datafilespath double !complex !defined(PETSC_USE_64BIT_INDICES)
382: args: -f ${DATAFILESPATH}/matrices/medium -ksp_view -ksp_monitor -ksp_max_it 100 -solve_normal
384: test:
385: suffix: 2
386: nsize: 2
387: requires: datafilespath double !complex !defined(PETSC_USE_64BIT_INDICES)
388: args: -f ${DATAFILESPATH}/matrices/shallow_water1 -ksp_view -ksp_monitor -ksp_max_it 100 -solve_normal -pc_type none
390: # Test handling failing VecLoad without abort
391: testset:
392: requires: double !complex !defined(PETSC_USE_64BIT_INDICES)
393: args: -ksp_type cg -ksp_view -ksp_converged_reason -ksp_monitor -ksp_max_it 10
394: test:
395: suffix: 3
396: nsize: {{1 2}separate output}
397: args: -f ${wPETSC_DIR}/share/petsc/datafiles/matrices/tiny_system
398: args: -f_x0 ${wPETSC_DIR}/share/petsc/datafiles/matrices/tiny_system_x0
399: test:
400: suffix: 3a
401: nsize: {{1 2}separate output}
402: args: -f ${wPETSC_DIR}/share/petsc/datafiles/matrices/tiny_system
403: args: -f_x0 NONEXISTING_FILE
404: test:
405: suffix: 3b
406: nsize: {{1 2}separate output}
407: args: -f ${wPETSC_DIR}/share/petsc/datafiles/matrices/tiny_system_with_x0 # this file includes all A, b and x0
408: test:
409: # Load square matrix, RHS and initial guess from HDF5 (Version 7.3 MAT-File)
410: suffix: 3b_hdf5
411: requires: hdf5 defined(PETSC_HDF5_HAVE_ZLIB)
412: nsize: {{1 2}separate output}
413: args: -f ${wPETSC_DIR}/share/petsc/datafiles/matrices/tiny_system_with_x0.mat -hdf5
415: # Test least-square algorithms
416: testset:
417: requires: datafilespath double !complex !defined(PETSC_USE_64BIT_INDICES)
418: args: -f ${DATAFILESPATH}/matrices/rectangular_ultrasound_4889x841
419: test:
420: suffix: 4
421: nsize: {{1 2 4}}
422: args: -ksp_converged_reason -ksp_monitor -ksp_rtol 1e-5 -ksp_max_it 100
423: args: -solve_normal -ksp_type cg
424: test:
425: suffix: 4a
426: nsize: {{1 2 4}}
427: args: -ksp_converged_reason -ksp_monitor -ksp_rtol 1e-5 -ksp_max_it 100
428: args: -ksp_type {{cgls lsqr}separate output}
429: test:
430: # Test KSPLSQR-specific options
431: suffix: 4b
432: nsize: 2
433: args: -ksp_converged_reason -ksp_rtol 1e-3 -ksp_max_it 200 -ksp_view
434: args: -ksp_type lsqr -ksp_convergence_test lsqr -ksp_lsqr_monitor -ksp_lsqr_compute_standard_error -ksp_lsqr_exact_mat_norm {{0 1}separate output}
435: test:
436: suffix: 4c
437: nsize: 4
438: requires: hpddm slepc defined(PETSC_HAVE_DYNAMIC_LIBRARIES) defined(PETSC_USE_SHARED_LIBRARIES)
439: filter: grep -v "shared subdomain KSP between SLEPc and PETSc" | grep -v "total: nonzeros="
440: args: -ksp_converged_reason -ksp_rtol 1e-5 -ksp_max_it 100 -ksp_view
441: args: -ksp_type lsqr -pc_type hpddm -pc_hpddm_define_subdomains -pc_hpddm_levels_1_eps_nev 20 -pc_hpddm_levels_1_st_share_sub_ksp {{false true}shared output}
442: args: -pc_hpddm_levels_1_pc_asm_sub_mat_type aij -pc_hpddm_levels_1_pc_asm_type basic -pc_hpddm_levels_1_sub_pc_type cholesky
443: test:
444: suffix: 4d
445: nsize: 4
446: requires: hpddm slepc suitesparse defined(PETSC_HAVE_DYNAMIC_LIBRARIES) defined(PETSC_USE_SHARED_LIBRARIES)
447: filter: grep -v "shared subdomain KSP between SLEPc and PETSc"
448: args: -ksp_converged_reason -ksp_rtol 1e-5 -ksp_max_it 100 -ksp_view
449: args: -ksp_type lsqr -pc_type hpddm -pc_hpddm_define_subdomains -pc_hpddm_levels_1_eps_nev 20 -pc_hpddm_levels_1_st_share_sub_ksp {{false true}shared output} -pc_hpddm_levels_1_st_pc_type qr
450: args: -pc_hpddm_levels_1_pc_asm_sub_mat_type normalh -pc_hpddm_levels_1_pc_asm_type basic -pc_hpddm_levels_1_sub_pc_type qr
451: test:
452: suffix: 4e
453: nsize: 4
454: requires: hpddm slepc defined(PETSC_HAVE_DYNAMIC_LIBRARIES) defined(PETSC_USE_SHARED_LIBRARIES)
455: args: -solve_augmented -ksp_type gmres
456: args: -pc_type fieldsplit -pc_fieldsplit_type schur -pc_fieldsplit_schur_precondition self -fieldsplit_0_pc_type jacobi -fieldsplit_ksp_type preonly
457: args: -prefix_push fieldsplit_1_ -pc_type hpddm -pc_hpddm_schur_precondition least_squares -pc_hpddm_define_subdomains -pc_hpddm_levels_1_eps_nev 20 -pc_hpddm_levels_1_st_share_sub_ksp -pc_hpddm_levels_1_sub_pc_type cholesky -prefix_pop -fieldsplit_1_mat_schur_complement_ainv_type {{lump blockdiag}shared output}
458: test:
459: suffix: 4f
460: nsize: 4
461: requires: hpddm slepc suitesparse defined(PETSC_HAVE_DYNAMIC_LIBRARIES) defined(PETSC_USE_SHARED_LIBRARIES)
462: filter: sed -e "s/(1,0) : type=mpiaij/(1,0) : type=transpose/g" -e "s/hermitiantranspose/transpose/g"
463: args: -solve_augmented -ksp_type gmres -ksp_view -explicit_transpose {{false true}shared output}
464: args: -pc_type fieldsplit -pc_fieldsplit_type schur -pc_fieldsplit_schur_precondition self -fieldsplit_0_pc_type jacobi -fieldsplit_ksp_type preonly
465: args: -prefix_push fieldsplit_1_ -pc_type hpddm -pc_hpddm_schur_precondition least_squares -pc_hpddm_define_subdomains -pc_hpddm_levels_1_eps_nev 20 -pc_hpddm_levels_1_st_share_sub_ksp -pc_hpddm_levels_1_sub_pc_type qr -prefix_pop
466: test:
467: suffix: 4f_nonzero
468: nsize: 4
469: requires: hpddm slepc suitesparse defined(PETSC_HAVE_DYNAMIC_LIBRARIES) defined(PETSC_USE_SHARED_LIBRARIES)
470: args: -solve_augmented -nonzero_A11 {{0.0 1e-14}shared output} -ksp_type gmres
471: args: -pc_type fieldsplit -pc_fieldsplit_type schur -pc_fieldsplit_schur_precondition self -fieldsplit_0_pc_type jacobi -fieldsplit_ksp_type preonly
472: args: -prefix_push fieldsplit_1_ -pc_type hpddm -pc_hpddm_schur_precondition least_squares -pc_hpddm_define_subdomains -pc_hpddm_levels_1_eps_nev 20 -pc_hpddm_levels_1_st_share_sub_ksp -pc_hpddm_levels_1_sub_pc_type qr -prefix_pop
473: test:
474: suffix: 4f_nonzero_shift
475: nsize: 4
476: output_file: output/ex27_4f_nonzero.out
477: requires: hpddm slepc defined(PETSC_HAVE_DYNAMIC_LIBRARIES) defined(PETSC_USE_SHARED_LIBRARIES)
478: args: -solve_augmented -nonzero_A11 {{0.0 1e-6}shared output} -ksp_type gmres
479: args: -pc_type fieldsplit -pc_fieldsplit_type schur -pc_fieldsplit_schur_precondition self -fieldsplit_0_pc_type jacobi -fieldsplit_ksp_type preonly
480: args: -prefix_push fieldsplit_1_ -pc_type hpddm -pc_hpddm_schur_precondition least_squares -pc_hpddm_define_subdomains -pc_hpddm_levels_1_eps_nev 20 -pc_hpddm_levels_1_st_share_sub_ksp -pc_hpddm_levels_1_sub_pc_type cholesky -pc_hpddm_levels_1_eps_gen_non_hermitian -prefix_pop
481: test:
482: suffix: 4g
483: nsize: 4
484: requires: hypre !defined(PETSC_HAVE_HYPRE_DEVICE)
485: args: -ksp_converged_reason -ksp_monitor -ksp_rtol 1e-5 -ksp_max_it 100
486: args: -ksp_type lsqr -pc_type hypre
487: test:
488: suffix: 4h
489: nsize: {{1 4}}
490: args: -solve_augmented -pc_type fieldsplit -pc_fieldsplit_type schur -pc_fieldsplit_schur_precondition self -pc_fieldsplit_detect_saddle_point -sbaij true -ksp_type fgmres
492: test:
493: # Load rectangular matrix from HDF5 (Version 7.3 MAT-File)
494: suffix: 4a_lsqr_hdf5
495: nsize: {{1 2 4 8}}
496: requires: datafilespath double !complex !defined(PETSC_USE_64BIT_INDICES) hdf5 defined(PETSC_HDF5_HAVE_ZLIB)
497: args: -f ${DATAFILESPATH}/matrices/matlab/rectangular_ultrasound_4889x841.mat -hdf5
498: args: -ksp_converged_reason -ksp_monitor -ksp_rtol 1e-5 -ksp_max_it 100
499: args: -ksp_type lsqr
500: args: -test_custom_layout {{0 1}}
502: # Test for correct cgls convergence reason
503: test:
504: suffix: 5
505: nsize: 1
506: requires: datafilespath double !complex !defined(PETSC_USE_64BIT_INDICES)
507: args: -f ${DATAFILESPATH}/matrices/rectangular_ultrasound_4889x841
508: args: -ksp_converged_reason -ksp_rtol 1e-2 -ksp_max_it 100
509: args: -ksp_type cgls
511: # Load a matrix, RHS and solution from HDF5 (Version 7.3 MAT-File). Test immediate convergence.
512: testset:
513: nsize: {{1 2 4 8}}
514: requires: datafilespath double !complex !defined(PETSC_USE_64BIT_INDICES) hdf5 defined(PETSC_HDF5_HAVE_ZLIB)
515: args: -ksp_converged_reason -ksp_monitor -ksp_rtol 1e-5 -ksp_max_it 10
516: args: -ksp_type lsqr
517: args: -test_custom_layout {{0 1}}
518: args: -hdf5 -x0_name x
519: test:
520: suffix: 6_hdf5
521: args: -f ${DATAFILESPATH}/matrices/matlab/small.mat
522: test:
523: suffix: 6_hdf5_rect
524: args: -f ${DATAFILESPATH}/matrices/matlab/small_rect.mat
525: test:
526: suffix: 6_hdf5_dense
527: args: -f ${DATAFILESPATH}/matrices/matlab/small_dense.mat -mat_type dense
528: test:
529: suffix: 6_hdf5_rect_dense
530: args: -f ${DATAFILESPATH}/matrices/matlab/small_rect_dense.mat -mat_type dense
532: # Test correct handling of local dimensions in PCApply
533: testset:
534: requires: datafilespath double !complex !defined(PETSC_USE_64BIT_INDICES)
535: requires: hdf5 defined(PETSC_HDF5_HAVE_ZLIB)
536: nsize: 3
537: suffix: 7
538: args: -f ${DATAFILESPATH}/matrices/matlab/small.mat -hdf5 -test_custom_layout 1 -ksp_type lsqr -pc_type jacobi
540: # Test complex matrices
541: testset:
542: requires: double complex !defined(PETSC_USE_64BIT_INDICES)
543: args: -f ${wPETSC_DIR}/share/petsc/datafiles/matrices/nh-complex-int32-float64
544: output_file: output/ex27_8.out
545: filter: grep -v "KSP type"
546: test:
547: suffix: 8
548: args: -solve_normal 0 -ksp_type {{lsqr cgls}}
549: test:
550: suffix: 8_normal
551: args: -solve_normal 1 -ksp_type {{cg bicg}}
553: testset:
554: requires: double suitesparse !defined(PETSC_USE_64BIT_INDICES)
555: args: -solve_normal {{0 1}shared output} -pc_type qr
556: output_file: output/ex27_9.out
557: filter: grep -v "KSP type"
558: test:
559: suffix: 9_real
560: requires: !complex
561: args: -f ${wPETSC_DIR}/share/petsc/datafiles/matrices/ns-real-int32-float64
562: test:
563: suffix: 9_complex
564: requires: complex
565: args: -f ${wPETSC_DIR}/share/petsc/datafiles/matrices/nh-complex-int32-float64
567: test:
568: suffix: 10
569: requires: !complex double suitesparse !defined(PETSC_USE_64BIT_INDICES)
570: nsize: 2
571: args: -f ${wPETSC_DIR}/share/petsc/datafiles/matrices/ns-real-int32-float64 -pc_type bjacobi -sub_pc_type qr
573: test:
574: suffix: 11
575: nsize: 4
576: requires: datafilespath double complex !defined(PETSC_USE_64BIT_INDICES) hpddm slepc defined(PETSC_HAVE_DYNAMIC_LIBRARIES) defined(PETSC_USE_SHARED_LIBRARIES)
577: args: -f ${DATAFILESPATH}/matrices/farzad_B_rhs -truncate
578: args: -ksp_converged_reason -ksp_rtol 1e-5 -ksp_max_it 100
579: args: -ksp_type lsqr -pc_type hpddm -pc_hpddm_define_subdomains -pc_hpddm_levels_1_eps_nev 20 -pc_hpddm_levels_1_eps_threshold_absolute 1e-6
580: args: -pc_hpddm_levels_1_pc_asm_sub_mat_type aij -pc_hpddm_levels_1_pc_asm_type basic -pc_hpddm_levels_1_sub_pc_type lu -pc_hpddm_coarse_pc_type lu
581: filter: sed -e "s/ 10/ 9/g"
583: TEST*/