Lecture 3
Learning objectives
After this class, you should be able to:
- Explain the following: (i) fork-join model used in OpenMP, (ii) shared variable, and (iii) private variable.
- Explain the purpose of the following directives, clauses, and functions: (i)
parallel
, (ii)omp_get_thread_num
, (iii)for
, (iv)single
, (v)nowait
, (vi)sections
, (vii)section
, (viii)omp_get_wtime
, (ix)omp_get_wtick
, (x)parallel for
, (xi)firstprivate
, (xii)lastprivate
, (xiii)private
, (xiv)omp_get_num_procs
, (xv)omp_set_num_threads
, (xvi)omp_get_max_threads
, (xvii)critical
, (xviii)reduction
, and (xix)schedule
.- Given sequential code, use the above features to parallelize the code.
- Given a code that is incorrectly parallelized using OpenMP, point out the errors.
Reading assignment
- OpenMP tutorial at: http://www.llnl.gov/computing/tutorials/openMP.
- Reference -- OpenMP 2 C/C++ specifications: http://www.openmp.org/mp-documents/cspec20.pdf.
Exercises and review questions
- Exercises and review questions on current lecture's material
- Parallelize the following loop using OpenMP.
a = 0;
for (i=0; i < n; i++)
a += b[i];
- Give an example to demonstrate the utility of the
single
pragma.- Use OpenMP to parallelize matrix multiplication using the loop ordering that gave better performance sequentially.
- Compare the performance of the OpenMP example with inverted loop on slide 53 of lecture 3, with a code that parallelizes the inner loop of the original sequential code. Report your timings on the discussion board for for different values of
m
,n
, and number of threads.- Preparation for the next lecture
- None.
Last modified: 13 Jan 2010