ctest1087.c 1.7 KB

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