Openmp Lab: Antonio Gómez-Iglesias Agomez@Tacc - Utexas.Edu Texas Advanced Computing Center
Openmp Lab: Antonio Gómez-Iglesias Agomez@Tacc - Utexas.Edu Texas Advanced Computing Center
Antonio Gómez-Iglesias
[email protected]
Texas Advanced Computing Center
Introduction
What you will learn
• How to compile Code (C and Fortran) with OpenMP
• How to parallelize code with OpenMP
– Use the correct header declarations
– Parallelize simple loops
• How to effectively hide OpenMP statements
ssh [email protected]
tar -xvf ~train00/lab_OpenMP.tar
cd lab_openmp
Running on compute nodes Interactively
neighbor update
Compile with: make f_neighbor
Parallel Region
Initialization: j_update make c_neighbor
Parallelize loop i
Loop i • Change the single
Loop j to a master construct
single or master
increment j_update • Run with 1 and 12 threads
end single or end master • How does the number
Loop k of j_update change?
b is calculated from a
Exercise 5: Red-Black Update; Part 1
• cd exercise_redblack
• Codes: f_red_black.f90/c_red_black.c
• make a copy and create f_red_black_v1.f90/c_read_black_v1.c
Compile with: make f_red_black_v1
red-black update make c_red_black_v1
Iteration Loop: niter Part 1
Loop: Update even elements
Loop: Update odd elements • Parallelize each loop separately
Initialize error • Use omp parallel do/for
Loop-summation: error for the Update loops
• Use a reduction
for the Error calculation
with the default(none) clause
• Try static scheduling
Exercise 5: Red-Black Update; Part 2
• cd exercise_redblack
• Start from version 1
• Codes: f_red_black.f90/c_red_black.c
• make a copy and create f_red_black_v2.f90/c_read_black_v2.c
Compile with: make f_red_black_v2
red-black update make c_red_black_v2
Iteration Loop: niter Part 2
Loop:
Update even and odd el. • Can the loops be combined?
Initialize error • Why can the update loops
Loop-summation: error
be combined?
• Why can the error loop
not be combined with the update
• Try static scheduling loops?
• Task:
Combine the update loops
Solution 5: Red-Black Update; Part 2