parent
f44797a958
commit
92a2e3e0b0
@ -0,0 +1,54 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <ctime>
|
||||
#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++){
|
||||
C[i][j]=0;
|
||||
for(int k=0;k<n;k++){
|
||||
C[i][j]+=A[i][k]*B[k][j];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main(){
|
||||
//分配矩阵内存
|
||||
float** A=new float*[SIZE];
|
||||
float** B=new float*[SIZE];
|
||||
float** C=new float*[SIZE];
|
||||
|
||||
for(int i=0;i<SIZE;i++){
|
||||
A[i]=new float[SIZE];
|
||||
B[i]=new float[SIZE];
|
||||
C[i]=new float[SIZE];
|
||||
}
|
||||
|
||||
//初始化
|
||||
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("初始稠密矩阵乘法时间:%f秒\n",(double)(end-start)/CLOCKS_PER_SEC);
|
||||
|
||||
for(int i=0;i<SIZE;i++){
|
||||
delete[] A[i];
|
||||
delete[] B[i];
|
||||
delete[] C[i];
|
||||
}
|
||||
delete[] A;
|
||||
delete[] B;
|
||||
delete[] C;
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in new issue