Actual source code: ex26.c
1: static char help[] = "Solves Laplacian with multigrid. Tests block API for PCMG\n\
2: -mx <xg>, where <xg> = number of grid points in the x-direction\n\
3: -my <yg>, where <yg> = number of grid points in the y-direction\n\
4: -Nx <npx>, where <npx> = number of processors in the x-direction\n\
5: -Ny <npy>, where <npy> = number of processors in the y-direction\n\n";
7: /* Modified from ~src/ksp/tests/ex19.c. Used for testing ML 6.2 interface.
9: This problem is modeled by
10: the partial differential equation
12: -Laplacian u = g, 0 < x,y < 1,
14: with boundary conditions
16: u = 0 for x = 0, x = 1, y = 0, y = 1.
18: A finite difference approximation with the usual 5-point stencil
19: is used to discretize the boundary value problem to obtain a linear
20: system of equations.
22: Usage: ./ex26 -ksp_monitor -pc_type ml
23: -mg_coarse_ksp_max_it 10
24: -mg_levels_1_ksp_max_it 10 -mg_levels_2_ksp_max_it 10
25: -mg_fine_ksp_max_it 10
26: */
28: #include <petscksp.h>
29: #include <petscdm.h>
30: #include <petscdmda.h>
32: /* User-defined application contexts */
33: typedef struct {
34: PetscInt mx, my; /* number grid points in x and y direction */
35: Vec localX, localF; /* local vectors with ghost region */
36: DM da;
37: Vec x, b, r; /* global vectors */
38: Mat J; /* Jacobian on grid */
39: Mat A, P, R;
40: KSP ksp;
41: } GridCtx;
43: static PetscErrorCode FormJacobian_Grid(GridCtx *, Mat);
45: /* Copies A into a new dense matrix of the same type, VecType, and layout, stored with a leading dimension larger by shift */
46: static PetscErrorCode DuplicateWithLDA(Mat A, PetscInt shift, Mat *B)
47: {
48: MatType type;
49: VecType vtype;
50: PetscInt m, n, M, N;
52: PetscFunctionBeginUser;
53: PetscCall(MatGetType(A, &type));
54: PetscCall(MatGetVecType(A, &vtype));
55: PetscCall(MatGetLocalSize(A, &m, &n));
56: PetscCall(MatGetSize(A, &M, &N));
57: PetscCall(MatCreate(PetscObjectComm((PetscObject)A), B));
58: PetscCall(MatSetSizes(*B, m, n, M, N));
59: PetscCall(MatSetType(*B, type));
60: PetscCall(MatSetVecType(*B, vtype));
61: PetscCall(MatDenseSetLDA(*B, m + shift));
62: PetscCall(MatSetUp(*B));
63: PetscCall(MatCopy(A, *B, SAME_NONZERO_PATTERN));
64: PetscFunctionReturn(PETSC_SUCCESS);
65: }
67: int main(int argc, char **argv)
68: {
69: PetscInt i, its, Nx = PETSC_DECIDE, Ny = PETSC_DECIDE, nlocal, nrhs = 1, lda_shift = 0;
70: PetscScalar one = 1.0;
71: Mat A, P = NULL, B, X;
72: GridCtx fine_ctx;
73: KSP ksp;
74: PetscBool Brand = PETSC_FALSE, transpose = PETSC_FALSE, product = PETSC_FALSE, new_pattern = PETSC_FALSE, new_interpolation = PETSC_FALSE, check_copies = PETSC_FALSE, check_references = PETSC_FALSE, flg;
76: PetscFunctionBeginUser;
77: PetscCall(PetscInitialize(&argc, &argv, NULL, help));
78: /* set up discretization matrix for fine grid */
79: fine_ctx.mx = 9;
80: fine_ctx.my = 9;
81: PetscCall(PetscOptionsGetInt(NULL, NULL, "-mx", &fine_ctx.mx, NULL));
82: PetscCall(PetscOptionsGetInt(NULL, NULL, "-my", &fine_ctx.my, NULL));
83: PetscCall(PetscOptionsGetInt(NULL, NULL, "-nrhs", &nrhs, NULL));
84: PetscCall(PetscOptionsGetInt(NULL, NULL, "-Nx", &Nx, NULL));
85: PetscCall(PetscOptionsGetInt(NULL, NULL, "-Ny", &Ny, NULL));
86: PetscCall(PetscOptionsGetBool(NULL, NULL, "-rand", &Brand, NULL));
87: PetscCall(PetscOptionsGetBool(NULL, NULL, "-transpose", &transpose, NULL));
88: PetscCall(PetscOptionsGetBool(NULL, NULL, "-product_into_solution", &product, NULL));
89: PetscCall(PetscOptionsGetInt(NULL, NULL, "-lda_shift", &lda_shift, NULL));
90: PetscCall(PetscOptionsGetBool(NULL, NULL, "-new_pattern", &new_pattern, NULL));
91: PetscCall(PetscOptionsGetBool(NULL, NULL, "-new_interpolation", &new_interpolation, NULL));
92: PetscCall(PetscOptionsGetBool(NULL, NULL, "-check_copies", &check_copies, NULL));
93: PetscCall(PetscOptionsGetBool(NULL, NULL, "-check_references", &check_references, NULL));
94: if (check_copies) PetscCall(PetscLogDefaultBegin());
95: PetscCall(PetscPrintf(PETSC_COMM_WORLD, "Fine grid size %" PetscInt_FMT " by %" PetscInt_FMT "\n", fine_ctx.mx, fine_ctx.my));
97: /* Set up distributed array for fine grid */
98: PetscCall(DMDACreate2d(PETSC_COMM_WORLD, DM_BOUNDARY_NONE, DM_BOUNDARY_NONE, DMDA_STENCIL_STAR, fine_ctx.mx, fine_ctx.my, Nx, Ny, 1, 1, NULL, NULL, &fine_ctx.da));
99: PetscCall(DMSetFromOptions(fine_ctx.da));
100: PetscCall(DMSetUp(fine_ctx.da));
101: PetscCall(DMCreateGlobalVector(fine_ctx.da, &fine_ctx.x));
102: PetscCall(VecDuplicate(fine_ctx.x, &fine_ctx.b));
103: PetscCall(VecGetLocalSize(fine_ctx.x, &nlocal));
104: PetscCall(DMCreateLocalVector(fine_ctx.da, &fine_ctx.localX));
105: PetscCall(VecDuplicate(fine_ctx.localX, &fine_ctx.localF));
106: PetscCall(DMCreateMatrix(fine_ctx.da, &A));
107: PetscCall(FormJacobian_Grid(&fine_ctx, A));
109: /* create linear solver */
110: PetscCall(KSPCreate(PETSC_COMM_WORLD, &ksp));
111: PetscCall(KSPSetDM(ksp, fine_ctx.da));
112: PetscCall(KSPSetDMActive(ksp, KSP_DMACTIVE_ALL, PETSC_FALSE));
114: /* set values for rhs vector */
115: PetscCall(VecSet(fine_ctx.b, one));
117: /* set options, then solve system */
118: PetscCall(KSPSetFromOptions(ksp)); /* calls PCSetFromOptions_ML if 'pc_type=ml' */
119: /* with -new_pattern the nonzero pattern of A changes after the first solve, while the preconditioner is built from an unchanged copy, so that PCSetUp() is not run again */
120: if (new_pattern) PetscCall(MatDuplicate(A, MAT_COPY_VALUES, &P));
121: PetscCall(KSPSetOperators(ksp, A, new_pattern ? P : A));
122: PetscCall(KSPSolve(ksp, fine_ctx.b, fine_ctx.x));
123: PetscCall(VecViewFromOptions(fine_ctx.x, NULL, "-debug"));
124: PetscCall(KSPGetIterationNumber(ksp, &its));
125: PetscCall(KSPGetIterationNumber(ksp, &its));
126: PetscCall(PetscPrintf(PETSC_COMM_WORLD, "Number of iterations = %" PetscInt_FMT "\n", its));
128: /* test multiple right-hand side */
129: PetscCall(MatCreateDense(PETSC_COMM_WORLD, nlocal, PETSC_DECIDE, fine_ctx.mx * fine_ctx.my, nrhs, NULL, &B));
130: PetscCall(MatSetOptionsPrefix(B, "rhs_"));
131: PetscCall(MatSetFromOptions(B));
132: PetscCall(MatDuplicate(B, MAT_DO_NOT_COPY_VALUES, &X));
133: /* start the -ksp_initial_guess_nonzero runs from a known state, MatDuplicate() zeroing is not guaranteed for all -rhs_mat_type values */
134: PetscCall(MatZeroEntries(X));
135: if (Brand) {
136: PetscCall(MatSetRandom(B, NULL));
137: } else {
138: PetscScalar *b;
140: PetscCall(MatDenseGetArrayWrite(B, &b));
141: for (i = 0; i < nlocal * nrhs; i++) b[i] = 1.0;
142: PetscCall(MatDenseRestoreArrayWrite(B, &b));
143: PetscCall(MatAssemblyBegin(B, MAT_FINAL_ASSEMBLY));
144: PetscCall(MatAssemblyEnd(B, MAT_FINAL_ASSEMBLY));
145: }
146: if (transpose) PetscCall(KSPMatSolveTranspose(ksp, B, X));
147: else PetscCall(KSPMatSolve(ksp, B, X));
148: if (check_copies) { /* the first solve sets the solver up, including the products it keeps, so a second solve with the same blocks runs on the device only */
149: PetscLogEvent event;
151: PetscCall(PetscLogEventRegister("SolveCheck", KSP_CLASSID, &event));
152: PetscCall(PetscLogEventBegin(event, 0, 0, 0, 0));
153: if (transpose) PetscCall(KSPMatSolveTranspose(ksp, B, X));
154: else PetscCall(KSPMatSolve(ksp, B, X));
155: PetscCall(PetscLogEventEnd(event, 0, 0, 0, 0));
156: #if PetscDefined(HAVE_DEVICE)
157: {
158: PetscEventPerfInfo info;
160: PetscCall(PetscLogEventGetPerfInfo(PETSC_DETERMINE, event, &info));
161: PetscCheck(info.GpuToCpuCount == 0 && info.CpuToGpuCount == 0, PETSC_COMM_SELF, PETSC_ERR_PLIB, "Unexpected copies in the second block solve: %g GPU to CPU (%g bytes) and %g CPU to GPU (%g bytes)", info.GpuToCpuCount, info.GpuToCpuSize, info.CpuToGpuCount,
162: info.CpuToGpuSize);
163: }
164: #endif
165: }
166: if (check_references) { /* the solver must not keep the blocks of the caller alive once the solve returns */
167: PetscInt nb, nx;
169: PetscCall(PetscObjectGetReference((PetscObject)B, &nb));
170: PetscCall(PetscObjectGetReference((PetscObject)X, &nx));
171: PetscCheck(nb == 1 && nx == 1, PETSC_COMM_SELF, PETSC_ERR_PLIB, "The solver keeps references to the blocks of the caller: %" PetscInt_FMT " to B and %" PetscInt_FMT " to X", nb, nx);
172: }
173: PetscCall(MatViewFromOptions(X, NULL, "-debug"));
175: PetscCall(PetscObjectTypeCompare((PetscObject)ksp, KSPPREONLY, &flg));
176: if ((flg || nrhs == 1) && !Brand && !transpose) { /* the operator is not symmetric, so KSPMatSolveTranspose() does not return the solution of KSPSolve() */
177: const PetscScalar *xx, *XX;
179: PetscCall(VecGetArrayRead(fine_ctx.x, &xx));
180: PetscCall(MatDenseGetArrayRead(X, &XX));
181: for (PetscInt n = 0; n < nrhs; n++) {
182: for (i = 0; i < nlocal; i++) {
183: if (PetscAbsScalar(xx[i] - XX[nlocal * n + i]) > PETSC_SMALL) {
184: PetscCall(PetscPrintf(PETSC_COMM_SELF, "[%d] Error local solve %" PetscInt_FMT ", entry %" PetscInt_FMT " -> %g + i %g != %g + i %g\n", PetscGlobalRank, n, i, (double)PetscRealPart(xx[i]), (double)PetscImaginaryPart(xx[i]), (double)PetscRealPart(XX[i]), (double)PetscImaginaryPart(XX[i])));
185: }
186: }
187: }
188: PetscCall(MatDenseRestoreArrayRead(X, &XX));
189: PetscCall(VecRestoreArrayRead(fine_ctx.x, &xx));
190: }
192: if (lda_shift > 0) { /* solve again with the same blocks stored with a larger leading dimension, which the solver must handle with what it kept from the first solve */
193: Mat B2, X2;
194: PetscReal norm, err;
196: PetscCall(DuplicateWithLDA(B, lda_shift, &B2));
197: PetscCall(DuplicateWithLDA(X, lda_shift, &X2));
198: PetscCall(MatZeroEntries(X2));
199: if (transpose) PetscCall(KSPMatSolveTranspose(ksp, B2, X2));
200: else PetscCall(KSPMatSolve(ksp, B2, X2));
201: PetscCall(MatNorm(X, NORM_FROBENIUS, &norm));
202: PetscCall(MatAXPY(X2, -1.0, X, SAME_NONZERO_PATTERN));
203: PetscCall(MatNorm(X2, NORM_FROBENIUS, &err));
204: PetscCheck(err <= PETSC_SMALL * norm, PETSC_COMM_WORLD, PETSC_ERR_PLIB, "Solution with a larger leading dimension has error %g relative to %g", (double)err, (double)norm);
205: PetscCall(MatDestroy(&B2));
206: PetscCall(MatDestroy(&X2));
207: }
209: if (new_pattern) { /* solve again after storing an explicit zero at a new location of A, which changes its nonzero pattern and the columns its rows couple to on other processes, but not the solution */
210: Mat X2;
211: PetscInt rstart, M;
212: PetscReal norm, err;
214: PetscCall(MatGetOwnershipRange(A, &rstart, NULL));
215: PetscCall(MatGetSize(A, &M, NULL));
216: PetscCall(MatSetOption(A, MAT_NEW_NONZERO_ALLOCATION_ERR, PETSC_FALSE));
217: PetscCall(MatSetValue(A, rstart, (rstart + M / 2) % M, 0.0, ADD_VALUES));
218: PetscCall(MatAssemblyBegin(A, MAT_FINAL_ASSEMBLY));
219: PetscCall(MatAssemblyEnd(A, MAT_FINAL_ASSEMBLY));
220: PetscCall(MatDuplicate(X, MAT_DO_NOT_COPY_VALUES, &X2));
221: PetscCall(MatZeroEntries(X2));
222: if (transpose) PetscCall(KSPMatSolveTranspose(ksp, B, X2));
223: else PetscCall(KSPMatSolve(ksp, B, X2));
224: PetscCall(MatNorm(X, NORM_FROBENIUS, &norm));
225: PetscCall(MatAXPY(X2, -1.0, X, SAME_NONZERO_PATTERN));
226: PetscCall(MatNorm(X2, NORM_FROBENIUS, &err));
227: PetscCheck(err <= PETSC_SMALL * norm, PETSC_COMM_WORLD, PETSC_ERR_PLIB, "Solution after the change of nonzero pattern has error %g relative to %g", (double)err, (double)norm);
228: PetscCall(MatDestroy(&X2));
229: }
231: if (new_interpolation) { /* solve again after replacing the finest interpolation and restriction by a copy with an explicit zero in a new off-process column */
232: PC pc;
233: Mat Pf, P2, X2;
234: PetscInt nlevels, rstart, cend, N;
235: PetscReal norm, err;
237: PetscCall(KSPGetPC(ksp, &pc));
238: PetscCall(PCMGGetLevels(pc, &nlevels));
239: PetscCall(PCMGGetInterpolation(pc, nlevels - 1, &Pf));
240: PetscCall(MatDuplicate(Pf, MAT_COPY_VALUES, &P2));
241: PetscCall(MatGetOwnershipRange(P2, &rstart, NULL));
242: PetscCall(MatGetOwnershipRangeColumn(P2, NULL, &cend));
243: PetscCall(MatGetSize(P2, NULL, &N));
244: PetscCall(MatSetOption(P2, MAT_NEW_NONZERO_ALLOCATION_ERR, PETSC_FALSE));
245: PetscCall(MatSetValue(P2, rstart, cend < N ? N - 1 : 0, 0.0, ADD_VALUES));
246: PetscCall(MatAssemblyBegin(P2, MAT_FINAL_ASSEMBLY));
247: PetscCall(MatAssemblyEnd(P2, MAT_FINAL_ASSEMBLY));
248: PetscCall(PCMGSetInterpolation(pc, nlevels - 1, P2));
249: PetscCall(PCMGSetRestriction(pc, nlevels - 1, P2));
250: PetscCall(MatDestroy(&P2));
251: PetscCall(MatDuplicate(X, MAT_DO_NOT_COPY_VALUES, &X2));
252: PetscCall(MatZeroEntries(X2));
253: if (transpose) PetscCall(KSPMatSolveTranspose(ksp, B, X2));
254: else PetscCall(KSPMatSolve(ksp, B, X2));
255: PetscCall(MatNorm(X, NORM_FROBENIUS, &norm));
256: PetscCall(MatAXPY(X2, -1.0, X, SAME_NONZERO_PATTERN));
257: PetscCall(MatNorm(X2, NORM_FROBENIUS, &err));
258: PetscCheck(err <= PETSC_SMALL * norm, PETSC_COMM_WORLD, PETSC_ERR_PLIB, "Solution after replacing the interpolation has error %g relative to %g", (double)err, (double)norm);
259: PetscCall(MatDestroy(&X2));
260: }
262: if (product) { /* a dense matrix created by the caller can be the result of MatMatMult() with MAT_REUSE_MATRIX, so the solve must not leave a MatProduct on the block of solutions */
263: Mat C;
264: PetscReal norm, err;
266: PetscCall(MatMatMult(A, B, MAT_INITIAL_MATRIX, PETSC_DETERMINE, &C));
267: PetscCall(MatMatMult(A, B, MAT_REUSE_MATRIX, PETSC_DETERMINE, &X));
268: PetscCall(MatNorm(C, NORM_FROBENIUS, &norm));
269: PetscCall(MatAXPY(C, -1.0, X, SAME_NONZERO_PATTERN));
270: PetscCall(MatNorm(C, NORM_FROBENIUS, &err));
271: PetscCheck(err <= PETSC_SMALL * norm, PETSC_COMM_WORLD, PETSC_ERR_PLIB, "Product into the block of solutions has error %g relative to %g", (double)err, (double)norm);
272: PetscCall(MatDestroy(&C));
273: }
275: /* free data structures */
276: PetscCall(VecDestroy(&fine_ctx.x));
277: PetscCall(VecDestroy(&fine_ctx.b));
278: PetscCall(DMDestroy(&fine_ctx.da));
279: PetscCall(VecDestroy(&fine_ctx.localX));
280: PetscCall(VecDestroy(&fine_ctx.localF));
281: PetscCall(MatDestroy(&A));
282: PetscCall(MatDestroy(&P));
283: PetscCall(MatDestroy(&B));
284: PetscCall(MatDestroy(&X));
285: PetscCall(KSPDestroy(&ksp));
287: PetscCall(PetscFinalize());
288: return 0;
289: }
291: PetscErrorCode FormJacobian_Grid(GridCtx *grid, Mat jac)
292: {
293: PetscInt i, j, row, mx, my, xs, ys, xm, ym, Xs, Ys, Xm, Ym, col[5];
294: PetscInt grow;
295: const PetscInt *ltog;
296: PetscScalar two = 2.0, one = 1.0, v[5], hx, hy, hxdhy, hydhx, value;
297: ISLocalToGlobalMapping ltogm;
299: PetscFunctionBeginUser;
300: mx = grid->mx;
301: my = grid->my;
302: hx = one / (PetscReal)(mx - 1);
303: hy = one / (PetscReal)(my - 1);
304: hxdhy = hx / hy;
305: hydhx = hy / hx;
307: /* Get ghost points */
308: PetscCall(DMDAGetCorners(grid->da, &xs, &ys, NULL, &xm, &ym, NULL));
309: PetscCall(DMDAGetGhostCorners(grid->da, &Xs, &Ys, NULL, &Xm, &Ym, NULL));
310: PetscCall(DMGetLocalToGlobalMapping(grid->da, <ogm));
311: PetscCall(ISLocalToGlobalMappingGetIndices(ltogm, <og));
313: /* Evaluate Jacobian of function */
314: for (j = ys; j < ys + ym; j++) {
315: row = (j - Ys) * Xm + xs - Xs - 1;
316: for (i = xs; i < xs + xm; i++) {
317: row++;
318: grow = ltog[row];
319: if (i > 0 && i < mx - 1 && j > 0 && j < my - 1) {
320: v[0] = -hxdhy;
321: col[0] = ltog[row - Xm];
322: v[1] = -hydhx;
323: col[1] = ltog[row - 1];
324: v[2] = two * (hydhx + hxdhy);
325: col[2] = grow;
326: v[3] = -hydhx;
327: col[3] = ltog[row + 1];
328: v[4] = -hxdhy;
329: col[4] = ltog[row + Xm];
330: PetscCall(MatSetValues(jac, 1, &grow, 5, col, v, INSERT_VALUES));
331: } else if ((i > 0 && i < mx - 1) || (j > 0 && j < my - 1)) {
332: value = .5 * two * (hydhx + hxdhy);
333: PetscCall(MatSetValues(jac, 1, &grow, 1, &grow, &value, INSERT_VALUES));
334: } else {
335: value = .25 * two * (hydhx + hxdhy);
336: PetscCall(MatSetValues(jac, 1, &grow, 1, &grow, &value, INSERT_VALUES));
337: }
338: }
339: }
340: PetscCall(ISLocalToGlobalMappingRestoreIndices(ltogm, <og));
341: PetscCall(MatAssemblyBegin(jac, MAT_FINAL_ASSEMBLY));
342: PetscCall(MatAssemblyEnd(jac, MAT_FINAL_ASSEMBLY));
343: PetscFunctionReturn(PETSC_SUCCESS);
344: }
346: /*TEST
348: test:
349: args: -ksp_monitor
351: test:
352: suffix: 2
353: args: -ksp_monitor
354: nsize: 3
356: test:
357: suffix: ml_1
358: args: -ksp_monitor -pc_type ml -mat_no_inode
359: nsize: 3
360: requires: ml
362: test:
363: suffix: ml_2
364: args: -ksp_monitor -pc_type ml -mat_no_inode -ksp_max_it 3
365: nsize: 3
366: requires: ml
368: test:
369: suffix: ml_3
370: args: -ksp_monitor -pc_type ml -mat_no_inode -pc_mg_type ADDITIVE -ksp_max_it 7
371: nsize: 1
372: requires: ml
374: test:
375: suffix: cycles
376: nsize: {{1 2}}
377: args: -ksp_view_final_residual -pc_type mg -mx 5 -my 5 -pc_mg_levels 3 -pc_mg_galerkin -ksp_monitor -mg_levels_ksp_type richardson -mg_levels_pc_type jacobi -pc_mg_type {{additive multiplicative full kaskade}separate output} -nrhs 1
379: test:
380: suffix: matcycles
381: nsize: {{1 2}}
382: args: -ksp_view_final_residual -ksp_type preonly -pc_type mg -mx 5 -my 5 -pc_mg_levels 3 -pc_mg_galerkin -ksp_monitor -mg_levels_ksp_type richardson -mg_levels_pc_type jacobi -pc_mg_type {{additive multiplicative full kaskade}separate output} -nrhs 7 -ksp_matsolve_batch_size {{4 7}separate output} -product_into_solution -check_references
384: test:
385: suffix: matcycles_richardson
386: nsize: {{1 2}}
387: args: -ksp_view_final_residual -ksp_type richardson -pc_type mg -mx 5 -my 5 -pc_mg_levels 3 -pc_mg_galerkin -mg_levels_ksp_type richardson -mg_levels_pc_type jacobi -nrhs 7 -ksp_matsolve_batch_size {{4 7}separate output}
389: test:
390: suffix: matcycles_richardson_guess
391: nsize: {{1 2}}
392: args: -ksp_view_final_residual -ksp_type richardson -ksp_initial_guess_nonzero -ksp_norm_type unpreconditioned -pc_type mg -mx 5 -my 5 -pc_mg_levels 3 -pc_mg_galerkin -mg_levels_ksp_type richardson -mg_levels_pc_type jacobi -nrhs 7 -ksp_matsolve_batch_size {{4 7}separate output}
394: test:
395: # the products interpolating and restricting the blocks, and the block residual, are set up once per level and reused by the following applications
396: suffix: matcycles_product_reuse
397: nsize: 2
398: requires: defined(PETSC_USE_INFO)
399: args: -ksp_type richardson -ksp_max_it 3 -ksp_richardson_scale 0.9 -pc_type mg -mx 5 -my 5 -pc_mg_levels 3 -pc_mg_galerkin -mg_levels_ksp_type richardson -mg_levels_pc_type jacobi -nrhs 7 -pc_mg_type {{additive multiplicative full kaskade}separate output} -info ex26info:mat
400: filter: grep -h "MatProduct API\|the supplied dense matrix" "ex26info.0" | sed -e "s/^\[0\] <[^>]*> [A-Za-z_]*(): //" | sort -b | uniq -c | sed -e "s/^ \{1,\}//"
402: test:
403: # a second solve after the nonzero pattern of the operator changes, the coarse operators are built from an unchanged copy
404: suffix: matcycles_new_pattern
405: nsize: 2
406: args: -ksp_type preonly -pc_type mg -pc_use_amat -mx 5 -my 5 -pc_mg_levels 3 -pc_mg_galerkin both -mg_levels_ksp_type richardson -mg_levels_pc_type jacobi -pc_mg_type {{additive multiplicative full kaskade}shared output} -nrhs 7 -new_pattern
407: output_file: output/ex26_matcycles_new_interpolation.out
409: test:
410: # a second solve after the finest interpolation and restriction are replaced by a matrix with an extra off-process column
411: suffix: matcycles_new_interpolation
412: nsize: 2
413: args: -ksp_type preonly -pc_type mg -mx 5 -my 5 -pc_mg_levels 3 -pc_mg_galerkin -mg_levels_ksp_type richardson -mg_levels_pc_type jacobi -pc_mg_type {{additive multiplicative full kaskade}shared output} -nrhs 7 -new_interpolation
415: # a second block solve must not copy between host and device; the coarse level uses PCJACOBI since PCLU factors on the host, and the parallel tests require GPU-aware MPI
416: testset:
417: requires: cuda kokkos_kernels defined(PETSC_USE_LOG)
418: args: -ksp_type preonly -pc_type mg -mx 5 -my 5 -pc_mg_levels 3 -pc_mg_galerkin -mg_levels_ksp_type richardson -mg_levels_pc_type jacobi -mg_coarse_pc_type jacobi -pc_mg_type {{additive multiplicative full kaskade}shared output} -nrhs 7 -dm_mat_type aijkokkos -dm_vec_type kokkos -rhs_mat_type densecuda -rhs_mat_vec_type kokkos -check_copies
419: output_file: output/ex26_matcycles_copies.out
421: test:
422: suffix: matcycles_kokkos_cuda_copies
424: test:
425: suffix: matcycles_kokkos_cuda_copies_par
426: nsize: 2
427: requires: defined(PETSC_HAVE_MPI_GPU_AWARE)
429: testset:
430: requires: cuda defined(PETSC_USE_LOG)
431: args: -ksp_type preonly -pc_type mg -mx 5 -my 5 -pc_mg_levels 3 -pc_mg_galerkin -mg_levels_ksp_type richardson -mg_levels_pc_type jacobi -mg_coarse_pc_type jacobi -pc_mg_type {{additive multiplicative full kaskade}shared output} -nrhs 7 -dm_mat_type aijcusparse -dm_vec_type cuda -rhs_mat_type densecuda -check_copies
432: output_file: output/ex26_matcycles_copies.out
434: test:
435: suffix: matcycles_cuda_copies
437: test:
438: suffix: matcycles_cuda_copies_par
439: nsize: 2
440: requires: defined(PETSC_HAVE_MPI_GPU_AWARE)
442: testset:
443: requires: hip kokkos_kernels defined(PETSC_USE_LOG)
444: args: -ksp_type preonly -pc_type mg -mx 5 -my 5 -pc_mg_levels 3 -pc_mg_galerkin -mg_levels_ksp_type richardson -mg_levels_pc_type jacobi -mg_coarse_pc_type jacobi -pc_mg_type {{additive multiplicative full kaskade}shared output} -nrhs 7 -dm_mat_type aijkokkos -dm_vec_type kokkos -rhs_mat_type densehip -rhs_mat_vec_type kokkos -check_copies
445: output_file: output/ex26_matcycles_copies.out
447: test:
448: suffix: matcycles_kokkos_hip_copies
450: test:
451: suffix: matcycles_kokkos_hip_copies_par
452: nsize: 2
453: requires: defined(PETSC_HAVE_MPI_GPU_AWARE)
455: testset:
456: requires: hip defined(PETSC_USE_LOG)
457: args: -ksp_type preonly -pc_type mg -mx 5 -my 5 -pc_mg_levels 3 -pc_mg_galerkin -mg_levels_ksp_type richardson -mg_levels_pc_type jacobi -mg_coarse_pc_type jacobi -pc_mg_type {{additive multiplicative full kaskade}shared output} -nrhs 7 -dm_mat_type aijhipsparse -dm_vec_type hip -rhs_mat_type densehip -check_copies
458: output_file: output/ex26_matcycles_copies.out
460: test:
461: suffix: matcycles_hip_copies
463: test:
464: suffix: matcycles_hip_copies_par
465: nsize: 2
466: requires: defined(PETSC_HAVE_MPI_GPU_AWARE)
468: test:
469: # a second solve with blocks of a larger leading dimension
470: suffix: matcycles_lda
471: nsize: 2
472: args: -ksp_type preonly -pc_type mg -mx 5 -my 5 -pc_mg_levels 3 -pc_mg_galerkin -mg_levels_ksp_type richardson -mg_levels_pc_type jacobi -pc_mg_type {{additive multiplicative full kaskade}shared output} -nrhs 7 -ksp_matsolve_batch_size {{4 7}shared output} -lda_shift 3
474: # the same on the device, solving the whole block at once so that the kept products get the new leading dimension
475: testset:
476: nsize: 2
477: args: -ksp_type preonly -pc_type mg -mx 5 -my 5 -pc_mg_levels 3 -pc_mg_galerkin -mg_levels_ksp_type richardson -mg_levels_pc_type jacobi -mg_coarse_pc_type jacobi -pc_mg_type {{additive multiplicative full kaskade}shared output} -nrhs 7 -lda_shift 3
478: output_file: output/ex26_matcycles_lda.out
480: test:
481: suffix: matcycles_lda_kokkos_cuda
482: requires: cuda kokkos_kernels
483: args: -dm_mat_type aijkokkos -dm_vec_type kokkos -rhs_mat_type densecuda -rhs_mat_vec_type kokkos
485: test:
486: suffix: matcycles_lda_cuda
487: requires: cuda
488: args: -dm_mat_type aijcusparse -dm_vec_type cuda -rhs_mat_type densecuda
490: test:
491: suffix: matcycles_lda_kokkos_hip
492: requires: hip kokkos_kernels
493: args: -dm_mat_type aijkokkos -dm_vec_type kokkos -rhs_mat_type densehip -rhs_mat_vec_type kokkos
495: test:
496: suffix: matcycles_lda_hip
497: requires: hip
498: args: -dm_mat_type aijhipsparse -dm_vec_type hip -rhs_mat_type densehip
500: test:
501: # the same with the solution scatter that MATSOLVERMUMPS keeps from the first solve
502: suffix: matsolve_lda_mumps
503: nsize: 2
504: requires: mumps
505: args: -ksp_type preonly -pc_type lu -pc_factor_mat_solver_type mumps -mx 5 -my 5 -nrhs 7 -lda_shift 3
506: output_file: output/ex26_matcycles_lda.out
508: test:
509: # the same with the subdomain scatters that PCASM keeps from the first solve
510: suffix: matsolve_lda_asm
511: nsize: {{1 2}}
512: args: -ksp_type preonly -pc_type asm -pc_asm_type {{basic restrict}shared output} -mx 5 -my 5 -nrhs 7 -lda_shift 3
513: output_file: output/ex26_matcycles_lda.out
515: test:
516: # the same with the subdomain scatters that PCGASM keeps from the first solve
517: suffix: matsolve_lda_gasm
518: nsize: 2
519: args: -ksp_type preonly -pc_type gasm -mx 5 -my 5 -nrhs 7 -lda_shift 3
520: output_file: output/ex26_matcycles_lda.out
522: test:
523: suffix: matcycles_richardson_transpose
524: nsize: {{1 2}}
525: args: -ksp_view_final_residual -ksp_type richardson -transpose -pc_type jacobi -mx 5 -my 5 -nrhs 7 -ksp_matsolve_batch_size {{4 7}separate output}
527: # a second transposed block solve must not copy between host and device; KSPRICHARDSON computes its block residuals B - A^T X with a MATPRODUCT_AtB product
528: testset:
529: requires: cuda kokkos_kernels defined(PETSC_USE_LOG)
530: args: -ksp_type richardson -transpose -pc_type jacobi -mx 5 -my 5 -nrhs 7 -dm_mat_type aijkokkos -dm_vec_type kokkos -rhs_mat_type densecuda -rhs_mat_vec_type kokkos -check_copies
531: output_file: output/ex26_matcycles_richardson_transpose_copies.out
533: test:
534: suffix: matcycles_richardson_transpose_kokkos_cuda_copies
536: test:
537: suffix: matcycles_richardson_transpose_kokkos_cuda_copies_par
538: nsize: 2
539: requires: defined(PETSC_HAVE_MPI_GPU_AWARE)
541: testset:
542: requires: cuda defined(PETSC_USE_LOG)
543: args: -ksp_type richardson -transpose -pc_type jacobi -mx 5 -my 5 -nrhs 7 -dm_mat_type aijcusparse -dm_vec_type cuda -rhs_mat_type densecuda -check_copies
544: output_file: output/ex26_matcycles_richardson_transpose_copies.out
546: test:
547: suffix: matcycles_richardson_transpose_cuda_copies
549: test:
550: suffix: matcycles_richardson_transpose_cuda_copies_par
551: nsize: 2
552: requires: defined(PETSC_HAVE_MPI_GPU_AWARE)
554: testset:
555: requires: hip kokkos_kernels defined(PETSC_USE_LOG)
556: args: -ksp_type richardson -transpose -pc_type jacobi -mx 5 -my 5 -nrhs 7 -dm_mat_type aijkokkos -dm_vec_type kokkos -rhs_mat_type densehip -rhs_mat_vec_type kokkos -check_copies
557: output_file: output/ex26_matcycles_richardson_transpose_copies.out
559: test:
560: suffix: matcycles_richardson_transpose_kokkos_hip_copies
562: test:
563: suffix: matcycles_richardson_transpose_kokkos_hip_copies_par
564: nsize: 2
565: requires: defined(PETSC_HAVE_MPI_GPU_AWARE)
567: testset:
568: requires: hip defined(PETSC_USE_LOG)
569: args: -ksp_type richardson -transpose -pc_type jacobi -mx 5 -my 5 -nrhs 7 -dm_mat_type aijhipsparse -dm_vec_type hip -rhs_mat_type densehip -check_copies
570: output_file: output/ex26_matcycles_richardson_transpose_copies.out
572: test:
573: suffix: matcycles_richardson_transpose_hip_copies
575: test:
576: suffix: matcycles_richardson_transpose_hip_copies_par
577: nsize: 2
578: requires: defined(PETSC_HAVE_MPI_GPU_AWARE)
580: test:
581: requires: ml
582: suffix: matcycles_ml
583: nsize: {{1 2}}
584: args: -ksp_view_final_residual -ksp_type preonly -pc_type ml -mx 5 -my 5 -ksp_monitor -mg_levels_ksp_type richardson -mg_levels_pc_type jacobi -pc_mg_type {{additive multiplicative full kaskade}separate output} -nrhs 7 -ksp_matsolve_batch_size {{4 7}separate output}
586: testset:
587: requires: hpddm
588: nsize: 2
589: args: -ksp_view_final_residual -ksp_type hpddm -pc_type mg -pc_mg_levels 3 -pc_mg_galerkin -mx 5 -my 5 -ksp_monitor -mg_levels_ksp_type richardson -mg_levels_pc_type jacobi -nrhs 7
590: test:
591: suffix: matcycles_hpddm_mg
592: args: -pc_mg_type {{additive multiplicative full kaskade}separate output} -ksp_matsolve_batch_size {{4 7}separate output}
593: test:
594: requires: double
595: suffix: hpddm_mg_mixed_precision_double_to_single
596: output_file: output/ex26_matcycles_hpddm_mg_pc_mg_type-multiplicative_ksp_matsolve_batch_size-4.out
597: args: -ksp_matsolve_batch_size 4 -ksp_hpddm_precision single
598: test:
599: requires: single
600: suffix: hpddm_mg_mixed_precision_single_to_double
601: output_file: output/ex26_matcycles_hpddm_mg_pc_mg_type-multiplicative_ksp_matsolve_batch_size-4.out
602: args: -ksp_matsolve_batch_size 4 -ksp_hpddm_precision double
603: test:
604: requires: __float128
605: suffix: hpddm_mg_mixed_precision___float128_to_double
606: output_file: output/ex26_matcycles_hpddm_mg_pc_mg_type-multiplicative_ksp_matsolve_batch_size-4.out
607: args: -ksp_matsolve_batch_size 4 -ksp_hpddm_precision double
608: test:
609: requires: double defined(PETSC_HAVE_F2CBLASLAPACK___FLOAT128_BINDINGS)
610: suffix: hpddm_mg_mixed_precision_double_to___float128
611: output_file: output/ex26_matcycles_hpddm_mg_pc_mg_type-multiplicative_ksp_matsolve_batch_size-4.out
612: args: -ksp_matsolve_batch_size 4 -ksp_hpddm_precision __float128
613: test:
614: requires: single defined(PETSC_HAVE_F2CBLASLAPACK___FP16_BINDINGS)
615: suffix: hpddm_mg_mixed_precision_single_to___fp16
616: output_file: output/ex26_matcycles_hpddm_mg_pc_mg_type-multiplicative_ksp_matsolve_batch_size-4.out
617: args: -ksp_matsolve_batch_size 4 -ksp_hpddm_precision __fp16 -ksp_rtol 1e-3
619: test:
620: requires: hpddm
621: nsize: 2
622: suffix: matcycles_hpddm_ilu
623: args: -ksp_view_final_residual -ksp_type hpddm -pc_type redundant -redundant_pc_type ilu -mx 5 -my 5 -ksp_monitor -nrhs 7 -ksp_matsolve_batch_size {{4 7}separate output}
625: TEST*/