Lecture 10 Shared Memory Programming with OpenMP.pptx
Lecture 10 Shared Memory Programming with OpenMP.pptx
Introduction: 1-7
Shared-Memory Model vs. Message Passing
Model
Shared-Memory Model
• One active thread at start and end of the program
• Number of active threads inside program changes dynamically during
execution
• Supports incremental parallelism
The process of converting a sequential program to a parallel program a little bit at
a time
Message-Passing Model
• All processes remain active throughout execution of program
• Sequential-to-parallel transformation requires major effort
• No incremental parallelism
Transformation done in one giant step rather than many tiny steps
Introduction to OpenMP
• OpenMP has emerged as a standard method for shared-memory
programming
Same as MPI has become the standard for distributed-memory
programming
• Compiler support
C, C++ & Fortran
Intel (icc -openmp), and GNU (gcc -fopenmp)
Introduction to OpenMP (Cont.)
• OpenMP (Open Multi Processing) is an API for writing
multithreaded applications
Source: http://openmp.org/mp-documents/omp-hands-on-SC08.pdf
Implementation using Visual Studio C++
• Turn on OpneMP support in Visual Studio
• Project properties 🡪 Configuration 🡪 C/C++/Language
How does OpenMP work?
• C programs often express data-parallel operations as for loops
for (i = first; i < size; i += 2)
marked[i] = 1;
Private Variable:
•Has different address in execution context of every thread
•omp_set_num_threads
omp_set_dynamic(0); // disable dynamic adjustment
https://www.youtube.com/watch?v=nE-xN4Bf8XI&list=PLLX-Q6B8xq
Z8n8bwjGdzBJ25X2utwnoEG&index=1
Questions?