1 2 static char help[] = "Tests DMGetGlobalVector() and DMRestoreGlobalVector().\n\n"; 3 4 /* 5 Use the options 6 -da_grid_x <nx> - number of grid points in x direction, if M < 0 7 -da_grid_y <ny> - number of grid points in y direction, if N < 0 8 -da_processors_x <MX> number of processors in x directio 9 -da_processors_y <MY> number of processors in x direction 10 */ 11 12 #include <petscdm.h> 13 #include <petscdmda.h> 14 15 int main(int argc,char **argv) 16 { 17 PetscInt M = 10,N = 8; 18 PetscErrorCode ierr; 19 PetscBool flg = PETSC_FALSE; 20 DM da; 21 Vec global1,global2,global3; 22 DMBoundaryType bx = DM_BOUNDARY_NONE,by = DM_BOUNDARY_NONE; 23 DMDAStencilType stype = DMDA_STENCIL_BOX; 24 25 ierr = PetscInitialize(&argc,&argv,(char*)0,help);if (ierr) return ierr; 26 CHKERRQ(PetscOptionsGetBool(NULL,NULL,"-star_stencil",&flg,NULL)); 27 if (flg) stype = DMDA_STENCIL_STAR; 28 29 /* Create distributed array and get vectors */ 30 CHKERRQ(DMDACreate2d(PETSC_COMM_WORLD,bx,by,stype,M,N,PETSC_DECIDE,PETSC_DECIDE,1,1,NULL,NULL,&da)); 31 CHKERRQ(DMSetFromOptions(da)); 32 CHKERRQ(DMSetUp(da)); 33 CHKERRQ(DMGetGlobalVector(da,&global1)); 34 CHKERRQ(DMGetGlobalVector(da,&global2)); 35 CHKERRQ(DMRestoreGlobalVector(da,&global1)); 36 CHKERRQ(DMRestoreGlobalVector(da,&global2)); 37 CHKERRQ(DMGetGlobalVector(da,&global1)); 38 CHKERRQ(DMGetGlobalVector(da,&global3)); 39 CHKERRQ(DMGetGlobalVector(da,&global2)); 40 CHKERRQ(DMRestoreGlobalVector(da,&global1)); 41 CHKERRQ(DMRestoreGlobalVector(da,&global3)); 42 CHKERRQ(DMRestoreGlobalVector(da,&global2)); 43 CHKERRQ(DMGetGlobalVector(da,&global1)); 44 CHKERRQ(DMGetGlobalVector(da,&global3)); 45 CHKERRQ(DMGetGlobalVector(da,&global2)); 46 CHKERRQ(DMRestoreGlobalVector(da,&global1)); 47 CHKERRQ(DMRestoreGlobalVector(da,&global3)); 48 CHKERRQ(DMRestoreGlobalVector(da,&global2)); 49 CHKERRQ(DMDestroy(&da)); 50 ierr = PetscFinalize(); 51 return ierr; 52 } 53 54 /*TEST 55 56 test: 57 58 TEST*/ 59