Programowanie równoległe i rozproszone - INZ3774 wykład ...kwiatkow/prog_row_roz/wyk1.pdf ·...
Transcript of Programowanie równoległe i rozproszone - INZ3774 wykład ...kwiatkow/prog_row_roz/wyk1.pdf ·...
1
Programowanie równoległe i rozproszone - INZ3774 wykład - 3 ECTS, laboratorium – 3 ECTS
Wykładowca: Jan Kwiatkowski, pokój 201/15, D-2 COMMUNICATION
• For questions, email to [email protected] with 'Subject=your name”. Make 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
2
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:
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
3
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
4 4
Wprowadzenie
System rozproszony jest kolekcją niezależnych, autonomicznych komputerów, które dla użytkownika prezentują się jak jeden komputer.
Moż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.
5 5
Klasyfikacja Architektur Równoległych
ze względu na mechanizm sterowania
- SIMD
- MIMD
ze względu na organizacje przestrzeni adresowej
- architektura message-passing
- architektura ze współdzielona pamięcią
- UMA
- NUMA
Ze względu na charakter sieci połączeniowej
- statyczne
- dynamiczne
6 6
Sieć
połączeniowa
P
M
P
M
P
M
Sieć
połączeniowa
P
P
P
M
M
M
UMA NUMA
Architektura ze współdzieloną pamięcią
7 7
Typowa architektura message-passing
Sieć Połączeniowa
P
M
P
M
P
M
P
M
P
M .............
.............
P - Procesor
M - Pamięć
8 8
Dynamiczne sieci połączeniowe
System z przełącznicą krzyżową
Architektura szynowa
Wielostanowa sieć połączeń
12 12
Sieć Omega
Przełączenie proste Przełączenie krzyżowe
000 001
010 011
100 101
110 111
000 001
010 011
100 101
110 111
13 13
000 001
010 011
100 101
110 111
000 001
010 011
100 101
110 111
Przykład blokowania w sieci Omega
14 14
Koszt & Wydajność
Ko
szt
Wyd
ajn
ość
Liczba procesorów Liczba procesorów
przełącznica wielostanowa
szyna
szyna
wielostanowa
przełącznica
15 15
Sieci Statyczne
Sieć pełna
Sieć typu gwiazda
Sieć typu magistrala
Sieć typu Ring
Sieć typu Mesh – krata (2D, 3D, z zapętleniami)
Sieć typu Hypercube (Hiperkostka)
16 16
Sieci Statyczne
Dwu-wymiarowa siec typu Mesh Dwu wymiarowa sieć Mesh z zapętleniami
Sieć typu magistrala Sieć typu ring
Siec pełna Sieć typu gwiazda
17 17
Sieci Statyczne
Trzy wymiarowa sieć typu Mesh (krata)
Procesor
Element
przełączający
Sieć typu drzewo binarne
18 18
0-D hypercube
1-D hypercube 2-D hypercube 3-D hypercube
0
1
00
01
10
11
010 000
001 011
100
101
110
111
0000
0001 0011
0100
0101
0110
0111
1000
1001 1011
1100
1101
1110
1111
4-D hypercube
0010 1010
Sieć Hypercube (hiperkostka)
19 19
Message passing parallel programming paradigm
several instances of the sequential paradigm are considered together
separate workers or processes
interact by exchanging information
M
P
Memory
Processor
M
P
M
P
M
P
…
communication network
20 20
Message Passing Interface – MPI
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
MPI supports the development of parallel libraries
MPI does not make any restrictive assumptions about the underlying hardware architecture
21 21
Message Passing Interface – MPI
MPI is very large (125 functions) - MPI’s extensive functionality requires many functions
MPI is very small and simple (6 functions) - many parallel programs can be written with just 6 basic functions
• MPI_Init()
• MPI_Finalize()
• MPI_Comm_rank()
• MPI_Comm_size()
• MPI_Send()
• MPI_Recv()
22 22
Two main functions
Initializing MPI
– every MPI program must call this routine once, before any other MPI routines
MPI_Init(&argc, &argv);
Clean-up of MPI
– every MPI program must call this routine when all communications have completed
MPI_Finalize();
23 23
Communicator
How do you identify different processes?
– an MPI process can query a communicator for information about the group
– a communicator returns in rank of the calling process
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
How many processes are contained within a communicator?
– a communicator returns the # of processes in the communicator
MPI_Comm_size(MPI_COMM_WORLD, &size);
24 24
An example
#include “mpi.h”
#include <stdio.h>
int 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);
printf(“Hello, world! I’m %d of %d\n”, rank, size);
MPI_Finalize();
return 0;
}
25 25
Communicator
Communicator – MPI processes can only communicate if they share a
communicator
– MPI_COMM_WORLD
- predefined default communicator in MPI_Init()call
26 26
Sending Messages
communication between only 2 processes
source process sends message to destination process
destination process is identified by its rank in the communicator
0
1
5
4
3
2 source
dest
communicator
27 27
MPI types
Message
– an array of elements of a particular MPI datatype
basic MPI datatype
- MPI_(UNSIGNED_)CHAR : signed(unsigned) char
- MPI_(UNSIGNED_)SHORT : signed(unsigned) short int
- MPI_(UNSIGNED_)INT : signed(unsigned) int
- MPI_(UNSIGNED_) LONG : signed(unsigned) long int
- MPI_FLOAT : float
- MPI_DOUBLE : double
MPI datatype
28 28
Send Message
MPI_Send(void* buf, int count, MPI_Datatype datatype, int
dest,
int tag, MPI_COMM_WORLD);
/* (IN) buf : address of the data to be sent */
/* (IN) count : # of elements of the MPI Datatype */
/* (IN) dest : destination process for the message
(rank of the destination process) */
/* (IN) tag : marker distinguishes used message type */
29 29
Receive Message
MPI_Recv(void *buf,
int count,
MPI_Datatype datatype,
int source, /* MPI_ANY_SOURCE */
int tag, /* MPI_ANY_TAG */
MPI_COMM_WORLD,
MPI_Status *status);
/* (IN) buf : address where the data should be placed*/
/* (IN) count : # of elements of the MPI 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 */