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>
7: int main(int argc,char **argv)
8: {
9: PetscMPIInt size,rank;
10: PetscInt n = 5,idx;
11: PetscScalar one = 1.0,two = 2.0,three = 3.0;
12: Vec x,y;
14: PetscInitialize(&argc,&argv,(char*)0,help);
15: PetscOptionsGetInt(NULL,NULL,"-n",&n,NULL);
16: if (n < 5) n = 5;
17: MPI_Comm_size(PETSC_COMM_WORLD,&size);
18: MPI_Comm_rank(PETSC_COMM_WORLD,&rank);
22: /* create two vector */
23: VecCreateSeq(PETSC_COMM_SELF,n,&x);
24: VecCreate(PETSC_COMM_WORLD,&y);
25: VecSetSizes(y,n,PETSC_DECIDE);
26: VecSetFromOptions(y);
27: VecSet(x,one);
28: VecSet(y,two);
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: } else {
35: idx = 7; VecSetValues(y,1,&idx,&three,INSERT_VALUES);
36: }
37: VecAssemblyBegin(y);
38: VecAssemblyEnd(y);
40: VecView(y,PETSC_VIEWER_STDOUT_WORLD);
42: VecDestroy(&x);
43: VecDestroy(&y);
45: PetscFinalize();
46: return 0;
47: }
49: /*TEST
51: test:
52: nsize: 2
54: test:
55: suffix: 2
56: nsize: 2
57: args: -vec_view ascii::ascii_info
59: TEST*/