Actual source code: ex10.c
petsc-3.6.1 2015-08-06
2: static char help[] = "Tests PetscMemmove()\n";
4: #include <petscsys.h>
8: int main(int argc,char **argv)
9: {
10: int i,*a,*b,ierr;
11: PetscInitialize(&argc,&argv,(char*)0,help);
13: PetscMalloc1(10,&a);
14: PetscMalloc1(20,&b);
16: /*
17: Nonoverlapping regions
18: */
19: for (i=0; i<20; i++) b[i] = i;
20: PetscMemmove(a,b,10*sizeof(int));
21: PetscIntView(10,a,0);
23: PetscFree(a);
25: /*
26: | | | |
27: b a b+15 b+20
28: a+10 a+15
29: */
30: a = b + 5;
31: PetscMemmove(a,b,15*sizeof(int));
32: PetscIntView(15,a,0);
33: PetscFree(b);
35: /*
36: | | | |
37: a b a+20 a+25
38: b+20
39: */
40: PetscMalloc1(25,&a);
41: b = a + 5;
42: for (i=0; i<20; i++) b[i] = i;
43: PetscMemmove(a,b,20*sizeof(int));
44: PetscIntView(20,a,0);
45: PetscFree(a);
47: PetscFinalize();
48: return 0;
49: }