Actual source code: ex18.c
1: static char help[] = "Compares BLAS dots on different machines. Input\n\
2: arguments are\n\
3: -n <length> : local vector length\n\n";
5: #include <petscvec.h>
7: int main(int argc, char **argv)
8: {
9: PetscInt n = 15, i;
10: PetscScalar v;
11: Vec x, y;
13: PetscFunctionBeginUser;
14: PetscCall(PetscInitialize(&argc, &argv, (char *)0, help));
15: PetscCall(PetscOptionsGetInt(NULL, NULL, "-n", &n, NULL));
16: if (n < 5) n = 5;
18: /* create two vectors */
19: PetscCall(VecCreateSeq(PETSC_COMM_SELF, n, &x));
20: PetscCall(VecCreateSeq(PETSC_COMM_SELF, n, &y));
22: for (i = 0; i < n; i++) {
23: v = ((PetscReal)i) + 1.0 / (((PetscReal)i) + .35);
24: PetscCall(VecSetValues(x, 1, &i, &v, INSERT_VALUES));
25: v += 1.375547826473644376;
26: PetscCall(VecSetValues(y, 1, &i, &v, INSERT_VALUES));
27: }
28: PetscCall(VecAssemblyBegin(y));
29: PetscCall(VecAssemblyEnd(y));
31: PetscCall(VecDot(x, y, &v));
32: PetscCall(PetscFPrintf(PETSC_COMM_WORLD, stdout, "Vector inner product %16.12e\n", (double)PetscRealPart(v)));
34: PetscCall(VecDestroy(&x));
35: PetscCall(VecDestroy(&y));
37: PetscCall(PetscFinalize());
38: return 0;
39: }
41: /*TEST
43: test:
45: TEST*/