1 2 static char help[] = "Tests PetscArraymove()/PetscMemmove()\n"; 3 4 #include <petscsys.h> 5 6 int main(int argc,char **argv) 7 { 8 PetscInt i,*a,*b; 9 10 CHKERRQ(PetscInitialize(&argc,&argv,(char*)0,help)); 11 12 CHKERRQ(PetscMalloc1(10,&a)); 13 CHKERRQ(PetscMalloc1(20,&b)); 14 15 /* 16 Nonoverlapping regions 17 */ 18 for (i=0; i<20; i++) b[i] = i; 19 CHKERRQ(PetscArraymove(a,b,10)); 20 CHKERRQ(PetscIntView(10,a,NULL)); 21 22 CHKERRQ(PetscFree(a)); 23 24 /* 25 | | | | 26 b a b+15 b+20 27 a+10 a+15 28 */ 29 a = b + 5; 30 CHKERRQ(PetscArraymove(a,b,15)); 31 CHKERRQ(PetscIntView(15,a,NULL)); 32 CHKERRQ(PetscFree(b)); 33 34 /* 35 | | | | 36 a b a+20 a+25 37 b+20 38 */ 39 CHKERRQ(PetscMalloc1(25,&a)); 40 b = a + 5; 41 for (i=0; i<20; i++) b[i] = i; 42 CHKERRQ(PetscArraymove(a,b,20)); 43 CHKERRQ(PetscIntView(20,a,NULL)); 44 CHKERRQ(PetscFree(a)); 45 46 CHKERRQ(PetscFinalize()); 47 return 0; 48 } 49 50 /*TEST 51 52 test: 53 54 TEST*/ 55