Actual source code: ex29.c

  1: /*$Id: ex29.c,v 1.18 2001/04/10 19:35:02 bsmith Exp $*/

  3: static char help[] = "Tests VecSetValues and VecSetValuesBlocked() on MPI vectors.n
  4: Where atleast a couple of mallocs will occur in the stash code.nn";

 6:  #include petscvec.h
 7:  #include petscsys.h

  9: int main(int argc,char **argv)
 10: {
 11:   int          i,j,n = 50,ierr,bs,size;
 12:   Scalar       val,*vals,zero=0.0;
 13:   Vec          x;

 15:   PetscInitialize(&argc,&argv,(char*)0,help);
 16:   MPI_Comm_size(PETSC_COMM_WORLD,&size);
 17:   bs = size;

 19:   PetscOptionsGetInt(PETSC_NULL,"-n",&n,PETSC_NULL);
 20:   VecCreateMPI(PETSC_COMM_WORLD,PETSC_DECIDE,n*bs,&x);
 21:   VecSetBlockSize(x,bs);

 23:   for (i=0; i<n*bs; i++) {
 24:     val  = i*1.0;
 25:     VecSetValues(x,1,&i,&val,INSERT_VALUES);
 26:   }
 27:   VecAssemblyBegin(x);
 28:   VecAssemblyEnd(x);

 30:   VecView(x,PETSC_VIEWER_STDOUT_WORLD);

 32:   /* Now do the blocksetvalues */
 33:   VecSet(&zero,x);
 34:   PetscMalloc(bs*sizeof(Scalar),&vals);
 35:   for (i=0; i<n; i++) {
 36:     for (j=0; j<bs; j++) {
 37:       vals[j] = (i*bs+j)*1.0;
 38:     }
 39:     VecSetValuesBlocked(x,1,&i,vals,INSERT_VALUES);
 40:   }

 42:   VecAssemblyBegin(x);
 43:   VecAssemblyEnd(x);

 45:   VecView(x,PETSC_VIEWER_STDOUT_WORLD);

 47:   VecDestroy(x);
 48:   PetscFree(vals);
 49:   PetscFinalize();
 50:   return 0;
 51: }
 52: