Actual source code: ex42a.c

  1: static char help[] = "Sends a PETSc vector to a socket connection, receives it back, within a loop. Must be run with ex42.c.\n";

  3: #include <petscvec.h>

  5: int main(int argc, char **args)
  6: {
  7:   Vec         b;
  8:   PetscViewer fd;
  9:   PetscInt    i;

 11:   PetscFunctionBeginUser;
 12:   PetscCall(PetscInitialize(&argc, &args, NULL, help));
 13:   /* server indicates we WAIT for someone to connect to our socket */
 14:   PetscCall(PetscViewerSocketOpen(PETSC_COMM_WORLD, "server", PETSC_DEFAULT, &fd));

 16:   PetscCall(VecCreateFromOptions(PETSC_COMM_WORLD, NULL, 1, 10000, PETSC_DECIDE, &b));
 17:   for (i = 0; i < 1000; i++) {
 18:     PetscCall(VecView(b, fd));
 19:     PetscCall(VecDestroy(&b));
 20:     PetscCall(VecCreate(PETSC_COMM_WORLD, &b));
 21:     PetscCall(VecLoad(b, fd));
 22:   }
 23:   PetscCall(VecDestroy(&b));
 24:   PetscCall(PetscViewerDestroy(&fd));
 25:   PetscCall(PetscFinalize());
 26:   return 0;
 27: }