Actual source code: ex18.c
petsc-3.8.4 2018-03-24
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: {
11: PetscInt n = 15,i;
12: PetscScalar v;
13: Vec x,y;
15: PetscInitialize(&argc,&argv,(char*)0,help);if (ierr) return ierr;
16: PetscOptionsGetInt(NULL,NULL,"-n",&n,NULL);
17: if (n < 5) n = 5;
20: /* create two vectors */
21: VecCreateSeq(PETSC_COMM_SELF,n,&x);
22: VecCreateSeq(PETSC_COMM_SELF,n,&y);
24: for (i=0; i<n; i++) {
25: v = ((PetscReal)i) + 1.0/(((PetscReal)i) + .35);
26: VecSetValues(x,1,&i,&v,INSERT_VALUES);
27: v += 1.375547826473644376;
28: VecSetValues(y,1,&i,&v,INSERT_VALUES);
29: }
30: VecAssemblyBegin(y);
31: VecAssemblyEnd(y);
33: VecDot(x,y,&v);
34: PetscFPrintf(PETSC_COMM_WORLD,stdout,"Vector inner product %16.12e\n",v);
36: VecDestroy(&x);
37: VecDestroy(&y);
39: PetscFinalize();
40: return ierr;
41: }