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: /*
  5:   Include "petscksp.h" so that we can use KSP solvers.  Note that this file
  6:   automatically includes:
  7:      petscsys.h       - base PETSc routines   petscvec.h - vectors
  8:      petscmat.h - matrices
  9:      petscis.h     - index sets            petscksp.h - Krylov subspace methods
 10:      petscviewer.h - viewers               petscpc.h  - preconditioners
 11: */
 12: #include <petscksp.h>

 14: int main(int argc,char **args)
 15: {
 16:   KSP            ksp;             /* linear solver context */
 17:   Mat            A;            /* matrix */
 18:   Vec            x,b;          /* approx solution, RHS, exact solution */
 19:   PetscViewer    fd;               /* viewer */

 21:   PetscInitialize(&argc,&args,(char*)0,help);
 22:   fd = PETSC_VIEWER_SOCKET_WORLD;

 24:   VecCreate(PETSC_COMM_WORLD,&b);
 25:   VecLoad(b,fd);
 26:   MatCreate(PETSC_COMM_WORLD,&A);
 27:   MatLoad(A,fd);
 28:   VecDuplicate(b,&x);

 30:   KSPCreate(PETSC_COMM_WORLD,&ksp);
 31:   KSPSetOperators(ksp,A,A);
 32:   KSPSetFromOptions(ksp);
 33:   KSPSetUp(ksp);
 34:   KSPSolve(ksp,b,x);
 35:   VecView(x,fd);
 36:   MatDestroy(&A);
 37:   VecDestroy(&b);
 38:   VecDestroy(&x);
 39:   KSPDestroy(&ksp);

 41:   PetscFinalize();
 42:   return 0;
 43: }

 45: /*TEST

 47:      build:
 48:        requires: defined(PETSC_USE_SOCKET_VIEWER)

 50:      test:
 51:        TODO: Need to figure out how to test examples that use sockets

 53: TEST*/