Actual source code: ex37.c
2: static char help[] = "VecView() with a DMDA1d vector and draw viewer.\n\n";
4: #include <petscdm.h>
5: #include <petscdmda.h>
6: #include <petscao.h>
8: PetscErrorCode apply(void *ctx,PetscInt n,const PetscScalar *x,PetscScalar *y)
9: {
10: PetscInt i;
12: for (i=0; i<n; i++) {y[3*i] = x[i]; y[3*i+1] = x[i]*x[i]; y[3*i+2] = x[i]*x[i]*x[i];}
13: return 0;
14: }
16: int main(int argc,char **argv)
17: {
18: DM da;
19: Vec global;
20: PF pf;
22: PetscInitialize(&argc,&argv,(char*)0,help);
23: DMDACreate1d(PETSC_COMM_WORLD,DM_BOUNDARY_NONE,10,3,1,NULL,&da);
24: DMSetFromOptions(da);
25: DMSetUp(da);
26: DMCreateGlobalVector(da,&global);
27: PFCreate(PETSC_COMM_WORLD,1,3,&pf);
28: PFSet(pf,apply,NULL,NULL,NULL,NULL);
29: PFApplyVec(pf,NULL,global);
30: PFDestroy(&pf);
31: VecView(global,PETSC_VIEWER_DRAW_WORLD);
32: VecDestroy(&global);
33: DMDestroy(&da);
34: PetscFinalize();
35: return 0;
36: }
38: /*TEST
40: test:
41: nsize: 2
42: requires: x
44: TEST*/