1000*1000 matrices A, B, c,c=a*b

Source: Internet
Author: User

Efficiency can be compared with MATLAB

int m;
int i, j, k;
double r;
double *A, *B, *C;
m = 1000;
A = new double[m*m];
B = new double[m*m];
C = new double[m*m];
//置初值
for (i=0; i<m*m; i++) {
A[i] = 1;
B[i] = 1;
C[i] = 0;
}
int bf; // blocking factor
int jj, kk, im;
int minj, mink;
bf = 48; // 可以修改
for (jj=0; jj<m; jj+=bf)
for (kk=0; kk<m; kk+=bf)
for ( i=0; i<m; ++i) {
minj = (jj+bf)<m ? (jj+bf):m;
for (j=jj; j<minj; ++j) {
r = 0;
im = i*m;
mink = (kk+bf)<m ? (kk+bf):m;
for (k=kk; k<mink; ++k) {
r += A[im+k]*B[k*m+j];
}
C[im+j] += r;
}
}
delete[] A;
delete[] B;
delete[] C;

This program is 1 time times slower than Matlab, I have to search the Web to a FORTRAN program (Block DGEMM), its speed is 0.5 times times slower than Matlab, do not know who can write a comparable with MATLAB program?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.