110 likes | 311 Views
OpenMP Lab Introduction. Compiling for OpenMP. Open project Properties dialog box Select OpenMP Support from C/C++ -> Language. Setting the Number of Threads. set OMP_NUM_THREADS=4. The default number of threads should be the number of cores available on the system.
E N D
Compiling for OpenMP Open project Properties dialog box Select OpenMP Support from C/C++ -> Language
Setting the Number of Threads set OMP_NUM_THREADS=4 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
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 • intomp_get_thread_num() • intomp_get_num_threads()
Convolution Filter 6 4 8 4 3 5 4 indata outdata Apply filter masks to a grayscale image Code uses 5-point stencil to simulate shifted image as filters
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 • Alternate Algorithm: 17 21 11 25 6 4 8 4 3 3 • 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 Prefix scan Compute the inclusive prefix sum from input array; store results in output array
Quicksort 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 • Recursive version of Quicksort algorithm • 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/ Apprentice Level Master Level Phase 1: May 31, 2010 to July 12, 2010 Phase 2: August 9, 2010 to November 1, 2010