Multiprocessing OpenMP
Multiprocessing OpenMP
• Introduction to OpenMP
• Basic Components of OpenMP
• OpenMP Parallel Regions
• Controlling the Number of Threads
• Parallelizing Loops with OpenMP
• Loop-Carried Dependencies and Synchronization
• How OpenMP Schedules for Loop Iterations
Introduction to OpenMP
• What is OpenMP?
– A parallel programming model for shared-memory
systems.
– Provides simple and flexible syntax for parallel
programming.
– Uses compiler directives, runtime libraries, and
environment variables to manage parallelism.
• Why OpenMP?
– Easy to implement and efficient for parallelizing loops and
tasks.
– Portable across platforms with minimal changes.
Basic Components of OpenMP
• Compiler Directives: Instructions that tell the compiler how to
parallelize the code.
• Will it work?
Loop-Carried Dependencies and Synchronization
• For Threads = 4 , N = 12
– Thread 0 gets iterations 0-2.
– Thread 1 gets iterations 3-5.
– Thread 2 gets iterations 6-8.
– Thread 3 gets iterations 9-11.
How OpenMP Schedules for Loop Iterations
• Dynamic Scheduling
• How it works: OpenMP assigns a chunk of iterations to a thread, but
threads request additional chunks as they finish processing. This is more
flexible and adapts to uneven workloads.
How OpenMP Schedules for Loop Iterations
• How dynamic scheduling works in OpenMP for the sum of array elements
example with 4 threads, N = 25, and a chunk size of 3
How OpenMP Schedules for Loop Iterations