DESA ANITSMessage Passing Interface1 Présentation Par : Khalil BADDOU Mohammed Ghaouth BELKASMI...

32
DESA ANITS Message Passing Interface 1 Présentation Par : Khalil BADDOU Mohammed Ghaouth BELKASMI Mohammed SABER Mounir GRARI Said BENBOUAZA Encadrant: Dr. Abdelhaq LAKHOUAJA Message Passing Interface

Transcript of DESA ANITSMessage Passing Interface1 Présentation Par : Khalil BADDOU Mohammed Ghaouth BELKASMI...

Page 1: DESA ANITSMessage Passing Interface1 Présentation Par : Khalil BADDOU Mohammed Ghaouth BELKASMI Mohammed SABER Mounir GRARI Said BENBOUAZA Encadrant: Dr.

DESA ANITS Message Passing Interface 1

Présentation

Par : Khalil BADDOU Mohammed Ghaouth BELKASMI Mohammed SABER Mounir GRARI Said BENBOUAZA

Encadrant: Dr. Abdelhaq LAKHOUAJA

Message Passing Interface

Page 2: DESA ANITSMessage Passing Interface1 Présentation Par : Khalil BADDOU Mohammed Ghaouth BELKASMI Mohammed SABER Mounir GRARI Said BENBOUAZA Encadrant: Dr.

DESA ANITS Message Passing Interface 2

Plan

o Tour d’Horizon : Monde MPI et Structure

Communication point to point

Communication Collective

o Types de Données MPI Dérivée

Page 3: DESA ANITSMessage Passing Interface1 Présentation Par : Khalil BADDOU Mohammed Ghaouth BELKASMI Mohammed SABER Mounir GRARI Said BENBOUAZA Encadrant: Dr.

DESA ANITS Message Passing Interface 3

Monde MPI et Structure

Page 4: DESA ANITSMessage Passing Interface1 Présentation Par : Khalil BADDOU Mohammed Ghaouth BELKASMI Mohammed SABER Mounir GRARI Said BENBOUAZA Encadrant: Dr.

DESA ANITS Message Passing Interface 4

MPI Structure

o Header File :

#include ‘’mpi.h’’

o Format des Fonctions MPI :

error = MPI_Xxxx ( Parametre , …);

MPI_Xxxx ( Parametre , …);

o Initialisation MPI :

int MPI_Init(int argc , char *argv[])

//doit être le premier appel(seulement une fois)

Page 5: DESA ANITSMessage Passing Interface1 Présentation Par : Khalil BADDOU Mohammed Ghaouth BELKASMI Mohammed SABER Mounir GRARI Said BENBOUAZA Encadrant: Dr.

DESA ANITS Message Passing Interface 5

MPI Communicator

o Collection des processus réservés, qui vont communiquer entre eux.

o Plus souvent, on utilise MPI_COMM_WORLD, le communicateur par défaut.

o Définie dans MPI_Init()

Page 6: DESA ANITSMessage Passing Interface1 Présentation Par : Khalil BADDOU Mohammed Ghaouth BELKASMI Mohammed SABER Mounir GRARI Said BENBOUAZA Encadrant: Dr.

DESA ANITS Message Passing Interface 6

Propriétés

o Rank : Process ID, identifiant assigné par le système quand le processus est initialisé.

o MPI_Comm_rank(MPI_Comm comm, int *rank)

o Utilisé pour spécifier la source et la destination des messages.

o Commence à partir de zéro.

o Size : Combien de processus sont dans le communicateur?

o MPI_Comm_size(MPI_Comm comm,int *size)

Page 7: DESA ANITSMessage Passing Interface1 Présentation Par : Khalil BADDOU Mohammed Ghaouth BELKASMI Mohammed SABER Mounir GRARI Said BENBOUAZA Encadrant: Dr.

DESA ANITS Message Passing Interface 7

Quitter MPI

o int MPI_Finalize()

o doit être appelé à la fin par tous les processus

o Exemple :

#include ‘’mpi.h’’

void main(int argc, char *argv[]) { int rank,size; MPI_Init(&argc, &argv); MPI_Comm_rank(MPI_COMM_WORLD,&rank); MPI_Comm_size(MPI_COMM_WORLD,&size);

/* ... code ici ...*/

MPI_Finalize();

}

Page 8: DESA ANITSMessage Passing Interface1 Présentation Par : Khalil BADDOU Mohammed Ghaouth BELKASMI Mohammed SABER Mounir GRARI Said BENBOUAZA Encadrant: Dr.

DESA ANITS Message Passing Interface 8

Communication Point à Point

o Communication entre deux processus

o Le processus source envoie un message au processus destination

o Destination reçoit le message

o La communication est établie à travers le Communicateur.

