4 Openmp
4 Openmp
Computation
Hello OpenMP
#pragma omp parallel
{
// I am now thread i of n
switch(omp_get_thread_num()) { Parallel
case 0 : blah1..
case 1: blah2.. Construct
}
}
// Back to normal
a=b=0
thread 1 thread 2
b=1 a=1
flush(b); flush(a); flush(a); flush(b);
if (a == 0) { if (b == 0) {
critical section critical section
} }
Beware more of Compiler Re-ordering
// Parallel construct
{
int b = initialSalary
print(“Initial Salary was %d\n”, initialSalary);
Book-keeping() // No read b or write initialSalary
if (b < 10000) {
raiseSalary(500);
}
}
Thread Control
E nvironment Variable Ways to modify value Way to retrieve value Initial value
OMP_SCHEDULE Implementation
* defined
• Is barrier sufficient?
• What change to the code is needed?
– Recall barrier is per-team