Actual source code: PetscMemcpy.c
petsc-3.7.3 2016-08-01
2: #include <petscsys.h>
3: #include <petsctime.h>
7: int main(int argc,char **argv)
8: {
9: PetscLogDouble x,y,z;
10: int i,ierr;
11: PetscScalar *A,*B;
13: PetscInitialize(&argc,&argv,0,0);
15: PetscMalloc1(8000000,&A);
16: PetscMalloc1(8000000,&B);
18: for (i=0; i<8000000; i++) {
19: A[i] = i%61897;
20: B[i] = i%61897;
21: }
22: /* To take care of paging effects */
23: PetscMemcpy(A,B,sizeof(PetscScalar)*0);
24: PetscTime(&x);
26: PetscTime(&x);
27: /*
28: PetscMemcpy(A,B,sizeof(PetscScalar)*8000000);
29: PetscMemcpy(A,B,sizeof(PetscScalar)*8000000);
30: PetscMemcpy(A,B,sizeof(PetscScalar)*8000000);
31: PetscMemcpy(A,B,sizeof(PetscScalar)*8000000);
32: PetscMemcpy(A,B,sizeof(PetscScalar)*8000000);
33: PetscMemcpy(A,B,sizeof(PetscScalar)*8000000);
34: PetscMemcpy(A,B,sizeof(PetscScalar)*8000000);
35: PetscMemcpy(A,B,sizeof(PetscScalar)*8000000);
36: PetscMemcpy(A,B,sizeof(PetscScalar)*8000000);
37: PetscMemcpy(A,B,sizeof(PetscScalar)*8000000); */
38: { int j;
39: for (j = 0; j<10; j++)
40: for (i=0; i<8000000; i++) B[i] = A[i];}
42: PetscTime(&y);
43: PetscMemcpy(A,B,sizeof(PetscScalar)*0);
44: PetscMemcpy(A,B,sizeof(PetscScalar)*0);
45: PetscMemcpy(A,B,sizeof(PetscScalar)*0);
46: PetscMemcpy(A,B,sizeof(PetscScalar)*0);
47: PetscMemcpy(A,B,sizeof(PetscScalar)*0);
48: PetscMemcpy(A,B,sizeof(PetscScalar)*0);
49: PetscMemcpy(A,B,sizeof(PetscScalar)*0);
50: PetscMemcpy(A,B,sizeof(PetscScalar)*0);
51: PetscMemcpy(A,B,sizeof(PetscScalar)*0);
52: PetscMemcpy(A,B,sizeof(PetscScalar)*0);
53: PetscTime(&z);
55: fprintf(stdout,"%s : \n","PetscMemcpy");
56: fprintf(stdout," %-15s : %e MB/s\n","Bandwidth",10.0*8*8/(y-x));
57: fprintf(stdout," %-15s : %e sec\n","Latency",(z-y)/10.0);
58: fprintf(stdout," %-15s : %e sec\n","Per PetscScalar",(2*y-x-z)/8000000.0);
60: PetscFree(A);
61: PetscFree(B);
62: PetscFinalize();
63: return(0);
64: }