o La source et la destination sont identifiées par leurs rangs dans le Communicateur.

Page 9: DESA ANITSMessage Passing Interface1 Présentation Par : Khalil BADDOU Mohammed Ghaouth BELKASMI Mohammed SABER Mounir GRARI Said BENBOUAZA Encadrant: Dr.

DESA ANITS Message Passing Interface 9

Modes de communication

Mode Completion Condition

Envoie Synchronisé (Synchronous send)

Only completes when the receive has completed

Buffered send Always completes (unless an error occurs), irrespective of receiver

Standard send Message sent (receive state unknown)

Ready send Always completes (unless an error occurs), irrespective of whether the receive has completed

Receive Completes when a message has arrived

Page 10: DESA ANITSMessage Passing Interface1 Présentation Par : Khalil BADDOU Mohammed Ghaouth BELKASMI Mohammed SABER Mounir GRARI Said BENBOUAZA Encadrant: Dr.

DESA ANITS Message Passing Interface 10

Routine

MODE MPI CALL

Standard send MPI_SEND

Synchronous send MPI_SSEND

Buffered send MPI_BSEND

Ready send MPI_RSEND

Receive MPI_RECV

o Envoie de Message :

int MPI_Ssend(void *buf,int count,MPI_Datatype datatype, int dest,int tag,MPI_Comm comm)

Page 11: DESA ANITSMessage Passing Interface1 Présentation Par : Khalil BADDOU Mohammed Ghaouth BELKASMI Mohammed SABER Mounir GRARI Said BENBOUAZA Encadrant: Dr.

DESA ANITS Message Passing Interface 11

Arguments

Buf starting address of the data to be sent

Count number of elements to be sent

Datatype MPI datatype of each element

Dest rank of destination process

Tag message marker (set by user)

Comm MPI communicator of processors involved

MPI_Ssend(data,500,MPI_FLOAT,6,33,MPI_COMM_WORLD);

Page 12: DESA ANITSMessage Passing Interface1 Présentation Par : Khalil BADDOU Mohammed Ghaouth BELKASMI Mohammed SABER Mounir GRARI Said BENBOUAZA Encadrant: Dr.

DESA ANITS Message Passing Interface 12

Communication Valide !o Sender must specify a valid destination rank

o Receiver must specify a valid source rank

o The communicator must be the same

o Tags must match

o Receiver's buffer must be large enough

De plus:o To receive from any source -- MPI_ANY_SOURCE

o To receive with any tag -- MPI_ANY_TAG

o Actual source and tag are returned in the receiver's status parameter.

Page 13: DESA ANITSMessage Passing Interface1 Présentation Par : Khalil BADDOU Mohammed Ghaouth BELKASMI Mohammed SABER Mounir GRARI Said BENBOUAZA Encadrant: Dr.

DESA ANITS Message Passing Interface 13

Message Order

o Les messages ne doublent pas l'un l'autre

o Process 0 envoie deux messages; Process 2 post deux receives qu’égal les 2 messages

l'ordre est conservé

Page 14: DESA ANITSMessage Passing Interface1 Présentation Par : Khalil BADDOU Mohammed Ghaouth BELKASMI Mohammed SABER Mounir GRARI Said BENBOUAZA Encadrant: Dr.

DESA ANITS Message Passing Interface 14

Exemple

----------------------------

P: 0 Got data from processor 1

P: 0 Got 100 elements

P: 0 value[5]=5.000000

Page 15: DESA ANITSMessage Passing Interface1 Présentation Par : Khalil BADDOU Mohammed Ghaouth BELKASMI Mohammed SABER Mounir GRARI Said BENBOUAZA Encadrant: Dr.

DESA ANITS Message Passing Interface 15

Communication Collective

Page 16: DESA ANITSMessage Passing Interface1 Présentation Par : Khalil BADDOU Mohammed Ghaouth BELKASMI Mohammed SABER Mounir GRARI Said BENBOUAZA Encadrant: Dr.

DESA ANITS Message Passing Interface 16

Définition

Communication entre un groupe de processus

Appelé par tous les processus dans le communicateur

Exemples: Barrier synchronization

Broadcast, scatter, gather, etc. (Data Distribution) Global sum, global maximum, etc. (Collective Operations)

Broadcast : (One-to-all communication) les même données sont envoyés de root process aux autres dans le communicateur

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

Page 17: DESA ANITSMessage Passing Interface1 Présentation Par : Khalil BADDOU Mohammed Ghaouth BELKASMI Mohammed SABER Mounir GRARI Said BENBOUAZA Encadrant: Dr.

DESA ANITS Message Passing Interface 17

Exemple

Page 18: DESA ANITSMessage Passing Interface1 Présentation Par : Khalil BADDOU Mohammed Ghaouth BELKASMI Mohammed SABER Mounir GRARI Said BENBOUAZA Encadrant: Dr.

