Actual source code: ex18.c


  2: static char help[] = "Compares BLAS dots on different machines. Input\n\
  3: arguments are\n\
  4:   -n <length> : local vector length\n\n";

  6: #include <petscvec.h>

  8: int main(int argc, char **argv)
  9: {
 10:   PetscInt    n = 15, i;
 11:   PetscScalar v;
 12:   Vec         x, y;

 14:   PetscFunctionBeginUser;
 15:   PetscCall(PetscInitialize(&argc, &argv, (char *)0, help));
 16:   PetscCall(PetscOptionsGetInt(NULL, NULL, "-n", &n, NULL));
 17:   if (n < 5) n = 5;

 19:   /* create two vectors */
 20:   PetscCall(VecCreateSeq(PETSC_COMM_SELF, n, &x));
 21:   PetscCall(VecCreateSeq(PETSC_COMM_SELF, n, &y));

 23:   for (i = 0; i < n; i++) {
 24:     v = ((PetscReal)i) + 1.0 / (((PetscReal)i) + .35);
 25:     PetscCall(VecSetValues(x, 1, &i, &v, INSERT_VALUES));
 26:     v += 1.375547826473644376;
 27:     PetscCall(VecSetValues(y, 1, &i, &v, INSERT_VALUES));
 28:   }
 29:   PetscCall(VecAssemblyBegin(y));
 30:   PetscCall(VecAssemblyEnd(y));

 32:   PetscCall(VecDot(x, y, &v));
 33:   PetscCall(PetscFPrintf(PETSC_COMM_WORLD, stdout, "Vector inner product %16.12e\n", (double)PetscRealPart(v)));

 35:   PetscCall(VecDestroy(&x));
 36:   PetscCall(VecDestroy(&y));

 38:   PetscCall(PetscFinalize());
 39:   return 0;
 40: }

 42: /*TEST

 44:    test:

 46: TEST*/