| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- #include <stdio.h>
- #include <stdlib.h>
- #include <sys/time.h>
- void kernel_cpu(int *A0,int *A1,int *A2,int *A3,int *A4,int N){
- for(int i=0;i<N;i++){
- A0[i] = A1[i]*A4[i];
- }
- }
- int main(int argc,char **argv) {
- int size=415743;
- int intBytes = size*sizeof(int);
- int floatBytes = size*sizeof(float);
- int *A0;
- A0 = (int *)malloc(intBytes);
- int *A1;
- A1 = (int *)malloc(intBytes);
- int *A2;
- A2 = (int *)malloc(intBytes);
- int *A3;
- A3 = (int *)malloc(intBytes);
- int *A4;
- A4 = (int *)malloc(intBytes);
- for(int i=0;i<415743;i++){
- A0[i] = 37+i+1;
- A1[i] = 10+i+1;
- A2[i] = 41+i+1;
- A3[i] = 27*i+1;
- A4[i] = 34*i+1;
- }
- struct timeval time0,time1;
- gettimeofday(&time0,NULL);
- FILE *file_for_block_of_interest = fopen("./profile_in_block.txt","w");
- if(file_for_block_of_interest) {
- char Buf[2] = "1";
- fwrite(Buf, 1, 1, file_for_block_of_interest);
- fclose(file_for_block_of_interest);}
- kernel_cpu(A0,A1,A2,A3,A4,415743);
- file_for_block_of_interest = fopen("./profile_in_block.txt","w");
- if(file_for_block_of_interest) {
- char Buf[2] = "0";
- fwrite(Buf, 1, 1, file_for_block_of_interest);
- fclose(file_for_block_of_interest);}
- gettimeofday(&time1,NULL);
- double totaltime10 = (time1.tv_sec*1000000.0 + time1.tv_usec) - (time0.tv_sec*1000000.0 + time0.tv_usec);
- fprintf(stderr, "CPU time: %lf msecs ", (totaltime10)/1000.0F);
- free(A0);
- free(A1);
- free(A2);
- free(A3);
- free(A4);
- printf("\n");return 0; }
|