INTEL CONFIDENTIAL Metodología de programación paralela Intel Software College.

Slides:



Advertisements
Presentaciones similares
Documentos de Construcción y Detalles
Advertisements

Autodesk® Revit® Structure Software Interfaz del Usuario
Enlace Ampliación de BIM para diseño y análisis estructural
Análisis Estructural Avanzado y Coordinación
Los programas de Intel Educación son patrocinados por la Fundación Intel y la Corporación Intel. Derechos de autor © 2007, Corporación Intel. Todos los.
Metodología de programación paralela
Windows Mobile 1. Configurar una cuenta de Correo Personal Configurar Yahoo! Microsoft Confidential2 Inicio Fin.
Programa Intel® Educar Curso Introductorio
© 2006 Microsoft Corporation. All rights reserved.
Los programas de Intel Educación son patrocinados por la Fundación Intel y la Corporación Intel. Derechos de autor © 2007, Corporación Intel. Todos los.
Reporting de segmento SAP Best Practices.
Programando con Hilos POSIX* Intel Software College.
Programando con OpenMP*
TecnoMETAL, Autodesk® Revit® y Naviswork® Solución BIM para el debujo y la producción de las estructura en acero Toffali Francesca Steel&Graphics srl.
CI6060-V - Data Shortcut = archivos livianos [AutoCAD® Civil 3D] 1ra Parte: Concepto Jeremy Ramírez Hernández Ingeniero Aplicaciones SONDA® - Autodesk®
PROCESADORES SUPERESCALARES
Copyright © 2009 Intel Corporation.
Simplifique sus Diseños con Autodesk® Inventor® Professional 2013
Civil 3D: Explanaciones y Movimientos de Tierra en proyectos complejos
Erick Stephens Director Nacional de Tecnolog í a Microsoft.
Lo que un usuario de Civil 3D necesita saber de MAP 3D y Raster Design (CI5831-V) Ing.Juan Carlos Serna A Division SIG - MicroCAD.
Derechos de autor © 2008, Corporación Intel. Todos los derechos reservados. Intel, el logo de la Iniciativa Intel Educación y el Programa Intel Educar.
Modelo Informatizado de Edificios (BIM)
Desarrollo Entrega continua Rodrigo Corral
11 Servidores basados en Arquitectura Intel Junio 2008 DataWarehouses de Alto Rendimiento.
INFORMATICA I Funciones CLASE 13.
Mi nombre es Jorge lopera Consultor Autodesk para nexsys de Colombia.
MA5740-V De Alias a Inventor, diseño sin límites
Planeación y Control de Producción (J06) Visión General Chile
Juan Carlos Guardia Campos
iLogic - Automatización Inteligente para Diseño Mecánico e Industrial
Join us on Twitter: #AU2013 Acelerando los flujos de trabajo de simulación dinámica y animaciones a través de la nueva herramienta Joint en Autodesk® Inventor®
Programación en los procecesadores Intel® Multi Core.
INTEL CONFIDENTIAL Paralelizando para mejorar el rendimiento con Intel® Threading Building Blocks Sesión:
Autodesk Revit© + 3D Scan para Modelado y Revisión de Proyectos
Usando Tablas de Planificación y Espacios para Calcular Cargas de Calefacción con Autodesk® Revit MEP® 2012 Pedro Rivera Diseñador Mecánico/Coordinador.
Los programas de Intel Educación son patrocinados por la Fundación Intel y la Corporación Intel. Derechos de autor © 2007, Corporación Intel. Todos los.
1  Ex Libris Ltd., Internal and Confidential GUAM XVII Reunión de Usuarios de Ex Libris en México 29 y 30 de Abril de 2013 Morelia, Michoacán Alan.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Analisis de Rendimiento.
Programación de Memoria Compartida
© 2011 Autodesk MA5584 – V No mas CV’s y curvas rebeldes… Tips que usted Debe Conocer Para Lograr Superficies Perfectas Martin Carcaño MFG Technical Specialist.
Programando con Hilos de Windows* Intel Software College.
Programación con OpenMP* Intel Software College. Copyright © 2006, Intel Corporation. All rights reserved. Intel and the Intel logo are trademarks or.
Modelado de una Planta Central de Energía con Autodesk® Revit MEP® 2012 Pedro Rivera Diseñador Mecánico/Coordinador de BIM.
© 2012 Autodesk AutoCAD® Mechanical los mejores planos de fabricación Módulo 1: Principales herramientas para documentación Victor M. Leija Autodesk Certified.
Programming with POSIX* Threads Intel Software College.
Patrones de Programación Paralela Sesión:. Copyright © 2006, Intel Corporation. All rights reserved. Intel and the Intel logo are trademarks or registered.
Los programas de Intel Educación son patrocinados por la Fundación Intel y la Corporación Intel. Derechos de autor © 2007, Corporación Intel. Todos los.
Alejandro García Sánchez Readiness Champion.. Licenciamiento para Pequeñas y Medianas Empresas Como Elegir el licenciamiento Correcto Preguntas y Respuestas.
Elementos de Intel ® Educar - Introducción. 2 Programa Intel ® Educar Derechos de autor © 2010, Corporaci ó n Intel. Todos los derechos reservados. Todos.
Conceptos básicos de procesamiento en procecesadores Intel® Multi Core.
Healthcare Applications Juan Torrego Hagens. Healthcare Applications 2.
Trabajando con proyectos en múltiples fases en Autodesk® Revit®
Compiladores Intel 9.x en el procesador Intel® Core Duo™ Windows version Intel Software College.
Programando con Hilos POSIX* Intel Software College.
© 2011 Autodesk Productividad en AutoCAD Néstor G. Barrera Líder U.N. Tecnología y Capacitación CIAR S.A. - Argentina Virtual Class ID: AC4596.
Compartir un Proyecto Autodesk ® Revit Structure ®
Derechos de autor © 2008, Corporación Intel. Todos los derechos reservados. Intel e Intel  Educación son marcas comerciales o marcas registradas de la.
Hilos Capítulo 5 Silberschatz Galvin. Copyright © 2006, Intel Corporation. All rights reserved. Intel and the Intel logo are trademarks or registered.
Un proceso ligero (thread o hebra) es un programa en ejecución que comparte la imagen de la memoria y otras informaciones con otros procesos ligeros.
Introducción a VTune™ Analizador de rendimiento
Derechos de autor © 2008, Corporación Intel. Todos los derechos reservados. Intel e Intel  Educación son marcas comerciales o marcas registradas de la.
Derechos de autor © 2008, Corporación Intel. Todos los derechos reservados. Intel e Intel  Educación son marcas comerciales o marcas registradas de la.
Derechos de autor © 2008, Corporación Intel. Todos los derechos reservados. Intel, el logo de la Iniciativa Intel Educación y el Programa Intel Educar.
Crear Referencias Febrero 10, Ingresar al portal Ingresar a la siguiente url: Ya que se haya entrado a la URL.
Programa de educación de Intel Un caso de colaboración público - privado Programa de educación de Intel Un caso de colaboración público - privado Patricia.
¡Bienvenido a tu nuevo Office!. ¡Instalá tu Office en todos tus dispositivos móviles! Colaboración en línea de tus archivos con todos tus compañeros de.
Diseño colaborativo. VERTICALES AUTODESKc MERCADO.
© 2013 Autodesk Autodesk ® Inventor ® 2014 Leonardo Alatorre Especialista técnico MFG.
Agosto 2016 David Iacobucci
Transcripción de la presentación:

