Actual source code: ex18.c

petsc-3.12.2 2019-11-22
Report Typos and Errors

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


  7:  #include <petscvec.h>

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

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


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

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

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

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

 40:   PetscFinalize();
 41:   return ierr;
 42: }



 46: /*TEST

 48:    test:

 50: TEST*/