ctest752.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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,float *B3,int N){
  5. for(int i=0;i<N;i++){
  6. A0[i] = A3[i]/A3[i]*A3[i];
  7. A1[i] = A2[i];
  8. B0[i] = B1[i]+B1[i]*B3[i]+B3[i];
  9. }
  10. }
  11. int main(int argc,char **argv) {
  12. int size=844049;
  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. float *B3;
  30. B3 = (float *)malloc(floatBytes);
  31. for(int i=0;i<844049;i++){
  32. A0[i] = 31*i+1;
  33. A1[i] = 91*i+1;
  34. A2[i] = 49*i+1;
  35. A3[i] = 7*i+1;
  36. B0[i] = 77.9618326236*i+1;
  37. B1[i] = 86.9477707207*i+1;
  38. B2[i] = 11.9250689118+i+1;
  39. B3[i] = 90.3060706671*i+1;
  40. }
  41. struct timeval time0,time1;
  42. gettimeofday(&time0,NULL);
  43. FILE *file_for_block_of_interest = fopen("./profile_in_block.txt","w");
  44. if(file_for_block_of_interest) {
  45. char Buf[2] = "1";
  46. fwrite(Buf, 1, 1, file_for_block_of_interest);
  47. fclose(file_for_block_of_interest);}
  48. kernel_cpu(A0,A1,A2,A3,B0,B1,B2,B3,844049);
  49. file_for_block_of_interest = fopen("./profile_in_block.txt","w");
  50. if(file_for_block_of_interest) {
  51. char Buf[2] = "0";
  52. fwrite(Buf, 1, 1, file_for_block_of_interest);
  53. fclose(file_for_block_of_interest);}
  54. gettimeofday(&time1,NULL);
  55. double totaltime10 = (time1.tv_sec*1000000.0 + time1.tv_usec) - (time0.tv_sec*1000000.0 + time0.tv_usec);
  56. fprintf(stderr, "CPU time: %lf msecs ", (totaltime10)/1000.0F);
  57. free(A0);
  58. free(A1);
  59. free(A2);
  60. free(A3);
  61. free(B0);
  62. free(B1);
  63. free(B2);
  64. free(B3);
  65. printf("\n");return 0; }