INTEL CONFIDENTIAL Metodología de programación paralela Intel Software College

Intel ® Software College Copyright © 2008, Intel Corporation. All rights reserved. Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. * Other brands and names are the property of their respective owners. 2 Objetivo Al final de este módulo Será capaz de realizar un prototipo y estimar el esfuerzo requerido para paralelizar regiones que consumen tiempo

Intel ® Software College Copyright © 2008, Intel Corporation. All rights reserved. Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. * Other brands and names are the property of their respective owners. 3 Agenda Un ciclo de desarrollo genérico Caso de estudio: Generación de números primos Algunos problemas de rendimiento comunes

Intel ® Software College Copyright © 2008, Intel Corporation. All rights reserved. Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. * Other brands and names are the property of their respective owners. 4 ¿Qué es paralelismo? Dos o más procesos o hilos se ejecutan al mismo tiempo Paralelismo para arquitecturas con varios núcleos Múltiples procesos –Comunicación a través de IPCs (Inter-Process Communication) Un solo proceso, múltiples hilos –Comunicación a través de memoria compartida

Intel ® Software College Copyright © 2008, Intel Corporation. All rights reserved. Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. * Other brands and names are the property of their respective owners. 5 n = número de procesadores T paralelo = { (1-P) + P/n } T serial Aceleración = T serial / T paralelo Ley de Amdahl Describe el límite máximo de aceleración con ejecución paralela El código serial limita la aceleración (1-P) P T serial (1-P) P/ /0.75 = 1.33 n = 2 n = ∞ ∞ P/ ∞ … /0.5 = 2.0

Intel ® Software College Copyright © 2008, Intel Corporation. All rights reserved. Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. * Other brands and names are the property of their respective owners. 6 Procesos e Hilos Los sistemas operativos modernos cargan programas como procesos –Tiene recursos –Ejecución Un proceso inicia ejecutando su punto de entrada como un hilo Los hilos pueden crear otros hilos dentro del proceso Cada hilo obtiene su propio stack Todos los hilos dentro de un proceso comparten código y segmentos de datos Procesos e Hilos Code segment Data segment thread main() … thread Stack

Intel ® Software College Copyright © 2008, Intel Corporation. All rights reserved. Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. * Other brands and names are the property of their respective owners. 7 Hilos – Beneficios y riesgos Beneficios Mayor rendimiento y mejor utilización de recursos –Incluso en sistemas con un solo procesador – para esconder latencia e incrementar el tiempo de respuesta Comunicación entre procesos a través de memoria compartida es más eficiente Riesgos Incrementa la complejidad de la aplicación Difícil de depurar (condiciones de concurso, interbloqueos, etc.)

Intel ® Software College Copyright © 2008, Intel Corporation. All rights reserved. Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. * Other brands and names are the property of their respective owners. 8 Preguntas comunes cuando se paralelizan aplicaciones ¿Dónde paralelizar? ¿Cuánto tiempo lleva paralelizar? ¿Cuánto esfuerzo para rediseñar se requiere? ¿Es útil paralelizar una región específica? ¿Qué tanto se espera acelerar? ¿El rendimiento va de acuerdo a mis expectativas? ¿Será escalable a más hilos/datos añadidos? ¿Qué modelo de paralelización utilizar?

