Actual source code: ex41.c
2: static char help[] = "Reads a PETSc matrix and vector from a socket connection, solves a linear system and sends the result back.\n";
4: /*T
5: Concepts: KSP^solving a linear system
6: Processors: n
7: T*/
9: /*
10: Include "petscksp.h" so that we can use KSP solvers. Note that this file
11: automatically includes:
12: petscsys.h - base PETSc routines petscvec.h - vectors
13: petscmat.h - matrices
14: petscis.h - index sets petscksp.h - Krylov subspace methods
15: petscviewer.h - viewers petscpc.h - preconditioners
16: */
17: #include <petscksp.h>
19: int main(int argc,char **args)
20: {
21: KSP ksp; /* linear solver context */
22: Mat A; /* matrix */
23: Vec x,b; /* approx solution, RHS, exact solution */
24: PetscViewer fd; /* viewer */
26: PetscInitialize(&argc,&args,(char*)0,help);
27: fd = PETSC_VIEWER_SOCKET_WORLD;
29: VecCreate(PETSC_COMM_WORLD,&b);
30: VecLoad(b,fd);
31: MatCreate(PETSC_COMM_WORLD,&A);
32: MatLoad(A,fd);
33: VecDuplicate(b,&x);
35: KSPCreate(PETSC_COMM_WORLD,&ksp);
36: KSPSetOperators(ksp,A,A);
37: KSPSetFromOptions(ksp);
38: KSPSetUp(ksp);
39: KSPSolve(ksp,b,x);
40: VecView(x,fd);
41: MatDestroy(&A);
42: VecDestroy(&b);
43: VecDestroy(&x);
44: KSPDestroy(&ksp);
46: PetscFinalize();
47: return 0;
48: }
50: /*TEST
52: build:
53: requires: defined(PETSC_USE_SOCKET_VIEWER)
55: test:
56: TODO: Need to figure out how to test examples that use sockets
58: TEST*/