xref: /petsc/src/benchmarks/PetscMemcpy.c (revision 66af8762ec03dbef0e079729eb2a1734a35ed7ff)
1 #include <petscsys.h>
2 #include <petsctime.h>
3 
4 int main(int argc,char **argv)
5 {
6   PetscLogDouble x,y;
7   PetscScalar    *A,*B;
8 
9   PetscCall(PetscInitialize(&argc,&argv,0,0));
10   PetscCall(PetscCalloc1(8000000,&A));
11   PetscCall(PetscMalloc1(8000000,&B));
12 
13   for (i=0; i<8000000; i++) {
14     A[i] = i%61897;
15     B[i] = i%61897;
16   }
17   /* To take care of paging effects */
18   PetscCall(PetscArraycpy(A,B,8000000));
19   PetscCall(PetscTime(&x));
20   PetscCall(PetscArraycpy(A,B,8000000));
21   PetscCall(PetscTime(&x));
22 
23   fprintf(stdout,"%s : \n","PetscMemcpy");
24   fprintf(stdout,"    %-15s : %e MB/s\n","Bandwidth",10.0*8*8/(y-x));
25 
26   PetscCall(PetscFree(A));
27   PetscCall(PetscFree(B));
28   PetscCall(PetscFinalize());
29   return 0;
30 }
31