|
5 | 5 |
|
6 | 6 | float tolerance = 0.000001;
|
7 | 7 |
|
| 8 | +float my_random(){ |
| 9 | + float val = (double)rand()/(double)RAND_MAX; |
| 10 | + return val; |
| 11 | +} |
| 12 | + |
8 | 13 | float* read_data(char str[],int rows,int cols){
|
9 | 14 | float* array = (float*)malloc(rows*cols*sizeof(float));
|
10 | 15 |
|
@@ -37,6 +42,18 @@ void write_data(char file_name[],float* matrix,int rows,int cols){
|
37 | 42 | return;
|
38 | 43 | }
|
39 | 44 |
|
| 45 | +float* generate_data(int rows,int cols){ |
| 46 | + float* arr = (float*)malloc(rows*cols*sizeof(float)); |
| 47 | + |
| 48 | + for(int i = 0;i<rows;i++){ |
| 49 | + for(int j = 0;j<cols;j++){ |
| 50 | + arr[i*cols + j] = my_random(); |
| 51 | + } |
| 52 | + } |
| 53 | + |
| 54 | + return arr; |
| 55 | +} |
| 56 | + |
40 | 57 | void print(float* array,int rows,int cols){
|
41 | 58 | for(int i = 0;i<rows;i++){
|
42 | 59 | for(int j = 0;j<cols;j++){
|
@@ -77,8 +94,10 @@ int main(int argc, char* argv[]){
|
77 | 94 | int n = atoi(argv[1]);
|
78 | 95 | char* file_name1 = argv[2];
|
79 | 96 | char* file_name2 = argv[3];
|
80 |
| - float* A = read_data(file_name1,n,32); |
81 |
| - float* B = read_data(file_name2,32,n); |
| 97 | + // float* A = read_data(file_name1,n,32); |
| 98 | + // float* B = read_data(file_name2,32,n); |
| 99 | + float* A = generate_data(n,32); |
| 100 | + float* B = generate_data(32,n); |
82 | 101 | float* prod = (float*)malloc(n*sizeof(float));
|
83 | 102 |
|
84 | 103 | multiply(A,B,prod,n);
|
|
0 commit comments