Actual source code: ex3.c

  1: /*$Id: ex3.c,v 1.52 2001/03/23 23:21:30 balay Exp $*/

  3: static char help[] = "Tests parallel vector assembly.  Input arguments aren
  4:   -n <length> : local vector lengthnn";

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

  9: int main(int argc,char **argv)
 10: {
 11:   int          n = 5,ierr,size,rank;
 12:   Scalar       one = 1.0,two = 2.0,three = 3.0;
 13:   Vec          x,y;
 14:   int          idx;

 16:   PetscInitialize(&argc,&argv,(char*)0,help);
 17:   PetscOptionsGetInt(PETSC_NULL,"-n",&n,PETSC_NULL);
 18:   if (n < 5) n = 5;
 19:   MPI_Comm_size(PETSC_COMM_WORLD,&size);
 20:   MPI_Comm_rank(PETSC_COMM_WORLD,&rank);

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

 24:   /* create two vector */
 25:   VecCreateSeq(PETSC_COMM_SELF,n,&x);
 26:   VecCreateMPI(PETSC_COMM_WORLD,n,PETSC_DECIDE,&y);
 27:   VecSet(&one,x);
 28:   VecSet(&two,y);

 30:   if (rank == 1) {
 31:     idx = 2; VecSetValues(y,1,&idx,&three,INSERT_VALUES);
 32:     idx = 0; VecSetValues(y,1,&idx,&two,INSERT_VALUES);
 33:     idx = 0; VecSetValues(y,1,&idx,&one,INSERT_VALUES);
 34:   }
 35:   else {
 36:     idx = 7; VecSetValues(y,1,&idx,&three,INSERT_VALUES);
 37:   }
 38:   VecAssemblyBegin(y);
 39:   VecAssemblyEnd(y);

 41:   VecView(y,PETSC_VIEWER_STDOUT_WORLD);

 43:   VecDestroy(x);
 44:   VecDestroy(y);

 46:   PetscFinalize();
 47:   return 0;
 48: }
 49: