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.
49 lines
953 B
49 lines
953 B
#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];
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|