DESA ANITS Message Passing Interface 18

MPI Data TypeMPI Datatype C datatype

MPI_CHAR signed char

MPI_SHORT signed short int

MPI_INT signed int

MPI_LONG signed long int

MPI_UNSIGNED_CHAR unsigned char

MPI_UNSIGNED_SHORT unsigned short int

MPI_UNSIGNED unsigned int

MPI_UNSIGNED_LONG unsigned long int

MPI_FLOAT float

MPI_DOUBLE double

MPI_LONG_DOUBLE long double

MPI_BYTE  

MPI_PACKED  

Page 19: DESA ANITSMessage Passing Interface1 Présentation Par : Khalil BADDOU Mohammed Ghaouth BELKASMI Mohammed SABER Mounir GRARI Said BENBOUAZA Encadrant: Dr.

DESA ANITS Message Passing Interface 19

Derived Data Type

Page 20: DESA ANITSMessage Passing Interface1 Présentation Par : Khalil BADDOU Mohammed Ghaouth BELKASMI Mohammed SABER Mounir GRARI Said BENBOUAZA Encadrant: Dr.

DESA ANITS Message Passing Interface 20

Procédure Dans les communications, les données échangées sont typées : MPI_INT, MPI_FLOAT,MPI_DOUBLE, etc.

On peut créer des structures de données plus complexes à l’aide de sous-programmes tels que:

MPI_Type_contiguous, MPI_Type_vector, MPI_Type_ struct MPI_Type_indexed, MPI_Type_hvector, MPI_Type_hindexed

chaque fois que l’on crée un type de données, il faut le valider à l’aide dusous-programme MPI_TYPE_COMMIT().

Si on souhaite réutiliser le même type, on doit le libérer avec le sous-programme MPI_TYPE_FREE().

MPI_Type_extent : sert à déterminer la taille (in bytes) du Data Type MPI_Type_extent (MPI_Datatype datatype, int* extent).

Page 21: DESA ANITSMessage Passing Interface1 Présentation Par : Khalil BADDOU Mohammed Ghaouth BELKASMI Mohammed SABER Mounir GRARI Said BENBOUAZA Encadrant: Dr.

DESA ANITS Message Passing Interface 21

Types contigus

• MPI_TYPE_CONTIGUOUS() crée une structure de données à partir d’un ensemble homogène de type prédéfini de données contiguës en mémoire.

int MPI_Type_contiguous (int count, MPI_Datatype oldtype, MPI_Datatype *newtype )

Page 22: DESA ANITSMessage Passing Interface1 Présentation Par : Khalil BADDOU Mohammed Ghaouth BELKASMI Mohammed SABER Mounir GRARI Said BENBOUAZA Encadrant: Dr.

DESA ANITS Message Passing Interface 22

Exemple

----------------------------

P:1 received coords are (15,23,6)

Page 23: DESA ANITSMessage Passing Interface1 Présentation Par : Khalil BADDOU Mohammed Ghaouth BELKASMI Mohammed SABER Mounir GRARI Said BENBOUAZA Encadrant: Dr.

DESA ANITS Message Passing Interface 23

MPI_TYPE_VECTOR() crée une structure de données à partir d’un ensemble homogène de type prédéfini de données distantes d’un pas constant en mémoire.Le pas est donné en nombre d’éléments.

Types Vector (avec un pas constant)

MPI_TYPE_VECTOR (6,1,5, MPI_FLOAT ,nouveau_type,code)

Synopsisint MPI_Type_vector( int count, int blocklen, int stride, MPI_Datatype

old_type, MPI_Datatype *newtype )

Page 24: DESA ANITSMessage Passing Interface1 Présentation Par : Khalil BADDOU Mohammed Ghaouth BELKASMI Mohammed SABER Mounir GRARI Said BENBOUAZA Encadrant: Dr.

DESA ANITS Message Passing Interface 24

Types HVECTOR (avec un pas constant)

MPI_TYPE_HVECTOR() crée une structure de données à partir d’un ensemble homogène de type prédéfini de données distantes d’un pas constant en mémoire.

Le pas est donné en nombre d’octets. Cette instruction est utile lorsque le type générique n’est plus un type de

base (MPI_INT, MPI_FLOAT,...) mais un type plus complexe construit à l’aide des sous-programmes MPI vus précédemment.

Le pas ne peut plus alors être exprimé en nombre d’éléments du type générique.

Synopsisint MPI_Type_hvector( int count, int blocklen, MPI_Aint stride, MPI_Datatype old_type,

MPI_Datatype *newtype ) Input Parameters

count number of blocks (nonnegative integer) blocklength number of elements in each block (nonnegative integer) stride number of bytes between start of each block (integer) old_type old datatype (handle)

