Lab 1
Lab 1
Overview
OpenMP versus MPI
We will use in our labs two software libraries: OpenMP and MPI:
OpenMP: to use all cores available on our deskop/laptops/servers to speedup the response time of a particular application;
MPI: to use the computation capacity of multiple computers (even millions of them, see Top500).
What is OpenMP
Please read the presentation from the textbook - page 226 (bottom of the page).
Instalation
For example, you can use the following guides:
• In Linux/MacOs for command lines: get the latest version of gcc, e.g. get the version gcc 4.6 that implements
version 3.0 of OpenMP standard: sudo apt-get install gcc-4.6. On MacOs you can use also: brew install
clang-omp
• In Windows for command lines: get Cygwin64 Terminal from https://cygwin.com/install.html that implements a
Linux simulator and select OpenMP (and MPI) at installation
• In Linux/MacOS/Windows for developing environment: get Eclipse PTP for C/C++ from https://www.eclipse.org/ptp/
(both for OpenMP and MPI).
First example
1. Write the Hello world code from the textbook - page 250 (first in the section 9.4.1)
2. Compile the code; in command line, for example: > gcc hello.c -o hello -fopenmp
3. Run the code, e.g. > ./hello. Uderstand the default value of number of threads and the role of private (run it
with and without). Modify the number of threads with (a) environment settings (b) the specific function (c) the
option on the pragma line.
1
Second example
1. The problem to solve: scalar multiplication between two vectors of dimension n, x and y:
n−1
X
< x, y >= xi yi (1)
i=0
How to do it faster? Partial sums on different cores! It there are p cores, than core k (0 ≤ i < p) will compute
(k+1)·n/p−1
X
xi yi (2)
i=k·n/p