ctest930.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <sys/time.h>
  4. void kernel_cpu(int *A0,int *A1,float *B0,int N){
  5. for(int i=0;i<N;i++){
  6. A0[i] = A1[i]*A1[i]*A1[i];
  7. B0[i] = B0[i]*B0[i];
  8. }
  9. }
  10. int main(int argc,char **argv) {
  11. int size=870913;
  12. int intBytes = size*sizeof(int);
  13. int floatBytes = size*sizeof(float);
  14. int *A0;
  15. A0 = (int *)malloc(intBytes);
  16. int *A1;
  17. A1 = (int *)malloc(intBytes);
  18. float *B0;
  19. B0 = (float *)malloc(floatBytes);
  20. for(int i=0;i<870913;i++){
  21. A0[i] = 95+i+1;
  22. A1[i] = 15*i+1;
  23. B0[i] = 92.0432343818*i+1;
  24. }
  25. struct timeval time0,time1;
  26. gettimeofday(&time0,NULL);
  27. FILE *file_for_block_of_interest = fopen("./profile_in_block.txt","w");
  28. if(file_for_block_of_interest) {
  29. char Buf[2] = "1";
  30. fwrite(Buf, 1, 1, file_for_block_of_interest);
  31. fclose(file_for_block_of_interest);}
  32. kernel_cpu(A0,A1,B0,870913);
  33. file_for_block_of_interest = fopen("./profile_in_block.txt","w");
  34. if(file_for_block_of_interest) {
  35. char Buf[2] = "0";
  36. fwrite(Buf, 1, 1, file_for_block_of_interest);
  37. fclose(file_for_block_of_interest);}
  38. gettimeofday(&time1,NULL);
  39. double totaltime10 = (time1.tv_sec*1000000.0 + time1.tv_usec) - (time0.tv_sec*1000000.0 + time0.tv_usec);
  40. fprintf(stderr, "CPU time: %lf msecs ", (totaltime10)/1000.0F);
  41. free(A0);
  42. free(A1);
  43. free(B0);
  44. printf("\n");return 0; }