Actual source code: ex18.c

  2: /* np = 1 */

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

 8:  #include petscvec.h
 9:  #include petscsys.h

 13: int main(int argc,char **argv)
 14: {
 16:   PetscInt       n = 15,i;
 17:   PetscScalar    v;
 18:   Vec            x,y;

 20:   PetscInitialize(&argc,&argv,(char*)0,help);
 21:   PetscOptionsGetInt(PETSC_NULL,"-n",&n,PETSC_NULL);
 22:   if (n < 5) n = 5;


 25:   /* create two vectors */
 26:   VecCreateSeq(PETSC_COMM_SELF,n,&x);
 27:   VecCreateSeq(PETSC_COMM_SELF,n,&y);

 29:   for (i=0; i<n; i++) {
 30:     v = ((PetscReal)i) + 1.0/(((PetscReal)i) + .35);
 31:     VecSetValues(x,1,&i,&v,INSERT_VALUES);
 32:     v += 1.375547826473644376;
 33:     VecSetValues(y,1,&i,&v,INSERT_VALUES);
 34:   }
 35:   VecAssemblyBegin(y);
 36:   VecAssemblyEnd(y);

 38:   VecDot(x,y,&v);
 39:   PetscFPrintf(PETSC_COMM_WORLD,stdout,"Vector inner product %16.12e\n",v);

 41:   VecDestroy(x);
 42:   VecDestroy(y);

 44:   PetscFinalize();
 45:   return 0;
 46: }
 47: