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 PetscBool flg = PETSC_FALSE; 19 DM da; 20 Vec global1,global2,global3; 21 DMBoundaryType bx = DM_BOUNDARY_NONE,by = DM_BOUNDARY_NONE; 22 DMDAStencilType stype = DMDA_STENCIL_BOX; 23 24 CHKERRQ(PetscInitialize(&argc,&argv,(char*)0,help)); 25 CHKERRQ(PetscOptionsGetBool(NULL,NULL,"-star_stencil",&flg,NULL)); 26 if (flg) stype = DMDA_STENCIL_STAR; 27 28 /* Create distributed array and get vectors */ 29 CHKERRQ(DMDACreate2d(PETSC_COMM_WORLD,bx,by,stype,M,N,PETSC_DECIDE,PETSC_DECIDE,1,1,NULL,NULL,&da)); 30 CHKERRQ(DMSetFromOptions(da)); 31 CHKERRQ(DMSetUp(da)); 32 CHKERRQ(DMGetGlobalVector(da,&global1)); 33 CHKERRQ(DMGetGlobalVector(da,&global2)); 34 CHKERRQ(DMRestoreGlobalVector(da,&global1)); 35 CHKERRQ(DMRestoreGlobalVector(da,&global2)); 36 CHKERRQ(DMGetGlobalVector(da,&global1)); 37 CHKERRQ(DMGetGlobalVector(da,&global3)); 38 CHKERRQ(DMGetGlobalVector(da,&global2)); 39 CHKERRQ(DMRestoreGlobalVector(da,&global1)); 40 CHKERRQ(DMRestoreGlobalVector(da,&global3)); 41 CHKERRQ(DMRestoreGlobalVector(da,&global2)); 42 CHKERRQ(DMGetGlobalVector(da,&global1)); 43 CHKERRQ(DMGetGlobalVector(da,&global3)); 44 CHKERRQ(DMGetGlobalVector(da,&global2)); 45 CHKERRQ(DMRestoreGlobalVector(da,&global1)); 46 CHKERRQ(DMRestoreGlobalVector(da,&global3)); 47 CHKERRQ(DMRestoreGlobalVector(da,&global2)); 48 CHKERRQ(DMDestroy(&da)); 49 CHKERRQ(PetscFinalize()); 50 return 0; 51 } 52 53 /*TEST 54 55 test: 56 57 TEST*/ 58