ctest135.c 1.6 KB

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