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