diff --git a/Yang/3.c b/Yang/3.c new file mode 100644 index 0000000..8ca0f13 --- /dev/null +++ b/Yang/3.c @@ -0,0 +1,52 @@ +#include +#include +#include + +#define SIZE 1024 + +void matmul(float** A, float** B, float** C, int n) { + int i, j, k; + for (i = 0; i < n; ++i) { + for (j = 0; j < n; ++j) { + C[i][j] = 0; + for (k = 0; k < n; ++k) { + C[i][j] += A[i][k] * B[k][j]; + } + } + } +} + +int main() { + float** A = (float**)malloc(SIZE * sizeof(float*)); + float** B = (float**)malloc(SIZE * sizeof(float*)); + float** C = (float**)malloc(SIZE * sizeof(float*)); + int i, j; + for (i = 0; i < SIZE; ++i) { + A[i] = (float*)malloc(SIZE * sizeof(float)); + B[i] = (float*)malloc(SIZE * sizeof(float)); + C[i] = (float*)malloc(SIZE * sizeof(float)); + } + + srand(time(0)); + for (i = 0; i < SIZE; ++i) { + for (j = 0; j < SIZE; ++j) { + A[i][j] = rand() % 100; + B[i][j] = rand() % 100; + } + } + clock_t start = clock(); + matmul(A, B, C, SIZE); + clock_t end = clock(); + double time = (double)(end - start) / CLOCKS_PER_SEC; + printf("%f\n", time); + + for (i = 0; i < SIZE; ++i) { + free(A[i]); + free(B[i]); + free(C[i]); + } + free(A); + free(B); + free(C); + return 0; +} \ No newline at end of file