Page 25: DESA ANITSMessage Passing Interface1 Présentation Par : Khalil BADDOU Mohammed Ghaouth BELKASMI Mohammed SABER Mounir GRARI Said BENBOUAZA Encadrant: Dr.

DESA ANITS Message Passing Interface 25

Types INDEXED (homogènes à pas variable)

MPI_TYPE_INDEXED() permet de créer une structure de données composée d’une séquence de blocs contenant un nombre variable d’éléments et séparés par un pas variable en mémoire. Ce dernier est exprimé en éléments.

Synopsisint MPI_Type_indexed( int count, int blocklens[], int indices[], MPI_Datatype

old_type, MPI_Datatype *newtype ) Input Parameterscount number of blocks -- also number of entries in indices and blocklens blocklens number of elements in each block (array of nonnegative integers) indices displacement of each block in multiples of old_type (array of integers) old_type old datatype (handle)

Page 26: DESA ANITSMessage Passing Interface1 Présentation Par : Khalil BADDOU Mohammed Ghaouth BELKASMI Mohammed SABER Mounir GRARI Said BENBOUAZA Encadrant: Dr.

DESA ANITS Message Passing Interface 26

Types HINDEXED (homogènes à pas variable)

MPI_TYPE_HINDEXED() a la même fonctionnalité que MPI_TYPE_INDEXED() sauf que le pas séparant deux blocs de données est exprimé en octets.Cette instruction est utile lorsque le type générique n’est pas un type de base MPI (MPI_INT, MPI_FLOAT, ...) mais un type plus complexe construit avec lessous-programmes MPI vus précédemment. On ne peut exprimer alors le pas ennombre d’éléments du type générique d’où le recours à MPI_TYPE_HINDEXED(). Attention à la portabilité avec MPI TYPE HINDEXED() !

Synopsisint MPI_Type_hindexed( int count, int blocklens[], MPI_Aint indices[], MPI_Datatype old_type, MPI_Datatype *newtype ) Input Parameterscount number of blocks -- also number of entries in indices and blocklens blocklens number of elements in each block (array of nonnegative integers) indices byte displacement of each block (array of MPI_Aint) old_type old datatype (handle)

Page 27: DESA ANITSMessage Passing Interface1 Présentation Par : Khalil BADDOU Mohammed Ghaouth BELKASMI Mohammed SABER Mounir GRARI Said BENBOUAZA Encadrant: Dr.

DESA ANITS Message Passing Interface 27

Types INDEXED

Page 28: DESA ANITSMessage Passing Interface1 Présentation Par : Khalil BADDOU Mohammed Ghaouth BELKASMI Mohammed SABER Mounir GRARI Said BENBOUAZA Encadrant: Dr.

DESA ANITS Message Passing Interface 28

Types HINDEXED

Page 29: DESA ANITSMessage Passing Interface1 Présentation Par : Khalil BADDOU Mohammed Ghaouth BELKASMI Mohammed SABER Mounir GRARI Said BENBOUAZA Encadrant: Dr.

DESA ANITS Message Passing Interface 29

Types STRUCT (hétérogènes)

Le sous-programme MPI_TYPE_STRUCT() est le constructeur de types le plus général. Il a les mêmes fonctionnalités que MPI_TYPE_INDEXED() mais permet en plus la réplication de blocs de données de types différents. Les paramètres de MPI_TYPE_STRUCT() sont les mêmes que ceux deMPI_TYPE_INDEXED() avec en plus :•le champ anciens types est maintenant un vecteur de types de données MPI ;•compte tenu de l’hétérogénéité des données et de leur alignement en mémoire,le calcul du déplacement entre deux éléments repose sur la différence de leurs adresses.MPI, via MPI_ADDRESS(), fournit un sous-programme portable qui permet de retourner l’adresse d’une variable.

Page 30: DESA ANITSMessage Passing Interface1 Présentation Par : Khalil BADDOU Mohammed Ghaouth BELKASMI Mohammed SABER Mounir GRARI Said BENBOUAZA Encadrant: Dr.

DESA ANITS Message Passing Interface 30

Page 31: DESA ANITSMessage Passing Interface1 Présentation Par : Khalil BADDOU Mohammed Ghaouth BELKASMI Mohammed SABER Mounir GRARI Said BENBOUAZA Encadrant: Dr.

DESA ANITS Message Passing Interface 31

Page 32: DESA ANITSMessage Passing Interface1 Présentation Par : Khalil BADDOU Mohammed Ghaouth BELKASMI Mohammed SABER Mounir GRARI Said BENBOUAZA Encadrant: Dr.

DESA ANITS Message Passing Interface 32

Exemple

P:1 my a is 6 3.140000 0.000000 1.000000 2.000000 3.000002