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