OpenMP Lab Introduction

advertisement
OpenMP Lab Introduction
upcrc.illinois.edu
Compiling for OpenMP
• Open project Properties dialog box
• Select OpenMP Support from C/C++ -> Language
Setting the Number of Threads
• The default number of threads should be the number of
cores available on the system.
• In command window, use the environment variable,
OMP_NUM_THREADS, to set the number of threads desired
set OMP_NUM_THREADS=4
General Instructions
• Use OpenMP to parallelize the given serial codes
• More detailed instructions given in lab directory
• Consult the OpenMP 3.0 Specification document for more
detailed information and additional constructs
– http://www.openmp.org for download
– API functions listed and explained
• int omp_get_thread_num()
• int omp_get_num_threads()
Convolution
• Apply filter masks to a grayscale image
• Code uses 5-point stencil to simulate shifted image as
filters
3
8
6
4
Filter
5
4
4
indata
outdata
Matrix-Matrix Multiplication
• Several different formulations of dense matrix-matrix
multiplication
– Triple-nested loop
– Blocked
– Recursive
• Try OpenMP in one or more
– Is one version easier to use with OpenMP?
– Is there a noticeable difference in execution speed in one version
over the others?
Sparse Matrix, Dense Vector
• Multiply a sparse matrix by a dense vector
– Matrix is stored in compressed sparse row (CSR) format
– Multiply only non-zero elements with corresponding vector
elements
Prefix Scan
• Compute the inclusive prefix sum from input array; store
results in output array
3
8
6
4
4
Prefix scan
3 11 17 21 25
Alternate Algorithm:
for j := 1 to log2n do
for all k in parallel do
if (k ≥ 2j-1) then
x[k] := x[k – 2j-1] + x[k]
fi
od
od
Quicksort
• Recursive version of Quicksort algorithm
485
041
340
526
188
739
489
387
988
488
188
041
340
387
485
739
489
526
988
488
041
188
340
387
485
488
489
526
739
988
• Consider using OpenMP tasks
– At some point (size of partition), overhead to create new task
become prohibitive; switch to serial Quicksort or other sort
algorithm
Minimum Spanning Tree
• Construct the Minimum Spanning Tree from a weighted
graph using Prim’s Algorithm
– Start with arbitrary node in MST
– While more nodes not in MST do
• Find smallest weight edge from node in MST to some node not in MST
• Add new edge and node to MST
• Caution: first nested loop finds the index of the minimum
http://www.intel.com/go/threadingchallenge2010/
Phase 1: May 31, 2010 to July 12, 2010
Phase 2: August 9, 2010 to November 1, 2010
Apprentice Level
Master Level
Download