Actual source code: ex10.c


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

  4: #include <petscsys.h>

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

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

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

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

 23:   PetscCall(PetscFree(a));

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

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

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

 51: /*TEST

 53:    test:

 55: TEST*/