I tested the following simple matrix multiplication program on my laptop, Inspiron 1501, the operating system Ubuntu Linux, the program did matrix multiplication C=AxB for 1000 times, A,B,C are all 300x300 matrix. Use time command, I get the following result,
Netlib BLAS:
real 0m2.150s
user 0m2.128s
sys 0m0.016s
ACML BLAS:
real 1m24.560s
user 1m22.985s
sys 0m1.556s
Goto BLAS:
real 1m22.421s
user 1m21.025s
sys 0m0.116s
Why Netlib BLAS are much much faster than those so-called optimized BLAS? I tested the same program under different operating systems and on different computers and got the similar results: plain Netlib BLAS is much faster. Can anybody tell me why?
CPP program
/////////////////////////////////////////////////////////////////////////////////////////
#include<iostream>
#include<complex>
// define complex type
typedef std::complex<double> zomplex;
const zomplex Im = zomplex(0.0, 1.0);
/* ZGEMM */
extern "C" void zgemm_(const char*, const char*, const int*, const int*, const int*,
const double*, void*, const int*, void*, const int*, const double*, void*, const int*);
const int m = 300; // the dimension of the matrices in the test
const int n = m*m; // the number of elements in a matrix
const int ntimes = 1000; // the number of times we do the computation C = AxB;
int main(void)
{
zomplex* A = new zomplex[m*m];
zomplex* B = new zomplex[m*m];
zomplex* C = new zomplex[m*m];
const char trans[] = {'N'};
const double alpha[] = {1.0, 0.0};
const double beta[] = {0.0, 0.0};
int i;
for (i = 0; i < ntimes; ++i)
{
zgemm_(trans, trans, &m, &m, &m, alpha, A, &m, B, &m, beta, C, &m);
}
delete[] A;
delete[] B;
delete[] C;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////
Makefile
//////////////////////////////
CXX = g++
CC = g++
CXXFLAGS = -Wall -W
#LOADLIBES= -lf77blas -latlas -lg2c
LOADLIBES= -lgotoblas -lg2c -lpthread
#LOADLIBES= -lblas -lg2c
#LOADLIBES= -lacml -lg2c
TARGETS = zgemm_test
all: $(TARGETS)
.PHONY: clean
clean:
rm -rf *.o *~ *orig *exe $(TARGETS)
////////////////////////////////////////////////////////

