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

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

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


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

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

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

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

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