Actual source code: ex18.c
petsc-3.4.2 2013-07-02

      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>

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

     17:   PetscInitialize(&argc,&argv,(char*)0,help);
     18:   PetscOptionsGetInt(NULL,"-n",&n,NULL);
     19:   if (n < 5) n = 5;

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

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

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

     38:   VecDestroy(&x);
     39:   VecDestroy(&y);

     41:   PetscFinalize();
     42:   return 0;
     43: }