You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

55 lines
1.3 KiB

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <arm_neon.h>
#define SIZE 1024
void matmul(float** A, float** B, float** C, int n) {
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
float sum = 0.0;
for (int k = 0; k < n; k++) {
sum += A[i][k] * B[k][j];
}
C[i][j] = sum;
}
}
}
int main() {
float** A = (float**)malloc(SIZE * sizeof(float*));
float** B = (float**)malloc(SIZE * sizeof(float*));
float** C = (float**)malloc(SIZE * sizeof(float*));
for (int 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(NULL));
for (int i = 0; i < SIZE; i++) {
for (int 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();
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˷<EFBFBD><EFBFBD><EFBFBD>ʱ: %lf <20><><EFBFBD><EFBFBD>\n", 1000.0 * (end - start) / CLOCKS_PER_SEC);
for (int i = 0; i < SIZE; i++) {
free(A[i]);
free(B[i]);
free(C[i]);
}
free(A);
free(B);
free(C);
return 0;
}