Skip to content

Commit 8898de8

Browse files
modified sequential code
1 parent 74e2451 commit 8898de8

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

A2/sequential.c

+21-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55

66
float tolerance = 0.000001;
77

8+
float my_random(){
9+
float val = (double)rand()/(double)RAND_MAX;
10+
return val;
11+
}
12+
813
float* read_data(char str[],int rows,int cols){
914
float* array = (float*)malloc(rows*cols*sizeof(float));
1015

@@ -37,6 +42,18 @@ void write_data(char file_name[],float* matrix,int rows,int cols){
3742
return;
3843
}
3944

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+
4057
void print(float* array,int rows,int cols){
4158
for(int i = 0;i<rows;i++){
4259
for(int j = 0;j<cols;j++){
@@ -77,8 +94,10 @@ int main(int argc, char* argv[]){
7794
int n = atoi(argv[1]);
7895
char* file_name1 = argv[2];
7996
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);
82101
float* prod = (float*)malloc(n*sizeof(float));
83102

84103
multiply(A,B,prod,n);

0 commit comments

Comments
 (0)