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. Inputn
  6: arguments aren
  7:   -n <length> : local vector lengthnn";

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

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

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


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

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

 36:   VecDot(x,y,&v);
 37:   PetscFPrintf(PETSC_COMM_WORLD,stdout,"Vector inner product %16.12en",v);

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

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