ctest1042.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <sys/time.h>
  4. void kernel_cpu(int *A0,int *A1,int *A2,float *B0,float *B1,float *B2,float *B3,int N){
  5. for(int i=0;i<N;i++){
  6. A0[i] = A2[i]+A1[i];
  7. B0[i] = B3[i]*B3[i];
  8. B1[i] = B3[i]/B3[i];
  9. B2[i] = B3[i]+B3[i]*B3[i]*B3[i];
  10. }
  11. }
  12. int main(int argc,char **argv) {
  13. int size=721963;
  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. float *B0;
  23. B0 = (float *)malloc(floatBytes);
  24. float *B1;
  25. B1 = (float *)malloc(floatBytes);
  26. float *B2;
  27. B2 = (float *)malloc(floatBytes);
  28. float *B3;
  29. B3 = (float *)malloc(floatBytes);
  30. for(int i=0;i<721963;i++){
  31. A0[i] = 91+i+1;
  32. A1[i] = 35*i+1;
  33. A2[i] = 72*i+1;
  34. B0[i] = 84.7106196208*i+1;
  35. B1[i] = 85.485667048*i+1;
  36. B2[i] = 98.1714173776+i+1;
  37. B3[i] = 11.4347524894*i+1;
  38. }
  39. struct timeval time0,time1;
  40. gettimeofday(&time0,NULL);
  41. FILE *file_for_block_of_interest = fopen("./profile_in_block.txt","w");
  42. if(file_for_block_of_interest) {
  43. char Buf[2] = "1";
  44. fwrite(Buf, 1, 1, file_for_block_of_interest);
  45. fclose(file_for_block_of_interest);}
  46. kernel_cpu(A0,A1,A2,B0,B1,B2,B3,721963);
  47. file_for_block_of_interest = fopen("./profile_in_block.txt","w");
  48. if(file_for_block_of_interest) {
  49. char Buf[2] = "0";
  50. fwrite(Buf, 1, 1, file_for_block_of_interest);
  51. fclose(file_for_block_of_interest);}
  52. gettimeofday(&time1,NULL);
  53. double totaltime10 = (time1.tv_sec*1000000.0 + time1.tv_usec) - (time0.tv_sec*1000000.0 + time0.tv_usec);
  54. fprintf(stderr, "CPU time: %lf msecs ", (totaltime10)/1000.0F);
  55. free(A0);
  56. free(A1);
  57. free(A2);
  58. free(B0);
  59. free(B1);
  60. free(B2);
  61. free(B3);
  62. printf("\n");return 0; }