// Matrix multiplication using C++ threads // c++ -std=c++11 -pthread -O2 matrix_mpy.cxx matrix.cxx matrix_mpy_user.cxx ee155_utils.cxx #include #include #include using namespace std; #include "bits.hxx" #include "ee155_utils.hxx" #include "matrix.hxx" // Simple algorithm for multiplying two matrices. void Matrix::mpy_dumb (const Matrix &A, const Matrix &B) { int N = this->N(); for (int r=0; rdata[index(r,c)] = sum; } } // Wrapper function around Matrix::mpy2(), which is the multithreaded/blocked // algorithm. It just runs ::mpy2() several times and checks how long it took. static void run_mpy2 (int BS, int n_threads, const Matrix &a, const Matrix &b, const Matrix &c, Matrix &d) { vector times; for (int i=0; i<5; ++i) { auto start = start_time(); d.mpy2 (a, b, BS, n_threads); double time_sec = delta_usec (start) / 1000000.0; times.push_back (time_sec); c.compare (d, "reference", "you"); cout<<"mpy2 with "< times; for (int i=0; i<5; ++i) { auto start = start_time(); d.mpy1 (a, b, BS); double time_sec = delta_usec (start) / 1000000.0; times.push_back (time_sec); c.compare (d, "reference", "you"); LOG ("2Kx2K mpy1 took "<