Actual source code: ex10.c

  1: static char help[] = "Tests PetscArraymove()/PetscMemmove()\n";

  3: #include <petscsys.h>

  5: int main(int argc, char **argv)
  6: {
  7:   PetscInt i, *a, *b;

  9:   PetscFunctionBeginUser;
 10:   PetscCall(PetscInitialize(&argc, &argv, (char *)0, help));

 12:   PetscCall(PetscMalloc1(10, &a));
 13:   PetscCall(PetscMalloc1(20, &b));

 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));

 22:   PetscCall(PetscFree(a));

 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));

 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));

 46:   PetscCall(PetscFinalize());
 47:   return 0;
 48: }

 50: /*TEST

 52:    test:

 54: TEST*/