parent
4a70d5f4ab
commit
e64991641d
@ -0,0 +1,48 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <ctime>
|
||||
#include <iostream>
|
||||
#include <ostream>
|
||||
#define SIZE 1024
|
||||
int main(){
|
||||
void matmul(float **A,float **B,float **C,int n);
|
||||
int i,j,n;
|
||||
float **A=new float*[n];
|
||||
float **B=new float*[n];
|
||||
float **C=new float*[n];
|
||||
for(i=0;i<n;i++){
|
||||
A[i]=new float[n];
|
||||
B[i]=new float[n];
|
||||
C[i]=new float[n];
|
||||
}
|
||||
for(i=0;i<n;i++){
|
||||
for(j=0;j<n;j++){
|
||||
A[i][j]=rand()%100;
|
||||
B[i][j]=rand()%100;
|
||||
}
|
||||
}
|
||||
clock_t start=clock();
|
||||
matmul(A,B,C,SIZE);
|
||||
clock_t end=clock();
|
||||
std::cout<<"基础稠密矩阵乘法时间:"<<double(end-start)/CLOCKS_PER_SEC<<"秒"<<std::endl;
|
||||
for(i=0;i<n;i++){
|
||||
delete[] A[i];
|
||||
delete[] B[i];
|
||||
delete[] C[i];
|
||||
}
|
||||
delete[] A;
|
||||
delete[] B;
|
||||
delete[] C;
|
||||
}
|
||||
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]=C[i][j]+A[i][k]*B[k][j];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in new issue