procesamiento paralelo - introducción a mpi procesamiento paralelo introducción a mpi javier...

Post on 21-Jul-2020

18 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Procesamiento ParaleloIntroducción a MPI

Javier Iparraguirre

Universidad Tecnológica Nacional, Facultad Regional Bahía Blanca11 de Abril 461, Bahía Blanca, Argentina

jiparraguirre@frbb.utn.edu.arhttp://www.frbb.utn.edu.ar/hpc/

8 de junio de 2016

¿Que es MPI?

Generalidades

• MPI = Message Passing Interface• MPI es una de las APIs más antiguas• Muy usada y portable• Demanda poco desde el punto de vista del hardware• Paralelización explícita

Modelo de programación

Historia

• 1994: MPI-1.0• 1998: MPI-2.0• 2012: MPI-3.0 fue aprobado como estándar

Modos de funcionamiento

Modos de funcionamiento

• Asincrónico• Comportamiento no-determinístico

• Sincronización suelta• Hay sincronización para realizar intercambio• Es viable una secuencia lógica

• SPMD Single Program Multiple Data• El mismo programa corre en todos los nodos• Simple de escalar• Puede haber sincronización suelta o completamente

sincrónico

Bloqueo sin buffer

Bloqueo con buffer

Sin bloqueo sin buffer

Cuadro de protocolos

Programando

Hola Mundo!

# inc lude < s t d i o . h># inc lude " mpi . h "

i n t main ( argc , argv )i n t argc ;char ∗∗argv ;{

i n t rank , s ize ;MPI_ In i t ( &argc , &argv ) ;MPI_Comm_size ( MPI_COMM_WORLD, &s ize ) ;MPI_Comm_rank ( MPI_COMM_WORLD, &rank ) ;p r i n t f ( " He l lo wor ld from process %d of %d \ n " ,

rank , s ize ) ;MPI_Final ize ( ) ;r e t u r n 0 ;

}

Salida

Hel lo wor ld from process 0 of 4He l lo wor ld from process 2 of 4He l lo wor ld from process 3 of 4He l lo wor ld from process 1 of 4

Funciones

• 125 funciones• 6 son las mas usadas

Comunicaciones MPI

Tipos de datos

Ejemplos

Ejemplo 1

# inc lude < s t d i o . h># inc lude " mpi . h "

i n t main ( argc , argv )i n t argc ;char ∗∗argv ;{

i n t rank , s ize ;MPI_ In i t ( &argc , &argv ) ;MPI_Comm_size ( MPI_COMM_WORLD, &s ize ) ;MPI_Comm_rank ( MPI_COMM_WORLD, &rank ) ;p r i n t f ( " He l lo wor ld from process %d of %d \ n " ,

rank , s ize ) ;MPI_Final ize ( ) ;r e t u r n 0 ;

}

Salida ejemplo 1

% mpicc −o he l l owo r l d he l l owo r l d . c% mpirun −np 4 he l l owo r l dHe l lo wor ld from process 0 of 4He l lo wor ld from process 3 of 4He l lo wor ld from process 1 of 4He l lo wor ld from process 2 of 4%

Ejemplo 2

# inc lude < s t d i o . h># inc lude " mpi . h "

i n t main ( argc , argv )i n t argc ;char ∗∗argv ;{

i n t rank , value ;MPI_ In i t ( &argc , &argv ) ;

MPI_Comm_rank ( MPI_COMM_WORLD, &rank ) ;do {

i f ( rank == 0)scanf ( " %d " , &value ) ;

MPI_Bcast ( &value , 1 , MPI_INT , 0 , MPI_COMM_WORLD ) ;

p r i n t f ( " Process %d got %d \ n " , rank , value ) ;} wh i le ( value >= 0 ) ;

MPI_Final ize ( ) ;r e t u r n 0 ;

}

Salida ejemplo 2

