Actual source code: ex1.c

petsc-3.9.4 2018-09-11
Report Typos and Errors

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

  4: /*T
  5:    requires: veccuda x
  6: T*/

  8:  #include <petscdm.h>
  9:  #include <petscdmda.h>

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

 21:   PetscInitialize(&argc,&argv,(char*)0,help);if (ierr) return ierr;
 22:   PetscViewerDrawOpen(PETSC_COMM_WORLD,0,"",300,0,300,300,&viewer);

 24:   /* Read options */
 25:   PetscOptionsGetInt(NULL,NULL,"-M",&M,NULL);
 26:   PetscOptionsGetInt(NULL,NULL,"-N",&N,NULL);
 27:   PetscOptionsGetInt(NULL,NULL,"-m",&m,NULL);
 28:   PetscOptionsGetInt(NULL,NULL,"-n",&n,NULL);

 30:   /* Create distributed array and get vectors */
 31:   DMDACreate2d(PETSC_COMM_WORLD, DM_BOUNDARY_NONE, DM_BOUNDARY_NONE,DMDA_STENCIL_BOX,M,N,m,n,1,1,NULL,NULL,&da);
 32:   DMSetFromOptions(da);
 33:   DMSetUp(da);
 34:   DMCreateGlobalVector(da,&global);
 35:   DMCreateLocalVector(da,&local);

 37:   value = -3.0;
 38:   VecSet(global,value);
 39:   DMGlobalToLocalBegin(da,global,INSERT_VALUES,local);
 40:   DMGlobalToLocalEnd(da,global,INSERT_VALUES,local);

 42:   MPI_Comm_rank(PETSC_COMM_WORLD,&rank);
 43:   value = rank+1;
 44:   VecScale(local,value);
 45:   DMLocalToGlobalBegin(da,local,ADD_VALUES,global);
 46:   DMLocalToGlobalEnd(da,local,ADD_VALUES,global);

 48:   VecView(global,PETSC_VIEWER_STDOUT_WORLD);
 49:   DMView(da,viewer);

 51:   /* Free memory */
 52:   PetscViewerDestroy(&viewer);
 53:   VecDestroy(&local);
 54:   VecDestroy(&global);
 55:   DMDestroy(&da);
 56:   PetscFinalize();
 57:   return ierr;
 58: }



 62: /*TEST

 64:    test:
 65:       nsize: 2
 66:       args: -nox
 67:       filter: grep -v -i Object

 69:    test:
 70:       suffix: cuda1
 71:       requires: veccuda
 72:       args: -dm_vec_type cuda -nox
 73:       filter: grep -v -i Object

 75:    test:
 76:       suffix: cuda2
 77:       nsize: 2
 78:       requires: veccuda
 79:       args: -dm_vec_type cuda -nox
 80:       filter: grep -v -i Object

 82: TEST*/