Actual source code: ex1.c

  2: static char help[] = "Tests various DA routines.\n\n";

 4:  #include petscda.h
 5:  #include petscsys.h

  9: int main(int argc,char **argv)
 10: {
 11:   PetscMPIInt    rank;
 12:   PetscInt       M = 10,N = 8,m = PETSC_DECIDE,n = PETSC_DECIDE;
 14:   DA             da;
 15:   PetscViewer    viewer;
 16:   Vec            local,global;
 17:   PetscScalar    value;

 19:   PetscInitialize(&argc,&argv,(char*)0,help);
 20:   PetscViewerDrawOpen(PETSC_COMM_WORLD,0,"",300,0,300,300,&viewer);

 22:   /* Read options */
 23:   PetscOptionsGetInt(PETSC_NULL,"-M",&M,PETSC_NULL);
 24:   PetscOptionsGetInt(PETSC_NULL,"-N",&N,PETSC_NULL);
 25:   PetscOptionsGetInt(PETSC_NULL,"-m",&m,PETSC_NULL);
 26:   PetscOptionsGetInt(PETSC_NULL,"-n",&n,PETSC_NULL);

 28:   /* Create distributed array and get vectors */
 29:   DACreate2d(PETSC_COMM_WORLD,DA_NONPERIODIC,DA_STENCIL_BOX,
 30:                     M,N,m,n,1,1,PETSC_NULL,PETSC_NULL,&da);
 31:   DACreateGlobalVector(da,&global);
 32:   DACreateLocalVector(da,&local);

 34:   value = -3.0;
 35:   VecSet(global,value);
 36:   DAGlobalToLocalBegin(da,global,INSERT_VALUES,local);
 37:   DAGlobalToLocalEnd(da,global,INSERT_VALUES,local);

 39:   MPI_Comm_rank(PETSC_COMM_WORLD,&rank);
 40:   value = rank+1;
 41:   VecScale(local,value);
 42:   DALocalToGlobal(da,local,ADD_VALUES,global);

 44:   PetscViewerPushFormat(PETSC_VIEWER_STDOUT_WORLD,PETSC_VIEWER_NATIVE);
 45:   VecView(global,PETSC_VIEWER_STDOUT_WORLD);
 46:   DAView(da,viewer);

 48:   /* Free memory */
 49:   PetscViewerDestroy(viewer);
 50:   VecDestroy(local);
 51:   VecDestroy(global);
 52:   DADestroy(da);
 53:   PetscFinalize();
 54:   return 0;
 55: }
 56: