tÉcnicas de optimizaciÓn y paralelizaciÓn
TRANSCRIPT
![Page 1: TÉCNICAS DE OPTIMIZACIÓN Y PARALELIZACIÓN](https://reader035.vdocument.in/reader035/viewer/2022070810/62c5ff632033f37c090a96e9/html5/thumbnails/1.jpg)
TÉCNICAS DE OPTIMIZACIÓN Y PARALELIZACIÓN
MANUEL ARENAZ
Associate Professor
Master en Computación de Altas Prestaciones Course 2012-2013
![Page 2: TÉCNICAS DE OPTIMIZACIÓN Y PARALELIZACIÓN](https://reader035.vdocument.in/reader035/viewer/2022070810/62c5ff632033f37c090a96e9/html5/thumbnails/2.jpg)
Agenda ! Do I really need parallelism? ! The HPC software marketplace can be organized from the
productivity viewpoint? ! What do I need to learn to write HPC Apps? ! How can I be more productive? ! Are there “Design Patterns” to help writing HPC Apps? ! Can you give an example of a parallel design pattern? ! Are there Hw-independent key concepts? ! Are there frequently used design patterns for HPC Apps? ! Can you propose a development methodology for GPU
programming? ! Can you meassure productivity? ! Conclusions
![Page 3: TÉCNICAS DE OPTIMIZACIÓN Y PARALELIZACIÓN](https://reader035.vdocument.in/reader035/viewer/2022070810/62c5ff632033f37c090a96e9/html5/thumbnails/3.jpg)
Software Marketplace
MANUAL
AUTOMATIC
SEMIAUTOMATIC
CUDA OpenCL ArrayFire MPI Posix Threads
HMPP
PGIACC
+
-
ICC XL Visual Studio
Pro Fortran
NAG Fortran
Math library
![Page 4: TÉCNICAS DE OPTIMIZACIÓN Y PARALELIZACIÓN](https://reader035.vdocument.in/reader035/viewer/2022070810/62c5ff632033f37c090a96e9/html5/thumbnails/4.jpg)
Software Technologies
MANUAL
AUTOMATIC
SEMIAUTOMATIC
+
- Threads
Intrinsics SSE
![Page 5: TÉCNICAS DE OPTIMIZACIÓN Y PARALELIZACIÓN](https://reader035.vdocument.in/reader035/viewer/2022070810/62c5ff632033f37c090a96e9/html5/thumbnails/5.jpg)
Summary from Session #2
VECTOR
![Page 6: TÉCNICAS DE OPTIMIZACIÓN Y PARALELIZACIÓN](https://reader035.vdocument.in/reader035/viewer/2022070810/62c5ff632033f37c090a96e9/html5/thumbnails/6.jpg)
Summary from Session #2
! Key concepts for parallel design patterns: " Parallel region " Work-sharing " Privatization " Synchronization " Reductions
! Support in widely-used software tools " MPI " OpenMP " OpenACC " SSE
![Page 7: TÉCNICAS DE OPTIMIZACIÓN Y PARALELIZACIÓN](https://reader035.vdocument.in/reader035/viewer/2022070810/62c5ff632033f37c090a96e9/html5/thumbnails/7.jpg)
Are there frequently used design patterns for HPC Apps?
![Page 8: TÉCNICAS DE OPTIMIZACIÓN Y PARALELIZACIÓN](https://reader035.vdocument.in/reader035/viewer/2022070810/62c5ff632033f37c090a96e9/html5/thumbnails/8.jpg)
Parallel Design Patterns
! Núcleo computacional REDUCCIÓN
! Núcleo computacional ASIGNACIÓN
! Núcleo computacional RECURRENCIA
! Núcleos computacionales REINICIALIZADOS
! Descripción de aplicaciones en términos de núcleos
computacionales
©Manuel Arenaz, 2011 Técnicas de Optimización y Paralelización (TOP) Pag. 83
![Page 9: TÉCNICAS DE OPTIMIZACIÓN Y PARALELIZACIÓN](https://reader035.vdocument.in/reader035/viewer/2022070810/62c5ff632033f37c090a96e9/html5/thumbnails/9.jpg)
Parallel Design Patterns
! Núcleo computacional REDUCCIÓN
! Núcleo computacional ASIGNACIÓN
! Núcleo computacional RECURRENCIA
! Núcleos computacionales REINICIALIZADOS
! Descripción de aplicaciones en términos de núcleos
computacionales
©Manuel Arenaz, 2011 Técnicas de Optimización y Paralelización (TOP) Pag. 84
![Page 10: TÉCNICAS DE OPTIMIZACIÓN Y PARALELIZACIÓN](https://reader035.vdocument.in/reader035/viewer/2022070810/62c5ff632033f37c090a96e9/html5/thumbnails/10.jpg)
Reduction
! Update the value of a set of memory locations as a function of the previous value stored in each memory location:
A = A ⊕ B The operator ⊕ is associative and commutative (e.g., sum, product, max/min).
! Types of reductions: " Scalar reduction: s=s+1 " Regular reduction: A(h)=A(h)+1 " Irregular reduction: A(f(h))=A(f(h))+1
![Page 11: TÉCNICAS DE OPTIMIZACIÓN Y PARALELIZACIÓN](https://reader035.vdocument.in/reader035/viewer/2022070810/62c5ff632033f37c090a96e9/html5/thumbnails/11.jpg)
Scalar Reduction
! Update the value of a set of memory locations as a function of the previous value stored in each memory location:
A = A ⊕ B The operator ⊕ is associative and commutative (e.g., sum, product, max/min).
! Types of reductions: " Scalar reduction: s=s+1 " Regular reduction: A(h)=A(h)+1 " Irregular reduction: A(f(h))=A(f(h))+1
![Page 12: TÉCNICAS DE OPTIMIZACIÓN Y PARALELIZACIÓN](https://reader035.vdocument.in/reader035/viewer/2022070810/62c5ff632033f37c090a96e9/html5/thumbnails/12.jpg)
Regular Reduction
! Update the value of a set of memory locations as a function of the previous value stored in each memory location:
A = A ⊕ B The operator ⊕ is associative and commutative (e.g., sum, product, max/min).
! Types of reductions: " Scalar reduction: s=s+1 " Regular reduction: A(h)=A(h)+1 " Irregular reduction: A(f(h))=A(f(h))+1
![Page 13: TÉCNICAS DE OPTIMIZACIÓN Y PARALELIZACIÓN](https://reader035.vdocument.in/reader035/viewer/2022070810/62c5ff632033f37c090a96e9/html5/thumbnails/13.jpg)
Irregular Reduction
! Update the value of a set of memory locations as a function of the previous value stored in each memory location:
A = A ⊕ B The operator ⊕ is associative and commutative (e.g., sum, product, max/min).
! Types of reductions: " Scalar reduction: s=s+1 " Regular reduction: A(h)=A(h)+1 " Irregular reduction: A(f(h))=A(f(h))+1
![Page 14: TÉCNICAS DE OPTIMIZACIÓN Y PARALELIZACIÓN](https://reader035.vdocument.in/reader035/viewer/2022070810/62c5ff632033f37c090a96e9/html5/thumbnails/14.jpg)
Parallel Design Patterns
! Núcleo computacional REDUCCIÓN
! Núcleo computacional ASIGNACIÓN
! Núcleo computacional RECURRENCIA
! Núcleos computacionales REINICIALIZADOS
! Descripción de aplicaciones en términos de núcleos
computacionales
©Manuel Arenaz, 2011 Técnicas de Optimización y Paralelización (TOP) Pag. 119
![Page 15: TÉCNICAS DE OPTIMIZACIÓN Y PARALELIZACIÓN](https://reader035.vdocument.in/reader035/viewer/2022070810/62c5ff632033f37c090a96e9/html5/thumbnails/15.jpg)
Assignment
! Modify the value of a set of memory locations overwriting the previous values:
A = B The previous value is lost, it is not used to update the value saved in the memory location.
! Types of assignments: " Scalar assignment: s=1 " Regular assignment: A(h)=1 " Irregular assignment: A(f(h))=1
![Page 16: TÉCNICAS DE OPTIMIZACIÓN Y PARALELIZACIÓN](https://reader035.vdocument.in/reader035/viewer/2022070810/62c5ff632033f37c090a96e9/html5/thumbnails/16.jpg)
Scalar Assignment
! Modify the value of a set of memory locations overwriting the previous values:
A = B The previous value is lost, it is not used to update the value saved in the memory location.
! Types of assignments: " Scalar assignment: s=1 " Regular assignment: A(h)=1 " Irregular assignment: A(f(h))=1
![Page 17: TÉCNICAS DE OPTIMIZACIÓN Y PARALELIZACIÓN](https://reader035.vdocument.in/reader035/viewer/2022070810/62c5ff632033f37c090a96e9/html5/thumbnails/17.jpg)
Regular Assignment
! Modify the value of a set of memory locations overwriting the previous values:
A = B The previous value is lost, it is not used to update the value saved in the memory location.
! Types of assignments: " Scalar assignment: s=1 " Regular assignment: A(h)=1 " Irregular assignment: A(f(h))=1
![Page 18: TÉCNICAS DE OPTIMIZACIÓN Y PARALELIZACIÓN](https://reader035.vdocument.in/reader035/viewer/2022070810/62c5ff632033f37c090a96e9/html5/thumbnails/18.jpg)
Irregular Assignment
! Modify the value of a set of memory locations overwriting the previous values:
A = B The previous value is lost, it is not used to update the value saved in the memory location.
! Types of assignments: " Scalar assignment: s=1 " Regular assignment: A(h)=1 " Irregular assignment: A(f(h))=1
![Page 19: TÉCNICAS DE OPTIMIZACIÓN Y PARALELIZACIÓN](https://reader035.vdocument.in/reader035/viewer/2022070810/62c5ff632033f37c090a96e9/html5/thumbnails/19.jpg)
Parallel Design Patterns
! Núcleo computacional REDUCCIÓN
! Núcleo computacional ASIGNACIÓN
! Núcleo computacional RECURRENCIA
! Núcleos computacionales REINICIALIZADOS
! Descripción de aplicaciones en términos de núcleos
computacionales
©Manuel Arenaz, 2011 Técnicas de Optimización y Paralelización (TOP) Pag. 138
![Page 20: TÉCNICAS DE OPTIMIZACIÓN Y PARALELIZACIÓN](https://reader035.vdocument.in/reader035/viewer/2022070810/62c5ff632033f37c090a96e9/html5/thumbnails/20.jpg)
Recurrences
! Update the value of a set of memory locations as a function of the previous values stored in several the memory locations:
A = A ⊕ … ⊕ A ⊕ B
! Types of recurrences: " Regular recurrences: A(h)=A(h-1)+1 " Irregular recurrences: A(f(h))=A(g(h))+1
![Page 21: TÉCNICAS DE OPTIMIZACIÓN Y PARALELIZACIÓN](https://reader035.vdocument.in/reader035/viewer/2022070810/62c5ff632033f37c090a96e9/html5/thumbnails/21.jpg)
Parallel Design Patterns
! Núcleo computacional REDUCCIÓN
! Núcleo computacional ASIGNACIÓN
! Núcleo computacional RECURRENCIA
! Núcleos computacionales REINICIALIZADOS
! Descripción de aplicaciones en términos de núcleos
computacionales
©Manuel Arenaz, 2011 Técnicas de Optimización y Paralelización (TOP) Pag. 144
![Page 22: TÉCNICAS DE OPTIMIZACIÓN Y PARALELIZACIÓN](https://reader035.vdocument.in/reader035/viewer/2022070810/62c5ff632033f37c090a96e9/html5/thumbnails/22.jpg)
Reinitialized Patterns
A = B A = A ⊕ C
! Combinación de dos núcleos computacionales " ASIGNACIÓN,
para inicializar un conjunto de datos
" REDUCCIÓN o RECURRENCIA, para la manipulación de dicho conjunto de datos
subroutine amux (n, x, y, a,ja,ia)real*8 x(*), y(*), a(*)integer n, ja(*), ia(*)real*8 tinteger i, kdo i = 1,n
t = 0.0d0do k=ia(i), ia(i+1)-1 t = t + a(k)*x(ja(k))enddoy(i) = t
enddoreturnend
Código: Producto matriz dispersa - vector Formato: Matriz CRS Fuente: SparskitII, módulo MATVEC,
rutina amux.f
![Page 23: TÉCNICAS DE OPTIMIZACIÓN Y PARALELIZACIÓN](https://reader035.vdocument.in/reader035/viewer/2022070810/62c5ff632033f37c090a96e9/html5/thumbnails/23.jpg)
Parallel Design Patterns
! Núcleo computacional REDUCCIÓN
! Núcleo computacional ASIGNACIÓN
! Núcleo computacional RECURRENCIA
! Núcleos computacionales REINICIALIZADOS
! Whole-Program analysis based on parallel design
patterns
©Manuel Arenaz, 2011 Técnicas de Optimización y Paralelización (TOP) Pag. 149
![Page 24: TÉCNICAS DE OPTIMIZACIÓN Y PARALELIZACIÓN](https://reader035.vdocument.in/reader035/viewer/2022070810/62c5ff632033f37c090a96e9/html5/thumbnails/24.jpg)
Whole-Program Analysis
do h = 1,Adim hist(h) = 0enddodo h = 1,fDim hist(f(h)) = hist(f(h)) + 1enddodo h = 2,Adim hist(h) = hist(h) + hist(h-1)enddo
Código: Cálculo del histograma acumulativo de un patrón de acceso irregular
Fuente: Inspector con balanceo de carga
! Hemos visto un ejemplo sencillo en el que podíamos describir el comportamiento del código como una secuencia de núcleos computacionales
ASIGNACIÓN REGULAR Paralelizable
REDUCCIÓN IRREGULAR Paralelizable
RECURRENCIA REGULAR No paralelizable!
©Manuel Arenaz, 2011 Técnicas de Optimización y Paralelización (TOP) Pag. 150
![Page 25: TÉCNICAS DE OPTIMIZACIÓN Y PARALELIZACIÓN](https://reader035.vdocument.in/reader035/viewer/2022070810/62c5ff632033f37c090a96e9/html5/thumbnails/25.jpg)
subroutine amux (n, x, y, a,ja,ia)real*8 x(*), y(*), a(*)integer n, ja(*), ia(*)real*8 tinteger i, kdo i = 1,n
t = 0.0d0do k=ia(i), ia(i+1)-1 t = t + a(k)*x(ja(k))enddoy(i) = t
enddoreturnend
! Podemos incluso describir el comportamiento de aplicaciones en cuya codificación aparecen los núcleos “entrelazados”
Código: Producto matriz dispersa - vector Formato: Matriz CRS Fuente: SparskitII, módulo MATVEC, rutina amux.f
Whole-Program Analysis
REDUCCIÓN ESCALAR REINICIALIZADA Privatizable
ASIGNACIÓN REGULAR Paralelizable
©Manuel Arenaz, 2011 Técnicas de Optimización y Paralelización (TOP) Pag. 151
![Page 26: TÉCNICAS DE OPTIMIZACIÓN Y PARALELIZACIÓN](https://reader035.vdocument.in/reader035/viewer/2022070810/62c5ff632033f37c090a96e9/html5/thumbnails/26.jpg)
subroutine amux (n, x, y, a,ja,ia)real*8 x(*), y(*), a(*)integer n, ja(*), ia(*)real*8 tinteger i, kdo i = 1,n
t = 0.0d0do k=ia(i), ia(i+1)-1 t = t + a(k)*x(ja(k))enddoy(i) = t
enddoreturnend
! Análisis contextual: Un mismo fragmento de sentencias puede ser descrito mediante núcleos computacionales diferentes según el ámbito en el que se analice
Código: Producto matriz dispersa - vector Formato: Matriz CRS Fuente: SparskitII, módulo MATVEC, rutina amux.f
Whole-Program Analysis
REDUCCIÓN ESCALAR Paralelizable
©Manuel Arenaz, 2011 Técnicas de Optimización y Paralelización (TOP) Pag. 152
![Page 27: TÉCNICAS DE OPTIMIZACIÓN Y PARALELIZACIÓN](https://reader035.vdocument.in/reader035/viewer/2022070810/62c5ff632033f37c090a96e9/html5/thumbnails/27.jpg)
MATMUL
©Manuel Arenaz, 2011 Técnicas de Optimización y Paralelización (TOP) Pag. 153
![Page 28: TÉCNICAS DE OPTIMIZACIÓN Y PARALELIZACIÓN](https://reader035.vdocument.in/reader035/viewer/2022070810/62c5ff632033f37c090a96e9/html5/thumbnails/28.jpg)
SOBEL
©Manuel Arenaz, 2011 Técnicas de Optimización y Paralelización (TOP) Pag. 154
![Page 29: TÉCNICAS DE OPTIMIZACIÓN Y PARALELIZACIÓN](https://reader035.vdocument.in/reader035/viewer/2022070810/62c5ff632033f37c090a96e9/html5/thumbnails/29.jpg)
Are there frequently used design patterns for HPC Apps?
![Page 30: TÉCNICAS DE OPTIMIZACIÓN Y PARALELIZACIÓN](https://reader035.vdocument.in/reader035/viewer/2022070810/62c5ff632033f37c090a96e9/html5/thumbnails/30.jpg)
TÉCNICAS DE OPTIMIZACIÓN Y PARALELIZACIÓN
MANUEL ARENAZ
Associate Professor
Master en Computación de Altas Prestaciones Course 2012-2013