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 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: PetscScalar 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: VecCreate(PETSC_COMM_WORLD,&y);
27: VecSetSizes(y,n,PETSC_DECIDE);
28: VecSetFromOptions(y);
29: VecSet(&one,x);
30: VecSet(&two,y);
32: if (rank == 1) {
33: idx = 2; VecSetValues(y,1,&idx,&three,INSERT_VALUES);
34: idx = 0; VecSetValues(y,1,&idx,&two,INSERT_VALUES);
35: idx = 0; VecSetValues(y,1,&idx,&one,INSERT_VALUES);
36: }
37: else {
38: idx = 7; VecSetValues(y,1,&idx,&three,INSERT_VALUES);
39: }
40: VecAssemblyBegin(y);
41: VecAssemblyEnd(y);
43: VecView(y,PETSC_VIEWER_STDOUT_WORLD);
45: VecDestroy(x);
46: VecDestroy(y);
48: PetscFinalize();
49: return 0;
50: }
51: