Actual source code: ex18.c

  1: /*$Id: ex18.c,v 1.30 2001/08/07 21:29:25 bsmith Exp $*/

  3: /* np = 1 */

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

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

 14: int main(int argc,char **argv)
 15: {
 16:   int          n = 15,ierr,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: