Solving Ax=b
173: /* - - - - - - Create the linear solver and set various options - - - - - - - */
177: /* Create linear solver context */
179: SLESCreate(PETSC_COMM_WORLD,&sles);
182: /* Set operators. Here the matrix that defines the linear system
also serves as the preconditioning matrix. */
185: SLESSetOperators(sles,A,A,DIFFERENT_NONZERO_PATTERN);
188: /* Set linear solver defaults for this problem (optional).
– By extracting the KSP (Krylov subspace methods) and PC (Preconditioner) contexts from
the SLES context, we can then directly call any KSP and PC routines to set various options.
– The following two statements are optional; all of these parameters could
alternatively be specified at runtime via SLESSetFromOptions().
All of these defaults can be overridden at runtime, as indicated below. */
198: SLESGetKSP(sles,&ksp);
199: KSPSetTolerances(ksp,1.e-2/((m+1)*(n+1)),1.e-50,PETSC_DEFAULT,PETSC_DEFAULT);
202: /* Set runtime options, e.g., -ksp_type <type> -pc_type <type> -ksp_monitor -ksp_rtol <rtol>
These options will override those specified above as long as SLESSetFromOptions()
is called _after_ any other customization routines. */
208: SLESSetFromOptions(sles);
211: /* - - - - - - Solve the linear system - - - - - - - */
214: SLESSolve(sles,b,x,&its);