项目作者: doomkit

项目描述 :
🎓 ČVUT | Comparison Single-threaded and Multi-threaded matrix multiplications in C++
高级语言: C++
项目地址: git://github.com/doomkit/matrixmultiplication.git
创建时间: 2019-07-23T16:59:35Z
项目社区:https://github.com/doomkit/matrixmultiplication

开源协议:

下载


Matrix multiplication

Single thread multiplication

Use -st flag to run this application using single thread.

For single thread option I’ve ovreloaded * operator for class matrix. It implements straightforward solution with 3 for-cyclus (O(n^3) complexity).

Multithreaded multiplication

Use -mt flag to run this application in multithreaded mode.

For multithread option I’ve created method strassenMultiplication( ) in class matrix. It devides given matrices into sub-matrices and each thread works with its own sub-matrix.

Important conditions:

  • Matrices should be square with even dimensions (For example: 2x2, 4x4, 6x6…)
  • Matrices should have same dimensions
  • 2 or more concurrent threads have to be supported (otherwise you can run only single thread multiplication)

Comparison

Comparison of these two multiplication in Release mode.
Computing power: 2,3 GHz Intel Core i5 , Cores 2, Threads 4
Memory leaks were not detected while testing app with build in xCode profile testing.

Output of single thread multiplication:

  1. Matrix Multiplication using single thread.
  2. Matrices were generated.
  3. Dimensions are: 1000x1000, 1000x1000
  4. Starting multiplication using single thread.
  5. Needed 8142 ms to finish multiplication using single thread.
  6. Program ended with exit code: 0

Multithread multiplication:

  1. Matrix Multiplication using multi thread.
  2. Matrices were generated.
  3. Dimensions are: 1000x1000, 1000x1000
  4. Starting multithread multiplication with 4 treads.
  5. Needed 1913 ms to finish multiplication using 4 threads.
  6. Program ended with exit code: 0

As the result we have 4-5 times faster multiplication using 4 threads instead of just one.

Build and Run

Go to Build/Products/Release/ and run from terminal ./MatrixMultiplication opt to execute release build or you can run

  1. cmake CMakeLists.txt
  2. make
  3. ./runfile opt

where opt is one of these options:

  • -help opens help menu
  • -st runs single thread multiplication
  • -mt runs multithread multiplication

Other

  • All matrices are generated randomly using get_random_double( ) method from CourseWare
  • Time test starts after matrices are generated, so it shows time spent on multiplication only
  • Both algorithms works correct (method printMatrix( ) allows us to check it manually on small matricies)