Actual source code: ex3.c

  2: static char help[] = "Tests parallel vector assembly.  Input arguments are\n\
  3:   -n <length> : local vector length\n\n";

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

 10: int main(int argc,char **argv)
 11: {
 12:   PetscMPIInt    size,rank;
 14:   PetscInt       n = 5,idx;
 15:   PetscScalar    one = 1.0,two = 2.0,three = 3.0;
 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;
 21:   MPI_Comm_size(PETSC_COMM_WORLD,&size);
 22:   MPI_Comm_rank(PETSC_COMM_WORLD,&rank);

 24:   if (size < 2) SETERRQ(1,"Must be run with at least two processors");

 26:   /* create two vector */
 27:   VecCreateSeq(PETSC_COMM_SELF,n,&x);
 28:   VecCreate(PETSC_COMM_WORLD,&y);
 29:   VecSetSizes(y,n,PETSC_DECIDE);
 30:   VecSetFromOptions(y);
 31:   VecSet(x,one);
 32:   VecSet(y,two);

 34:   if (rank == 1) {
 35:     idx = 2; VecSetValues(y,1,&idx,&three,INSERT_VALUES);
 36:     idx = 0; VecSetValues(y,1,&idx,&two,INSERT_VALUES);
 37:     idx = 0; VecSetValues(y,1,&idx,&one,INSERT_VALUES);
 38:   }
 39:   else {
 40:     idx = 7; VecSetValues(y,1,&idx,&three,INSERT_VALUES);
 41:   }
 42:   VecAssemblyBegin(y);
 43:   VecAssemblyEnd(y);

 45:   VecView(y,PETSC_VIEWER_STDOUT_WORLD);

 47:   VecDestroy(x);
 48:   VecDestroy(y);

 50:   PetscFinalize();
 51:   return 0;
 52: }
 53: