tÉcnicas de optimizaciÓn y paralelizaciÓn

30
TÉCNICAS DE OPTIMIZACIÓN Y PARALELIZACIÓN MANUEL ARENAZ Associate Professor Master en Computación de Altas Prestaciones Course 2012-2013 [email protected]

Upload: others

Post on 07-Jul-2022

6 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: TÉCNICAS DE OPTIMIZACIÓN Y PARALELIZACIÓN

TÉCNICAS DE OPTIMIZACIÓN Y PARALELIZACIÓN

MANUEL ARENAZ

Associate Professor

Master en Computación de Altas Prestaciones Course 2012-2013

[email protected]

Page 2: TÉCNICAS DE OPTIMIZACIÓN Y PARALELIZACIÓN

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

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

Software Technologies

MANUAL

AUTOMATIC

SEMIAUTOMATIC

+

- Threads

Intrinsics SSE

Page 5: TÉCNICAS DE OPTIMIZACIÓN Y PARALELIZACIÓN

Summary from Session #2

VECTOR

Page 6: TÉCNICAS DE OPTIMIZACIÓN Y PARALELIZACIÓN

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

Are there frequently used design patterns for HPC Apps?

Page 8: TÉCNICAS DE OPTIMIZACIÓN Y PARALELIZACIÓN

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Are there frequently used design patterns for HPC Apps?

Page 30: TÉCNICAS DE OPTIMIZACIÓN Y PARALELIZACIÓN

TÉCNICAS DE OPTIMIZACIÓN Y PARALELIZACIÓN

MANUEL ARENAZ

Associate Professor

Master en Computación de Altas Prestaciones Course 2012-2013

[email protected]