Module 10: Open Multi-Processing
  Lecture 19: What is Parallelization?
 


The “omp for” Directive

Clauses Supported

  • Schedule(type[ ,chunk ] )
  • Private(list)
  • Lastprivate(list)
  • Collapse\
  • Ordered
  • Firstprivate(list)
  • Shared(list)
  • Reduction(operator:list)
  • Nowait

Example 1

A Parallel For Loop Example

#pragma omp parallel
{
#pragma omp for
for(int i = 0; i < N; i++){
do some work( i );
}
}
  • The variable i is made private to each thread by default you could do it explicitly by private(i) clause.

The “sections” Directive

  • It specifies that the enclosed section(s) of codes are to be divided among the threads in the team
#pragma omp sections [ clause(s) ]
{
#pragma omp section
< codeblock1 >
#pragma omp section
< codeblock2 >
#pragma omp section
:
}
  • Independent section directives are nested within a sections directive.Each section is executed once by a thread in the team.