% mpicc −o bcast bcast . c% mpirun −np 4 bcast10Process 0 got 1022Process 0 got 22−1Process 0 got −1Process 1 got 10Process 1 got 22Process 1 got −1Process 2 got 10Process 2 got 22Process 2 got −1Process 3 got 10Process 3 got 22Process 3 got −1

Ejemplo 3

# inc lude < s t d i o . h># inc lude " mpi . h "

i n t main ( argc , argv )i n t argc ;char ∗∗argv ;{

i n t rank , value , s ize ;MPI_Status s ta tus ;

MPI_ In i t ( &argc , &argv ) ;

MPI_Comm_rank ( MPI_COMM_WORLD, &rank ) ;MPI_Comm_size ( MPI_COMM_WORLD, &s ize ) ;do {

i f ( rank == 0) {scanf ( " %d " , &value ) ;MPI_Send ( &value , 1 , MPI_INT , rank + 1 , 0 , MPI_COMM_WORLD ) ;

}e lse {

MPI_Recv ( &value , 1 , MPI_INT , rank − 1 , 0 , MPI_COMM_WORLD,&s ta tus ) ;

i f ( rank < s ize − 1)MPI_Send ( &value , 1 , MPI_INT , rank + 1 , 0 , MPI_COMM_WORLD ) ;

}p r i n t f ( " Process %d got %d \ n " , rank , value ) ;

} wh i le ( value >= 0 ) ;

MPI_Final ize ( ) ;r e t u r n 0 ;

}

Salida ejemplo 3

% mpicc −o r i n g r i n g . c% mpirun −np 4 r i n g10Process 0 got 1022Process 0 got 22−1Process 0 got −1Process 3 got 10Process 3 got 22Process 3 got −1Process 2 got 10Process 2 got 22Process 2 got −1Process 1 got 10Process 1 got 22Process 1 got −1%

Instalando en máquina personal

OpenMPI en Ubuntu

aptitude install openmpi-bin openmpi-doc libopenmpi-dev

Compilando

mpicc −o b i n a r i o 01−example . c

Ejecutando

mpirun −np 8 b i n a r i o

Ejecutando en un cluster

Cluster remoto

• Se dispone de un cluster remoto.• Se define la lista de nodos en un archivo (my_hostfile)

Corriendo remoto: lista archivos

compile . shmain . cmy_hos t f i l erun . sh

Corriendo remoto: fuente

# inc lude <mpi . h># inc lude < s t d i o . h>i n t main ( i n t argc , char ∗argv [ ] ) {

i n t myrank , s ize ;MPI_ In i t (& argc , &argv ) ;MPI_Comm_rank (MPI_COMM_WORLD, &myrank ) ;MPI_Comm_size (MPI_COMM_WORLD, &s ize ) ;p r i n t f ( " Hola desde e l proceso %d de %d \ n " ,

myrank , s ize ) ;MPI_Final ize ( ) ;r e t u r n 0 ;

}

Corriendo remoto: compilando

mpicc −o b i n a r i o main . c

Corriendo remoto: nodos en my_hostfile

c5n04 s l o t s =2c5n05 s l o t s =2c5n06 s l o t s =2c5n07 s l o t s =2c5n08 s l o t s =2

Corriendo remoto: ejecutando

mpirun −h o s t f i l e my_hos t f i l e −np 4 b i n a r i o

Corriendo remoto: salida

Hola desde e l proceso 0 de 4Hola desde e l proceso 1 de 4Hola desde e l proceso 2 de 4Hola desde e l proceso 3 de 4

¡Muchas gracias!

¿Preguntas?jiparraguirre@frbb.utn.edu.ar

Referencias

• G. Ananth, G. Anshul, K. George, and K. Vipin.Introduction to parallel computing, 2003.

• MPI Tutorial, Blaise Barney, Lawrence Livermore NationalLaboratoryhttps://computing.llnl.gov/tutorials/mpi/

• ANL MPI Tutotial http://www.mcs.anl.gov/research/projects/mpi/tutorial/

top related