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 */

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

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

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

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

 46: /*TEST

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

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

 54: TEST*/