Actual source code: ex1.c

  1: /*$Id: ex1.c,v 1.49 2001/08/07 03:04:42 balay Exp $*/

  3: static char help[] = "Tests various DA routines.nn";

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

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

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

 19:   /* Read options */
 20:   PetscOptionsGetInt(PETSC_NULL,"-M",&M,PETSC_NULL);
 21:   PetscOptionsGetInt(PETSC_NULL,"-N",&N,PETSC_NULL);
 22:   PetscOptionsGetInt(PETSC_NULL,"-m",&m,PETSC_NULL);
 23:   PetscOptionsGetInt(PETSC_NULL,"-n",&n,PETSC_NULL);

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

 31:   value = -3.0;
 32:   VecSet(&value,global);
 33:   DAGlobalToLocalBegin(da,global,INSERT_VALUES,local);
 34:   DAGlobalToLocalEnd(da,global,INSERT_VALUES,local);

 36:   MPI_Comm_rank(PETSC_COMM_WORLD,&rank);
 37:   value = rank+1;
 38:   VecScale(&value,local);
 39:   DALocalToGlobal(da,local,ADD_VALUES,global);

 41:   PetscViewerPushFormat(PETSC_VIEWER_STDOUT_WORLD,PETSC_VIEWER_NATIVE);
 42:   VecView(global,PETSC_VIEWER_STDOUT_WORLD);
 43:   DAView(da,viewer);

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