ctest1037.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <sys/time.h>
  4. void kernel_cpu(int *A0,int *A1,int *A2,int *A3,int *A4,int *A5,int *A6,float *B0,float *B1,int N){
  5. for(int i=0;i<N;i++){
  6. A0[i] = A6[i];
  7. A1[i] = A6[i]/A4[i]*A6[i]-A4[i];
  8. A2[i] = A3[i]-A3[i]*A6[i];
  9. B0[i] = B1[i];
  10. }
  11. }
  12. int main(int argc,char **argv) {
  13. int size=715558;
  14. int intBytes = size*sizeof(int);
  15. int floatBytes = size*sizeof(float);
  16. int *A0;
  17. A0 = (int *)malloc(intBytes);
  18. int *A1;
  19. A1 = (int *)malloc(intBytes);
  20. int *A2;
  21. A2 = (int *)malloc(intBytes);
  22. int *A3;
  23. A3 = (int *)malloc(intBytes);
  24. int *A4;
  25. A4 = (int *)malloc(intBytes);
  26. int *A5;
  27. A5 = (int *)malloc(intBytes);
  28. int *A6;
  29. A6 = (int *)malloc(intBytes);
  30. float *B0;
  31. B0 = (float *)malloc(floatBytes);
  32. float *B1;
  33. B1 = (float *)malloc(floatBytes);
  34. for(int i=0;i<715558;i++){
  35. A0[i] = 71*i+1;
  36. A1[i] = 4*i+1;
  37. A2[i] = 49+i+1;
  38. A3[i] = 86*i+1;
  39. A4[i] = 70+i+1;
  40. A5[i] = 30*i+1;
  41. A6[i] = 8*i+1;
  42. B0[i] = 60.9035292968*i+1;
  43. B1[i] = 77.6052770175*i+1;
  44. }
  45. struct timeval time0,time1;
  46. gettimeofday(&time0,NULL);
  47. FILE *file_for_block_of_interest = fopen("./profile_in_block.txt","w");
  48. if(file_for_block_of_interest) {
  49. char Buf[2] = "1";
  50. fwrite(Buf, 1, 1, file_for_block_of_interest);
  51. fclose(file_for_block_of_interest);}
  52. kernel_cpu(A0,A1,A2,A3,A4,A5,A6,B0,B1,715558);
  53. file_for_block_of_interest = fopen("./profile_in_block.txt","w");
  54. if(file_for_block_of_interest) {
  55. char Buf[2] = "0";
  56. fwrite(Buf, 1, 1, file_for_block_of_interest);
  57. fclose(file_for_block_of_interest);}
  58. gettimeofday(&time1,NULL);
  59. double totaltime10 = (time1.tv_sec*1000000.0 + time1.tv_usec) - (time0.tv_sec*1000000.0 + time0.tv_usec);
  60. fprintf(stderr, "CPU time: %lf msecs ", (totaltime10)/1000.0F);
  61. free(A0);
  62. free(A1);
  63. free(A2);
  64. free(A3);
  65. free(A4);
  66. free(A5);
  67. free(A6);
  68. free(B0);
  69. free(B1);
  70. printf("\n");return 0; }