1 rogramowanie równoległe i rozproszone - INZ3774 wykład - 3 ECTS, laboratorium 3 ECTS Wykładowca: Jan Kwiatkowski, pokój 201/15, D-2 COUNICATION For questions, email to jan.kwiatkowski@pwr.edu.pl with 'Subject=your name. ake sure to email from an account I can reply to. All course information will be available at https://www.ii.pwr.edu.pl/~kwiatkowski/ 1 1 ZASADY ZALICZANIA WYKŁADU Na wykładzie odbędzie się jedno kolokwium oraz dwie kartkówki Obecność na kolokwium oraz kartkówkach jest obowiązkowa, nie będzie organizowane specjalne kolokwium dodatkowe, ani kartkówki, w szczególnych przypadkach każda nieobecność będzie rozpatrywana indywidualnie Na kolokwium będzie można zdobyć 80 punktów Łącznie z kartkówek będzie można zdobyć 20 punktów W ciągu semestru będzie można zdobyć 100 punktów. Ocena końcowa będzie ustalana według poniższej skali: 2 60 punktów (60%) dostateczny 68 punktów (68) dostateczny plus 75 punktów (75%) - dobry 85 punktów (83%) dobry plus 90 punktów (90%) bardzo dobry 2 ZASADY ZALICZANIA WYKŁADU Ocenę celującą otrzymają osoby, które zdobędą największą ilość punktów (liczba ocen celujących będzie zależeć od średniej całej grupy. Dla osób, które nie uzyskają zaliczenia w podstawowym terminie odbędzie się kolokwium poprawkowe. Dla osób piszących kolokwium poprawkowe ocena końcowa będzie ustalana w następujący sposób: ocena końcowa wyrażona w procentach otrzymana w terminie podstawowym * 0,2 plus punkty zdobyte na kolokwium poprawkowym (na kolokwium poprawkowym będzie można zdobyć 64 punkty), a następnie według skali jak poprzednio. 3 3 age 1
2 Wprowadzenie System rozproszony jest kolekcją niezależnych, autonomicznych komputerów, które dla użytkownika prezentują się jak jeden komputer. ożna wyróżnić dwa aspekty tej definicji: sprzętowy komputery są autonomiczne użytkownika dla użytkownika system sprawia wrażenie jakby pracował na jednym komputerze. 4 4 Klasyfikacja Architektur Równoległych ze względu na mechanizm sterowania - SID - ID ze względu na organizacje przestrzeni adresowej - architektura message-passing - architektura ze współdzielona pamięcią - UA - NUA Ze względu na charakter sieci połączeniowej - statyczne - dynamiczne 5 5 Architektura ze współdzieloną pamięcią Sieć połączeniowa Sieć połączeniowa UA NUA 6 6 age 2
3 Typowa architektura message-passing Sieć ołączeniowa...... - rocesor - amięć 7 7 Dynamiczne sieci połączeniowe System z przełącznicą krzyżową Architektura szynowa Wielostanowa sieć połączeń 8 8 System z przełącznicą krzyżową 0 1 2 3 0 0 1 2 3 4 Element przełączający p-1 9 9 age 3
4 Architektura Szynowa amięć Główna Szyna rocesor rocesor rocesor 10 10 Wielostanowa sieć połączeń rocesory 0 1 Banki amięci 0 1 Stan 1 Stan 2 Stan n p-1 b-1 11 11 Sieć Omega rzełączenie proste rzełączenie krzyżowe 000 001 010 011 100 101 110 111 000 001 010 011 100 101 110 111 12 12 age 4
Koszt Wydajność 5 rzykład blokowania w sieci Omega 000 001 010 011 100 101 110 111 000 001 010 011 100 101 110 111 13 13 Koszt & Wydajność przełącznica wielostanowa szyna przełącznica wielostanowa szyna Liczba procesorów Liczba procesorów 14 14 Sieć pełna Sieci Statyczne Sieć typu gwiazda Sieć typu magistrala Sieć typu Ring Sieć typu esh krata (2D, 3D, z zapętleniami) Sieć typu Hypercube (Hiperkostka) 15 15 age 5
6 Sieci Statyczne Siec pełna Sieć typu gwiazda Sieć typu magistrala Sieć typu ring Dwu-wymiarowa siec typu esh Dwu wymiarowa sieć esh z zapętleniami 16 16 Sieci Statyczne Trzy wymiarowa sieć typu esh (krata) rocesor Element przełączający 17 Sieć typu drzewo binarne 17 Sieć Hypercube (hiperkostka) 0 00 10 000 100 010 110 0-D hypercube 1 01 11 101 001 011 111 1-D hypercube 2-D hypercube 3-D hypercube 0000 0100 0110 1100 0010 1000 1010 1110 0101 0111 1101 1111 0001 0011 1001 1011 4-D hypercube 18 18 age 6
7 essage passing parallel programming paradigm several instances of the sequential paradigm are considered together separate workers or processes interact by exchanging information emory rocessor communication network 19 19 essage assing Interface I extended message-passing model for parallel computers, clusters and heterogeneous networks not a language or compiler specification not a specific implementation or product support send/receive primitives communicating with other workers in-order data transfer without data loss several point-to-point and collective communications I supports the development of parallel libraries I does not make any restrictive assumptions about the underlying hardware architecture 20 20 essage assing Interface I I is very large (125 functions) - I s extensive functionality requires many functions I is very small and simple (6 functions) - many parallel programs can be written with just 6 basic functions I_Init() I_Finalize() I_Comm_rank() I_Comm_size() I_Send() I_Recv() 21 21 age 7
8 Two main functions Initializing I every I program must call this routine once, before any other I routines I_Init(&argc, &argv); Clean-up of I every I program must call this routine when all communications have completed I_Finalize(); 22 22 Communicator How do you identify different processes? an I process can query a communicator for information about the group a communicator returns in rank of the calling process I_Comm_rank(I_CO_WORLD, &rank); How many processes are contained within a communicator? a communicator returns the # of processes in the communicator I_Comm_size(I_CO_WORLD, &size); 23 23 #include mpi.h #include <stdio.h> An example int main(int argc, char** argv) { int rank, size; I_Init(&argc, &argv); I_Comm_rank(I_CO_WORLD, &rank); I_Comm_size(I_CO_WORLD, &size); printf( Hello, world! I m %d of %d\n, rank, size); I_Finalize(); return 0; } 24 24 age 8
9 Communicator Communicator I processes can only communicate if they share a communicator I_CO_WORLD - predefined default communicator in I_Init()call 25 25 Sending essages communicator 0 1 3 source 4 5 dest 2 communication between only 2 processes source process sends message to destination process destination process is identified by its rank in the communicator 26 26 I types essage an array of elements of a particular I datatype I datatype basic I datatype - I_(UNSIGNED_)CHAR : signed(unsigned) char - I_(UNSIGNED_)SHORT : signed(unsigned) short int - I_(UNSIGNED_)INT : signed(unsigned) int - I_(UNSIGNED_) LONG : signed(unsigned) long int - I_FLOAT : float - I_DOUBLE : double 27 27 age 9
10 Send essage I_Send(void* buf, int count, I_Datatype datatype, int dest, int tag, I_CO_WORLD); /* (IN) buf : address of the data to be sent */ /* (IN) count : # of elements of the I Datatype */ /* (IN) dest : destination process for the message (rank of the destination process) */ /* (IN) tag : marker distinguishes used message type */ 28 28 Receive essage I_Recv(void *buf, int count, I_Datatype datatype, int source, /* I_ANY_SOURCE */ int tag, /* I_ANY_TAG */ I_CO_WORLD, I_Status *status); /* (IN) buf : address where the data should be placed*/ /* (IN) count : # of elements of the I Datatype */ /* (IN) source : rank of the source of the message */ /* (IN) tag : receives a message having this tag*/ /* (OUT) status : some information to be used at later */ 29 29 age 10