Skip to content

Latest commit

 

History

History
25 lines (22 loc) · 2.48 KB

README.md

File metadata and controls

25 lines (22 loc) · 2.48 KB

Intro to Multithreading

AM205 Fall 2020 group activity

In this repository, you'll find sample scripts illustrating concepts from the Intro to Multithreading group activity.

Core usage visualization

  • I highly recommend installing the utility htop. It graphically shows real-time usage of each core on your system.

Matrix multiplication example

  • mat_mul.cc and mat_mul.py are C++ and Python implementations of matrix multiplication using shared memory parallelization. Each takes two arguments:
    • N, such that the system size of the multiplication is 2^N
    • t, the number of threads to parallelize over
  • C++
    • running "make" will generate the executable ./mat_mul representing the C++ implementation.
    • if you are running on a Mac, you will need to install a C++ compiler (preferably gcc10) with OpenMP support from MacPorts or Homebrew. There is a tutorial here.
      • After install, run cp ./.Makefile.hb Makefile.hb or cp ./.Makefile.mp Makefile.mp depending on which one you installed. I should have the Makefile set up to work after that; if it's still not compiling, let me know.
    • If you are running on Linux, the default Gnu compiler will work out of the box.
    • to run the C++ implementation, call ./mat_mul N t.
  • Python
    • running the python script ./mat_mul.py requires the numpy and joblib libraries to be installed. Both can be installed using your preferred package manager (pip, conda, system package managers e.g. pacman, apt, etc.)
    • to run the python script, call ./mat_mul.py [-v] N t. The optional argument "-v" switches from for-looping code parallelized with joblib to a vectorized implementation using numpy and OpenMP.
  • Data output and plotting
    • mat_mul.sh is a bash script which loops over several values of N and t while calling ./mat_mul, ./mat_mul.py, or ./mat_mul.py -v. It writes output to a series of output files in the form of four columns (N t time efficiency). Each group of N is separated by two newlines and labeled so that they can be plotted using gnuplot's index keywork
    • plot.gp is a gnuplot script reading in the out files produced by ./mat_mul.sh and producing a png threading.png as shown in the slides.
    • You don't need to run these if you don't want; I'm just including them for you to play around with if you'd like.