operaciones colectivas en mpi

Download Operaciones Colectivas en MPI

If you can't read please download the document

Upload: manuel-martin

Post on 16-Apr-2017

3.089 views

Category:

Documents


1 download

TRANSCRIPT

Operaciones Colectivas en MPI

Manuel Martn Salvador

[email protected]

http://draxus.org

Programacin Concurrente

I.T. Informtica de Sistemas

Granada, 16 enero 2007

Operaciones colectivas

Operaciones en las que participan todos los procesos de un comunicador

- Barreras de sincronizacin

- Broadcast (difusin)

- Gather (recoleccin)

- Scatter (distribucin)

- Operaciones de reduccin (suma, mnimo...)

- Combinaciones de todas ellas

Barrier (barerra)

int MPI_Barrier(MPI_Comm comm)

Bloquea a los procesos de un comunicador hasta que todos ellos han llegado a la barrera.

int main()

{ ...

rank = MPI_Rank();

if(rank==0){

a[0][0] = b[0][0] + c[0][0];

a[0][1] = b[0][1] + c[0][1];

}else{

a[1][0] = b[1][0] + c[1][0];

a[1][1] = b[1][1] + c[1][1];

}

MPI_Barrier(MPI_COMMWORLD);

if(MPI_Rank()==0)

//Imprimo matriz a

}

Broadcast (difusin)

int MPI_Bcast(void *buffer, int count, MPI_Datatype datatype, int root, MPI_Comm com)

Sirve para que un proceso, el raz, enve un mensaje a todos los miembros del comunicador.

Broadcast (difusin)

Ejemplo: Difusin de un vector de 100 enteros

int main(){

MPI_Comm comm;

int array[100];

int root=0;

...

MPI_Bcast(array, 100, MPI_INT, root, comm);

...

}

001021304261537

Gather (recoleccin)

int MPI_Gather(void *sendbuf, int sendcount, MPI_Datatype sendtype, void *recvbuf, int recvcount, MPI_Datatype recvtype, int root, MPI_Comm comm)

Realiza una recoleccin de datos en el proceso raz. Recopila un vector de datos, al que contribuyen todos los procesos del comunicador con la misma cantidad de datos. Almacena las contribuciones de forma consecutiva.

Gather (recoleccin)

Ejemplo: Recolectar 100 enteros de cada proceso en el proceso raz

int main(){MPI_Comm comm; int gsize,sendarray[100]; int root, myrank, *rbuf; ... MPI_Comm_rank(comm, myrank); if (myrank == root) { MPI_Comm_size(comm, &gsize); rbuf = (int *)malloc(gsize*100*sizeof(int)); } MPI_Gather(sendarray, 100, MPI_INT, rbuf, 100, MPI_INT, root, comm); ...}

Gather (recoleccin)

int MPI_Gatherv(void *sendbuf, int sendcount, MPI_Datatype sendtype, void *recvbuf, int *recvcounts, int *displs, MPI_Datatype recvtype, int root, MPI_Comm comm)

Permite almacenar los datos recogidos en forma no consecutiva y que cada proceso contribuya con bloques de datos de diferente tamao.

Ejemplo: Recolectar 100 enteros de cada proceso en el proceso raz

int main(){MPI_Comm comm; int gsize,sendarray[100]; int root, *rbuf, stride; int *displs,i,*rcounts; ...MPI_Comm_size( comm, &gsize);rbuf = (int *)malloc(gsize*stride*sizeof(int));displs = (int *)malloc(gsize*sizeof(int));rcounts = (int *)malloc(gsize*sizeof(int));for (i=0; i