● Agenda
• Background• Multiprocessing Programming• Preference• Programming Model• Parallel Section• Clauses• Synchronization
● Background
Parallel has no semantic impact
Concurrency has a substantial semantic impact
● Background
• Symmetric Multi Processor(SMP)– Shared Memory Multiprocessing Programming– OpenMP
• Massively Parallel Processor(MPP)– Message Passing Interface Programming– MPI
● Background
● Multiprocessing Programming
● Multiprocessing Programming
• General Threading Model– Main thread executes the program’s main function– Main thread creates subthreads, witch execute other
functions in the program.– Subthreads can also create additional threads.
● Multiprocessing Programming
• Benefits– Increased performance and better resource utilization
• Even on single processor systems – for hiding latency and increasing throughput
– IPC thread shared memory is more efficient
• Risk– Increases complexity of the application– Difficult to debug (data races, deadlocks, etc.)
● OpenMP Preference (later VS2005)
● OpenMP Preference (later GCC 4.2)
● Programming Model
• Generate multi-thread code by referencing directive code
• Compiler is required to support openMP
• To eliminate synchronization and dependency
●
Section3
JoinFork
Section1
JoinFork
Section2
JoinFork
Programming Model
● Parallel Section (for)
#pragma omp for [clause [clause …] ] { for loop}
Fork
for loop
Join
● Parallel Section (sections)
#pragma omp sections [clause [clause …] ] { [#progma omp section] structured code block}
Fork
sections
Join
● Clauses
• private(var1, …)– to block sharing selected values with threads
• shared(var1, …)– to share selected values with threads
• schedule(type [, chunk_size])– to divide work with threads for equality
• static• dynamic
● Synchronization (critical section)
• Declaring critical section in parallel section
• Running only single thread at moment
#pragma omp critical [(name)]{ structured code block}
OPEN MPShared Memory Multiprocessing Programming
https://computing.llnl.gov/tutorials/openMP/