Actual source code: ex10.c
petsc-3.12.4 2020-02-04
Report Typos and Errors

      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;

     11:   PetscInitialize(&argc,&argv,(char*)0,help);if (ierr) return ierr;

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

     16:   /*
     17:       Nonoverlapping regions
     18:   */
     19:   for (i=0; i<20; i++) b[i] = i;
     20:   PetscArraymove(a,b,10);
     21:   PetscIntView(10,a,NULL);

     23:   PetscFree(a);

     25:   /*
     26:      |        |                |       |
     27:      b        a               b+15    b+20
     28:                               a+10    a+15
     29:   */
     30:   a    = b + 5;
     31:   PetscArraymove(a,b,15);
     32:   PetscIntView(15,a,NULL);
     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:   PetscArraymove(a,b,20);
     44:   PetscIntView(20,a,NULL);
     45:   PetscFree(a);

     47:   PetscFinalize();
     48:   return ierr;
     49: }

     53: /*TEST

     55:    test:

     57: TEST*/