xref: /petsc/src/sys/tests/ex10.c (revision d71ae5a4db6382e7f06317b8d368875286fe9008)
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   PetscFunctionBeginUser;
11   PetscCall(PetscInitialize(&argc, &argv, (char *)0, help));
12 
13   PetscCall(PetscMalloc1(10, &a));
14   PetscCall(PetscMalloc1(20, &b));
15 
16   /*
17       Nonoverlapping regions
18   */
19   for (i = 0; i < 20; i++) b[i] = i;
20   PetscCall(PetscArraymove(a, b, 10));
21   PetscCall(PetscIntView(10, a, NULL));
22 
23   PetscCall(PetscFree(a));
24 
25   /*
26      |        |                |       |
27      b        a               b+15    b+20
28                               a+10    a+15
29   */
30   a = b + 5;
31   PetscCall(PetscArraymove(a, b, 15));
32   PetscCall(PetscIntView(15, a, NULL));
33   PetscCall(PetscFree(b));
34 
35   /*
36      |       |                    |       |
37      a       b                   a+20   a+25
38                                         b+20
39   */
40   PetscCall(PetscMalloc1(25, &a));
41   b = a + 5;
42   for (i = 0; i < 20; i++) b[i] = i;
43   PetscCall(PetscArraymove(a, b, 20));
44   PetscCall(PetscIntView(20, a, NULL));
45   PetscCall(PetscFree(a));
46 
47   PetscCall(PetscFinalize());
48   return 0;
49 }
50 
51 /*TEST
52 
53    test:
54 
55 TEST*/
56