Intel ® Software College Copyright © 2008, Intel Corporation. All rights reserved. Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. * Other brands and names are the property of their respective owners. 9 Generación de Números Primos bool TestForPrime(int val) { // let’s start checking from 3 int limit, factor = 3; limit = (long)(sqrtf((float)val)+0.5f); while( (factor <= limit) && (val % factor) ) factor += 2; return (factor > limit); } void FindPrimes(int start, int end) { int range = end - start + 1; for( int i = start; i <= end; i += 2 ) { if( TestForPrime(i) ) globalPrimes[gPrimesFound++] = i; ShowProgress(i, range); } ifactor

Intel ® Software College Copyright © 2008, Intel Corporation. All rights reserved. Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. * Other brands and names are the property of their respective owners. 10 Actividad 1 Ejecutar la versión serial de los números primos Buscar el directorio PrimeSingle Compilar con Intel® Parallel Composer en Visual Studio Ejecutar algunas veces con rangos diferentes

Intel ® Software College Copyright © 2008, Intel Corporation. All rights reserved. Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. * Other brands and names are the property of their respective owners. 11 Metodología de Desarrollo Análisis Buscar código donde se realiza cómputo intensivo Diseño (Introducir Hilos) Determinar como implementar una solución paralelizada Depurar Detectar cualquier problema como resultado de usar hilos Afinar para mejorar el rendimiento Lograr el mejor rendimiento en paralelo

Intel ® Software College Copyright © 2008, Intel Corporation. All rights reserved. Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. * Other brands and names are the property of their respective owners. 12 Ciclo de Desarrollo Análisis –Intel® Parallel Amplifier Diseño (Introducir Hilos) –Intel® Performance libraries: IPP y MKL –OpenMP* (Intel® Parallel Composer) –Creción explícita de hilos (Win32*, Pthreads*) Depuración –Intel® Parallel Inspector –Intel Debugger Afinar para mejorar el rendimiento –Intel® Parallel Amplifier

Intel ® Software College Copyright © 2008, Intel Corporation. All rights reserved. Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. * Other brands and names are the property of their respective owners. 13 Usaremos el proyecto PrimeSingle para el análisis PrimeSingle Ejemplo:./PrimeSingle Análisis de Hotspot Usa Parallel Amplifier para encontrar los hotspots en la aplicación bool TestForPrime(int val) { // let’s start checking from 3 int limit, factor = 3; limit = (long)(sqrtf((float)val)+0.5f); while( (factor <= limit) && (val % factor)) factor ++; return (factor > limit); } void FindPrimes(int start, int end) { // start is always odd int range = end - start + 1; for( int i = start; i <= end; i+= 2 ){ if( TestForPrime(i) ) globalPrimes[gPrimesFound++] = i; ShowProgress(i, range); } Identifica las regiones que consumen tiempo

Intel ® Software College Copyright © 2008, Intel Corporation. All rights reserved. Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. * Other brands and names are the property of their respective owners. 14 Análisis - Call Stack Inspeccionar el código desde el nodo (TestForPrime) Buscar un loop para paralelizar Si no se encuentra ninguno, avanza en el call stack hasta encontrar un ciclo adecuado o llamada a función para paralelizar Este es el nivel en el árbol de llamadas donde necesitamos paralelizar Usado para encontrar el nível apropiado en el árbol de llamadas para paralelizar

Intel ® Software College Copyright © 2008, Intel Corporation. All rights reserved. Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. * Other brands and names are the property of their respective owners. 15 Actividad 2 Ejecuta el código con el rango de ‘ ’ para obtener la medición base Tomar nota para referencias futuras Hacer el análisis de Hotspots en el código serial ¿Qué función se lleva la mayor parte del tiempo?

Intel ® Software College Copyright © 2008, Intel Corporation. All rights reserved. Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. * Other brands and names are the property of their respective owners. 16 Metodología de Diseño de Foster De “Designing and Building Parallel Programs” por Ian Foster Cuatro pasos: ParticionarParticionar –Dividir cómputo y datos ComunicaciónComunicación –Intercambio de datos entre cómputos AglomeraciónAglomeración –Agrupar tareas para mejorar rendimiento MapeoMapeo –Asignar tareas a procesadores/hilos

Intel ® Software College Copyright © 2008, Intel Corporation. All rights reserved. Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. * Other brands and names are the property of their respective owners. 17 Diseñando programas paralelos Particionar Divide el problema en tareasComunicar Determina la cantidad y el patrón de comunicaciónAglomerar Combinar tareasMapear Asignar tareas aglomeradas a los hilos generados Problema Tareas iniciales Comunicación Tareas combinadas Programa final

Intel ® Software College Copyright © 2008, Intel Corporation. All rights reserved. Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. * Other brands and names are the property of their respective owners. 18 Modelos de Programación Paralela Descomposición funcional Paralelismo de tareas Dividir el cómputo, asociarle datos Tareas independientes del mismo problema Descomposición de datos La misma operación ejecutando diferentes datos Dividir datos en piezas, asociarles cómputo

Intel ® Software College Copyright © 2008, Intel Corporation. All rights reserved. Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. * Other brands and names are the property of their respective owners. 19 Métodos de descomposición Descomposición funcional Enfocarse a cómputo puede revelar la estructura en un problema Grid reprinted with permission of Dr. Phu V. Luong, Coastal and Hydraulics Laboratory, ERDC Descomposición por dominio Enfocarse en la estructura de datos más grande o más frecuentemente accesada Paralelismo en los datos –La misma operación aplicada a todos los datos Modelo atmosférico Modelo Oceano Modelo terrestre Modelo de hidrología

Intel ® Software College Copyright © 2008, Intel Corporation. All rights reserved. Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. * Other brands and names are the property of their respective owners. 20 Descomposición en Pipeline La computación se hace en etapas independientes Descomposición funcional Los hilos se asignan a una etapa a computar Línea de ensamble de automóviles Descomposición de datos Los hilos procesan todas las etapas de una sola instancia Un trabajador construye un auto completito

Intel ® Software College Copyright © 2008, Intel Corporation. All rights reserved. Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. * Other brands and names are the property of their respective owners. 21 Ejemplo de LAME Encoder LAME MP3 encoder Proyecto Open source Herramienta educativa El objetivo de este proyecto es Mejorar la calidad Mejorar la velocidad de la codificación a MP3

Intel ® Software College Copyright © 2008, Intel Corporation. All rights reserved. Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. * Other brands and names are the property of their respective owners. 22 Estrategia de LAME Pipeline Frame N Frame N + 1 Tiempo Otro N Preludio N Acústicos N Codificación N T 2 T 1 Acústicos N+1 Preludio N+1 Otro N+1 Codificación N+1 Acústicos N+2 Preludio N+2 T 3 T 4 Preludio N+3 Barrera Jerárquica OtroPreludioAcústicosCodificación Frame Extraer siguiente frame Caracterización del frame Poner parámetros del encoder Analisis FFT long/short Ensamblar el filtro Aplicar filtros Suprimir ruidos Cuantiza y cuenta bits Agregar encabezado del frame Verificar si es correcto Escribe al disco

Intel ® Software College Copyright © 2008, Intel Corporation. All rights reserved. Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. * Other brands and names are the property of their respective owners. 23 Diseño ¿Cuál es el beneficio esperado? ¿Cómo logramos esto con el menor esfuerzo? ¿Cuánto se lleva paralelizar? ¿Cuánto esfuerzo se requiere para rediseñar? Prototipo rápido con OpenMP Aceleración(2P) = 100/(96/2+4) = ~1.92X

Intel ® Software College Copyright © 2008, Intel Corporation. All rights reserved. Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. * Other brands and names are the property of their respective owners. 24 OpenMP Paralelismo Fork-join: El hilo maestro se divide en un grupo de hilos como sea necesario El paralelismo va incrementando –Un programa secuencial evoluciona a un programa paralelo Regiones Paralelas Hilo maestro

Intel ® Software College Copyright © 2008, Intel Corporation. All rights reserved. Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. * Other brands and names are the property of their respective owners. 25 Diseño #pragma omp parallel for for( int i = start; i <= end; i+= 2 ){ if( TestForPrime(i) ) globalPrimes[gPrimesFound++] = i; ShowProgress(i, range); } OpenMP Crea hilos aquí para Esta región paralela for Divide iteraciones de el ciclo for

Intel ® Software College Copyright © 2008, Intel Corporation. All rights reserved. Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. * Other brands and names are the property of their respective owners. 26 Actividad 3 Ejecuta la versión OpenMP del código Localiza el directorio PrimeOpenMP y la solución Compila el código Ejecuta con ‘ ’ para comparar –¿Cuál es la aceleración?

Intel ® Software College Copyright © 2008, Intel Corporation. All rights reserved. Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. * Other brands and names are the property of their respective owners. 27 Diseño ¿Cuál es el beneficio esperado? ¿Cómo logras esto con el menor esfuerzo? ¿Cuánto tiempo se llevó paralelizar? ¿Cuánto esfuerzo se requiere para rediseñar? ¿Es la mejor aceleración posible? Aceleración de 1.40X (menor que 1.92X)

Intel ® Software College Copyright © 2008, Intel Corporation. All rights reserved. Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. * Other brands and names are the property of their respective owners. 28 Depuración ¿Es la implementación correcta de paralelismo? No! Los resultados son diferentes cada ejecución …

Intel ® Software College Copyright © 2008, Intel Corporation. All rights reserved. Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. * Other brands and names are the property of their respective owners. 29 Depuración Intel® Parallel Inspector indica errores notorios en la paralelizacion como condiciones de concurso e interbloqueos Análisis de errores en la paralelización Intel® Parallel Inspector Dónde están los Interbloqueos o Condiciones de Concurso Colector De Datos en tiempo de ejecución

Intel ® Software College Copyright © 2008, Intel Corporation. All rights reserved. Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. * Other brands and names are the property of their respective owners. 30 Intel® Parallel Inspector (Errores en la Paralelización) Seleccionar información en relación con condiciones de concurso e interbloqueos Ver la descripción general de errores de la paralelización (Ti3) Selecciona el error e inspecciona el código

Intel ® Software College Copyright © 2008, Intel Corporation. All rights reserved. Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. * Other brands and names are the property of their respective owners. 31 Actividad 4 Usa Parallel Inspector para analizar la aplicación paralelizada Usa Intel Parallel Inspector para encontrar la condición de concurso que hace que el cálculo de números primos sea incorrecto Ejecuta la aplicación ¿Se reportan errores?

Intel ® Software College Copyright © 2008, Intel Corporation. All rights reserved. Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. * Other brands and names are the property of their respective owners. 32 Depuración ¿Cuánto esfuerzo de requiere para rediseñar? ¿Cuánto nos llevará paralelizar? Parallel Inspector solo reportó 3 dependencias, por lo tanto no hay mayores compliaciones

Intel ® Software College Copyright © 2008, Intel Corporation. All rights reserved. Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. * Other brands and names are the property of their respective owners. 33 Depuración #pragma omp parallel for for( int i = start; i <= end; i+= 2 ){ if( TestForPrime(i) ) #pragma omp critical globalPrimes[gPrimesFound++] = i; ShowProgress(i, range); } #pragma omp critical { gProgress++; percentDone = (int)(gProgress/range *200.0f+0.5f) } Creará una sección crítica para esta referencia Creará una sección crítica para ambas referencias

Intel ® Software College Copyright © 2008, Intel Corporation. All rights reserved. Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. * Other brands and names are the property of their respective owners. 34 Actividad 5 Modifica y ejecuta la versión de Open MP del código Añade pragmas de regiones críticas al código Compila el código Ejecuta Parallel Inspector (Errores de Paralelización) –Si los errores siguen presentes, haz las correcciones apropiadas al código y ejecuta de nuevo en Parallel Inspector Ejecuta con ‘ ’ para comparar –Compila y ejecuta sin debugging –¿Cuál es la aceleración?

Intel ® Software College Copyright © 2008, Intel Corporation. All rights reserved. Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. * Other brands and names are the property of their respective owners. 35 Depuración 1.33 Respuesta correcta, pero el rendimiento bajo al ~1.33X ¿Es lo mejor que podemos esperar de este algoritmo? No! De acuerdo a la Ley de Amdahl, podemos esperar una aceleración cerca de 1.9X

Intel ® Software College Copyright © 2008, Intel Corporation. All rights reserved. Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. * Other brands and names are the property of their respective owners. 36 Problemas comunes de rendimiento Sobrecarga en paralelo Dada por la creación de hilos, planificación… Sincronización Datos globales excesivos, contención de los mismos objetos de sincronización Carga desbalanceada Distribución no adecuada del trabajo en paralelo Granularidad No hay suficiente trabajo paralelo

Intel ® Software College Copyright © 2008, Intel Corporation. All rights reserved. Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. * Other brands and names are the property of their respective owners. 37 Afinando para mejorar el rendimiento Parallel Amplifier (Locks y Waits) apunta a cuellos de botella en el rendimiento en aplicaciones con hilos Locks & Waits Locks & Waits Intel® Parallel Amplifier Intel® Parallel Amplifier

Intel ® Software College Copyright © 2008, Intel Corporation. All rights reserved. Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. * Other brands and names are the property of their respective owners. 38 Parallel Amplifier/ Locks y Waits La gráfica muestra una porción de tiempo significativa en condición ociosa como resultado de la sección crítica FindPrimes() y ShowProgress() están significativamente impactadas por el tiempo ocioso ocurriendo en la sección crítica

Intel ® Software College Copyright © 2008, Intel Corporation. All rights reserved. Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. * Other brands and names are the property of their respective owners. 39 Parallel Amplifier/ Locks y Waits ShowProgress() consume 558/657 (85%) del tiempo permaneciendo ocioso en una sección crítica Haz Double Click en ShowProgress() en la sección crítica más larga para ver el código fuente

Intel ® Software College Copyright © 2008, Intel Corporation. All rights reserved. Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. * Other brands and names are the property of their respective owners. 40 Parallel Amplifier/ Resumen El tiempo transcurrido muestra.571 sec Tiempo de espera/ Núcleos = 1.87/4 =.47 sec Esperando el 82% del tiempo transcurrido en una sección crítica La mayoría del tiempo 1 núcleo y ocasionalmente están ocupados 2

Intel ® Software College Copyright © 2008, Intel Corporation. All rights reserved. Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. * Other brands and names are the property of their respective owners. 41 Parallel Amplifier/ Concurrencia Concurrencia (Function –Caller Function Tree) ShowProgress es llamada de FindPrimes y representa mayormente la razón por la cual la concurrencia es pobre

Intel ® Software College Copyright © 2008, Intel Corporation. All rights reserved. Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. * Other brands and names are the property of their respective owners. 42 Parallel Amplifier/ Concurrencia Concurrencia (Thread –Function –Caller Function Tree) Esta pantalla muestra como cada hilo contribuye al problema de concurrencia Expandiendo cualquier hilo las funciones que más contibuyen

Intel ® Software College Copyright © 2008, Intel Corporation. All rights reserved. Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. * Other brands and names are the property of their respective owners. 43 Rendimiento Double Click en ShowProgress en la segunda sección crítica más larga Esta implementación tiene llamadas de sincronización implícita - printf Esto limita la mejora del rendimiento debido a cambios de contexto resultantes De regreso a la etapa de diseño

Intel ® Software College Copyright © 2008, Intel Corporation. All rights reserved. Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. * Other brands and names are the property of their respective owners. 44 Actividad 6 Usar Parallel Amplifier para analizar la aplicación con hilos Usar la herramienta Parallel Amplifier (Análisis de Locks y Waits) Identifica los waits y locks que más contribuyen

Intel ® Software College Copyright © 2008, Intel Corporation. All rights reserved. Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. * Other brands and names are the property of their respective owners. 45 Rendimiento ¿Es esto mucha contención esperada? El algoritmo tiene muchas más actualizaciones a variables que las 10 necesitadas para mostrar el progreso void ShowProgress( int val, int range ) { int percentDone; gProgress++; percentDone = (int)((float)gProgress/(float)range*200.0f+0.5f); if( percentDone % 10 == 0 ) printf("\b\b\b\b%3d%", percentDone); } void ShowProgress( int val, int range ) { int percentDone; gProgress++; percentDone = (int)((float)gProgress/(float)range*200.0f+0.5f); if( percentDone % 10 == 0 ) printf("\b\b\b\b%3d%", percentDone); } void ShowProgress( int val, int range ) { int percentDone; static int lastPercentDone = 0; #pragma omp critical { gProgress++; percentDone = (int)((float)gProgress/(float)range*200.0f+0.5f); } if( percentDone % 10 == 0 && lastPercentDone < percentDone / 10){ printf("\b\b\b\b%3d%", percentDone); lastPercentDone++; } void ShowProgress( int val, int range ) { int percentDone; static int lastPercentDone = 0; #pragma omp critical { gProgress++; percentDone = (int)((float)gProgress/(float)range*200.0f+0.5f); } if( percentDone % 10 == 0 && lastPercentDone < percentDone / 10){ printf("\b\b\b\b%3d%", percentDone); lastPercentDone++; } Este cambio debe arreglar el problema de contención

Intel ® Software College Copyright © 2008, Intel Corporation. All rights reserved. Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. * Other brands and names are the property of their respective owners. 46 Diseño Meta Elimina la contención debido a la sincronización implícita 2.32X ¡La aceleración es 2.32X ! ¿Es correcto?

Intel ® Software College Copyright © 2008, Intel Corporation. All rights reserved. Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. * Other brands and names are the property of their respective owners. 47 Rendimiento Nuestra medida base original tenía la actualización del algoritmo de progreso “defectuoso” ¿Es lo mejor que podemos esperar de este algoritmo? 1.40X ¡La aceleración actual es 1.40X (<<1.9X)!

Intel ® Software College Copyright © 2008, Intel Corporation. All rights reserved. Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. * Other brands and names are the property of their respective owners. 48 Actividad 7 Modifica la función ShowProgress (en la versiones serial y OpenMP) para solo mostrar la salida necesaria Recompila y ejecuta el programa –Asegurarse que no se están usando banderas de instrumentación ¿Cuál es la aceleración con respecto a la versión serial? if( percentDone % 10 == 0 && lastPercentDone < percentDone){ printf("\b\b\b\b%3d%", percentDone); lastPercentDone += 10; } if( percentDone % 10 == 0 && lastPercentDone < percentDone){ printf("\b\b\b\b%3d%", percentDone); lastPercentDone += 10; }

Intel ® Software College Copyright © 2008, Intel Corporation. All rights reserved. Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. * Other brands and names are the property of their respective owners. 49 Revisando el Rendimiento Locks y Waits – Antes y Después de cambiar a la función printf En la versión más rápida – el printf es llamado ~ 10x menos veces - lastPercentDone < percentDone / 10 Locks y Waits “self wait count” y “poor” muestran una diferencia significativa entre versiones

Intel ® Software College Copyright © 2008, Intel Corporation. All rights reserved. Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. * Other brands and names are the property of their respective owners. 50 Revisando el Rendimiento Veamos los Locks de OpenMP… void FindPrimes(int start, int end) { // start is always odd int range = end - start + 1; #pragma omp parallel for for( int i = start; i <= end; i += 2 ) { if( TestForPrime(i) ) #pragma omp critical globalPrimes[gPrimesFound++] = i; ShowProgress(i, range); } void FindPrimes(int start, int end) { // start is always odd int range = end - start + 1; #pragma omp parallel for for( int i = start; i <= end; i += 2 ) { if( TestForPrime(i) ) #pragma omp critical globalPrimes[gPrimesFound++] = i; ShowProgress(i, range); } Hay un lock en un ciclo void FindPrimes(int start, int end) { // start is always odd int range = end - start + 1; #pragma omp parallel for for( int i = start; i <= end; i += 2 ) { if( TestForPrime(i) ) globalPrimes[InterlockedIncrement(&gPrimesFound)] = i; ShowProgress(i, range); } void FindPrimes(int start, int end) { // start is always odd int range = end - start + 1; #pragma omp parallel for for( int i = start; i <= end; i += 2 ) { if( TestForPrime(i) ) globalPrimes[InterlockedIncrement(&gPrimesFound)] = i; ShowProgress(i, range); }

Intel ® Software College Copyright © 2008, Intel Corporation. All rights reserved. Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. * Other brands and names are the property of their respective owners. 51 Revisando el Rendimiento Veamos el segundo lock void ShowProgress( int val, int range ) { int percentDone; static int lastPercentDone = 0; #pragma omp critical { gProgress++; percentDone = (int)((float)gProgress/(float)range*200.0f+0.5f); } if( percentDone % 10 == 0 && lastPercentDone < percentDone / 10){ printf("\b\b\b\b%3d%", percentDone); lastPercentDone++; } void ShowProgress( int val, int range ) { int percentDone; static int lastPercentDone = 0; #pragma omp critical { gProgress++; percentDone = (int)((float)gProgress/(float)range*200.0f+0.5f); } if( percentDone % 10 == 0 && lastPercentDone < percentDone / 10){ printf("\b\b\b\b%3d%", percentDone); lastPercentDone++; } Este es un lock que está siendo llamado dentro de un ciclo void ShowProgress( int val, int range ) { long percentDone, localProgress; static int lastPercentDone = 0; localProgress = InterlockedIncrement(&gProgress); percentDone = (int)((float) localProgress /(float)range*200.0f+0.5f); if( percentDone % 10 == 0 && lastPercentDone < percentDone / 10){ printf("\b\b\b\b%3d%", percentDone); lastPercentDone++; } void ShowProgress( int val, int range ) { long percentDone, localProgress; static int lastPercentDone = 0; localProgress = InterlockedIncrement(&gProgress); percentDone = (int)((float) localProgress /(float)range*200.0f+0.5f); if( percentDone % 10 == 0 && lastPercentDone < percentDone / 10){ printf("\b\b\b\b%3d%", percentDone); lastPercentDone++; }

Intel ® Software College Copyright © 2008, Intel Corporation. All rights reserved. Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. * Other brands and names are the property of their respective owners. 52 Actividad 8 Modifica las regiones críticas de OpenMP para usar InterlockedIncrement en vez de Re-compila y ejecuta el programa ´¿Cuál es la aceleración con respecto a la versión serial?

Intel ® Software College Copyright © 2008, Intel Corporation. All rights reserved. Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. * Other brands and names are the property of their respective owners. 53 Análisis del balanceo de carga Usa el análisis de concurrencia de Parallel Amplifier Selecciona “Thread –Function -Caller Function Tree” Observa que los 4 hilos hacen cantidades de trabajo desiguales

Intel ® Software College Copyright © 2008, Intel Corporation. All rights reserved. Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. * Other brands and names are the property of their respective owners. 54 Arreglando el Desbalanceo de Carga Distribuye el trabajo de manera más uniforme void FindPrimes(int start, int end) { // start is always odd int range = end - start + 1; #pragma omp parallel for schedule(static,8) for( int i = start; i <= end; i += 2 ) { if( TestForPrime(i) ) globalPrimes[InterlockedIncrement(&gPrimesFound)] = i; ShowProgress(i, range); } void FindPrimes(int start, int end) { // start is always odd int range = end - start + 1; #pragma omp parallel for schedule(static,8) for( int i = start; i <= end; i += 2 ) { if( TestForPrime(i) ) globalPrimes[InterlockedIncrement(&gPrimesFound)] = i; ShowProgress(i, range); } 1.68X La aceleración lograda es 1.68X

Intel ® Software College Copyright © 2008, Intel Corporation. All rights reserved. Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. * Other brands and names are the property of their respective owners. 55 Modifica el código para un mejor balanceo de carga Añade la cláusula schedule (static, 8) al pragma de OpenMP parallel for Re-compila y ejecuta el programa ¿Cuál es la aceleración comparada con la versión serial? Actividad 9

Intel ® Software College Copyright © 2008, Intel Corporation. All rights reserved. Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. * Other brands and names are the property of their respective owners. 56 Análisis final de balanceo de carga 1.80X La aceleración lograda es 1.80X

Intel ® Software College Copyright © 2008, Intel Corporation. All rights reserved. Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. * Other brands and names are the property of their respective owners. 57 Análisis Comparativo Paralelizar aplicaciones requiere varias iteraciones a través del ciclo de desarrollo de software

Intel ® Software College Copyright © 2008, Intel Corporation. All rights reserved. Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. * Other brands and names are the property of their respective owners. 58 Metodología de paralelización Lo que se Cubrió Cuatro pasos del ciclo de desarrollo para escribir aplicaciones paralelas desde el código serial y las herramientas de Intel® para soportar cada paso Análisis Diseño (Introducir Hilos) Depurar para la correctud Afinar el rendimiento Las aplicaciones paralelas requieren múltiples iteraciones de diseño, depuración y afinación de rendimiento Usar las herramientas para mejorar productividad

Intel ® Software College Copyright © 2008, Intel Corporation. All rights reserved. Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. * Other brands and names are the property of their respective owners. 59