Actual source code: ex3.c
1: /*$Id: ex3.c,v 1.54 2001/09/08 03:18:25 bsmith Exp $*/
3: static char help[] = "Tests parallel vector assembly. Input arguments are\n\
4: -n <length> : local vector length\n\n";
6: #include petscvec.h
7: #include petscsys.h
11: int main(int argc,char **argv)
12: {
13: int n = 5,ierr,size,rank;
14: PetscScalar one = 1.0,two = 2.0,three = 3.0;
15: Vec x,y;
16: int idx;
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(&one,x);
32: VecSet(&two,y);
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: