ctest562.c 1.3 KB

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